xxxxxxxxxx
67
let hearts = [];
function setup() {
createCanvas(400, 400);
}
function doubleClicked(){
let z;
let h = new Heart (mouseX, mouseY,z);
hearts.push(h);
}
function mouseClicked(){
for (let i = hearts.length - 1; i >= 0; i--){
if(hearts[i].contains(mouseX,mouseY)){
hearts.splice(i,1);
}
}
}
function draw() {
background(220);
textSize(16);
text('Double click to feel my heartbeat ///w///',10,30);
text('Click to kill my heart(s) QAQ',10,50);
text('Press "F" to show ____________',10,70);
if (keyIsPressed === true) {
text(' Respect (^^ゞ',140,70);
}
for (let heart of hearts){
heart.show();
heart.beat();
}
}
class Heart{
constructor(x,y,z,angle){
this.x = x;
this.y = y;
this.z = z;
this.angle = 0;
}
show(){
beginShape();
vertex(this.x, this.y);
bezierVertex(this.x - this.z / 2, this.y - this.z / 2, this.x - this.z, this.y + this.z / 3, this.x, this.y + this.z);
bezierVertex(this.x + this.z, this.y + this.z / 3, this.x + this.z / 2, this.y - this.z / 2, this.x, this.y);
endShape(CLOSE);
}
beat(){
this.z = sin(this.angle) * 10 + 50;
this.angle = this.angle + 0.05;
}
contains(px,py){
let d = dist(px,py,this.x,this.y);
if (d<this.z){
return true;
} else {
return false;
}
}
}