# MSX-BASIC Meditation of the Day

Barnsley Fern (Wikipedia)

```10 REM BARNSLEY FERN FOR MSX-BASIC
20 SCREEN 2: X=0: Y=0
30 P=RND(1)*100
40 IF P<=1 THEN NX=0: NY=0.16*Y: GOTO 80
50 IF P<=8 THEN NX=0.2*X-0.26*Y: NY=0.23*X+0.22*Y+1.6: GOTO 80
60 IF P<=15 THEN NX=-0.15*X+0.28*Y: NY=0.26*X+0.24*Y+0.44: GOTO 80
70 NX=0.85*X+0.04*Y: NY=-0.04*X+0.85*Y+1.6
80 X=NX: Y=NY
90 PSET(127+X*17,190-Y*17)
100 IF INKEY\$="" THEN 30
```

Next?

Good idea ```10 '
30 ' (pag 153; The Mathematics of Oz; Clifford A. Pickover)
40 '
50 COLOR2,1,1:SCREEN 8
60 ' Coordinates
70 OX=128:OY=106
90 R1=60:R2=R1/2:R3=R1/3
100 ' angular velocity of wheels (rad/s)
110 W1=1:W2=7*W1:W3=-17*W1
120 ' Drawing (1 ciclo)
125 PSET(OX+R1+R2+R3-1,OY),32*7
130 FOR A=0 TO 6.29 STEP .01
140 X3=R3*COS(W3*A)+R2*COS(W2*A)+R1*COS(W1*A)
150 Y3=R3*SIN(W3*A)+R2*SIN(W2*A)+R1*SIN(W1*A)
160 LINE -(X3+OX,Y3+OY),32*7
170 NEXT A
180 A\$=INPUT\$(1)
190 END```

and the last one

```10 '
20 '  FABERGE EGGS
30 ' (pag 179; Wonders of Numbers; Clifford A. Pickover)
40 '
50 KEYOFF:COLOR2,1,1:SCREEN 8
60 ' 0  < A,Z < 1
70 AR=.2:AG=.7:AB=.5
80 ZR=.3:ZG=.1:ZB=.65
90 ' 0.15 < F < .80
100 FR=.61:FG=.15:FB=.8
110 ' 0 < B < 10    y      B < M < +20
120 BR=3:BG=9:BB=5
130 MR=15:MG=10:MB=7
140 '
150 FOR J=0 TO 211:FOR I=0 TO 255
160 '
170 CR=1+.5*(SIN(AR+FR*I)+SIN(ZR+FR*J))
180 CG=1+.5*(SIN(AG+FG*I)+SIN(ZG+FG*J))
190 CB=1+.5*(SIN(AB+FB*I)+SIN(ZB+FB*J))
200 '
210 CR=INT(MR*CR) MOD BR
220 CG=INT(MG*CG) MOD BG
230 CB=INT(MB*CB) MOD BB
240 '
250 CR=CR MOD 8
260 CG=CG MOD 8
270 CB=CB MOD 4
280 '
290 CO=CG*32+CR*4+CB
300 VPOKE J*256+I,CO
310 '
320 IF INKEY\$<>"" THEN END
330 NEXT I,J
340 '
350 IF INKEY\$="" THEN GOTO 350 ELSE END```

Modify values from 60 to 130 to get new textures.

I would recommend to use a TR and KunBasic for making execution faster bye

Hopalong Attractor

```10 REM HOPALONG ATTRACTOR
20 R=RND(-TIME)
30 SCREEN 2: COLOR 15,0,0: CLS
40 A=RND(1)*100-50: B=RND(1)*100-50: C=RND(1)*100-50
50 Z=RND(1)+1:CLR=RND(1)*13+2
60 X=0: Y=0
70 XN=Y-SGN(X)*SQR(ABS(B*X-C)): YN=A-X
80 PSET(128+X*Z,96+Y*Z), CLR
90 X=XN:Y=YN
100 K\$=INKEY\$: IF K\$="" THEN 70 ELSE IF K\$=" " THEN 30
```

Space to start a new drawing. Any other key to quit. Rewards patience...

Treadmill was pretty easy to port to MSX1; just need to change SCREEN 8 to SCREEN 2 on line 50, OY=106 to OY=96 on line 70., and 32*7 to 2 at the end of lines 125 and 160. Probably won't be able to do Fabrege Eggs justice with 16 colors but I will see what I can do. Looks pretty neat on openMSX though. Speed wise, I'm getting spoiled by my homebrew MSX1-compatible running at 10MHz. Treadmill runs over 3X faster than an emulated MSX2.

This MSX-BASIC code was used to pre-calculate the 108 frames of the animated pixel-ball in ANMA's demo 'RELAX', which was released in 1992. This pixel-ball was used in 3 parts of the demo: Bouncy Bouncy, GONYOID mini-game, End Part.

```10 RESTORE 700
20 COLOR 15,1,1 :SCREEN 5:SETPAGE3,3:CLS:SETPAGE2,2:CLS:SETPAGE 1,1:CLS
30 AT=0:FOR PG=1 TO 3:FOR Y5=0 TO 128 STEP 64
40 FOR X5=0 TO 192 STEP 64
60 V=Y5+32:U=X5+32:GOSUB 160:AT=AT+1
70 NEXT X5,Y5,PG
80 SET PAGE 0,0:TL=AT
90 FOR PG=1 TO 3:FOR Y5=0 TO 128 STEP 64:FOR X5=0 TO 192 STEP 64
100 COPY(X5,Y5)-(X5+63,Y5+63),PG TO (80,64),0
110 IF TIME<2 THEN 110 ELSE TIME=0
120 TL=TL-1:IF TL<>0 THEN NEXT X5,Y5,PG
130 A\$=INKEY\$:IF A\$="" THEN 130 ELSE IF A\$=" "THEN 80
140 END
150 '
160 SET PAGE PG,PG:PI=4*ATN(1):S=22.5:D=12
170 R=31:RD=PI/180:H=.5
180 S1=SIN(A*RD):S2=SIN(B*RD):S3=SIN(C*RD)
190 C1=COS(A*RD):C2=COS(B*RD):C3=COS(C*RD)
200 '
210 ' rotatiematrix berekenen
220 AX=C2*C3:AY=-C2*S3:AZ=S2
230 BX=C1*S3+S1*S2*C3
240 BY=C1*C3-S1*S2*S3:BZ=-S1*C2
250 CX=S1*S3-C1*S2*C3
260 CY=S1*C3+C1*S2*S3:CZ=C1*C2
270 '
280 ' draw dots
290 FOR P=-90 TO 90 STEP D
300 F1=0
310 FOR L=0 TO 360  STEP S
320 GOSUB 390
330 IF XX<0 THEN  XB=INT(U+XX-H) ELSE XB=INT(U+XX+H)
340 IF ZZ<0 THEN  YB=INT(V+ZZ-H) ELSE YB=INT(V+ZZ+H)
350 PSET(XB,YB)
360 NEXT L
370 NEXT P
380 RETURN
390 '
400 ' XX,YY,ZZ berekeneeeee !
410 X=R*COS(P*RD)*COS(L*RD)
420 Y=R*COS(P*RD)*SIN(L*RD)
430 Z=R*SIN(P*RD)
440 '
450 ' (x,y,z) naar (XX,YY,ZZ) draaie
460 XX=AX*X+AY*Y+AZ*Z
470 YY=BX*X+BY*Y+BZ*Z
480 ZZ=CX*X+CY*Y+CZ*Z
490 RETURN
500 '
510 DATA 00,00,00
520 DATA 03,02,00
530 DATA 05,03,00
540 DATA 07,05,00
550 DATA 10,07,00
560 DATA 12,08,00
570 DATA 15,10,00
580 DATA 17,11,00
590 DATA 19,13,00
600 DATA 22,15,00
610 DATA 24,16,00
620 DATA 26,18,00
630 DATA 29,20,00
640 DATA 31,21,00
650 DATA 33,23,00
660 DATA 36,25,00
670 DATA 38,26,00
680 DATA 40,28,00
690 DATA 43,30,00
700 DATA 45,31,00
710 DATA 47,33,00
720 DATA 50,35,00
730 DATA 52,36,00
740 DATA 54,38,00
750 DATA 57,40,00
760 DATA 59,41,00
770 DATA 61,43,00
780 DATA 63,45,00
790 DATA 65,46,00
800 DATA 67,48,00
810 DATA 70,50,00
820 DATA 72,51,00
830 DATA 74,53,00
840 DATA 77,55,00
850 DATA 79,56,00
860 DATA 81,58,00
870 DATA 84,60,00
880 DATA 86,61,00
890 DATA 88,63,00
900 DATA 91,65,00
910 DATA 93,66,00
920 DATA 95,68,00
930 DATA 98,70,00
940 DATA 100,71,00
950 DATA 102,73,00
960 DATA 105,75,00
970 DATA 107,76,00
980 DATA 109,78,00
990 DATA 112,80,00
1000 DATA 114,81,00
1010 DATA 116,83,00
1020 DATA 118,85,00
1030 DATA 120,86,00
1040 DATA 122,88,00
1050 DATA 124,90,00
1060 DATA 122,92,00
1070 DATA 120,94,00
1080 DATA 118,95,00
1090 DATA 116,97,00
1100 DATA 114,99,00
1110 DATA 112,100,00
1120 DATA 109,102,00
1130 DATA 107,104,00
1140 DATA 105,105,00
1150 DATA 102,107,00
1160 DATA 100,109,00
1170 DATA 98,110,00
1180 DATA 95,112,00
1190 DATA 93,114,00
1200 DATA 91,115,00
1210 DATA 88,117,00
1220 DATA 86,119,00
1230 DATA 84,120,00
1240 DATA 81,122,00
1250 DATA 79,124,00
1260 DATA 77,125,00
1270 DATA 74,127,00
1280 DATA 72,129,00
1290 DATA 70,130,00
1300 DATA 67,132,00
1310 DATA 65,134,00
1320 DATA 63,135,00
1330 DATA 61,137,00
1340 DATA 59,139,00
1350 DATA 57,140,00
1360 DATA 54,142,00
1370 DATA 52,144,00
1380 DATA 50,145,00
1390 DATA 47,147,00
1400 DATA 45,149,00
1410 DATA 43,150,00
1420 DATA 40,152,00
1430 DATA 38,154,00
1440 DATA 36,155,00
1450 DATA 33,157,00
1460 DATA 31,159,00
1470 DATA 29,160,00
1480 DATA 26,162,00
1490 DATA 24,164,00
1500 DATA 22,165,00
1510 DATA 19,167,00
1520 DATA 17,169,00
1530 DATA 15,170,00
1540 DATA 12,172,00
1550 DATA 10,174,00
1560 DATA 07,175,00
1570 DATA 05,177,00
1580 DATA 03,178,00
1590 DATA 1000,0,0
```

Details:
This code first draws 36 frames of a 240-point pixel-ball (very slow on real MSX) by using PAGE 1, 2 and 3 in SCREEN 5 mode. After that use SPACE to animate the 36 frames (turn off emulator Throttle, otherwise animation is too fast). Use another key to exit. By setting the 'RESTORE' in line 10, you can choose which of the 108 frames will be drawn and animated:

```10 RESTORE 510     ' -> first 36 frames
10 RESTORE 870     ' -> middle 36 frames
10 RESTORE 1230    ' -> last 36 frames
```

The DATA lines (from line 510 onwards) can be modified to change the rotating axes.
For the demo RELAX all 108 frames were converted to sprite-data: 4 x 4 sprites (= 64 x 64 pixels). In the Bouncy Bouncy part, two of these balls are rotating and bouncing.
Cheers!