All right, that's a bit easier with all the assets.
Made some changes:
Adapted Code
Made some changes:
- Put all the read()'s into draw which indeed seems to solve the flickering issue. Plus it allows for more efficient masking. Once per new frame, instead of once per circle.
- Adapted shape selection.
- Adapted shape movement.
Adapted Code
- // Processing 2.0b8
- import processing.video.*;
- int numCircles = 16;
- PImage maskImage;
- Movie[] eye = new Movie[2];
- Circle[] circles = new Circle[numCircles];
- int selectedCircle = -1;
- void setup() {
- size(1920, 1000);
- imageMode(CENTER);
- smooth();
- maskImage = loadImage("mask-bg.jpg");
- eye[0] = new Movie(this, "eye.mov");
- eye[1] = new Movie(this, "eye2.mov");
- for (int i=0; i<eye.length; i++) {
- eye[i].loop();
- }
- for (int i=0; i<circles.length; i++) {
- circles[i] = new Circle();
- }
- }
- void draw() {
- background(0);
- for (int i=0; i<eye.length; i++) {
- if (eye[i].available()) {
- eye[i].read();
- eye[i].mask(maskImage);
- }
- }
- for (int i=0; i< circles.length; i++) {
- circles[i].display();
- }
- }
- void mousePressed() {
- for (int i=0; i<circles.length; i++) {
- if (circles[i].mouseOverCircle()) {
- selectedCircle = i;
- break;
- }
- }
- }
- void mouseDragged() {
- if (selectedCircle>-1) {
- circles[selectedCircle].move();
- }
- }
- void mouseReleased() {
- selectedCircle = -1;
- }
- class Circle {
- float r, xpos, ypos;
- int selectedMovie;
- Circle() {
- xpos = random(width);
- ypos = random(height);
- r = 100;
- selectedMovie = (int) random(eye.length);
- }
- void display() {
- image(eye[selectedMovie], xpos, ypos);
- }
- boolean mouseOverCircle() {
- return (dist(mouseX, mouseY, xpos, ypos)<r);
- }
- void move() {
- xpos += (mouseX-pmouseX);
- ypos += (mouseY-pmouseY);
- if (xpos>width) { xpos = 0; }
- if (ypos>height) { ypos = 0; }
- }
- }