1 / 44

getting started

getting started. with the turtle. l earning objectives. basic editor usage basic coding skills publishing and sharing scripts and lots of turtle fun!. turtle programming. you control a turtle the turtle has a pen and draws a line as it moves

ashlyn
Download Presentation

getting started

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. getting started with the turtle

  2. learning objectives • basic editor usage • basic coding skills • publishing and sharing scripts • and lots of turtle fun!

  3. turtle programming • you control a turtle • the turtle has a pen and draws a line as it moves • you have to give commands to the turtle to move forward or turn • see LOGO for reference

  4. square “think like the turtle”…

  5. square forward 100

  6. square forward 100 left turn 90 (degrees)

  7. square forward 100 left turn 90 forward 100

  8. square forward 100 left turn 90 forward 100 left turn 90 …

  9. square forward 100 left turn 90 forward 100 left turn 90 forward 100 left turn 90

  10. square forward 100 left turn 90 forward 100 left turn 90 forward 100 left turn 90 forward 100 left turn 90

  11. scripts • a script is an app created in TouchDevelop • a script can be published to TouchDevelop so that other users can use it • a script can be exportedinto a Windows app or Windows Phone app.

  12. navigate the script code editor scroll to the bottom

  13. tap to select tap to select

  14. tap to select tap to delete or press backspace

  15. loading turtle • type for ‘turtle’ in the search bar • Tap on ‘search for libraries’ • tap on ‘turtle’ from the ‘TouchDevelop Samples’ user

  16. and we keep taping to build the code tap to add a new line

  17. type and select type “turtle” and insert type “init” and insert

  18. keep coding then run run your script

  19. run again go back to the editor the turtle

  20. select multiple lines copy to clipboard paste it!

  21. that’s how your code should look like we’ve got a square!

  22. custom pen • change the color of the pen libs->turtle->pen color(colors→random) • change the thickness of the pen libs->turtle->set thickness(20)

  23. exercises • change to color on each stroke • (optional) draw a triangle with the turtle • (optional) draw a pentagon with the turtle

  24. publishing • publish your script to the cloud • anybody can see it on internet • once published, take screenshots • (optional)

  25. 1. tap here 3. published scripts have a unique id 2. tap here

  26. run the published app take screenshot

  27. for loops • for loop: repeats the same code multiple times • definition for 0 ≤ index < count do ... • index starts at 0, increments by 1 on each iteration and finishes at count-1. index goes through 0, 1, 2, … , count-1

  28. square for 0 ≤ index < 4 do turtle->forward(100) turtle->left turn(90) index = 0

  29. square for 0 ≤ index < 4 do turtle->forward(100) turtle->left turn(90) index = 1

  30. square for 0 ≤ index < 4 do turtle->forward(100) turtle->left turn(90) index = 2

  31. square for 0 ≤ index < 4 do turtle->forward(100) turtle->left turn(90) index = 3

  32. add a new line and tap on ‘for’ use number keypad or type 4

  33. local variables • alocal variable holds a value in memory; • a local variable can be read or written too. • definition var x := 0 • reading x->post to wall • update with new value x := 5

  34. spiral c holds the current distance to move forward var c := 100 for 0 ≤ index < 10 do turtle->forward(c) turtle->left turn(90)c := c + 5 increase c by 5 so that the turtle moves a little bit more on the next iteration

  35. if .. then .. else .. if statement: executes different code based on a Boolean condition if ... then ... else ... true or false happens when true happens when false

  36. random walk returns a random number between 0 (included) and 2 (excluded) ifmath->random(2) = 0 then ... else ... 50% chance true or false

  37. random walk turtle->forward(10) if math->random(2) = 0 then turtle->left turn(90) else turtle->right turn(90)

  38. actions functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs. action square(x : Number) returns r : Number r := x * x x is an input, it is a number the action is called ‘square’ r is an output, it is a number storing x*x into r

  39. nested square action square(c : Number) for 0 ≤ index < 4 do turtle->forward(c) turtle->left turn(90) action main() var c := 100 for 0 ≤ index < 10 docode->square(c)c := c + 5

  40. drawing a tree

  41. see script /gdmw

  42. homework 1 • recreate the following turtle drawing

  43. color gradients • create gradient effects var c := colors→linear gradient(colors→red, colors →blue, index / 3) ♺turtle→pencolor(c)

  44. homework 2 You will create a script that uses the turtle library to draw a design of your own creation. The design itself is up to you, but it must include all of the technical elements described below. • Your drawing must be created when you run the Main function. • You must use three other functions, each of which draws something. • You must use at least one for loop and at least one if statement. • Your functions should be appropriately named, and each should do something unique. • At least one function must use a parameter, and it must be called using multiple values for that parameter. • All functions must be used more than once. Using a function within a loop works for this purpose. • You must use at least three colors, and you must change the pen thickness at least once. • Your program should terminate within a reasonable amount of time. • Ideas If you don’t know what to draw, here are a few ideas: • Try drawing a shape, then rotating the turtle some amount, and then doing it again, and so on. • Try writing functions that don’t end in the same place they started. • You can draw irregular shapes, like diamonds, isosceles triangles, or stars. • Try using the pen up and move to functions to draw the same shape on different parts of the screen. • Instead of drawing a geometric shape, draw a stick figure

More Related