Fractal Generator
Author 
Message 
s_climax

Posted: Sun May 09, 2004 4:15 pm Post subject: Fractal Generator 


Please ignore the names of the vars.
If you uncomment the last 3 drawing things it looks cooler, but I'm not sure if its still a fractal.
code: 
setscreen ("graphics:600,600")
var first_time : boolean
var a, b, c, d, e, f, g, h, i, j, t, l, x_shift, y_shift : real
var rando : real
var rand0, rand1, size : int
size := 300
a := 0
b := 0
c := 50
d := 100
e := 100
f := 0
l := 0
first_time := true
loop
%delay(1)
randint (rand0, 1, 1000)
randint (rand1, 1, 1000)
if rand0 < rand1 then
rando := rand0 / rand1
else
rando := rand1 / rand0
end if
% Begin fractal draw
if first_time = true then
a := 0
b := 0
c := size
d := size * 2
e := size * 2
f := 0
l := 0
x_shift := maxx div 2  size
y_shift := maxy div 2  size
c := 0
h := 0
first_time := false
g := 0
end if
t := ceil (3 * rando)
if t = 1 then
g := g + (a  g) / 2
h := h + (b  h) / 2
end if
if t = 2 then
g := g + (c  g) / 2
h := h + (d  h) / 2
end if
if t = 3 then
g := g + (e  g) / 2
h := h + (e  h) / 2
end if
drawdot (round (g + x_shift), round (h + y_shift), 7)
%drawdot (round (maxx  (g + x_shift)), round (maxy  (h + y_shift)), 7)
%drawdot (round ((g + x_shift)), round (maxy  (h + y_shift)), 7)
%drawdot (round (maxx  (g + x_shift)), round ((h + y_shift)), 7)
exit when hasch
end loop







Sponsor Sponsor



guruguru

Posted: Sun May 09, 2004 4:44 pm Post subject: (No subject) 


Geez, how'd you think of that? That is pretty freakin awsome. I personally like the first way but wow thats nice.






s_climax

Posted: Sun May 09, 2004 5:16 pm Post subject: (No subject) 


This one is much better. This is the mandelbrot fractal.
code:  var r, j, rmin, rmax, jmin, jmax, rinc, jinc : real
var rsq, jsq, oldr, oldj, nj, nr: real
var maxdwell : int
var finished : boolean
rmin := 2
rmax := 1.2
jmin := 1.5
jmax := 2.2
maxdwell := 50
rinc := (rmax  rmin) / 640
jinc := (jmax  jmin) / 480
j := jmin
for my : 1 .. 479
r := rmin
for mx : 1 .. 639
oldr := r
oldj := j
rsq := oldr * oldr
jsq := oldj * oldj
for dwell : 0 .. maxdwell
nr := (rsq  jsq) + r
nj := (2 * oldr * oldj) + j
rsq := nr * nr
jsq := nj * nj
if (rsq + jsq) > 4 then
drawdot (mx, my, (dwell*2)+70)
finished := true
end if
oldr := nr
oldj := nj
exit when finished = true
end for
finished:= false
r += rinc
end for
j += jinc
end for







Delos

Posted: Sun May 09, 2004 7:39 pm Post subject: (No subject) 


Now that one I like .






s_climax

Posted: Sun May 09, 2004 10:07 pm Post subject: (No subject) 


Yep the second one is MUCH better for a couple reasons. First it uses colour, second it does not just draw random dots like the other one. It also looks a lot cooler when its done.






Paul

Posted: Mon May 10, 2004 4:01 pm Post subject: (No subject) 


Can anyone explain to me what the significance of fractals and the code used to make it?






Delos

Posted: Mon May 10, 2004 6:40 pm Post subject: (No subject) 


Recursion. Big time. (Or so I'm told).
Plus, pretty pictures!






Catalyst

Posted: Mon May 10, 2004 9:32 pm Post subject: (No subject) 


to generate these fractals u treat each point on the screen as a point on the complex plane where x is the real component and y is imaginary component
in the form
then for each point iterate through a formula, for Mandlebrot and Julia Sets it is
where both z and c are complex numbers . For the Julia Set c is constant (different c values produce different images), for the Mandlebrot Set c is equal to x+yi. The initial z value for both sets is x+yi (but 0+0i also works for mandlebrot)
Each time the equation is iterated the distance from the origin is checked (the imaginary and real components are treated as x,y) if it passes a certain distance (usually 2 or 4) then it is not part of the set. If it the maximum number of iterations (cant iterate forever) is reached and the point is still inside the distance it is considered part of the set (> max # of iterations, >accuratcy of fractal)
Those pretty colors are usually derived from how many iterations it took to escape ( i.e. numIterations/maxIterations*someThing)
Fractals are very important as they provide infinite complexity with fairly simple rules and the result varies wildly depending on small changes in the intial input (Fractals are also related to chaos theory)






s_climax

Posted: Mon May 10, 2004 9:44 pm Post subject: (No subject) 


Well said.






Delos

Posted: Tue May 11, 2004 6:34 pm Post subject: (No subject) 


Iterate.
Irritate? Iternis? Intermediate?
Definition not found.
Please define this term.






Mazer





Delos

Posted: Tue May 11, 2004 9:11 pm Post subject: (No subject) 


In my memory banks...apparently my vocab has...er...smalled itself.







