import processing.video.*;
MovieMaker mm;
color[][] clre;
PVector[][] posizioni;
PVector origin;
ArrayList particles = new ArrayList();
int numParticles = 10000;
int z = 0;
void setup()
{
size(400, 400);
colorMode(HSB, 360, 100, 100, 100);
PFont font = loadFont("Standard0757-8.vlw");
textFont(font, 32);
clre = new color[width][height/2];
posizioni = new PVector[width][height/2];
//mm = new MovieMaker(this, width, height, "drawing.mov", 30, MovieMaker.VIDEO, MovieMaker.LOSSLESS);
}
void draw()
{
background(1, 0, 100);
textAlign(CENTER);
fill(1, 100, 100, 1);
text("Hello World."+'\n'+"We are Pixels." , width/2, 50);
for(int i=0; i<width; i++) {
for(int j = 0; j<height/2; j++) {
clre[i][j] = get(i,j);
if(clre[i][j] != -1){
if(z < numParticles){
posizioni[i][j] = new PVector(i,j,0);
origin = new PVector(posizioni[i][j].x, 130+posizioni[i][j].y, 0);
PVector a = new PVector();
PVector v = new PVector();
PVector l = new PVector(random(width), random(height) , 0);
particles.add(new Particle(a,v,l, origin, random(0.05f, 2.0f)));
z++;
}
}
}
}
for (int h = 0; h<particles.size()-1; h++){
Particle prt = (Particle) particles.get(h);
prt.run();
PVector actualVel = prt.getVelocity();
PVector attrito = PVector.mult(actualVel,-0.05);
prt.add_force(attrito);
if(keyPressed) {
if (key == 'a' || key == 'A')
{
PVector origLoc = prt.getOrigin();
PVector diff = PVector.sub(origLoc,prt.getLocation());
diff.normalize();
float factor = 0.5f;
diff.mult(factor);
prt.setAcceleration(diff);
}
if (key == ' ' || key == ' ')
{
mm.finish();
}
}
if(mousePressed) {
PVector mouseLoc = new PVector(mouseX, mouseY, 0);
PVector diff = PVector.sub(mouseLoc,prt.getLocation());
diff.normalize();
float factor = 1.0f;
diff.mult(factor);
prt.setAcceleration(diff);
}
}
//mm.addFrame();
}
class Particle {
PVector or;
PVector loc;
PVector vel;
PVector acc;
float ms;
float distance;
Particle(PVector a, PVector v, PVector l, PVector o, float ms_) {
acc = a;
vel = v;
loc = l;
ms = ms_;
or = o;
}
void run() {
update();
render();
}
void update() {
vel.add(acc);
loc.add(vel);
acc = new PVector();
}
void render() {
stroke(1, 100, 0);
point(loc.x,loc.y);
}
void add_force(PVector force) {
force.div(ms);
vel.add(force);
}
float getMass() {
return ms;
}
PVector getLocation() {
return loc;
}
PVector getOrigin() {
return or;
}
PVector getVelocity() {
return vel;
}
void setLocation(PVector l){
loc = l;
}
void setAcceleration(PVector a){
acc = a;
}
}