Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvised indentation, Added comments, well structured code, Reduced LOC #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 84 additions & 90 deletions Tricks/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,118 +9,112 @@
};

var eye2 = {
x: 382 ,
y: 210

x: 382 ,
y: 210
};

//You can also use querySelector to get the element either with Id or Class name...
//or below statement query Selector can be used as...document.querySelector("ctx").onmousemove = function()....

document.getElementById("ctx").onmousemove = function(mouse){
mouseX = mouse.clientX - document.getElementById("ctx").getBoundingClientRect().left ;
mouseY = mouse.clientY - document.getElementById("ctx").getBoundingClientRect().top ;
mouseX = mouse.clientX - document.getElementById("ctx").getBoundingClientRect().left ;
mouseY = mouse.clientY - document.getElementById("ctx").getBoundingClientRect().top ;
}

}
updateEyes = function(){

ctx.clearRect(0 , 0 , 500 , 450);

updateEyes = function(){
ctx.beginPath();
ctx.arc(100 , 200 , 30 , 0 , 2*Math.PI);
ctx.stroke();

ctx.clearRect(0 , 0 , 500 , 450);

ctx.beginPath();
ctx.arc(100 , 200 , 30 , 0 , 2*Math.PI);
ctx.stroke();

ctx.beginPath();
ctx.arc(400 , 200 , 30 , 0 , 2*Math.PI);
ctx.stroke();

ctx.beginPath();
ctx.arc(eye1.x , eye1.y , 14 , 0 ,2*Math.PI);
ctx.fill();

ctx.beginPath();
ctx.arc(eye2.x , eye2.y , 14 , 0 ,2*Math.PI);
ctx.fill();

if(mouseX < eye1.x && mouseY < eye1.y - 30 ){

eye1.y = 190 ;
eye2.y = 190 ;
eye1.x = 82;
eye2.x = 382;
}

else if(mouseX< eye1.x && mouseY >= eye1.y - 30 && mouseY < eye1.y + 30){

eye1.y = 200 ;
eye2.y = 200 ;
eye1.x = 80 ;
eye2.x = 380 ;
}

else if(mouseX < eye1.x - 30 && mouseY >= eye1.y + 30){
eye1.y = 215 ;
eye2.y = 215 ;
eye1.x = 82 ;
eye2.x = 382;
}

else if(mouseX > eye1.x && mouseX <= eye2.x + 30 && mouseY < eye1.y - 30 ){

eye1.y = 190 ;
eye1.x = 120 ;
eye2.y = 190 ;
eye2.x = 382 ;
}

else if(mouseX > 100 && mouseX < 400 && mouseY > 170 && mouseY < 230){

eye1.x = 120 ;
eye1.y = 200 ;
eye2.x = 378 ;
eye2.y = 200;
}
ctx.beginPath();
ctx.arc(400 , 200 , 30 , 0 , 2*Math.PI);
ctx.stroke();

else if(mouseX >100 && mouseX < 400 && mouseY > 230){
ctx.beginPath();
ctx.arc(eye1.x , eye1.y , 14 , 0 ,2*Math.PI);
ctx.fill();

eye1.x = 115 ;
eye1.y = 215 ;
eye2.x = 380 ;
eye2.y = 215;
}
ctx.beginPath();
ctx.arc(eye2.x , eye2.y , 14 , 0 ,2*Math.PI);
ctx.fill();

else if(mouseX > 400 && mouseY < 200 ){
if(mouseX < eye1.x && mouseY < eye1.y - 30 ){

eye1.x = 120 ;
eye1.y = 190 ;
eye2.x = 415 ;
eye2.y = 188;
}
eye1.y = 190 ;
eye2.y = 190 ;
eye1.x = 82;
eye2.x = 382;
}

else if(mouseX > 400 && mouseY > 200 && mouseY < 300){
eye1.x = 122;
eye1.y = 200 ;
eye2.x = 420 ;
eye2.y = 200;
}
else if(mouseX< eye1.x && mouseY >= eye1.y - 30 && mouseY < eye1.y + 30){

else if(mouseX > 400 && mouseY > 300){
eye1.x = 120 ;
eye1.y = 215 ;
eye2.x = 418 ;
eye2.y = 215
}
eye1.y = 200 ;
eye2.y = 200 ;
eye1.x = 80 ;
eye2.x = 380 ;
}

else if(mouseX < eye1.x - 30 && mouseY >= eye1.y + 30){

eye1.y = 215 ;
eye2.y = 215 ;
eye1.x = 82 ;
eye2.x = 382;
}

else if(mouseX > eye1.x && mouseX <= eye2.x + 30 && mouseY < eye1.y - 30 ){

eye1.y = 190 ;
eye1.x = 120 ;
eye2.y = 190 ;
eye2.x = 382 ;
}

}
else if(mouseX > 100 && mouseX < 400 && mouseY > 170 && mouseY < 230){

eye1.x = 120 ;
eye1.y = 200 ;
eye2.x = 378 ;
eye2.y = 200;
}


else if(mouseX >100 && mouseX < 400 && mouseY > 230){

eye1.x = 115 ;
eye1.y = 215 ;
eye2.x = 380 ;
eye2.y = 215;
}

else if(mouseX > 400 && mouseY < 200 ){

eye1.x = 120 ;
eye1.y = 190 ;
eye2.x = 415 ;
eye2.y = 188;
}

else if(mouseX > 400 && mouseY > 200 && mouseY < 300){
eye1.x = 122;
eye1.y = 200 ;
eye2.x = 420 ;
eye2.y = 200;
}

else if(mouseX > 400 && mouseY > 300){
eye1.x = 120 ;
eye1.y = 215 ;
eye2.x = 418 ;
eye2.y = 215
}

}

setInterval(updateEyes, 40);