I’m having trouble figuring out the math involved in changing a line’s stroke color based on its variable length. The goal is that when the line gets shorter it will be gradually drawn red and when it gets longer it gradually draws blue. And there is a middle ground where in between shorter and longer it is just white. For example:
-- line test
supportedOrientations(LANDSCAPE_ANY)
function setup()
parameter.integer( "length", 100, 600, 350 )
parameter.watch( "i" )
RED_MIN = 200
RED_MAX = 100
BLUE_MIN = 500
BLUE_MAX = 600
end
function draw()
if length <= RED_MIN then
-- i = 255 - (255 * a value between 0 and 1, where 0 is f(length=RED_MIN) and 1 is f(length=RED_MAX)
c = color(255, i, i, 255)
elseif length >= BLUE_MIN then
-- i = 255 - (255 * a value between 0 and 1, where 0 is f(length=BLUE_MIN) and 1 is f(length=BLUE_MAX)
c = color(i, i, 255, 255)
else
c = color(255,255,255,255)
end
background(40, 40, 50)
strokeWidth(5)
stroke(c)
line(70, HEIGHT/2, 70+length, HEIGHT/2)
end
Thanks again guys!