We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone
I need help to add interactivity to a work I've done, can you help me with this?
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
PVector force,friction;
float mass,r,distance,loc;
float maxForce, maxSpeed,strength;
int id,val;
color c;
float k = 0.02;
int age = 0;
int spawnAge = (int)random(80,120);
float minr = 0;
float maxr = 5.0;
boolean spawned = false;
Particle(float x, float y,int _id) {
mass = 0.1;
id = _id;
r = 0.1;
maxSpeed = 1;
maxForce = 10;
location = new PVector(constrain(x,r,width-r), constrain(y,r,height-r));
velocity = new PVector(0, 0);
acceleration = new PVector(0, 0);
}
void applyForce(PVector force) {
//PVector f = PVector.div(force, mass);
acceleration.add(force);
}
void update() {
velocity.add(acceleration);
velocity.limit(maxSpeed);
location.add(velocity);
acceleration.mult(0);
friction();
borders();
age+=1;
}
void friction(){
friction = velocity.copy();
friction.mult(-1);
friction.normalize();
friction.mult(k);
applyForce(friction);
}
void display() {
ellipse(location.x,location.y,r*2,r*2);
}
PVector attract(Particle p) {
force = PVector.sub(p.location,location);
distance = force.magSq();
distance = constrain(distance, 1.0, 5000.0);
force.normalize();
strength = (g) / (distance*4*PI);
force.mult(strength);n
return force;
}
void setRadius (PImage img){
loc = (int)location.x + (int)location.y*img.width;
//c= img.get((int)location.x,(int)location.y);
//c = img.pixels[int(loc)];
val = img.pixels[int(loc)] & 0xFF;
r= lerp(r,map(val,0.0,255.0,minr,maxr),0.01);
}
void borders() {
if ( location.x < r || location.x > width-r){
velocity.x = -velocity.x;
}
if ( location.y < r || location.y > height-r){
velocity.y = -velocity.y;
}
if (location.x> width-r) location.x = width-r;
if (location.x< r) location.x = r;
if (location.y> height-r) location.y = height-r;
if (location.y< r) location.y = r;
}
}
Answers
How to post in the processing forum.
Best is to hit ctrl-t in processing first before copy paste into the forum (https://forum.processing.org).
You can edit your post (click the small gear and the 'Edit').
How to format Code:
can you post the class Particle as well please ?
Still main code missing and class Grid
Where is
setup()
? Where isdraw()
?POST A COMPLETE SKETCH. POST IT ALL AT ONCE. POST IT IN ONE NEW POST. MAKE SURE IT RUNS.
Then tell us what is wrong with it! What does it do that you don't want it to do? What doesn't it do that you do want it to do?
While the above post of mine asks some great questions, if you want interaction, well, try adding a
mousePressed()
function. What do you want to happen when the mouse is pressed? Can you write code to do that thing? So where do you think you should put the code that you want to happen when the mouse is pressed?In fact, I do not know much about mousePressed, so I needed to join the forum. This is all I want to accidentally add points with the mousePressed function. But I will try.