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)
}

No comments:

Post a Comment