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
}

No comments:

Post a Comment