1/17/12 Fractal Fractal refers to objects which appear to be geometrically complex with certain characteris6cs They have a rough or complicated shape They are self- similar at different scales Fractals In other words, they appear just as complex when you zoom in and enlarge your view of them Self- similar means the small parts look like the whole object scaled down Some other commonly cited characteris6cs (there is no clear agreement that these are required to call something a fractal): A brief introduc6on detailed structure appears at arbitrarily small scale It is not easily described with ordinary geometry It is easily described using recursive (self- referen6al) terms It is described mathema6cally with frac6onal dimensions (the concept of a Hausdorff dimension) ~ frac6onal dimension is claimed to be the source of the term fractal in many sources Some objects seem to be easier to describe and understand as fractals than using conven6onal concepts of structure. 87 88 By Jon Sullivan [Public domain], via Wikimedia Commons By Jon Sullivan [Public domain], via Wikimedia Commons 89 By AndreasHeinemann at Zeppelinzentrum Karlsruhe, Germany h`p:// www.rad- zep.de (h`p://www.rad- zep.de) [GFDL (www.gnu.org/copylec/ fdl.html) or CC- BY- SA- 3.0 (www.crea6vecommons.org/licenses/by- sa/3.0/)], via Wikimedia Commons 90 L- Systems By Mark Charles Langdon, Waterloo, Ontario, Canada (Photographed by: Mark Charles Langdon) [CC- BY- 3.0 (www.crea6vecommons.org/licenses/by/ 3.0)], via Wikimedia Commons We will be using Lindenmeyer Systems (L- Systems) to explore some introductory ideas in Fractals Aris%d Lindenmayer (November 17, 1925 October 30, 1989) introduced L- Systems as a way of modelling biological growth L- Systems use groups of symbols (strings) and replacement rules which can be interpreted as (or given meaning as) geometric objects Before we can look at L- Systems, we need to look at Turtle Graphics the graphics used to interpret symbols in L- Systems We ll return to L- Systems once we ve looked at Turtle Graphics 91 92 1
Readings & Socware READINGS and SOFTWARE on turtle graphics BFOIT introduc6on h`p://www.bfoit.org/itp/defcmds.html Read sec6ons Commanding a Turtle Pseudocode Adding New Commands Itera6on Addi6onal readings: Seymore Papert popularized the use of turtle graphics for pedegogical purposes in his book MIndStorms h`p://books.google.ca/books? id=hhieagufghwc&printsec=frontcover&source=gbs_ge_summary_r&cad=0#v=onepage&q&f=false The TG applet should run off your webpage if you have JAVA installed. The page for BFOIT turtle graphics is h`p://www.bfoit.org/intro_to_programming/tg.html Note this page has a summary of a lot of commands at the bo`om If you want Turtle Graphics on your own computer, so you don t need an internet connec6on, you can try NetLogo: h`p://ccl.northwestern.edu/netlogo/ This has many more features, and you may need a few hints to get going with NetLogo. Draw a square!repeat 4 [fd 100 rt 90]! 93 94 L- Systems socware Turtle Graphics There are lots of L- Systems socware We ll be using FractalGrower by Joel Castellanos, Department of Computer Science, University of New Mexico socware h`p://www.cs.unm.edu/~joel/paperfoldingfractal/ paper.html Note you need a JRE (Java Run6me Environment) installed on your computer to use this on your own. (If you don t want to use our labs). If you have difficul6es with this, we might be able to arrange some help. What is turtle graphics? Turtle => an early dome- shaped robot Issue commands to the turtle The turtle could trace its movements on paper Now we use an analog of a turtle robot on the screen DEMO 95 96 Basic Turtle Commands Addi6onal Helpful Commands Command Descrip%on Example FD FORWARD BK BACK LT LEFT RT RIGHT Moves the turtle forward, in the direc6on it is facing, by the specified number of turtle steps. FD 100 Moves the turtle backward, i.e., exactly opposite to the direc6on that it's facing, by the specified number of turtle steps. BACK 150 Turns the turtle counterclockwise by the specified angle measured by a number of degrees (1/360 of a circle). LEFT 180 Turns the turtle clockwise by the specified angle, measured in degrees (1/360 of a circle). RT 90 Command Description Example Moves the turtle to the center of the graphics canvas, HOME i.e., coordinates 0,0. PU Lifts the turtle's pen up so that it leaves no trace PENUP when the turtle moves. PD Puts the turtle's pen down so that it leaves a trace PENDOWN when the turtle moves. Erases (cleans) everything that the turtle has drawn on the graphics area (ClearGraphics). The turtle's CG state (position, heading, pen color, etc.) is not CLEAN changed. SETPC Sets the turtle's color - the color of its pen. Color is SETC expressed as a number. SETPENCOLOR SETPC 4 SETPS Sets the width of the turtle's pen, which determines SETPENSIZE the thickness of the trace it leaves, the line it draws. SETPS 5 HT HIDETURTLE Hides the turtle, makes it invisible. With these, try drawing a square, a triangle, an octagon and approximate a circle ST SHOWTURTLE Makes the turtle visible. SETH SETHEADING Set the turtles direction to a specified angle given in degrees SETH 0 97 98 2
Logo programming language LOGO was designed as a general programming language With turtle graphics commands added to the language, it became popular for teaching programming concepts (and therefore problem solving) to children. Cogni6ve aid ocen used with children: Pretend you are the turtle Use your body sense by ac6ng out the commands the turtle receives LOGO programming constructs: repeat Repe66on and Procedures are two LOGO program language constructs for combining commands that we will look at Repe66on (loop) is provided in LOGO with the repeat command: Repeats a block of commands a given number of 6mes Example: repeat 4 [fd 20 rt 45 bk 10]! 99 100 LOGO programming constructs: repeat Repe66on and Procedures are two LOGO program language constructs for combining commands that we will look at Repe66on (loop) is provided in LOGO with the repeat command: Repeats a block of commands a given number of 6mes Example: repeat 4 [fd 20 rt 45 bk 10]! Penta What does this draw? repeat 5 [fd 100 rt 144]! Number of repe66ons Block of commands to repeat 101 102 LOGO programming constructs: procedure LOGO programming constructs: procedure Procedures teach the turtle a new command to do something Example: to cross! fd 100! bk 20! rt 90! bk 40! lt 90! bk 80! end! Procedures teach the turtle a new command to do something Example: to cross! fd 100! bk 20! rt 90! bk 40! lt 90! bk 80! end! Name of new command Meaning of the new command (what to do) 103 104 3
What does this draw?!repeat 4[fd 100 rt 90]! Draw a circle Move a bit, turn a bit How would you draw a bigger circle repeat 10 [square rt 10]! to circle!!repeat 36 [fd 5 rt 10]! 105 106 Combining drawings What does this draw? to sunburst!!repeat 36 [fd 100 bk 100 rt 10]!! repeat 4 [fd 10 rt 90]! repeat 36 [fd 100 square bk 100 rt 10]! 107 108 In Class- Exercise: Challenges Using repeat, to and the basic turtle commands How many of these you can figure out? Which are Hard? Which are Easy? 109 110 4
Reviewing the exercise.. What makes a problem (a figure) hard? You can t figure it out It takes a lot of commands to finish It takes a lot of steps for the turtle It isn t possible to produce with these commands It isn t possible to produce with any commands Are there figures (drawings) that can t be created? This is like our earlier ques6on: are there things that can t be computed? Are there things that are hard? 111 5