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

Posted: 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

ZetaEta

Posted: 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
LiamMB59

Posted: 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.
ZetaEta

Posted: 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
TokenHerbz

Posted: Mon Apr 13, 2020 4:59 am   Post subject: RE:Sierpinski\'s Triangle

never steal code, make it your own.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 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: