beautypg.com

Listing 9, Listing 10 – ETC Unison Mosaic Designer v1.11.0 User Manual

Page 232

background image

Unison Mosaic Designer User Manual

Earlier in this document, we stated that the pixel function should return 3 numbers, representing the red, green
and blue components of a colour. This was not the entire truth. We are also allowed to return a single variable of
type colour. This function is therefore equivalent to Listing 8:

Listing 9

function pixel(frame,x,y)

local c = colour.new(255,0,0)

return c

end

Once again, we return to our vertical band example and use colour variables to specify the band colour and the
background colour:

Listing 10

-- width of the bands in pixels

band_width = 4

-- space between bands in pixels

band_spacing = 1

-- the colour of the band

band_colour = colour.new(255,0,0)

-- the colour of the space between bands

background_colour = colour.new(0,0,255)

-- get the combined width of band and separator

local total_band_width = band_width+band_spacing

-- get the number of visible bands

local bands = width/total_band_width

-- modulo operator (a%b)

function mod(a,b)

return a - math.floor(a/b)*b

end

-- the pixel function

function pixel(frame,x,y)

if (mod(x,total_band_width)>=band_width) then

-- in band separator

return background_colour

end

-- get the band in which this pixel falls

local band = math.floor(x/total_band_width)

-- get the fraction through the effect

local t = frame/frames

-- get the height of the band in which this pixel falls

local band_height = (math.sin((band/bands+t)*math.pi*2)+1)/4

- 232 -