0010  // Chaos demo-program
0020
0030 USE UNIGRAPHICS
0040
0050  // ********* Here is the main program ********
0060
0070 LOOP
0080   setup
0090   FOR k:=kmin TO kmax STEP (kmax-kmin)/300 DO
0100     x:=0.1
0110     clear_graph
0120     plottext(120,155,"k = "+str$(int((10000*k+0.5))/10000))
0130     FOR nr:=1 TO 50 DO
0140       x:=k*x*(1-x)
0150       plot(4*nr,150+x*50)
0160       a$:=key$
0170       IF a$<>"" THEN pause
0180       IF nr>cutoff THEN
0190         alpha:=600/(kmax-kmin)
0200         beta:=-alpha*kmin
0210         kval:=alpha*k+beta
0220         xval:=150*x
0230         plot(kval,xval)
0240       ENDIF
0250     ENDFOR nr
0260   ENDFOR k
0270
0280   pause
0290
0300 ENDLOOP
0310
0320  // ************ Here are all the user procedures ***********
0330
0340 PROC setup
0350   page
0360   PRINT AT 5,5: "CHAOTIC BEHAVIOUR OF THE LOGISTIC EQUATION"
0370   PRINT AT 7,20: " X := k X (1-X)"
0380   INPUT AT 10,10: "Minimum value for k (for instance 2): ": kmin
0390   INPUT AT 12,10: "Maximum value for k (for instance 4): ": kmax
0400   INPUT AT 14,10: "Cutoff value for iteration (for instance 20): ": cutoff
0410
0420   textscreen
0430   graphicscreen(0)
0440   clear
0450   box(0,0,639,199)
0460   box(0,150,200,199)
0470   plottext(250,175,"CHAOTIC BEHAVIOUR OF THE LOGISTIC EQUATION")
0480   plottext(275,160," X := k X (1-X)")
0490   plottext(10,130,"X")
0500   plottext(600,5,"k")
0510   plottext(10,5,str$(kmin))
0520   plottext(300,5,str$(int(100*(kmax+kmin)/2+0.5)/100))
0530   plottext(550,5,str$(kmax))
0540   moveto(4*cutoff,145);draw(0,5)
0550   plottext(4*cutoff+8,140,"cutoff")
0560 ENDPROC setup
0570
0580 PROC box(xmin,ymin,xmax,ymax)
0590   moveto(xmin,ymin);drawto(xmax,ymin)
0600   drawto(xmax,ymax);drawto(xmin,ymax)
0610   drawto(xmin,ymin)
0620 ENDPROC box
0630
0640 PROC clear_graph
0650   viewport(1,199,151,198)
0660   clear
0670   viewport(0,619,0,199)
0680 ENDPROC clear_graph
0690
0700 PROC pause
0710   WHILE key$="" DO WAIT
0720 ENDPROC pause
