Monday, April 4, 2011

A random spiral script

Today we started with a spiral, then added some colours, moved it into a command and called it multiple times.


reset
canvassize 1000,1000
# start in the middle
gox 500
goy 500

#
# This command creates a spiral
#
# $scale: how big should the spiral be
# $redcolor, $greencolor, $bluecolor: RGB colours for the spiral
#
learn spiral $scale, $redcolor, $greencolor, $bluecolor {
  pencolor $redcolor, $greencolor, $bluecolor
  for $i = 0 to 71 {
    forward $scale * 20
    turnright 30
    forward $scale * 5
    turnleft 175
    forward $scale * 100
  }
}

# draw the spirals
for $i = 0 to 40 {
  penup
  turnright random 0,360
  forward 200
  turnleft 90
  # if we are too close to the edge jump somewhere random
  # so we don't wander off the canvas
  if (getx < 20 or getx > 980) {
    gox (random 100,900)
  }
  if (gety < 20 or gety > 980) {
    goy (random 100,900)
  }    
  pendown
  spiral (random 1,20)/5, (random 0,255), (random 0,255), (random 0,255)
}

Wednesday, March 30, 2011

Overlaid spirals in colour

This is an extension of the simple spiral script to overlay multiple spirals of increasing size in red, green and blue. The first image is colourful, but very messy.

The messiness is caused by the turtle starting from the direction that the spiral ended in. For the second image we reset the direction, so it looks more organised.

reset
canvassize 500,500

for $y = 5 to 20 {
  go 250,250
  direction 0
  if $y ==5 {
    pencolor 0, 0, 0
  }
  else if $y < 11 {
    pencolor 105 + ((10 - $y)*30), 0, 0
  }
  else if $y < 16 {
    pencolor 0, 105 + ((15 - $y)*30), 0
  }
  else {
    pencolor 0, 0, 105 + ((20 - $y)*30)
  }
  for $x = 2 to 20 {
    repeat $x {
      forward $y
      turnright 105 / $x
    }
  }
}

Friday, March 25, 2011

A messy colour spiral

A rather messy spiral. We originally wrote this in black, but then added the random colour to show a little more of what was happening.

This script is a great one to experiment with changing the forward and turnright values.
reset

for $x = 2 to 50 {
  pencolor (random 0,255), (random 0,255), (random 0,255)
 repeat $x {
  forward 20
  turnright 555 / $x
}

Wednesday, March 16, 2011

A simple spiral

This script draws a simple spiral. It came from a simple change to the polygon spiral script.

reset
penup
turnleft 180
forward 150
turnright 90
pendown

for $x = 2 to 80 {
 repeat $x {
  forward 10
  turnright 105 / $x
}

Sunday, March 6, 2011

Polygon with colour

The plain black polygon was visually boring, so we started by changing the colour to gold:


Friday, March 4, 2011

Polygon

This is a simple script drawing polygons. Note how as the number of lines in the polygon increases the shape looks more and more like a circle.
reset

penup
turnleft 180
forward 150
turnright 90
pendown

for $x = 2 to 50 {
 repeat $x {
  forward 20
  turnright 360 / $x
}

Saturday, February 26, 2011

A rotated polygon

Following on from the rotated square we extended the script to draw the regular polygons from nonagon to triangle.
We chose custom colours for each of the polygons.
reset

for $y = 9 to 3 step -1
{
  if $y == 3 {
    pencolor 194, 0, 0 
  }
  else if $y == 4 {
    pencolor 0, 194, 0 
  }
  else if $y == 5 {
    pencolor 0, 0, 194 
  }
  else if $y == 6 {
    pencolor 0, 194, 194 
  }
  else if $y == 7 {
    pencolor 194, 194, 0 
  }
  else if $y == 8 {
    pencolor 194, 0, 194
  }
  else if $y == 9 {
    pencolor 255, 239, 59
  }
  repeat 24 {
    turnright 15
    repeat $y {
      forward 60
      turnleft 360/$y
    }
  }
}