/** * MoviePainter * Copyright (C) 2009 Eric Nguyen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Contact information: * Eric Nguyen * * @version 0.1 * @url http://mindtangle.net/2009/02/23/moviepainter/ */ import jmcvideo.*; JMCMovie brushMovie; PImage brushMask; float scale = 1; float rotation = 0; float degradingAvX = 0; float degradingAvY = 0; float brushsize = 1.5; float opacity = 20; float alpha = .1; // for IIR Filter int background = 255; void setup() { size(1000, 800, P3D); background(background); brushMovie = new JMCMovie(this, "movie4.mov"); brushMovie.loop(); brushMask = loadImage("b-vignette.jpg"); brushMask.resize(brushMovie.width, brushMovie.height); // font of choice PFont font; font = loadFont("FuturaBT-Bold-48.vlw"); textFont(font); } void mouseDragged() { // calculate rotation based on mouse direction // average mouse positions, using IIR (Infinite Impulse Response) filter if (degradingAvX > 0 || degradingAvY > 0) { degradingAvX = (alpha * mouseX) + ((1 - alpha) * degradingAvX); degradingAvY = (alpha * mouseY) + ((1 - alpha) * degradingAvY); } else { degradingAvX = mouseX; degradingAvY = mouseY; } rotation = atan2(mouseY-degradingAvY, mouseX-degradingAvX) - HALF_PI; scale = brushsize/sqrt(dist(mouseX, mouseY, degradingAvX, degradingAvY)); } void draw() { if (mousePressed) { brushMovie.mask(brushMask); translate(mouseX, mouseY); rotate(rotation); scale(scale, scale); tint(255, opacity); image(brushMovie, -1*(brushMovie.width/2), -1*(brushMovie.height/2)); } } // Called every time a new frame is available to read void movieEvent(JMCMovie m) { m.read(); } void keyPressed() { if (key == ' ') { // blank out screen background(background); } }