CPCWiki forum

General Category => Programming => Topic started by: demoniak on 12:37, 06 September 11

Title: Mandelbrot in one basic line
Post by: demoniak on 12:37, 06 September 11
Just for fun ;-)

Code: [Select]
10 MODE 0:e=-1.3:FOR y%=0 TO 199:d=-2.4:FOR x%=0 TO 159:z=0:i=0:a%=0:WHILE a%<15 AND (z*z+i*i)<4:s=(z*z)-(i*i)+d:r=(2*i*z)+e:z=s:i=r:a%=a%+1:WEND:PLOT x%*4,y%*2,a%:d=d+0.0215:NEXT:e=e+0.013:NEXT
Be carefull, It's very slow...
Title: Re: Mandelbrot in one basic line
Post by: adamioan on 15:30, 06 September 11
Awesome    +1  8)
Title: Re: Mandelbrot in one basic line
Post by: Devilmarkus on 15:46, 06 September 11
Cool thing! Tried to add a palette set for green screen but then I got a "Line too long" :(

Anyway:
This is how it looks on green screen (Color routine: 1 FOR t=0 to 15:ink t,26-t*1.6:NEXT)
Title: Re: Mandelbrot in one basic line
Post by: Devilmarkus on 15:58, 06 September 11
Well got it! For GT65 Greenies:
Code: [Select]
10 FOR t=0 TO 15:INK t,25-t*1.6:NEXT:MODE 0:e=-1.3:FOR y=0 TO 199:d=-2.4:FOR x=0 TO 159:z=0:i=0:a=0:WHILE a<15 AND (z*z+i*i)<4:s=z*z-i*i+d:r=2*i*z+e:z=s:i=r:a=a+1:WEND:PLOT x*4,y*2,a:d=d+0.0215:NEXT:e=e+0.013:NEXT
;)
Title: Re: Mandelbrot in one basic line
Post by: demoniak on 16:28, 06 September 11
Well got it! For GT65 Greenies:
Code: [Select]
10 FOR t=0 TO 15:INK t,25-t*1.6:NEXT:MODE 0:e=-1.3:FOR y=0 TO 199:d=-2.4:FOR x=0 TO 159:z=0:i=0:a=0:WHILE a<15 AND (z*z+i*i)<4:s=z*z-i*i+d:r=2*i*z+e:z=s:i=r:a=a+1:WEND:PLOT x*4,y*2,a:d=d+0.0215:NEXT:e=e+0.013:NEXT
 ;)

congratulations !
Title: Re: Mandelbrot in one basic line
Post by: mr_lou on 17:04, 06 September 11
I remember typing in a little BASIC program as a kid, to draw Mandelbrott, and then wait for several days before it was done.
Each day I'd come home from school and check how far it had gotten.

How about having a contest? Coders try to get the CPC to draw the Mandelbrott the fastest. Would like to see that.  :)
Title: Re: Mandelbrot in one basic line
Post by: Gryzor on 18:53, 08 September 11
Very impressive. Haven't dabbled in fractals for a while, so it was interesting to try and decipher the equations... :)
Title: Re: Mandelbrot in one basic line
Post by: EgoTrip on 19:52, 09 September 11
This is really good, it reminds me of an old ACU magazine where they had a competition for one-liners. Maybe there should be a new contest on here just for fun, to see what can be done in one line of code.
Title: Re: Mandelbrot in one basic line
Post by: AMSDOS on 01:34, 10 September 11
Nice one.


The example I have on my website which I ported from 16bit Turbo Pascal is slow while it's compiling the 4 Data files for the Colour points (all 64k of Information), so once them files (which I should have on my site) have been compiled, the thing takes about 9 minutes to draw, not bad for something done in a High Level Language, though I understand some Assembly versions have taken a bit of time to complete as well. I only real way I can think of for improving that time (besides saving it as a Screen and loading it in) is to store the colour data as a series of PEN Masks then poking those masks to screen, which is only approx 16Kb of Info.
Title: Re: Mandelbrot in one basic line
Post by: Devilmarkus on 12:26, 26 September 11
So, how is the competition going? ;)
Who is coding such an algorithm which works as fast as possible?
Title: Re: Mandelbrot in one basic line
Post by: MaV on 22:35, 13 September 12
Well, then. No competition entry as such and not in Basic, but an attempt to write a fast mandelbrot plotter in MODE 0 (normal and overscan screen).

It calcs the normal small mandelbrot in 24 seconds and the overscan in about 32-ish seconds. The zooms take a bit more.

MaVdelbrot &ndash; a fast Mandelbrot set calculation by MaV | The Amstrad CPC (http://www.octoate.de/wp/2012/09/13/mavdelbrot-a-fast-mandelbrot-set-calculation-by-mav/)

Download-Link:
http://www.octoate.de/wp/download/demos/mavdelbrot.zip (http://www.octoate.de/wp/download/demos/mavdelbrot.zip)

Enjoy!
Title: Re: Mandelbrot in one basic line
Post by: Devilmarkus on 23:58, 13 September 12
Nice prod!
Now I want a rectangle,too, to select zoom area ;)
Move rectangle across the painted mandelbrot and press space to render selected region :)
Title: Re: Mandelbrot in one basic line
Post by: MaV on 10:18, 14 September 12
Now I want a rectangle,too, to select zoom area ;)
Move rectangle across the painted mandelbrot and press space to render selected region :)
That's not likely to happen, at least not in the near future.

You could zoom a little and select regions, but the program is designed for speed.  As always it's a trade off of accuracy vs. speed; if you'd zoom into the plane a bit deeper the calculations would become inaccurate.

Besides, I've worked on it on and off in the last months, and would like to go on and do other stuff.
Title: Re: Mandelbrot in one basic line
Post by: Gryzor on 13:08, 14 September 12
Oh this is lovely. Green, especially... and it's fast indeed!!
Title: Re: Mandelbrot in one basic line
Post by: AMSDOS on 13:50, 14 September 12
Wonder how this would go, if this were done in mode 2 and using SCR FILL BOX on a 80x25 txt display. The colour numbers could represent the encoded pens which are being gathered to show a pattern. Unsure if it would work or if it's a waste of time.  ???
Title: Re: Mandelbrot in one basic line
Post by: SuTeKH/Epyteor on 14:30, 14 September 12
How about having a contest? Coders try to get the CPC to draw the Mandelbrott the fastest. Would like to see that.  :)
Well, then. No competition entry as such and not in Basic, but an attempt to write a fast mandelbrot plotter in MODE 0 (normal and overscan screen).

Well, I have to say that the MaVdelbrot calculation is a lot faster today than it was when I last saw it a few weeks back.
You'd have to use a look-up table to get any faster, methinks!

EDIT:
Wonder how this would go, if this were done in mode 2 and using SCR FILL BOX on a 80x25 txt display. The colour numbers could represent the encoded pens which are being gathered to show a pattern. Unsure if it would work or if it's a waste of time.  ???
If you calculate every 8th x and y coordinate (or smaller, depending on speed), then there's no reason why you can't iterate further down past 16 (ie find more than 16 stipple patterns) and create a blocky mandelbrot image. From there, of course, you can zoom into the fractal, making a real-time mandelbrot zoomer on CPC in MODE 2. And, because the code wouldn't be that large, you could steal 32k for overscan; then there's no reason why the image couldn't be 96x34 characters. It would be interesting to see how fast a CPC could calculate the zoomer.

The same concept could be used for any of the other MODEs, you'd just need to program in a stipple on odd PENs, but it would look best on MODEs 1 or 2.
Title: Re: Mandelbrot in one basic line
Post by: Nicolas Lecoq on 21:57, 07 July 19
Very nice :o
Title: Re: Mandelbrot in one basic line
Post by: demoniak on 19:25, 26 July 19
Here is a 2 lines version, in mode 2 :
Code: [Select]
10 MODE 2:BORDER 0:INK 0,0:INK 1,26:PAPER 0:PEN 1:a$=" .:-;!/>)=&IH%*#":y=-13:WHILE y<12:k=1:FOR x=0 TO 79:PRINT MID$(a$,k,1);:i=0:r=0:k=0
20 j=r*r-i*i-2+x/25:i=2*r*i+y/10:r=j:k=k+1:IF j*j+i*i<11 AND k<16 THEN 20 ELSE NEXT:y=y+1:WEND:CALL &BB18
It takes about 7 minutes to finish...
Title: Re: Mandelbrot in one basic line
Post by: Nicolas Lecoq on 13:06, 27 July 19
Faster but I prefer the first one with beautiful colors. :P :P
Title: Re: Mandelbrot in one basic line
Post by: HAL 6128 on 23:58, 27 July 19
I like the ASCII art.
Title: Re: Mandelbrot in one basic line
Post by: billamu on 06:11, 01 August 19
Faster but I prefer the first one with beautiful colors. :P :P
You could cheat with CALL &BD1C: (ie. Print in Mode 2 but display in Mode 0)

Code: [Select]
10 MODE 2:CALL &BD1C:BORDER 0:INK 0,0:INK 1,26:PAPER 0:PEN 1:a$=" .:-;!/>)=&IH%*#":y=-13:WHILE y<12:k=1:FOR x=0 TO 79:PRINT MID$(a$,k,1);:i=0:r=0:k=0
20 j=r*r-i*i-2+x/25:i=2*r*i+y/10:r=j:k=k+1:IF j*j+i*i<11 AND k<16 THEN 20 ELSE NEXT:y=y+1:WEND:CALL &BB18

Title: Re: Mandelbrot in one basic line
Post by: Urusergi on 01:17, 09 August 19
Just for fun ;-)

Code: [Select]
10 MODE 0:e=-1.3:FOR y%=0 TO 199:d=-2.4:FOR x%=0 TO 159:z=0:i=0:a%=0:WHILE a%<15 AND (z*z+i*i)<4:s=(z*z)-(i*i)+d:r=(2*i*z)+e:z=s:i=r:a%=a%+1:WEND:PLOT x%*4,y%*2,a%:d=d+0.0215:NEXT:e=e+0.013:NEXT
Be carefull, It's very slow...

A slight improvement:
Code: [Select]
10 MODE 0:e=-1.3:FOR y%=0 TO 398 STEP 2:d=-2.4:FOR x%=0 TO 636 STEP 4:z=0:i=z:c=z:b=z:a%=0:WHILE 15>a% AND 4>c+b:s=d+c-b:r=e+2*i*z:z=s:i=r:a%=a%+1:c=z*z:b=i*i:WEND:PLOT x%,y%,a%:d=d+0.0215:NEXT:e=e+0.013:NEXT
~77 minutes vs ~66 minutes  8)
Title: Re: Mandelbrot in one basic line
Post by: TotO on 12:14, 28 September 19
Less than 0.1s here: https://benchmarko.github.io/CPCBasic/cpcbasic.html (https://benchmarko.github.io/CPCBasic/cpcbasic.html)  ;D