' Chaos: start at any point, this program uses the middle of the screen (or universe. One of six ' degrees of freedom (a direction) is chosen at random (by throwing a six-sided die), and a line ' is drawn from the old point to the new point in the direction indicated by the pip on the die. ' ' The traverse distance is always a fraction of the last distance drawn; the fraction (here) uses: ' ' +- -+ ' | | ' distance <=== old_distance * | 1/2 - 1/8 - 1/32 - 1/128 - ... | ' | | ' +- -+ ' ---or--- ' +- -+ ' | 1 1 1 1 | ' distance <=== old_distance * | --- - --- - ---- - ----- - ... | ' | 2**1 2**3 2**5 2**7 | ' +- -+ ' ' (The series above has a limit of 1/3.) ' ' The six degrees of freedom: 1 6 ' ' \ / ' \ / ' \ / ' 2 <------ X ------> 5 ' / \ ' / \ ' / \ ' ' 3 4 ' ' When the amount to be moved is too small to show on the terminal screen, the chaos curve is ' starting again (from the initial point, the middle of the screen/universe). ' ' All subsequent chaos curves are superimposed on the first curve. ' ' The envelope of this chaos curve is defined as the snowflake curve. ' ' If any cursor key (one of the "arrow" keys) is pressed, program execution is halted. ' ' If any function key is pressed during execution, the random chaos curve is stopped, the screen ' cleared, and the snowflake curve is drawn by a non-random method (brute force). ' ' Once the random snowflake (chaos) curve is being drawn, the pressing of function keys 1-->9 will ' force the randomness to move in a particular direction, the direction (the degree of freedom) is ' the direction indicated by the number of times that function key is pressed for that curve point. ' That is, function key 1 is used for the first point (part of the chaos curve), function key 2 is ' used for the second point, function key 3 for the third point, etc. DEFINT A-Y ' define variables that begin with A-->Y as integers. DEFSNG Z ' define variables that begin with Z as single precision. DIM XP(16,6),YP(16,6),KY(16) ' define some (integer) arrays. MP= 16 ' set the maximum number of points (1st dimension) that can be plotted. CLS ' clear the screen for visual fidelity. SCREEN 2 ' make the screen high-res graphics. GOTO 230 ' branch around a RETURN statement that ON KEY(i) uses. 220 RETURN 230 FK= 0 ' set FK (used to indicate that a function key was pressed). FOR I=1 TO 10 ' allow the use of function keys to stop the deliberate snowflake ' curve and start drawing it randomly. KY(I)= 0 ON KEY(I) GOSUB 220 ' allow the trapping of function keys, but don't process it as yet. KEY(I) ON KEY(I) STOP NEXT I CLS ' clear the screen for visual fidelity. ZZ= 2 + TIMER ' on some PCs, a pause of at least one second prevents scrolling. 240 IF TIMER 0 THEN N0= II IF YP(II, I) <> 0 THEN N0= II NEXT I NEXT II FOR I=11 TO 14 ' quit if any cursor key is pressed. ON KEY(I) GOSUB 598 KEY(I) ON NEXT I FOR I=1 TO 10 ' If any function key is pressed during execution, the deliberate ON KEY(I) GOSUB 400 ' curve is stopped, the screen is cleared, and the snowflake curve is KEY(I) ON ' drawn by a random process (AKA, the chaos curve). NEXT I GOTO 500 400 FK= 1 ' come here when any function or cursor key is pressed, and set FK ' that is checked by the deliberate snowflake curve generator. RETURN 500 CLS ' clear the screen before starting (for visual fidelity). FOR I1=1 TO 6 ' plot the curve via non-random (deliberate calculation) points. X1= XO + XP(1, I1) Y1= YO + YP(1, I1) IF FK THEN GOTO 600 LINE (XO, YO) - (X1, Y1) FOR I2=1 TO 6 X2= X1 + XP(2,I2) Y2= Y1 + YP(2,I2) IF FK THEN GOTO 600 LINE (X1, Y1) - (X2, Y2) FOR I3=1 TO 6 X3= X2 + XP(3, I3) Y3= Y2 + YP(3, I3) IF FK THEN GOTO 600 LINE (X2, Y2) - (X3, Y3) FOR I4=1 TO 6 X4= X3 + XP(4, I4) Y4= Y3 + YP(4, I4) IF FK THEN GOTO 600 LINE (X3, Y3) - (X4, Y4) FOR I5=1 TO 6 X5= X4 + XP(5, I5) Y5= Y4 + YP(5, I5) IF FK THEN GOTO 600 LINE (X4, Y4) - (X5, Y5) NEXT I5 NEXT I4 NEXT I3 NEXT I2 NEXT I1 ZZ= 10+TIMER ' The snowflake curve is now complete. 555 IF TIMERN0 THEN GOTO 900 ' # points drawn exceeds possible? Start another chaos curve. ' start of diminishing loop to create an envelope for the chaos curve. IF KY(N) THEN R= KY(N) ELSE R= 1 + INT(RND*6) X= X + XP(N, R) ' exercise a degree of freedom (one of six). Y= Y + YP(N, R) LINE -(X, Y) ' depending on the "die", draw the next part of the chaos curve. GOTO 900 ' now, go and do another point.