forked from picocomputer/ehbasic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mandelbrot.txt
62 lines (53 loc) · 2.37 KB
/
Mandelbrot.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
1 REM Mandelbrot ported from Applesoft BASIC. Ref: Rosettacode.org
2 REM Addresses for our four new functions from mapfile:
3 LET HGR = $E98B : REM F_HGR->init_bitmap_graphics()
4 LET HPLOT = $E993 : REM F_HPLOT->draw_pixel()
5 LET TEXTMODE = $E9CF : REM F_TEXT->init_console_text()
6 LET HOME = $E9D7 : REM F_CLS->cls()
7 LET CLS = HOME : REM cls()
8 LET WHITE = 15 : REM white ON EHBASIC HPLOT.
9 REM EhBasic Colorrange 8(grey) 9(red) - 14(cyan) 15(wht); A2 ran 0(blk) - 7(wht2)
10 REM call HGR with $FF for 320x240x4bpp(4:3); $00 for 320x180x8bpp(16:9)
11 CALL HGR,$FF
20 XC = -0.5 : REM CENTER COORD X
30 YC = 0 : REM " " Y
40 S = 2 : REM SCALE
45 IT = 20 : REM ITERATIONS
50 XR = S * (280 / 192): REM TOTAL RANGE OF X
60 YR = S : REM " " " Y
70 X0 = XC - (XR/2) : REM MIN VALUE OF X
80 X1 = XC + (XR/2) : REM MAX " " X
90 Y0 = YC - (YR/2) : REM MIN " " Y
100 Y1 = YC + (YR/2) : REM MAX " " Y
110 XM = XR / 279 : REM SCALING FACTOR FOR X
120 YM = YR / 191 : REM " " " Y
130 FOR YI = 0 TO 3 : REM INTERLEAVE
140 REM FOR YS = 0+YI TO 188+YI STEP 4 : REM Y SCREEN COORDINATE
141 REM FOR YS = 0+YI TO 176+YI STEP 4 : REM EhBASIC y-limit hack $00
142 FOR YS = 0+YI TO 236+YI STEP 4 : REM EhBASIC y-limit hack $FF
143 REM HCOLOR=3 : REM HPLOT 0,YS TO 279,YS : REM On A2: Clear-to-white 1st
144 REM On pico6502, unnecessary to 1st clear each line to white
145 REM FOR XJ = 0 TO 255 : CALL HPLOT,XJ,YS,WHITE : NEXT XJ
150 REM FOR XS = 0 TO 278 STEP 2 : REM X SCREEN COORDINATE
151 FOR XS = 0 TO 254 STEP 2 : REM EhBASIC x-limit hack
170 X = XS * XM + X0 : REM TRANSL SCREEN TO TRUE X
180 Y = YS * YM + Y0 : REM TRANSL SCREEN TO TRUE Y
190 ZX = 0
200 ZY = 0
210 XX = 0
220 YY = 0
230 FOR I = 0 TO IT
240 ZY = 2 * ZX * ZY + Y
250 ZX = XX - YY + X
260 XX = ZX * ZX
270 YY = ZY * ZY
280 C = IT-I
290 IF XX+YY >= 4 GOTO 301
300 NEXT I
301 IF C >= 8 THEN C = C - 8 : GOTO 301
309 IF C=0 THEN LET C=-8 :REM EhBASIC hack, force grey->black
310 REM HCOLOR = C : REM HPLOT XS, YS TO XS+1, YS
311 CALL HPLOT,XS,YS,C+8 : CALL HPLOT,XS+1,YS,C+8
320 NEXT XS
330 NEXT YS
340 NEXT YI