class Particle {
PVector or;
PVector loc;
PVector vel;
PVector acc;
float ms;
float distance;
float timer;
Particle(PVector a, PVector v, PVector l, PVector o, float ms_) {
acc = a;
vel = v;
loc = l;
ms = ms_;
or = o;
timer = random(400,500);
}
void run() {
update();
render();
}
void update() {
vel.add(acc);
loc.add(vel);
acc = new PVector();
timer -= 1.0;
}
void render() {
stroke(1, 100, 0, 100);
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;
}
boolean dead() {
if (timer <= 0) {
return true;
} else {
return false;
}
}
}
import processing.video.*;
MovieMaker mm;
String s = "";
String sCopy = s;
float xoff = 0.0f;
float w;
float h = 50;
float fpx = 40;
float fpy = 60;
int tempw;
PVector[][] posizioni;
PVector origin;
ArrayList particles = new ArrayList();
void setup()
{
size(640, 400);
colorMode(HSB, 360, 100, 100, 100);
PFont font = loadFont("Standard0757-8.vlw");
textFont(font, 24);
posizioni = new PVector[width][height];
//mm = new MovieMaker(this, width, height, "drawing.mov", 30, MovieMaker.VIDEO, MovieMaker.LOSSLESS);
}
void draw() {
background(1, 0, 100, 100);
fill(1, 100, 100, 1);
text(s, 40, 100);
fill(1, 100, 100, 0);
text(sCopy, 40, 50);
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);
PVector origLoc = prt.getOrigin();
PVector diff = PVector.sub(origLoc,prt.getLocation());
diff.normalize();
diff.mult(0.30f);
prt.setAcceleration(diff);
if(prt.dead()){
particles.remove(h);
}
if(mousePressed) {
PVector mouseLoc = new PVector(mouseX, mouseY, 0);
PVector dif2 = PVector.sub(mouseLoc,prt.getLocation());
dif2.normalize();
dif2.mult(1.0f);
prt.setAcceleration(dif2);
}
}
//print(get(mouseX, mouseY) + " ");
//mm.addFrame();
}
void findScanArea(String ss){
w = int(textWidth(ss));
}
void scan(){
for(int i=int(fpx); i<int(fpx+w); i++) {
for(int j = int(fpy); j<int(fpy+h); j++) {
if(get(i,j) == -258){
posizioni[i][j] = new PVector(i,j,0);
origin = new PVector(posizioni[i][j].x, 100 + 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.5f, 1.0f)));
}
}
}
}
void keyPressed(){
//if(s.length() <= 35){
if(textWidth(s) <= 560){
s += key;
fpx += tempw;
sCopy = s.substring(s.length()-1);
tempw = int(textWidth(sCopy));
}
else {
s = "";
sCopy = s;
fpx = 40;
tempw = int(textWidth(sCopy));
}
if((key == DELETE) || (key == BACKSPACE))
{
mm.finish();
}
}
void keyReleased(){
findScanArea(s);
scan();
}