Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: Hezad on July 12, 2009

Title: [Snippet] Playing with fractal rules
Post by: Hezad on July 12, 2009
Hey :D I wanted to play a bit with fractals and It brought me to this. The basis rule is nearly the mandelbrot one but I added some trigonometric functions. Here's the result :) It's not fast, sorry for that, just wanted to share the thing :)

Code: [Select]
Screenres 640,480,32,2

Dim as Uinteger ptr Scrptr = Screenptr

Dim as single zx,zy,cx,cy,norm,oldzx,offsetX,t,offsetY,g,b
Dim as integer nbloops

cx = 1.23
cy = 0.44

Do
t+=.1
offsetX = cos(t)
offsetY = sin(t)
cx = t

screenlock : cls

For i as integer = -320 to 319
for j as integer = -240 to 239

zx = i*.01 + offsetX
zy = j*.01 + offsetY

nbloops = 0

do
oldzx = zx
zx = cos(zx*zx + 2*zx*zy + cx)
zy = sin(zy*zy + 2*zy*oldzx + cy)

nbloops+=1

if nbloops>2 then exit do

Loop

norm = (zx*zx+zy*zy)
g = norm
b = norm

if norm>1 then norm=1
if g>1 then g=1
if b>1 then b=1

norm*=255
g*=255
b*=255

ScrPtr[i+320+(j+240)*640] = rgb(norm,g,b)

next
next

screenunlock : sleep 1,1
Loop until multikey(&h01)

Title: Re: [Snippet] Playing with fractal rules
Post by: benny! on July 12, 2009
Screenie looks nice. Having a quick look at the
source - it seems that this baby is in motion, too.

Any chance of an compiled version ?
Title: Re: [Snippet] Playing with fractal rules
Post by: Shockwave on July 12, 2009
Here's an exe.

It's an interesting display :) I'd like to see an optimised version using tinyptc.
I cant recall ever seeing this pattern before.
Title: Re: [Snippet] Playing with fractal rules
Post by: benny! on July 13, 2009
Thanks for the exe, Shocky.

It looks indeed very interesting and stylish!
Title: Re: [Snippet] Playing with fractal rules
Post by: Hezad on July 13, 2009
Thanks a lot mates :D

Sorry for not posting any exe, i'm under debian and I can't get the cross-compiling to work :S

Shockie > Hum.. I never used tiny ptc (but that's a good occasion to learn :P I'll try it in my next code :) )
Title: Re: [Snippet] Playing with fractal rules
Post by: Shockwave on July 13, 2009
tinyptc_ext++ is the best version to use mate.
You will find it in this freebasic board :D