Wednesday, May 25, 2022

Lorentz Attractor in BASIC

In case you couldn't tell, I was on a BASIC kick recently.  Another port I posted to facebook.

"This BASIC code represents the Lorentz attractor for Commodore 64."

Here is a port of one I got from a Commodore group. The original C64 code is there but with REM in front of the lines that changed. Delete lines 1-4, lines 1000 on, and change the POKE to 65495 to run this on a CoCo 1/2.



0 POKE65497,0:PCLEAR4:PMODE 4,1:PCLS:SCREEN 1,0
1 AD=VAL("&HFA0C")
2 FORI=0 TO 64:READ B$:A=VAL("&H"+B$)
3 POKE AD+I,A:NEXT
REM $BB00 JMP $FA0C
4 POKE VAL("&HBB02"),VAL("&H7E"):POKE VAL("&HBB03"),VAL("&HFA"):POKE VAL("&HBB04"),VAL("&H0C")
REM 10 rem skydda basic
REM 20 poke 56,32:poke 52,32
REM 30 rem pixelgrafik
REM 40 clr:poke 53272,25
REM 50 poke 53265,peek(53265) or 32
REM 60 print "{clear}"
REM 70 rem rensa befintliga pixlar
REM 80 poke 88,0:poke 89,63
REM 90 poke 113,64:poke 114,31
REM 100 poke 12,1:sys 45760
110 rem lorenz
120 x=5
130 y=5
140 z=5
150 t=0
REM 160 s=1/200
160 s=1/192
170 d=10
180 r=28
190 b=8/3
200 t=t+0.1
210 dx=d*(y-x)
220 x1=x+dx*s
230 dy=(r*x-y)-x*z
240 y1=y+dy*s
250 dz=x*y-b*z
260 z1=z+dz*s
270 x=x1
280 y=y1
290 z=z1
300 rem position
REM 310 xx=150+4*x:yy=20+3*z
310 xx=120+4*x:yy=10+3*z
320 rem rita pixel
REM 330 row=int(yy/8):ch=int(xx/8)
REM 340 line=yy and 7:bit=7-(xx and 7)
REM 350 byte=8192+row*320+ch*8+line
REM 360 poke byte,peek(byte) or 2^bit
330 PSET(XX,YY)
370 rem upprepa
380 if t<1000 goto 200
1000 DATA 32,79,E7,60,96,60,3D,ED,63,E6,60,96,5E,3D,ED,61,E6,60,96,5D
1001 DATA 3D,ED,65,E6,60,96,5F,3D,E3,62,ED,62,EC,65,E9,61,89,00,ED,60
1002 DATA EC,63,D3,15,97,16,D7,63,EC,61,D9,14,99,13,DD,14,A6,60,89,00
1003 DATA 97,13,32,67,39

 

No comments:

Post a Comment