|
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!
|
|
|
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).
|
|
|
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.
|
|
|
Post by StefanPendl on Aug 11, 2013 1:18:24 GMT -5
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.
|
|
|
Post by krzysztof on Aug 15, 2013 5:14:43 GMT -5
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.
|
|
|
Post by StefanPendl on Aug 16, 2013 4:02:31 GMT -5
Sorry, it should have been the Runtime Timeout
|
|
|
Post by krzysztof on Aug 16, 2013 6:18:59 GMT -5
Does not work, too. In the free version of RunBASIC, settings in the preferences are disabled. There is appropriate information: "Note: The following preferences can only be changed with the upgraded version of Run BASIC".
|
|
|
Post by StefanPendl on Aug 16, 2013 11:13:51 GMT -5
It was a correction for those who are running the registered version and are therefore able to change the setting.
|
|