Listing 13, Listing 14, Listing 15 – ETC Unison Mosaic Designer v1.11.0 User Manual
Page 234

Unison Mosaic Designer User Manual
local c1 = colour.new(255,0,0)
local c2 = colour.new(0,0,255)
local g = gradient.new(c1, c2)
To find the colour of the gradient at a specific point, use the lookup function, passing in a number between 0 and
1. For example:
Listing 13
local red = colour.new(255,0,0)
local blue = colour.new(0,0,255)
local g = gradient.new(red, blue)
function pixel(frame,x,y)
-- note the use of the colon operator
return g:lookup(x/(width-1))
end
This creates a horizontal gradient from red to blue, but we have already seen that there are other ways to generate
the same result which will probably be more efficient. To show where the gradient library offers more power:
Listing 14
local red = colour.new(255,0,0)
local blue = colour.new(0,0,255)
local g = gradient.new(red,blue)
-- add a third point to the middle of the gradient
local green = colour.new(0,255,0)
g:add_point(0.5,green)
function pixel(frame,x,y)
return g:lookup(x/(width-1))
end
We used the add_point function to insert a green colour midway between the red and the blue colours. This gen-
erates a horizontal gradient that fades from red to green to blue.
Back to the vertical band example, we will use a gradient to colour the bands:
Listing 15
-- width of the bands in pixels
band_width = 4
-- space between bands in pixels
band_spacing = 1
-- the colour of the band
band_gradient = gradient.new(colour.new(255,0,0), colour.new
(255,255,0))
-- the colour of the space between bands
background_colour = colour.new(0,0,0)
- 234 -