160 likes | 398 Views
Computer Programming with Logo. Glenn Bresnahan glenn@bu.edu. 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
E N D
Computer Programming with Logo Glenn Bresnahan glenn@bu.edu
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 http://scv.bu.edu/BPC/MaterialsSpring07/lectures/BPC-Class-LogoNotes.doc • Example programs(to be provided) http://scv.bu.edu/BPC/MaterialsSpring07/aux/Logo/ BPC: Art and Computation – Summer 2007
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 2007
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 2007
Concepts • Computers and stored programs • Procedures/algorithms • Analogies to cooking/recipes • Programming languages • Logo history/background BPC: Art and Computation – Summer 2007
Logo Language • Logo words • Verbs and nouns • Commands/imperatives • Inputs • Functions (procedures that ouput) • Numbers and arithmetic BPC: Art and Computation – Summer 2007
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 2007
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 2007
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 2007
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 2007
Conditionals • if statements • Testing for conditions • Comparison operators • Logical operators BPC: Art and Computation – Summer 2007
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 2007
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 2007
Hunting algorithm - Random to hunt make “steps 1 while [smellfood < 1000] [findfood] print se [Found food at] pos3d end to findfood make "lastsniff smellfood rt3d 90-random 180 fd3d 2 if smellfood < :lastsniff [ rt3d 180 fd3d 4 ] end BPC: Art and Computation – Summer 2007
Hunting algorithm – Binary Search to findfood make "lastsniff smellfood if (:steps = 1) [ find.direction 360] fd3d 2 if smellfood < :lastsniff [ rt3d 180 fd3d 4 find.direction 180] end BPC: Art and Computation – Summer 2007
Hunting algorithm – Binary Search to find.direction :range if (abs :range) < 1.0 [make "food.direction heading3d stop] localmake "alpha 0.25*:range rt3d :alpha fd3d 1 localmake "smell1 smellfood rt3d -(90+:alpha) fd3d 2*sin :alpha rt3d (90-:alpha) localmake "smell2 smellfood if :smell1 > :smell2 [rt3d :alpha+90 fd3d 2*sin :alpha rt3d -(90-:alpha) ] pr (se [now at] heading3d :range) find.direction 0.5*:range end BPC: Art and Computation – Summer 2007