Skip to content

Commit

Permalink
Ready: Identify when mouse is clicked inside the arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
marianaviro committed May 3, 2018
1 parent 1e062e6 commit e1bd501
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions sketch1.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,32 @@ var firstPrinciple = function(s) {
}

s.mouseClicked = function() {
var mx = s.windowWidth - x;
var my = s.windowHeight - y;

//Check if the mouse is inside the arrow's rectangle
// var mx = s.windowWidth - x;
// var my = s.windowHeight - y;
var dx = Math.abs(s.mouseX - s.windowWidth + x);
var dy = Math.abs(s.mouseY - s.windowHeight + y);
if( dx < 20 && dy < 20) {
var dx = s.mouseX - mx;
var dy = s.mouseY - my;
if(0 < dx && dx < 20 && 0 < dy && dy < 20) {
s.down();
} else {
//Check if the mouse is inside the arrow's left triangle
var lx = Math.abs(s.mouseX - mx + 10);
var ly = Math.abs(s.mouseY - my - 20);
if(lx < 20 && ly < 20 && lx > ly) {
console.log('entro izq');
s.down();
} else {
//Check if the mouse is inside the arrow's right triangle
var rx = 20 - Math.abs(s.mouseX - mx - 10);
var ry = Math.abs(s.mouseY - my - 20);
if(rx < 20 && ry < 20 && rx > ry) {
console.log('entro der');
s.down();
}
}
}
}


}

var one = new p5(firstPrinciple, 'one');

0 comments on commit e1bd501

Please sign in to comment.