Example Mandelbrot plot

new BookmarkLockedFalling
krzysztof
New Member
*

krzysztof Avatar

Posts: 45

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 set
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
I 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:
10 REM Mandelbrot set
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
The speed is very low!
Last Edit: Aug 9, 2013 14:45:20 GMT -5 by krzysztof
krzysztof
New Member
*

krzysztof Avatar

Posts: 45

Post by krzysztof on Aug 10, 2013 1:46:12 GMT -5

This is a bit modified code that allows You to draw a larger picture of Mandelbrot set.
'Mandelbrot set
graphic #Mandelbrot, 200, 200

for i = 0 to 200
for j = 0 to 200

k = i / 80 - 1.75
m = j / 80 - 1.25

x = k
y = m

for n = 1 to 150
x1 = x * x - y * y + k
y = 2 * x * y + m
d = x1 * x1 + y * y
if d > 4 then exit for
x = x1
next n

#Mandelbrot color("black")
#Mandelbrot set(i, j)
if d > 4 then #Mandelbrot color(1.7 * n, 255 / n, 50 / n)
#Mandelbrot set(i, j)

next j
next i
render #Mandelbrot
end
Increasing the size is limited because of error message "Your program has exceeded the allowable execution time". But with the current settings of the program, You should not receive this message.
For fun, try a a different palettes of colors, for example: color(n + 105, 1.7 * n, 0) or color(1.7 * n, 1.7 * n, 0).
Last Edit: Aug 10, 2013 4:03:07 GMT -5 by krzysztof
krzysztof
New Member
*

krzysztof Avatar

Posts: 45

Post by krzysztof on Aug 10, 2013 17:47:32 GMT -5

In both programs You can enter a small improvement in the main loop. Termination of
for...to...
...
next
by the
exit for
is a little bit inelegant. This can be corrected in the very first program by placing a loop
while i <= 100 and d <= 4
...
i = i + 1
wend
It is necessary to insert
i = 1
d = 0
before this new loop! If You receive the color error when You start such modified program, change the expression
2.55 * i
to
2.5 * i
The second program for Mandelbrot set written in RunBASIC can be improved in the similar way.
Last Edit: Aug 10, 2013 18:00:09 GMT -5 by krzysztof
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
krzysztof
New Member
*

krzysztof Avatar

Posts: 45

Post by krzysztof on Aug 15, 2013 5:14:43 GMT -5

StefanPendl Avatar
krzysztof Avatar
Increasing the size is limited because of error message "Your program has exceeded the allowable execution time".


You can overcome this by increasing the session timeout limit in the preferences.


Does not work in downloadable free version of RunBASIC.
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
krzysztof
New Member
*

krzysztof Avatar

Posts: 45

Last Edit: Aug 16, 2013 6:19:18 GMT -5 by krzysztof
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM