Example Mandelbrot plot
Aug 5, 2013 4:25:28 GMT -5
Post by krzysztof on Aug 5, 2013 4:25:28 GMT -5
Hello everyone :) I am new here and it is my first post about Run BASIC. I don't want to start a new topic, so I decided to write in this one. I'd like to show You simple and short program for drawing Mandelbrot set (fractal).
'Mandelbrot setI wondered how fast it is, compared with other BASIC dialects. Similar program written in Free BASIC is very fast, but Free BASIC is compiler and differs in action. But one can compare speed of above program with other web-based BASIC dialect, for instance Quite BASIC www.quitebasic.com . Here is code for that interpreter:
graphic #Mandelbrot, 100, 100
for r1 = -2 to 2 step 0.04
for r2 = -2 to 2 step 0.04
x = 0
y = 0
for i = 1 to 100
x1 = x * x - y * y + r1
y = 2 * x * y + r2
x = x1
d = x * x + y * y
if d > 4 then exit for
next i
#Mandelbrot color("white")
#Mandelbrot set(25 * r1 + 50, 25 * r2 + 50)
if d > 4 then #Mandelbrot color(0, 255 / i, 50 / i)
#Mandelbrot set(25 * r1 + 50, 25 * r2 + 50)
next r2
next r1
render #Mandelbrot
end
10 REM Mandelbrot setThe speed is very low!
20 CLS
30 FOR R1 = -2 TO 2 STEP 0.04
40 FOR R2 = -2 TO 2 STEP 0.04
50 LET X = 0
60 LET Y = 0
70 LET J = 0
80 FOR I = 0 TO 100
90 LET X1 = X * X - Y * Y + R1
100 LET Y = 2 * X * Y + R2
110 LET X = X1
120 IF X * X + Y * Y > 4 THEN GOTO 150
130 NEXT I
140 LET J = 1
150 IF J = 0 THEN PLOT 25 * R1 + 50 , 25 * R2 + 50 , I
160 IF J = 1 THEN PLOT 25 * R1 + 50 , 25 * R2 + 50 , "BLACK"
170 NEXT R2
180 NEXT R1
190 END