BPC: Art and Computation – Summer 2007 Computer Programming with Logo Glenn Bresnahan
BPC: Art and Computation – Summer Synopsis Introduction to computer programming and the Logo programming language Concepts of programming, computer languages and algorithms Programming constructs Combination of lecture and hands-on labs -Class-LogoNotes.doc -Class-LogoNotes.doc (to be provided) Example programs (to be provided)
BPC: Art and Computation – Summer Programming Constructs Procedures Arithmetic operations and math functions Variables (naming) Iteration Recursion Conditionals and logical operations Parameters and scoping Data structures –words (i.e.strings) –lists
BPC: Art and Computation – Summer Using Logo Computer generate images –Turtle graphics –Patterns and design 2D Animation –Animated patterns and figures DAFFIE agents –Controlling 3D DAFFIE objects –Turtle3D
BPC: Art and Computation – Summer Concepts Computers and stored programs Procedures/algorithms –Analogies to cooking/recipes Programming languages Logo history/background
BPC: Art and Computation – Summer Logo Language Logo words Verbs and nouns Commands/imperatives Inputs Functions (procedures that ouput) Numbers and arithmetic
BPC: Art and Computation – Summer Turtle graphics Using turtle graphics to draw a pattern –Interactive drawing Defining procedures using to –Saving the pattern Saving and loading the Logo workspace Using iteration to draw patterns repeat 4 [ forward 100 right 90] –Drawing polygons and patterns
BPC: Art and Computation – Summer Variables Using words to name values –“word vs :word –thing “word Using symbolic names to change the behavior of a procedure Inputs to procedures –Formal parameters and arguments –Binding –Scoping Recommend exercises to reinforce these concepts
BPC: Art and Computation – Summer Words and Lists Manipulating words (strings) –word –first, butfirst, last, butlast –Numbers as words Manipulating lists –list, sentence –first, butfirst, last, butlast –lput, lput
BPC: Art and Computation – Summer Numerical Computing Arithmetic operations Trig functions Using trig to calculate turtle movements –How do I get to point (x,y)?
BPC: Art and Computation – Summer Conditionals if if statements –Testing for conditions –Comparison operators –Logical operators
BPC: Art and Computation – Summer DAFFIE Agents – Turtle3D Turtle3D - Logo/DAFFIE interface –Control a 3D DAFFIE turtle –Turtle World –General mechanism to manipulate DAFFIE objects DAFFIE Robots
BPC: Art and Computation – Summer DAFFIE Robot Searching for food –smellfood returns an indicator of how far away the food is, 1 to 1000 Strategies –Complete traversal Traversal patterns –Random walks –Binary search
BPC: Art and Computation – Summer Hunting algorithm - Random to hunt make “steps 1 make “steps 1 while [smellfood < 1000] [findfood] while [smellfood < 1000] [findfood] print se [Found food at] pos3d print se [Found food at] pos3dend to findfood make "lastsniff smellfood make "lastsniff smellfood rt3d 90-random 180 rt3d 90-random 180 fd3d 2 fd3d 2 if smellfood < :lastsniff [ rt3d 180 fd3d 4 ] if smellfood < :lastsniff [ rt3d 180 fd3d 4 ]end
BPC: Art and Computation – Summer Hunting algorithm – Binary Search to findfood make "lastsniff smellfood make "lastsniff smellfood if (:steps = 1) [ find.direction 360] if (:steps = 1) [ find.direction 360] fd3d 2 fd3d 2 if smellfood < :lastsniff [ rt3d 180 fd3d 4 find.direction 180] if smellfood < :lastsniff [ rt3d 180 fd3d 4 find.direction 180]end
BPC: Art and Computation – Summer Hunting algorithm – Binary Search to find.direction :range if (abs :range) < 1.0 [make "food.direction heading3d stop] if (abs :range) < 1.0 [make "food.direction heading3d stop] localmake "alpha 0.25*:range localmake "alpha 0.25*:range rt3d :alpha fd3d 1 rt3d :alpha fd3d 1 localmake "smell1 smellfood localmake "smell1 smellfood rt3d -(90+:alpha) fd3d 2*sin :alpha rt3d (90-:alpha) rt3d -(90+:alpha) fd3d 2*sin :alpha rt3d (90-:alpha) localmake "smell2 smellfood localmake "smell2 smellfood if :smell1 > :smell2 [rt3d :alpha+90 fd3d 2*sin :alpha rt3d - (90-:alpha) ] if :smell1 > :smell2 [rt3d :alpha+90 fd3d 2*sin :alpha rt3d - (90-:alpha) ] pr (se [now at] heading3d :range) pr (se [now at] heading3d :range) find.direction 0.5*:range find.direction 0.5*:rangeend