Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // Creating variables
  2. var myX=300,myY=300,tX=100,tY=100;
  3. function distance(aX,aY,bX,bY){
  4. return Math.sqrt((aX-bX)*(aX-bX)+(aY-bY)*(aY-bY));
  5. }
  6.  
  7. function update() {
  8. myX+=(myX-tX)/distance(tX,tY,myX,myY);
  9. myY+=(myY-tY)/distance(tX,tY,myX,myY);
  10.  
  11. }
  12.  
  13. function draw() {
  14. // This is how you draw a rectangle
  15. context.fillRect(myX,myY,20,20);
  16. context.fillRect(tX,tY,10,10);
  17. };
  18.  
  19. function keyup(key) {
  20. // Show the pressed keycode in the console
  21. console.log("Pressed", key);
  22. };
  23.  
  24. function mouseup() {
  25. // Show coordinates of mouse on click
  26. console.log("Mouse clicked at", mouseX, mouseY);
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement