FAQ  •  Register  •  Login

Fractal

Moderator: nitrofurano

<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Feb 18, 2012 7:32 pm

Fractal

Just for fun.

Incidentally, if I change the float types to fixed, it crashes. Has something gone wrong with fixed type maths?

EDIT: Updated with fixed and exit for, so if people use it here, they get the best version.

  Code:
#define width 256
#define height 192

DIM x,y as FIXED
DIM xstart,xstep,ystart,ystep as FIXED
DIM xend,yend as FIXED
DIM z,zi,newz,newzi as FIXED
DIM colour as byte
DIM iter as uInteger
DIM col as uInteger
DIM i,k as uByte
DIM j as uInteger
dim inset as uByte



xstart=-1.6
xend=0.65
ystart=-1.15
yend=-ystart
iter=24

xstep=(xend-xstart)/width
ystep=(yend-ystart)/height

'Main loop
x=xstart
y=ystart

border 0
paper 0
ink 7
CLS

for i=0 to ( height -1 )/2 +1
        for j=0 to width -1
            z=0
            zi=0
            inset=1
                for k=0 to iter
                    ';z^2=(a+bi)*(a+bi) = a^2+2abi-b^2
                    newz=(z*z)-(zi*zi)+x
                    newzi=2*z*zi+y
                    z=newz
                    zi=newzi
                   
                    if (z*z)+(zi*zi) > 4 then
                        inset=0
                        colour=k
                        exit for
                    END IF
                next k
               

                if NOT inset then
                    if colour BAND 1 THEN
                        plot j,i
                        plot j,192-i
                    END IF
                end if
                   
                x=x+xstep
         next j
               
        y=y+ystep
        x=xstart
print at 23,0;CAST(uinteger,i)*200/height;"%"
next i
                           
BEEP 1,1
PAUSE 0


(This will take a long time. Even if you push an emulator to top speed)
Last edited by britlion on Sat Apr 07, 2012 10:41 am, edited 1 time in total.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Feb 18, 2012 7:49 pm

Re: Fractal

Awesome!!! :shock:
I'll put this in the Wiki, if you don't mind, in the Examples section. :?:
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Feb 18, 2012 8:02 pm

Re: Fractal

Course you can.

(Though again - why does it seem to break with fixed, not float?)
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Feb 18, 2012 8:06 pm

Re: Fractal

Oh - I also thought I should be able to use "end for" in the place I have "goto screen". Not sure why it refuses to compile that.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Feb 18, 2012 8:07 pm

Re: Fractal

It might be a bug, or might be a matter of precision. :?:
Don't know. I know there's an integer version of Mandelbrot, BTW.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Feb 18, 2012 8:19 pm

Re: Fractal

britlion wrote:Oh - I also thought I should be able to use "end for" in the place I have "goto screen". Not sure why it refuses to compile that.

The correct syntax for that is "EXIT FOR" (this is like a Break sentence in C/C++)
<<

slenkar

Posts: 282

Joined: Sun Feb 13, 2011 3:33 am

Location: Kentucky US, used to be Birmingham UK

Post Sat Feb 18, 2012 9:53 pm

Re: Fractal

quite nice
Image
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Feb 18, 2012 9:55 pm

Re: Fractal

boriel wrote:
britlion wrote:Oh - I also thought I should be able to use "end for" in the place I have "goto screen". Not sure why it refuses to compile that.

The correct syntax for that is "EXIT FOR" (this is like a Break sentence in C/C++)



Doh! Me idiot.

Yes, that works. Much better than a goto.
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Feb 18, 2012 9:57 pm

Re: Fractal

boriel wrote:It might be a bug, or might be a matter of precision. :?:
Don't know. I know there's an integer version of Mandelbrot, BTW.



I don't think a lack of precision should cause a restart, however...

And yes. I didn't do that one :) integer would be faster.
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Feb 18, 2012 9:58 pm

Re: Fractal

slenkar wrote:quite nice


Oh slenkar! Now you've given it away :)
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Feb 18, 2012 10:01 pm

Re: Fractal

britlion wrote:
boriel wrote:It might be a bug, or might be a matter of precision. :?:
Don't know. I know there's an integer version of Mandelbrot, BTW.



I don't think a lack of precision should cause a restart, however...

And yes. I didn't do that one :) integer would be faster.

A restart???
Please send me the code. I would like to test it, please :?:
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Feb 18, 2012 10:06 pm

Re: Fractal

Same code, with "FIXED" wherever DIM had "FLOAT"

I could believe in it going out of bounds or something, but shouldn't just crash...

  Code:
#define width 256
#define height 192

DIM x,y as FIXED
DIM xstart,xstep,ystart,ystep as FIXED
DIM xend,yend as FIXED
DIM z,zi,newz,newzi as FIXED
DIM colour as byte
DIM iter as uInteger
DIM col as uInteger
DIM i,k as uByte
DIM j as uInteger
dim inset as uByte



xstart=-1.6
xend=0.65
ystart=-1.15
yend=-ystart
iter=24

xstep=(xend-xstart)/width
ystep=(yend-ystart)/height

'Main loop
x=xstart
y=ystart

border 0
paper 0
ink 7
CLS

for i=0 to ( height -1 )/2 +1
        for j=0 to width -1
            z=0
            zi=0
            inset=1
                for k=0 to iter
                    ';z^2=(a+bi)*(a+bi) = a^2+2abi-b^2
                    newz=(z*z)-(zi*zi)+x
                    newzi=2*z*zi+y
                    z=newz
                    zi=newzi
                   
                    if (z*z)+(zi*zi) > 4 then
                        inset=0
                        colour=k
                        exit for
                    END IF
                next k
               
screen:               
                if NOT inset then
                    if colour BAND 1 THEN
                        plot j,i
                        plot j,192-i
                    END IF
                end if
                   
                x=x+xstep
         next j
               
        y=y+ystep
        x=xstart
print at 23,0;CAST(uinteger,i)*200/height;"%"
next i
                           
BEEP 1,1
PAUSE 1
PAUSE 0

                   
                       
       
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Feb 25, 2012 12:40 pm

Re: Fractal

It was a bug in Fixed multiplication.
Please, download release 1.2.9s789 or newer, and tell mi if it works (it did for me!).
I don't see much improvement. :?: :?: :?:
Can you measure the time it takes to draw the fractal with fixed variables, please? There should be some performance gain.

NOTE: This release includes your MLDepacker routine (fastcalled).

NOTE2: Happy Birthday! :!: :mrgreen:
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Feb 25, 2012 9:41 pm

Re: Fractal

boriel wrote:It was a bug in Fixed multiplication.
Please, download release 1.2.9s789 or newer, and tell mi if it works (it did for me!).
I don't see much improvement. :?: :?: :?:
Can you measure the time it takes to draw the fractal with fixed variables, please? There should be some performance gain.


I added a timer function to it, and grabbed the timer before and afterwards.

Float:
s777 : 5237.6 Seconds.
s789 : 5237.9 Seconds

Fixed:
S789 : 2159.76 Seconds

I think that's a fair speed improvement, actually....

boriel wrote:NOTE: This release includes your MLDepacker routine (fastcalled).


Nice! I added that to the library - so there's a link to the packer program in there too. You might want to tweak that to note that it's in the package.
boriel wrote:NOTE2: Happy Birthday! :!: :mrgreen:


Thankee Kindly. I'm /really/ getting old now!
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Feb 25, 2012 10:11 pm

Re: Fractal

Should be able to get it faster still using the integer method - which cheats and multiplies up decimals:

DIM xl,yl as long
DIM xstartl,xstepl,ystartl,ystepl as long
DIM xendl,yendl as long
DIM zl,zil,newzl,newzil as long

#DEFINE MULTIPLIER 10000

xstartl=xstart * MULTIPLIER
xendl=xend * MULTIPLIER
ystartl=ystart * MULTIPLIER
yendl=yend * MULTIPLIER
xl = x * MULTIPLIER
yl = y * MULTIPLIER


Though I tried this to abject failure. Anyone else get anywhere?

Return to Gallery

Who is online

Users browsing this forum: No registered users and 2 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO