xxxxxxxxxx
/**
Copyright 2017 Tianyue Wu ALL RIGHTS RESERVED
**/
var posX,posY;
function Particle(posX,posY){
this.speed = 1;
//this.color = color(150,85,85,50);
this.posX = posX;
this.posY = posY;
//this.lifespan = 255;
}
Particle.prototype = {
constructor: Particle,
bounce : function(){
if(this.posY != mouseY || this.posX != mouseX){
if(mouseX > this.posX){
this.posX += this.speed;
}else{
this.posX -= this.speed;
}
if(mouseY > this.posY){
this.posY +=this.speed;
}else{
this.posY -= this.speed;
}
}
if(this.lifespan <= 0){
}
// this.lifespan--;
}
};
//var particles = [];
var particle;
function setup() {
createCanvas(500,500);
frameRate(50);
colorMode(HSB,360,100,100,255);
particle = new Particle(mouseX,mouseY);
//particles[] = new Particle(mouseX,mouseY);
//particles.push(new Particle(mouseX,mouseY));
//particles.length-1;
//particles.splice(particles.length-1,1);
}
function draw() {
//background(0,0,90,4);
noStroke();
translate(particle.posX,particle.posY);
balls();
}
//function mousePressed(){
//particle.push(new Particle(mouseX,mouseY));
//particle = new Particle(mouseX,mouseY);
//}
function balls(){
var i,j;
var from = color(0,85,85);//particle.lifespan
var to = color(270,85,85);// particle.lifespan
var amt = map(mouseX,0,500,0,1);
var lerpedCol = lerpColor(from,to,amt);//
for(i = -50;i < 50;i+=10){
for(j = -50;j < 50;j+=10){
fill(lerpedCol);
noStroke();
ellipse(i,j,2,2);
}
}
particle.bounce();
}