February 21, 2018

Turtle Graphics

Turtle Graphics in 1967

Created by Seymur Papert and Cynthia Solomon

MIT’s Artificial Intelligence Laboratory

… to teach children …

… how to think with computers

Key parts of computational thinking

Decomposition
breaking down a complex problem or system into smaller parts
Pattern Recognition
looking for similarities among and within problems
Abstraction
focusing on the important parts only, ignoring irrelevant detail
Algorithms
developing a step-by-step solution to the problem

You can make your own turtle

You can also have a turtle in R

You can install TurtleGraphics in R with this command

install.packages("TurtleGraphics")

Then you load into the session using

library(TurtleGraphics)

Now you start a new “terrarium” with

turtle_init()

Turtle lives in a terrarium

Set Up a New, Shiny Terrarium

turtle_init(width = 100, height = 100, mode = c("error", "clip", "cycle"))
width
numeric; plot width.
height
numeric; plot height.
mode
character string; one of “error”, “clip”, or “cycle”.

We will explore these options later

The turtle can move

Move the Turtle Forward or Backward
turtle_move(10) move (10) steps
Turn (Rotate) the Turtle
turtle_right(15) turn cw (15) degrees
turtle_left(15) turn ccw (15) degrees
Set the Turtle’s Position and Direction
turtle_setangle(90) point in direction (90 v)
turtle_goto(0,0) go to x:(0) y:(0)

She can draw and hide

Pen commands
turtle_up() pen up
turtle_down() pen down
Display Options
turtle_col(0) set pen color to (0)
turtle_lwd(1) set pen size to (1)
turtle_lty(1) Change line type
Show or Hide the Turtle
turtle_hide() hide
turtle_show() show

Where is the Turtle?

Get the Turtle’s Current Position and Direction
turtle_getangle() (direction)
turtle_getpos() (x position) (y position)

“Turbo” Mode

Evaluate a Larger Portion of Turtle Drawing Code

  • turtle_do({code here})

Let’s redo the Quiz on R

By default the terrarium size is 100,100

turtle_init()

In R, the turtle is not at (0,0)

turtle_getangle()
angle 
    0 
turtle_getpos()
 x  y 
50 50 

So we have to adapt our code (how?)

Terrarium has borders

turtle_move(80)
Error in .turtle_draw_error(distance, curX, curY, curAng, curGp, curDraw, : The Turtle escaped from the terrarium. :-(

We can relax the border control

turtle_init(mode = "clip")

Here we work on Rstudio

Please write in paper what we do on Rstudio

What happens when the turtle gets out?

Since the turtle is at (50,50),
How do we change our code?

Decomposition

Separating a complex problem into smaller, more manageable parts

Here we separate a complex figure into many smaller parts

Homework: Draw a stick man using R Turtle Graphics

Pattern recognition

Is this problem similar to another?

Are there parts of this problem that are similar to each other?

Please answer this question

Computational Thinking

Source: https://www.bbc.co.uk/education/guides/zp92mp3/revision

What is computational thinking?

from BBC website

Computers can be used to help us solve problems. However, before a problem can be tackled, the problem itself and the ways in which it could be solved need to be understood.

Computational thinking allows us to do this.

Computational thinking allows us to take a complex problem, understand what the problem is and develop possible solutions. We can then present these solutions in a way that a computer, a human, or both, can understand.

The four key techniques of computational thinking

decomposition
breaking down a complex problem or system into smaller, more manageable parts
pattern recognition
looking for similarities among and within problems
abstraction
focusing on the important information only, ignoring irrelevant detail
algorithms
developing a step-by-step solution to the problem, or the rules to follow to solve the problem

Each cornerstone is as important as the others

They are like legs on a table

  • if one leg is missing, the table will probably collapse

Correctly applying all four techniques will help when programming a computer.

Computational thinking in practice

A complex problem is one that, at first glance, we don’t know how to solve easily.

Computational thinking involves taking that complex problem and breaking it down into a series of small, more manageable problems (decomposition). Each of these smaller problems can then be looked at individually, considering how similar problems have been solved previously (pattern recognition) and focusing only on the important details, while ignoring irrelevant information (abstraction). Next, simple steps or rules to solve each of the smaller problems can be designed (algorithms).

Finally, these simple steps or rules are used to program a computer to help solve the complex problem in the best way.

Thank you for your attention