Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // Creating variables
  2. var w = 300, h=100;
  3. var angle = 0;
  4. var x = [], y = [];
  5. var x1 = [], y1 = [];
  6.  
  7. function update() {
  8. for (var i=0; i<4; ++i){
  9. x[i] = Math.cos(angle + Math.PI/2*i)/2;
  10. y[i] = Math.sin(angle + Math.PI/2*i)/2;
  11. if (i%2==0){x[i]*=w; y[i]*=w;}
  12. else{x[i]*=h; y[i]*=h;}
  13. }
  14. angle += 0.01;
  15. for (var i = 0; i<4; ++i){
  16. x1[i] = x[i] + x[(i+1)%4];
  17. y1[i] = y[i] + y[(i+1)%4];
  18. }
  19. }
  20.  
  21. function draw() {
  22. // This is how you draw a rectangle
  23. context.beginPath();
  24. for (var i=0; i<4; ++i){
  25. context.lineTo(x1[i] + 400, y1[i] + 300);
  26. }
  27. context.fill();
  28.  
  29. }
  30.  
  31. function keyup(key) {
  32. // Show the pressed keycode in the console
  33. console.log("Pressed", key);
  34. }
  35. function mouseup() {
  36. // Show coordinates of mouse on click
  37. console.log("Mouse clicked at", mouseX, mouseY);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement