Amber
December 5, 2022, 7:49pm
1
(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
Bri_G
December 5, 2022, 9:57pm
2
@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.
John
December 5, 2022, 11:14pm
3
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.
-- Colour manipulation
-- Author: Andrew Stacey
-- Website: http://www.math.ntnu.no/~stacey/HowDidIDoThat/iPad/Codea.html
-- Licence: CC0 (http://wiki.creativecommons.org/CC0)
--[[
This provides some functions for basic colour manipulation such as
colour blending. This version works by extending the color userdata object.
--]]
local mt = getmetatable(color())
if not mt.__is_extended then
mt.__is_extended = true
-- Should we modify the alpha of our colours?
mt.ModifyAlpha = false
local __hsl,__hsv,__svg,__x11,__clone,__byName,__random
__svg = {}
__x11 = {}
This file has been truncated. show original
1 Like