/* * Virtual Playhead - Timed Item - Timed Image * http://subpixels.com * Version 0.2, 2009-01-29 */ // ----------------------------------------------------------------------------- // A timed item for images // ----------------------------------------------------------------------------- public class TimedImage extends TimedItem { PImage img; // --------------------------------------------------------------------------- // Constructors // --------------------------------------------------------------------------- public TimedImage(float t1, float t2, PImage img) { this(t1, t2, img, 0, 0, 0, 0, 0, 0); } public TimedImage(float t1, float t2, PImage img, float x1, float x2, float y1, float y2, float rot1, float rot2) { super(t1, t2, x1, x2, y1, y2, rot1, rot2); this.img = img; } public void render(float time) { // Nothing to render if we're outside of the start and end time if (!active(time)) return; // Calculate the position or "progress" (from 0.0 to 1.0) float pos = (time - t1) / duration; // Offsets are so rotation appears to be about the centre of the image float xoff = -(img.width >> 1); float yoff = -(img.height >> 1); pushMatrix(); translate(lerp(x1, x2, pos), lerp(y1, y2, pos)); if (rot1 != 0 || rot2 != 0) rotate(lerp(rot1, rot2, pos)); image(img, xoff, yoff); popMatrix(); } }