Computer Science Canada

Chaos Game

Author:  Catalyst [ Mon Mar 31, 2003 4:54 pm ]
Post subject:  Chaos Game

an algorithm that generate fractals...

r and n change the look of it


takes a sec to load up, so be patient
code:
View.Set ("graphics:640;640,nobuttonbar")
var ptx, pty : array 1 .. 120 of int
var n : int := 4
var r : real := (6 / 10)
function distance (x1, y1, x2, y2 : real) : real
    result ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
end distance
proc drawRegPolygon (n0, a, x02, y02, C : int)
    var x, y, x12, y12 : int
    x12 := round (a * cosd ((360 / n0) * 0) + x02)
    y12 := round (a * sind ((360 / n0) * 0) + y02)
    for i : 1 .. n0
        x := round (a * cosd ((360 / n0) * i) + x02)
        y := round (a * sind ((360 / n0) * i) + y02)
        ptx (i) := round (x)
        pty (i) := round (y)
        drawline (round (x), round (y), x12, y12, C)
        x12 := round (x)
        y12 := round (y)
    end for
    drawfillpolygon (ptx, pty, n0, C)
end drawRegPolygon
drawRegPolygon (n, maxx div 3, maxx div 2, maxy div 2, 7)

var screen : array 1 .. maxx, 1 .. maxy of boolean
for x : 1 .. maxx
    for y : 1 .. maxy
        if whatdotcolor (x, y) not= 0 then
            screen (x, y) := true
        else
            screen (x, y) := false
        end if
    end for
end for
cls
var x, y, dx, dy : real
loop
    x := Rand.Int (0, maxx)
    y := Rand.Int (0, maxy)
    exit when screen (round (x), round (y)) = true
end loop
drawfillbox (0, 0, maxx, maxy, 7)
for i : 1 .. 100000
    if screen (round (x), round (y)) = true then
        drawdot (round (x), round (y), 0)
        dx := (ptx (Rand.Int (1, n)) - x) * r
        dy := (pty (Rand.Int (1, n)) - y) * r
        if (x + dx) > 1 and (x + dx) < maxx and (y + dy) > 1 and (y + dy) < maxy then
            if screen (round (x + dx), round (y + dy)) then
                x := x + dx
                y := y + dy
            end if
        end if
    end if
end for


MOD Edit: interesting... looks cool too Smile +15Bits

Author:  Blade [ Mon Mar 31, 2003 8:20 pm ]
Post subject: 

just a question catalyst, but how long have you been programming... and why have you only limited to turing? you're too good for just turing...

Author:  Catalyst [ Mon Mar 31, 2003 9:58 pm ]
Post subject: 

ive been programming since october, and am currently learning other languages (c++,java and vb)

Author:  yuethomas [ Tue Apr 01, 2003 11:47 pm ]
Post subject: 

October? Man, you're a natural.

I've been programming since grade 2 (in other words, 9 years) and I still can't make the 3d engine like you did.

(Well, I'm not into graphics, but that's beside the point)

Author:  Vicous [ Thu Apr 03, 2003 11:00 am ]
Post subject: 

wow, 3d graphics make my head hurt lol

Author:  UraniumLobster [ Wed Sep 12, 2007 9:36 am ]
Post subject:  RE:Chaos Game

I onll wish I could do half the things you guys do... haha Im completely new!

Author:  Clayton [ Wed Sep 12, 2007 3:53 pm ]
Post subject:  RE:Chaos Game

So.... old... This thread is locked


: