Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Creating variables
- var myX=300,myY=300,tX=100,tY=100;
- function distance(aX,aY,bX,bY){
- return Math.sqrt((aX-bX)*(aX-bX)+(aY-bY)*(aY-bY));
- }
- function update() {
- myX+=(myX-tX)/distance(tX,tY,myX,myY);
- myY+=(myY-tY)/distance(tX,tY,myX,myY);
- }
- function draw() {
- // This is how you draw a rectangle
- context.fillRect(myX,myY,20,20);
- context.fillRect(tX,tY,10,10);
- };
- function keyup(key) {
- // Show the pressed keycode in the console
- console.log("Pressed", key);
- };
- function mouseup() {
- // Show coordinates of mouse on click
- console.log("Mouse clicked at", mouseX, mouseY);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement