Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Sierpinski Triangle
Author Message
Catalyst

Posted: Thu Mar 27, 2003 9:25 pm   Post subject: Sierpinski Triangle

another fractal....

 code: View.Set ("graphics:800,600,nobuttonbar") function mid (n, n2 : real) : int     result round ((n2 + n) / 2) end mid function distance (x1, y1, x2, y2 : real) : real     result ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 end distance var count : int := 1 proc drawTri (x1, y1, x2, y2, x3, y3 : real)     var xd, yd, mx, my : array 1 .. 3 of int     var size : real     mx (1) := mid (x2, x1)     mx (2) := mid (x2, x3)     mx (3) := mid (x1, x3)     my (1) := mid (y1, y2)     my (2) := mid (y2, y3)     my (3) := mid (y1, y3)     xd (1) := round(x1)     xd (2) := round(x2)     xd (3) := round(x3)     yd (1) := round(y1)     yd (2) := round(y2)     yd (3) := round(y3)     size := distance (mx (1), my (1), mx (2), my (2))     if size <= 2 then         return     end if     drawfillpolygon (xd, yd, 3, gray)     drawfillpolygon (mx, my, 3, black)     drawTri (mx (1), my (1), mx (2), my (2), x2, y2)     drawTri (mx (3), my (3), mx (2), my (2), x3, y3)     drawTri (mx (1), my (1), mx (3), my (3), x1, y1) end drawTri drawfillbox (0, 0, maxx, maxy, 7) drawTri (50, 50, maxx div 2, maxy - 50, maxx - 50, 50)

Hey, cool I remember my teacher asking me to do something like that... but I didnt feel like it, and since my compsci class is soo relaxed, it was the end of it. +10Bits -Tony