void keyPressed() { setup(); }
class Sable {
float x,y,v,r;
Sable(float x_, float y_, float r_){
x = x_;
y = y_;
v = 17;
r = r_;
}
void update(){
float distance = dist(mouseX,mouseY,x,y);
if (distance < 14 ){
if (mousePressed){
float radians = atan2(mouseY-y,mouseX-x)+PI;
x = x + v * cos(radians);
y = y + v * sin(radians);
}
}
x = constrain (x,r/2,width-r/2);
y = constrain(y,r/2,height-r/2);
noStroke();
fill(242,238,110);
ellipse(x,y,r,r);
}
}
Sable sable;
ArrayList sables;
void setup() {
size(256,256);
sables = new ArrayList();
for (int i = 0; i < 10000; i++) {
sables.add(new Sable (random(width),random(height),0.5));
}
}
void draw() {
background (162,158,26);
for ( int i = 0 ; i < sables.size(); i ++){
Sable sable = (Sable) sables.get(i);
sable.update();
}
}
Hey hi again !
This is a little something to paint. it is like if you're painting into the sand ! Hold the mouse button to draw.
If someone know how I should implement a code to restart the skecth when the user press a key, plz answer me ! THX
Carl