Color operations

(Moved…)

I would like it if color could be treated just like a vector.

Maybe I just missed the proper way of doing this but I tried to mix between 2 colors and this is what I ended up doing…

function setup()
    t = 0.5
    --col1 = color(255, 0, 0, 255)
    --col2 = color(0, 0, 255, 255)
    col1 = vec4(255, 0, 0, 255)
    col2 = vec4(0, 0, 255, 255)    
end

function draw()
    --local blend = col1:lerp(col2,t)   --doesn't work
    --local blend = col1*(1-t) + col2*t --doesn't work
    local blend = color(col1:lerp(col2,t):unpack())
    background(blend)
end 

@Amber - I know @sim has posted on this, and I don’t see a problem with using vec4() interchangeable with color().

You might also consider using a graphics package to create a lerp in and reading the colour values from that.

I’ll make a note of adding some math operations to the color() class for situations like this. But for blending specifically you can use col1:mix(col2, t), which obviously needs to be added to the documentation as well

1 Like

In case it’s of use, here’s my ColourExt code which adds a load of functionality to the color userdata.

1 Like