Mandelbrot Set in BASIC

General discussions related to the Altair 8800 Clone

Mandelbrot Set in BASIC

Postby gmh » April 16th, 2015, 2:24 pm

I was just checking out a retro computer page on G+ and a guy had posted about using BASIC to build a Mandelbrot set on a BBC Computer emulator.

I checked out the link to the original site http://rosettacode.org/wiki/Mandelbrot_set and they had a DEC BASIC-PLUS/PDP-11 version. So I fired up my Clone and converted the program to Microsoft MBASIC.

I have to say it doesn't look as nice as the BBC version, but hey it works!

Code: Select all
10 X1=59:Y1=21
20 I1=-1:I2=1:R1=-2:R2=1
30 S1=(R2-R1)/X1:S2=(I2-I1)/Y1
40 FOR Y=0 TO Y1
50 I3=I1+S2*Y
60 FOR X=0 TO X1
70 R3=R1+S1*X:Z1=R3:Z2=I3
80 FOR N=0 TO 30
90 A=Z1*Z1:B=Z2*Z2
100 IF A+B>4 THEN GOTO 130
110 Z2=2*Z1*Z2+I3:Z1=A-B+R3
120 NEXT N
130 IF N=31 THEN PRINT " "; ELSE PRINT CHR$(62-N);
140 NEXT X
150 PRINT
160 NEXT Y
170 END
gmh
 
Posts: 38
Joined: August 12th, 2014, 5:19 am
Location: Melbourne, AU

Re: Mandelbrot Set in BASIC

Postby gio74 » April 16th, 2015, 3:01 pm

great catch!
gio74
 
Posts: 54
Joined: January 30th, 2015, 2:43 pm

Re: Mandelbrot Set in BASIC

Postby gio74 » April 20th, 2015, 4:09 am

it works great!!!

I'd love to port it to assembly and run it as a Prom
yummmm
gio74
 
Posts: 54
Joined: January 30th, 2015, 2:43 pm

Re: Mandelbrot Set in BASIC

Postby gio74 » April 21st, 2015, 6:09 am

Here is the Mandelbrot set ported to .COM file for CP/M users
(RUNS FASTER THAN BASIC)
I've upgraded the size of the plot, now is 79 * 29
Attachments
Mandel.zip
(825 Bytes) Downloaded 252 times
gio74
 
Posts: 54
Joined: January 30th, 2015, 2:43 pm

Re: Mandelbrot Set in BASIC

Postby gmh » April 21st, 2015, 10:12 pm

Well I've done something completely stupid, 131x59 in BASIC.

Code: Select all
10 WIDTH 132
20 X1=131:Y1=59
30 I1=-1:I2=1:R1=-2:R2=1
40 S1=(R2-R1)/X1:S2=(I2-I1)/Y1
50 FOR Y=0 TO Y1
60 I3=I1+S2*Y
70 FOR X=0 TO X1
80 R3=R1+S1*X:Z1=R3:Z2=I3
90 FOR N=0 TO 30
100 A=Z1*Z1:B=Z2*Z2
110 IF A+B>4 THEN GOTO 140
120 Z2=2*Z1*Z2+I3:Z1=A-B+R3
130 NEXT N
140 IF N=31 THEN PRINT " "; ELSE PRINT CHR$(62-N);
150 NEXT X
160 PRINT
170 NEXT Y
180 END

For those who really don't want to wait for this to finish (over an hour), here's a spoiler: https://i.imgur.com/PTgJxh7.png
gmh
 
Posts: 38
Joined: August 12th, 2014, 5:19 am
Location: Melbourne, AU

Re: Mandelbrot Set in BASIC

Postby gio74 » April 22nd, 2015, 6:10 am

Well done!

I might upgrade the com file to this size. it would speed up a good deal.
Any idea of what parameter to tweak to change the zoom?
gio74
 
Posts: 54
Joined: January 30th, 2015, 2:43 pm

Re: Mandelbrot Set in BASIC

Postby gmh » April 22nd, 2015, 2:23 pm

I think the best size is 131x41 (based on the larger terminal size of 132x43), and this is the size I've actually settled on. I only did the massive 1 because I was sitting at work, on a conference call and bored out of my mind.

You really need to change everything to get a good zoomed image. I'd suggest you check out the link I posted in my original post, as it has links to the mathematics of fractals. All of these tweaks are the reason I've actually been using BASIC not Assembler, plus to be perfectly honest I like how long they take in BASIC. Something to watch drawing in (slowly) on a remote terminal at work, while I'm configuring an Oracle server, or Cisco router.

Next step for me is to see how long it takes to generate a Julia Set.
gmh
 
Posts: 38
Joined: August 12th, 2014, 5:19 am
Location: Melbourne, AU

Re: Mandelbrot Set in BASIC

Postby jibanes » July 1st, 2015, 11:29 pm

How about mining bitcoins? :)
jibanes
 
Posts: 50
Joined: February 8th, 2014, 1:07 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest