RetroChallenge Day 22 – Post 9 – Using Graphics to Plot Normal Distributions and Menus

During this past week I have been learning use graphics in Kyan Pascal on the Atari 800 emulator Altirra.  A program to plot three overlapping normal distribution plots was written and it can illustrate the shift in mean or difference in spread of the plot of a normal distribution, given the mean and standard deviation of the distribution.  Also a short menu system was added to the STATS program which utilizes the “CHAIN” feature of Kyan Pascal.  These three topics will be discussed below.

From the main splash screen for STATS there are three options, Demo, Menu and Quit.

stats menu1

When M is entered on this screen the following menu is presented:

stats menu

The selections at this time are limited, but are sufficient to demonstrate how one program can call to another already compiled program.  Show below is the code that is execute when [N] is entered to run the Normal Distribution Plot  program.  The current program terminates and starts the executable named in the CHAIN procedure, ‘STATNP’ in this case.

statsmenu 3

STATNP is passed the variable MODE from the calling program.  All variables declared by the initial VAR command are available to the new executable, so long as the VAR statement matches in variable type in the called program.

So in this case the CHAR variable MODE in STATS.P is passed into the CHAR variable CH in STATSNP.P.  In the STATNP program checks to see if CH is ‘D’ for demo, if so it will provide a default set of plots, otherwise the user is prompted for means and standard deviations for three plots.


When STATSNP is selected from the menu the user will enter information for three normal plots.  In the example below, the first plot will have a mean of 0, and standard deviation of 1, the second curve has a different mean, 3, and will show as a curve of the same shape, just shifted right, and the third curve has the same mean, but a small standard deviation, and will plot as a taller, narrower curve.


Here is the resulting plots, plot one in red, plot two in green and plot 3 in white :


Plotting on the graphics screen is pretty straight forward once one gets comfortable with 0,0 being in the upper left corner.  What is not easy is trying to add labels to the plot,  and I run into issues using a graphics mode that has the split screen with graphics and text modes (I will cover that in a future post).

As for the formulas and code to produce a normal distribution plot.  The Normal Probability Density Function is used to create the curve.  From Wikipedia here is the notation and formula for calculation the Normal PDF  :



and this is translated into Pascal below and converted to integers for plotting :


Below is the code to set the graphics mode to 23, set up the background color and three foreground colors.  There is an interesting mapping from the SETCOLOR(x, command to using the color in a PLOT or other graphics routine, in that the value of the color is x+1 from the SETCOLOR call.



In my next post I will describe to issues I had with the graphics mode, trying to use a combined text and graphics mode, and in doing real number calculations once in graphics mode.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s