 Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members
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    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
 code: x+yi

then for each point iterate through a formula, for Mandlebrot and Julia Sets it is
 code: z=z^2+c

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)

It-e-rate.

Irritate? Iternis? Intermediate? Mazer  Posted: Tue May 11, 2004 6:46 pm   Post subject: (No subject)

Where did you look?
http://www.hyperdictionary.com/search.aspx?define=iterate&sourceid=Mozilla-search Delos  Posted: Tue May 11, 2004 9:11 pm   Post subject: (No subject)

In my memory banks...apparently my vocab has...er...smalled itself. Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First         Page 1 of 1  [ 12 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: