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.


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.




reset
penwidth 5
penup

learn  drawarc $innerRadius, $width, $redColour, $greenColour, $blueColour {
pencolor $redColour, $greenColour, $blueColour
  for $i = 0 to 180 {
    forward $innerRadius
    pendown
    forward $width
    penup
    turnleft 180
    forward $innerRadius + $width
    turnleft 179
  }
  turnright 179
}



turnleft 90
drawarc 50, 5, 143, 0, 255
drawarc 60, 5, 111, 0, 255
drawarc 70, 5, 0, 127, 163
drawarc 80, 5, 0, 255, 0
drawarc 90, 5, 255, 255, 0
drawarc 100, 5, 255, 165, 0
drawarc 110, 5, 255, 0, 0

No comments:

Post a Comment