Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Note: For Animate Mickey to Eat the Cheese (filename: animatemickey.html and animatemickey.js ) Please follow the instructions carefully and complete all of the steps. When
Note: For
(filename: animatemickey.html and animatemickey.js)
Please follow the instructions carefully and complete all of the steps.
mickeyAngle = Math.atan2((cheeseY - mickeyY), (cheeseX - mickeyX));
mickeyX += mickeyDistance * Math.cos(-mickeyAngle); mickeyY -= mickeyDistance * Math.sin(-mickeyAngle);
Source code: (Javascript) function drawCheese(x,y) { ctx.save(); // move to the position (x,y) ctx.translate(x,y); ctx.beginPath(); ctx.fillStyle = "yellow"; // draw the triangle ctx.lineTo(-30,20); ctx.lineTo(20,0); ctx.lineTo(-30,-20); ctx.lineTo(-30,20); ctx.fill(); // draw the four circles ctx.fillStyle = "orange"; ctx.beginPath(); ctx.arc(2,1,4,0,2*Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(-18,6,4,0,2*Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(-10,6,4,0,2*Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(-20,-5,4,0,2*Math.PI); ctx.fill(); ctx.restore(); } function drawMickey(x,y) { ctx.save(); // move to the position (x,y) ctx.translate(x,y); // draw the nose ctx.beginPath(); ctx.arc(0,0,2,0,2*Math.PI); ctx.fill(); // draw the triangle ctx.beginPath(); ctx.lineTo(0,0); ctx.lineTo(-20,10); ctx.lineTo(-20,-10); ctx.lineTo(0,0); ctx.stroke(); // draw the ears ctx.fillStyle = "white"; ctx.beginPath(); ctx.arc(-20,-10,5,0,2*Math.PI); ctx.fill(); ctx.stroke(); ctx.beginPath(); ctx.arc(-20,10,5,0,2*Math.PI); ctx.fill(); ctx.stroke(); // draw the eyes ctx.fillStyle = "black"; ctx.beginPath(); ctx.arc(-14,-4,2,0,2*Math.PI); ctx.fill(); ctx.beginPath(); ctx.arc(-14,4,2,0,2*Math.PI); ctx.fill(); // draw the whiskers ctx.beginPath(); ctx.lineTo(-4,-2); ctx.lineTo(-4,-10); ctx.lineTo(-4,-2); ctx.lineTo(0,-8); ctx.lineTo(-4,-2); ctx.stroke(); ctx.beginPath(); ctx.lineTo(-4,2); ctx.lineTo(-4,10); ctx.lineTo(-4,2); ctx.lineTo(0,8); ctx.lineTo(-4,2); ctx.stroke(); ctx.restore(); } var dist = 0; var x1=300,y1=300; var x2=-10,y2=-10; function calcDist() { return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } function canvasClicked(evt) { x2=evt.x; y2=evt.y; draw(); } function canvasKeyDown(evt) { if(evt.keyCode==39) x1 = x1 + 10; if(evt.keyCode==38) y1 = y1 - 10; if(evt.keyCode==37) x1 = x1 - 10; if(evt.keyCode==40) y1 = y1 + 10; draw(); } function draw() { ctx.clearRect(0,0,600,600); drawMickey(x1,y1); dist = calcDist(); if(dist>15) { if(x2>=0 && y2>=0) drawCheese(x2,y2); } else { x2=-10; y2=-10; } } function setup() { var canvas = document.getElementById('surface'); ctx = canvas.getContext('2d'); // add the events to canvas canvas.addEventListener('click', canvasClicked, false); window.addEventListener('keydown', canvasKeyDown, true); // draw mickey & the cheese draw(); }
(filename: animatestreet.html and animatestreet.js) Implement the following steps to animate the street. (For this question you may use any pictures you want)
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started