Sunday, March 6, 2011

Polygon with colour

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




reset

penup
turnleft 180
forward 150
turnright 90
pendown

for $x = 2 to 50 {
  pencolor 255, 221, 37
  repeat $x {
    forward 20
    turnright 360 / $x
  }
}

This was still pretty dull, so we adjusted the script to add some randomness. Note how we allow the randomness to grow as the polygons become larger.

reset

penup
turnleft 180
forward 150
turnright 90
pendown

for $x = 2 to 50 {
  $red = 255 - (random 0, $x * 4)
  $green = 221 - (random 0, $x * 4)
  $blue = 37 + (random 0, $x * 4)
  pencolor $red, $green, $blue
  repeat $x {
    forward 20
    turnright 360 / $x
  }
}






No comments:

Post a Comment