reset
pencolor 194, 0, 0
repeat 24 {
turnright 15
repeat 4 {
forward 120
turnleft 90
}
}
Wednesday, February 23, 2011
A rotated square
We started with a square and then rotated it.
Saturday, February 19, 2011
Learning RGB - more colours
This is a rewrite of the previous Learning RGB script. It loops through a few more colours.
reset
penwidth 2
penup
turnleft 90
forward 113
turnleft 90
forward 113
turnleft 180
pendown
for $r = 0 to 1 {
for $g = 0 to 1 {
for $b = 0 to 1 {
for $x = 0 to 255 step 2 {
pencolor $r*$x,$g*$x,$b*$x
forward 16
turnright 90
forward 1
turnright 90
pencolor $r*($x + 1),$g*($x + 1),$b*($x + 1)
forward 16
turnleft 90
forward 1
turnleft 90
}
penup
turnleft 90
forward 256
turnright 90
forward 17
pendown
}
}
}
Thursday, February 10, 2011
Learning RGB
This is a simple script, which draws three lines changing the red, green and blue values.
reset
penwidth 2
penup
turnleft 90
forward 113
turnleft 90
forward 113
turnleft 180
pendown
for $x = 0 to 255 step 2 {
pencolor $x,0,0
forward 16
turnright 90
forward 1
turnright 90
pencolor ($x + 1),0,0
forward 16
turnleft 90
forward 1
turnleft 90
}
penup
turnleft 90
forward 256
turnright 90
forward 17
pendown
pendown
for $x = 0 to 255 step 2 {
pencolor 0,$x,0
forward 16
turnright 90
forward 1
turnright 90
pencolor 0,($x + 1),0
forward 16
turnleft 90
forward 1
turnleft 90
}
penup
turnleft 90
forward 256
turnright 90
forward 17
pendown
pendown
for $x = 0 to 255 step 2 {
pencolor 0,0,$x
forward 16
turnright 90
forward 1
turnright 90
pencolor 0,0,($x + 1)
forward 16
turnleft 90
forward 1
turnleft 90
}
Tuesday, February 8, 2011
Rainbow
Often we start by sketching a picture of what we want to code. This is a sketch of the rainbow, with RGB colours in hexadecimal.
Here is a screenshot of the finished program followed by a video of the turtle in action.
This is the rainbow we created based on the above drawing. It is not the most efficient code, but it works.
Here is a screenshot of the finished program followed by a video of the turtle in action.
Thursday, February 3, 2011
Spiral traffic light
Today we created a spiral traffic light. We started with a plain spiral, changed the colour to red, then added a green spiral and finally a yellow one in the middle.
reset
# red spiral
for $x = 1 to 72 {
pencolor 4 * $x, 0, 0
forward 123
turnright 67
forward 7
turnleft 156
forward 7
turnleft 156
}
penup
turnleft 90
forward 20
turnleft 90
forward 50
pendown
# green spiral
for $x = 1 to 72 {
pencolor 0 , 4 * $x, 0
forward 123
turnright 67
forward 7
turnleft 156
forward 7
turnleft 156
}
penup
forward 50
turnleft 190
pendown
# yellow spiral
for $x = 1 to 72 {
pencolor 4 * $x, 4 * $x, 0
forward 123
turnright 67
forward 7
turnleft 156
forward 7
turnleft 156
}
Wednesday, February 2, 2011
Star
This code uses some basic trigonometry to draw stars with various point sizes. Some examples of starts with 5 and 10 points.
And an overlay of starts with points ranging from 2 to 10:
reset
turnleft 90
$baseLength = 40
$starHeight = 60
$starLength = sqrt($starHeight * $starHeight + ($baseLength/2)*($baseLength/2))
for $x = 2 to 10 {
repeat $x {
# draw the base line
forward $baseLength
# calculate the angle of triangle at the bottom corner
$angle = arctan (($baseLength/2) / $starHeight)
# turn to draw the side
turnleft 90 + $angle
# draw the side
forward $starLength
# turn to draw the other side
turnleft 2 * (90 - $angle)
# draw the other side
forward $starLength
# turn to draw the base (again)
turnleft 90 + $angle
# draw the base (again)
forward $baseLength
# turn the turtle to start the next point
turnright 360 / $x
}
}
Sunday, January 30, 2011
Another spiral variant
Another variant of a spiral with a small inner circle and longer outer arms.
We wanted to add some colour so we split the loop into three parts and added a different colour for each loop.
reset
penup
forward 50
turnright 180
pendown
# red layer
pencolor 255, 0, 0
for $x = 1 to 60 {
forward 109
turnright 100
forward 39
turnleft 29
forward 78
turnleft 189
}
# green layer
pencolor 0, 255, 0
for $x = 1 to 60 {
forward 109
turnright 100
forward 39
turnleft 29
forward 78
turnleft 189
}
# blue layer
pencolor 0, 0, 255
for $x = 1 to 60 {
forward 109
turnright 100
forward 39
turnleft 29
forward 78
turnleft 189
}
Subscribe to:
Posts (Atom)










