We are about to switch to a new forum software. Until then we have removed the registration on this forum.
please tell us how to draw this code.
We want to draw some particle. at this moment, the particle should be drawn on the color that we tracking.
the particle that we want to draw is as in the following.
the main tap is ↓
/**
* Simple Particle System
* by Daniel Shiffman.
*
* Particles are generated each cycle through draw(),
* fall with gravity and fade out over time
* A ParticleSystem object manages a variable size (ArrayList)
* list of particles.
*/
ParticleSystem ps;
void setup() {
size(640,360);
ps = new ParticleSystem(new PVector(width/2,50));
}
void draw() {
background(0);
if(mousePressed)
{ ps.updateOrigin(new PVector(mouseX, mouseY)); }
ps.addParticle();
ps.run();
}
and the second tap is ↓
// A simple Particle class
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
float lifespan;
Particle(PVector l) {
acceleration = new PVector(0,0.05);
velocity = new PVector(random(-1,1),random(-2,0));
location = l.copy();
lifespan = 255.0;
}
void run() {
update();
display();
}
// Method to update location
void update() {
velocity.add(acceleration);
location.add(velocity);
lifespan -= 1.0;
}
// Method to display
void display() {
stroke(255,lifespan);
fill(255,lifespan);
ellipse(location.x,location.y,8,8);
}
// Is the particle still useful?
boolean isDead() {
if (lifespan < 0.0) {
return true;
} else {
return false;
}
}
}
and the third tap is ↓
// A class to describe a group of Particles
// An ArrayList is used to manage the list of Particles
class ParticleSystem {
ArrayList<Particle> particles;
PVector origin;
ParticleSystem(PVector location) {
origin = location.copy();
particles = new ArrayList<Particle>();
}
void addParticle() {
//particles.add(new Particle(new PVector(mouseX, mouseY)));
particles.add(new Particle(origin));
}
void run() {
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = particles.get(i);
p.run();
if (p.isDead()) {
particles.remove(i);
}
}
}
void updateOrigin(PVector newOrigin)
{ origin = newOrigin.copy(); }
}
Answers
There is an example that comes with the video library. In the Processing IDE, open Files >> examples and then go to the folder Libraries >> Video> Capture >BrightnessTracking
Now, instead of trying to figure out the point with the highest brightness, you just need to look for the points that has the most red on it. For this, I suggest you use the distance function:
The last thing you need to consider is what would happen if you have multiple red colors?
Kf
Check out Learning Processing Ch16, Color Tracking example:
https://github.com/shiffman/LearningProcessing/blob/master/chp16_video/example_16_11_ColorTrack/example_16_11_ColorTrack.pde
I can't understand ;( I know i need to check out the example_16_11 , Despite i checked out the example , i can't make the code that i want .... :(( Please teach me again
Please post the code you have so far for color tracking and your attempt to bring them together.
Kf
this example is the ellipse follow the color that i clicked(mousePressed), but what i want to do is the ellipse follow color like red or blue etc. that i put in the "code" without any click.