var al = [];
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background('#fff');
//닷
stroke('rgb(237, 34, 93)');
strokeWeight(2);
for(var i=0; i<width; i=i+20) {
for(var j=0; j<height; j=j+20) {
point(i, j);
}
}
strokeWeight(1);
al.push(new Rays());
for( var i = 0; i < al.length; i++ ) {
var r = al[i];
r.applyForce(new p5.Vector(random(0.5, 0.5), random(0.5, 0.5)));
r.update();
r.render();
if(r.isDead())
al.shift();
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function Rays() {
this.counter = 0;
this.position = new p5.Vector(mouseX,mouseY );
this.velocity = new p5.Vector(0, 0);
this.acceleration = new p5.Vector(0, 0);
this.lifeSpan = 3;
}
Rays.prototype.applyForce = function(force) {
acceleration = force;
}
Rays.prototype.update = function() {
this.velocity.add(this.acceleration);
this.position.add(this.velocity);
this.lifeSpan -= 0.04;
}
Rays.prototype.render = function() {
var c = color('rgba(237, 34, 93,' + this.lifeSpan + ')');
stroke( c );
line(this.position.x, this.position.y, pmouseX, pmouseY);
}
Rays.prototype.isDead = function() {
if( this.lifeSpan < 0.001 )
return true;
else
return false;
}
What’s on our mind?
Collection of articles, design, site, and resources made by designers and publisher
@Menu View
ad