Computer Science Canada

Sierpinski's Triangle

Author:  LiamMB59 [ Sun Mar 08, 2020 8:29 pm ]
Post subject:  Sierpinski's Triangle

I'm new to Turing and have just started because of my computer science class (grade 10). I have about 2 months of experience. My assignment is to construct Sierpinski's Triangle using the chaos game, and I'm a bit overwhelmed. I understand you have an equilateral triangle, and you need to first place a random dot within the triangle. Then pick a random point of the triangle and place a dot on the midpoint between your dot and said random point. I know the basics to do this, I just don't really know where to start. How do I set boundaries for the first random point? I know it's 2020 and Turing is barely used but I'll take any help I can get. Thanks

Author:  ZetaEta [ Mon Mar 09, 2020 9:34 pm ]
Post subject:  RE:Sierpinski\'s Triangle

Any update? I have also been asked to do the same assignment. I do understand the concept but I'm a bit lost. If you ever figure this out, could you help me? Thank you

Author:  LiamMB59 [ Tue Mar 10, 2020 10:03 am ]
Post subject:  Re: Sierpinski's Triangle

This was actually much easier than I thought:

Turing:


setscreen ("graphics:1000;800")

var x, y : int
var randomVertex : int

randint (x, 0, maxx)
randint (y, 0, maxy)
drawdot (x, y, black)

loop
    randint (randomVertex, 1, 3)
    if randomVertex = 1 then
        x := (x + 0) div 2
        y := (y + 0) div 2
    else
        if randomVertex = 2 then
            x := (x + maxx) div 2
            y := (y + 0) div 2
        else
            if randomVertex = 3 then
                x := (x + maxx div 2) div 2
                y := (y + maxy) div 2
            end if
        end if
    end if
    drawdot (x, y, black)
end loop



So the first random point doesn't have to be within the triangle to work. This made things way easier. You get a random integer that decides which vertex you'll use, then use if statements to decide the midpoint for each one. Very simple and very cool graphic! Also colour customization is easy.

Author:  ZetaEta [ Tue Mar 10, 2020 7:57 pm ]
Post subject:  Re: Sierpinski's Triangle

So by using such a small range for randint to pick from (1-3), you were able to predict the 3 possibilities, which is 1,2 or 3 and created if statements based of off them. Wow, this made me look at randint from a different perspective. randint may be random, but it isn't unpredictable. Thank you so much for your help and for opening my eyes Very Happy

Author:  TokenHerbz [ Mon Apr 13, 2020 4:59 am ]
Post subject:  RE:Sierpinski\'s Triangle

never steal code, make it your own.


: