February 19, 2020
Things move, appear or disappear
But is hard to handle biological data
On the other hand R works well with data
But it is hard to make movies and games in R
What do they have in common?
In this version of Scratch, the Turtle is called Pen
It is an extension that you can use
Instead of a Turtle you get a Cat
move (10) steps
turn cw (15) degrees
turn ccw (15) degrees
go to x:(0) y:(0)
point in direction (90 v)
pen up
pen down
set pen color to (0)
set pen size to (1)
(direction)
(x position)
(y position)
hide
show
Write a script that make the cat do the following:
Let’s draw a star using Turtle graphics in Scratch!
This part is on the Scratch webpage
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()
Set Up a new Terrarium
turtle_init(width = 100, height = 100, mode = "error")
turtle_move(10)
move (10) steps
turtle_right(15)
turn cw (15) degrees
turtle_left(15)
turn ccw (15) degrees
turtle_goto(0,0)
go to x:(0) y:(0)
turtle_setangle(90)
point in direction (90 v)
turtle_setpos(0,0)
Move without drawingturtle_up()
pen up
turtle_down()
pen down
turtle_col(0)
set pen color to (0)
turtle_lwd(1)
set pen size to (1)
turtle_lty(1)
Change line typeturtle_hide()
hide
turtle_show()
show
turtle_getangle()
(direction)
turtle_getpos()
(x position)
(y position)
Evaluate a Larger Portion of Turtle Drawing Code
turtle_do({
code here})
turtle_init()
turtle_getangle()
angle 0
turtle_getpos()
x y 50 50
So we have to adapt our code (how?)
turtle_move(80)
Error in .turtle_draw_error(distance, curX, curY, curAng, curGp, curDraw, : The Turtle escaped from the terrarium. :-(
turtle_init(mode = "clip")
Now you should be able to draw stars and moons in R
Please do it.
Write the code to draw a star in R
In Science, validity of results depends on peer review
Your work is evaluated by someone like you
Do it with the work of your classmates
Answer in the Google Form
Be honest, and be a good team player