Author Topic: Mandelbrot in one basic line  (Read 5045 times)

0 Members and 1 Guest are viewing this topic.

Offline demoniak

  • CPC664
  • ***
  • Posts: 81
  • Country: fr
  • Liked: 65
  • Likes Given: 40
Mandelbrot in one basic line
« 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...

Offline adamioan

  • Speccy
  • *
  • Posts: 1
    • GreekFunZone
  • Liked: 0
  • Likes Given: 4
Re: Mandelbrot in one basic line
« Reply #1 on: 15:30, 06 September 11 »
Awesome    +1  8)

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1011
  • Likes Given: 926
Re: Mandelbrot in one basic line
« Reply #2 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)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1011
  • Likes Given: 926
Re: Mandelbrot in one basic line
« Reply #3 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
;)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline demoniak

  • CPC664
  • ***
  • Posts: 81
  • Country: fr
  • Liked: 65
  • Likes Given: 40
Re: Mandelbrot in one basic line
« Reply #4 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 !

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 2.921
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1091
  • Likes Given: 2304
Re: Mandelbrot in one basic line
« Reply #5 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.  :)

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 15.168
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 3007
  • Likes Given: 5334
Re: Mandelbrot in one basic line
« Reply #6 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... :)

Offline EgoTrip

  • 6128 Plus
  • ******
  • Posts: 1.051
  • Country: gl
    • http://egochip.blogspot.co.uk/
  • Liked: 677
  • Likes Given: 294
Re: Mandelbrot in one basic line
« Reply #7 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.
EgoTrip&#39;s Stuff
EgoTrip's Stuff

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.718
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 952
  • Likes Given: 1676
Re: Mandelbrot in one basic line
« Reply #8 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.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1011
  • Likes Given: 926
Re: Mandelbrot in one basic line
« Reply #9 on: 12:26, 26 September 11 »
So, how is the competition going? ;)
Who is coding such an algorithm which works as fast as possible?
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline MaV

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.097
  • Country: at
  • Ius summum saepe summa est malitia.
  • Liked: 388
  • Likes Given: 822
Re: Mandelbrot in one basic line
« Reply #10 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 &amp;ndash; a fast Mandelbrot set calculation by MaV | The Amstrad CPC
MaVdelbrot &ndash; a fast Mandelbrot set calculation by MaV | The Amstrad CPC

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

Enjoy!
« Last Edit: 23:15, 13 September 12 by MaV »
Black Mesa Transit Announcement System:
"Work safe, work smart. Your future depends on it."

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1011
  • Likes Given: 926
Re: Mandelbrot in one basic line
« Reply #11 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 :)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline MaV

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.097
  • Country: at
  • Ius summum saepe summa est malitia.
  • Liked: 388
  • Likes Given: 822
Re: Mandelbrot in one basic line
« Reply #12 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.
Black Mesa Transit Announcement System:
"Work safe, work smart. Your future depends on it."

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 15.168
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 3007
  • Likes Given: 5334
Re: Mandelbrot in one basic line
« Reply #13 on: 13:08, 14 September 12 »
Oh this is lovely. Green, especially... and it's fast indeed!!

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.718
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 952
  • Likes Given: 1676
Re: Mandelbrot in one basic line
« Reply #14 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.  ???
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline SuTeKH/Epyteor

  • 6128 Plus
  • ******
  • Posts: 1.331
  • Country: 00
  • Semi-professional acceptance testing engineer!
    • Epyteor titles on CPC-Power
  • Liked: 1254
  • Likes Given: 1997
Re: Mandelbrot in one basic line
« Reply #15 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.
« Last Edit: 17:50, 14 October 12 by tastefulmrship »

Offline Nicolas Lecoq

  • CPC464
  • **
  • Posts: 9
  • Country: fr
  • CPC 6128 + CPC 464
  • Liked: 7
  • Likes Given: 29
Re: Mandelbrot in one basic line
« Reply #16 on: 21:57, 07 July 19 »
Very nice :o

Offline demoniak

  • CPC664
  • ***
  • Posts: 81
  • Country: fr
  • Liked: 65
  • Likes Given: 40
Re: Mandelbrot in one basic line
« Reply #17 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...

Offline Nicolas Lecoq

  • CPC464
  • **
  • Posts: 9
  • Country: fr
  • CPC 6128 + CPC 464
  • Liked: 7
  • Likes Given: 29
Re: Mandelbrot in one basic line
« Reply #18 on: 13:06, 27 July 19 »
Faster but I prefer the first one with beautiful colors. :P :P

Offline HAL 6128

  • 464 Plus
  • *****
  • Posts: 491
  • Country: de
    • index.php?action=treasury
  • Liked: 243
  • Likes Given: 1213
Re: Mandelbrot in one basic line
« Reply #19 on: 23:58, 27 July 19 »
I like the ASCII art.
...proudly supported Schnaps Demo and Pentomino, NQ-Music-Disc with GFX

Offline billamu

  • CPC464
  • **
  • Posts: 9
  • Country: nz
  • Liked: 13
  • Likes Given: 4
Re: Mandelbrot in one basic line
« Reply #20 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

« Last Edit: 06:52, 01 August 19 by billamu »

Offline Urusergi

  • CPC6128
  • ****
  • Posts: 172
  • Country: es
  • Liked: 253
  • Likes Given: 1202
Re: Mandelbrot in one basic line
« Reply #21 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)

Offline TotO

  • 6128 Plus
  • ******
  • Posts: 3.463
  • Country: fr
    • ?area=showdonations;u=4
  • Liked: 2636
  • Likes Given: 1565
Re: Mandelbrot in one basic line
« Reply #22 on: 12:14, 28 September 19 »
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)