YUDA RETHANKS as usual is the 1/3 at stage 2 obligatory ? try 1/4 !!! m Yehuda Katz wrote: > Hello there, > > The Sierpinski Triangle was discussed, sometime ago, on this list. > Here's a "square" version of it. > There are several ways to do it, this one does it chaotically by > Logo's RND function. > > The algorithm is as follows: > > Find the locations of the four corners of a square and the locations > of the centers of its sides. These are 8 points. > Place yourself anywhere on the screen. > > 1. Select at random one of the 8 points. > 2. From your position move one third of the distance towards that > selected point. > 3. Mark this point, and position yourself on it. > 4. Return to 1. > > Here's a possible Logo program to perform the above algorithm: > > ====================================== > to main ; Gasket > cs ht > select rndpt 0 > end > > to select :pnt :dummy > setpc last :pnt > pu setxy x y pd > if :dummy>5[fd 0] ; draw a dot > select rndpt 1+:dummy > end > > to rndpt > op pick[ > [-243 243 4][0 243 6][243 243 4] > [-243 0 6] [243 0 6] > [-243 -243 4][0 -243 6][243 -243 4]] > end > > to x > op(xcor + item 1 :pnt)/3 > end > > to y > op(ycor + item 2 :pnt)/3 > end > ====================================== > > A few remarks here might be in place: > > The gasket is drawn around the center of the screen. > If you look closely at the attached drawing you might see how precise > it is, down to the last pixel. It's because the chosen length of the > half side of the square - 243 - is a power of 3 (3^5). > If the drawing is too big to fit on your screen, replace each 243 with > 81 (=3^4). > > The RNDPT procedure was arranged and spaced so that the sub-list > containing the coordinates of each of the 8 point can be recognized > easily. You will see it better in a non-proportional font, like > COURIER. > The last member in each sub-list is the dot color. > > The first few points fluctuate a little bit until settling down, so I > made the program ignore the first 5 (DUMMY) points. > > I didn't include in my program a stop rule, you must stop it by brute > force. > > Let the program run for a few minutes, and see how, like a miracle, > the "gasket" builds up. > > The program was written in UCBLogo, but will run, I think, on any > other flavor of Logo. > > Enjoy... > > [[Yehuda]] > > > > > ------------------------------------------------------------------------------------------------------------- > > [Image] --------------------------------------------------------------- Please post messages to the Logo forum to logo-l@gsn.org. Mail questions about the list administration to logofdn@gsn.org. To unsubscribe send unsubscribe logo-l to majordomo@gsn.org.
Global SchoolNet Foundation -
Linking Kids Around the World!
Copyright GSN - All Rights Reserved
- Comments
& Questions
Visit GSN's
Global
Schoolhouse for more exciting learning resources!
Search our Site
-
Home