xxxxxxxxxx
108
class particle {
constructor() {
this.position = createVector(width / 2, height / 2);
//this.velocity = p5.Vector.random2D();
// this.velocity = p5.Vector.fromAngle(random(0,PI/4));
this.velocity = createVector(0,0);
this.topSpeed = 1
// this.velocity.mult(5);
this.acceleration = createVector(0,0);
//this.topspeed = 10;
this.size = createVector(10, 10)
}
pushToMouse(){
}
applyForce(force) {
this.acceleration.add(force);
}
update() {
this.position.add(this.velocity);
this.position.x=this.position.x+(random(-3,3));
this.position.y=this.position.y+(random(-3,3));
this.velocity.limit(this.topspeed);
this.velocity.add(this.acceleration);
this.acceleration.mult(0,1);
}
mousePush(){
let ballClose1 = (((mouseX-this.position.x))+((mouseY-this.position.y)));
let mouseForce = createVector(ballClose1/400, ballClose1/400);
this.acceleration.add(mouseForce);
}
display() {
let t=0
t++
const r = random(t);
if (color<1){
colorhue=3
}
if (color>255){
colorhue=-1+(r)
}
color=color+colorhue+r
stroke(255)
fill (color, color/2, color/3, 200)
ellipse (this.position.x, this.position.y, this.size.x, this.size.y);
}
checkEdges() {
const r = randomGaussian();
let bounce = 0.7
if (this.position.x > width) {
this.velocity.x *= -bounce-(r/2);
this.position.x = width;
} else if (this.position.x < 0) {
this.velocity.x *= -bounce-(r/2);
this.position.x = 0;
}
if (this.position.y > height) {
this.velocity.y *= -bounce-(r/2);
this.position.y = height;
} else if (this.position.y < 0) {
this.velocity.y *= -bounce-(r/2);
this.position.y = 0;
}
}
ballGrowth(){
let ballClose = ((abs(mouseX-this.position.x))+(abs(mouseY-this.position.y)));
// s++
// if (s<=1000){
// s=1
// }
// let ballclose= 5*(sin(s))
// print(ballclose)
// ballclose = ballclose*(cos+1);
if (this.ballclose>=47){
this.size.x=5
this.size.y=5
}
else{
background (random(150,255),random(150,255), random(250,255), 1)
this.size.x=40-(ballClose/2)
this.size.y=40-(ballClose/2)
}
}
}