beautypg.com

More colours than just red, Listing 7 – ETC Unison Mosaic Designer v1.11.0 User Manual

Page 230

background image

Unison Mosaic Designer User Manual

-- adjust y to be relative to the center of the effect

y = y-(height/2)+0.5

-- decide if this pixel is inside the band

if (math.abs(y)/(height/2) <= band_height) then

return 255,0,0

else

return 0,0,0

end

end

We are using a sine function to set the height of each band, where the argument to the sine function is offset
based on the index of the band and the current fraction through the effect. The result of this is that the height of
each band differs from its neighbour according the sine function, and this relationship is modified over time to cre-
ate a ripple.

More colours than just red

So far, we have just been creating red effects, but there are more colours than red, so why should we stick with
that? We will modify the vertical band example to show how different colours can be created. For this example,
we introduce the built-in function, hsi_to_rgb, which converts an HSI (hue, saturation, intensity) colour into an
RGB (red, green, blue) colour:

Listing 7

-- width of the bands in pixels

band_width = 4

-- space between bands in pixels

band_spacing = 1

-- 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

-- rainbow lookup

function rainbow(hue)

return hsi_to_rgb(hue*math.pi*2,1,1)

end

-- the pixel function

function pixel(frame,x,y)

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

-- in band separator

return 0,0,0

end

- 230 -