Animation, Listing 4 – ETC Unison Mosaic Designer v1.11.0 User Manual
Page 228

Unison Mosaic Designer User Manual
and
-- decide if we are in the band or in the separator between bands
if (mod(x,band_width+band_spacing)<band_width) then
-- in band
return 255,0,0
else
-- in band separator
return 0,0,0
end
end
You will note that we have defined a new function, mod, to implement the modulo operator. This was done to
make the script more readable. We will discuss user-defined functions again later.
We also defined two variables, band_width and band_spacing. These we placed outside of the pixel func-
tion because they are the same for every pixel of every frame of the effect, so it is more efficient to not execute
the assignment for every pixel. Any code outside of the pixel function is executed once, before the pixel func-
tion is called for the first time.
Animation
Filling every frame of an animation with a single colour is not very exciting, so we can use the frame argument to
change the colour of a given pixel (x,y) based on the current frame.
Here is an example:
Listing 4
function pixel(frame,x,y)
if (x<frame) then
return 255,0,0
else
return 0,0,0
end
end
This creates a red horizontal wipe, advancing 1 pixel towards the right for each frame. You may have noted that
once the wipe reaches the right side of the frame, the whole frame stays red for a period of time before the anim-
ation loops back to the beginning. This is because the number of frames exceeded the number of pixels across
the frame.
Ideally, we want our effects to loop seamlessly. To do this, we introduce three global variables that have been
already been defined for you:
l
frames
- the total number of frames in the animation
l
width
- the width of the animation in pixels
l
height
- the height of the animation in pixels
We can rewrite Listing 4 as follows:
- 228 -