We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Bubble making
Page Index Toggle Pages: 1
Bubble making (Read 448 times)
Bubble making
Apr 26th, 2010, 8:53pm
 
I want to make a process that tracks a color (yellow highlighter). When the color moves, I want bubbles (with random colors) to emit from the highlighter and float upward and fade away. Here's what I have so far. I got stuck and could use some help. I'm pretty new to processing.


Tab 1:

import processing.video.*;

Ball[] balls = new Ball[1];
float gravity = .01;

Capture video;
color trackColor;

void setup() {
 size(420, 340);
 video = new Capture(this, 420, 340, 40);
 
 balls[0] = new Ball(50,0,16);
}

void draw() {
 if (video.available()) {
   video.read();
   trackColor = color(255,240,0);
 }
 
 

 video.loadPixels();
 
 float closestValue = 500.0;
 float cX = 0;
 float cY = 0;
 
 
 for (int x=0; x < video.width; x++) {
   for( int y=0; y< video.height; y++) {
     int loc = x + y * video.width;
     color currentColor = video.pixels[loc];
     float r1 = red(currentColor);
     float g1 = green(currentColor);
     float b1 = blue(currentColor);
     float r2 = red(trackColor);
     float g2 = green(trackColor);
     float b2 = blue(trackColor);
     float distance = dist(r1, g1, b1, r2, g2, b2);
     if(distance < closestValue) {
       closestValue = distance;
       cX = x;
       cY = y;
     }
    }
   }
   
   image(video, 0,0);
   /*
   smooth();
   ellipseMode(CENTER);
   fill(220,220,220,1);
   stroke(255);
   strokeWeight(4);
   ellipse(cX, cY,20,20);
   */

}


void mousePressed() {
 int loc = mouseX + mouseY * video.width;
 trackColor = video.pixels[loc];
}







Tab 2: Ball


import processing.video.*;

Ball[] balls = new Ball[1];
float gravity = .01;

Capture video;
color trackColor;

void setup() {
 size(420, 340);
 video = new Capture(this, 420, 340, 40);
 
 balls[0] = new Ball(50,0,16);
}

void draw() {
 if (video.available()) {
   video.read();
   trackColor = color(255,240,0);
 }
 
 

 video.loadPixels();
 
 float closestValue = 500.0;
 float cX = 0;
 float cY = 0;
 
 
 for (int x=0; x < video.width; x++) {
   for( int y=0; y< video.height; y++) {
     int loc = x + y * video.width;
     color currentColor = video.pixels[loc];
     float r1 = red(currentColor);
     float g1 = green(currentColor);
     float b1 = blue(currentColor);
     float r2 = red(trackColor);
     float g2 = green(trackColor);
     float b2 = blue(trackColor);
     float distance = dist(r1, g1, b1, r2, g2, b2);
     if(distance < closestValue) {
       closestValue = distance;
       cX = x;
       cY = y;
     }
    }
   }
   
   image(video, 0,0);
   /*
   smooth();
   ellipseMode(CENTER);
   fill(220,220,220,1);
   stroke(255);
   strokeWeight(4);
   ellipse(cX, cY,20,20);
   */

}


void mousePressed() {
 int loc = mouseX + mouseY * video.width;
 trackColor = video.pixels[loc];
}


Page Index Toggle Pages: 1