Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. <canvas id="myCanvas" width="500" height="500"></canvas>
  2. <div class="fillMe"></div>
  3.  
  4. <style>
  5. #myCanvas {
  6. border: 1px solid #DDD;
  7. }
  8. .input, .input-once {
  9. font-size: 18px;
  10. }
  11.  
  12. </style>
  13. <script>
  14.  
  15. var c = document.getElementById("myCanvas");
  16. var ctx = c.getContext("2d");
  17.  
  18.  
  19. stacker+= 1;
  20. if (stacker > 360) {
  21. stacker = 0;
  22. }
  23.  
  24.  
  25. $(".fillMe").html(stacker);
  26.  
  27. toAng = stacker;
  28.  
  29. function rotateX(px, py, ang) {
  30. rx = (Math.cos(ang*(Math.PI/180))*px)+(-1*Math.sin(ang*(Math.PI/180))*py);
  31. ry = (Math.sin(ang*(Math.PI/180))*px)+(Math.cos(ang*(Math.PI/180))*py);
  32. return [rx, ry];
  33. }
  34.  
  35.  
  36.  
  37. //x' = x*cos q - y*sin q
  38.  
  39.  
  40. function rotateZ(px, py, ang) {
  41. rx = (Math.cos(ang*(Math.PI/180))*px)+(-1*Math.sin(ang*(Math.PI/180))*py);
  42. ry = (Math.sin(ang*(Math.PI/180))*px)+(Math.cos(ang*(Math.PI/180))*py);
  43. return [rx, ry];
  44. }
  45.  
  46. var tri1= {
  47. a:[50, 0],
  48. b:[100, 100],
  49. c:[0, 100]
  50. };
  51.  
  52.  
  53. ctx.fillStyle = "#ff0000";
  54. ctx.fillRect(10,10, 5,5);
  55. //ctx.fillRect(rotateX(10,10)[0], 10, 5, 5);
  56.  
  57. transOne = 0
  58. transTwo = stacker*0.01*toAng
  59. transThree = 0
  60.  
  61. ctx.fillStyle = "#ff0000";
  62. sec2x = rotateX(tri1.a[0], tri1.a[1], transOne)[0];
  63. sec2y = rotateX(tri1.a[0], tri1.a[1], transTwo)[1];
  64. lec2xy = rotateX(sec2x, sec2y, transThree);
  65.  
  66. ssec2x = rotateX(tri1.b[0], tri1.b[1], transOne)[0];
  67. ssec2y = rotateX(tri1.b[0], tri1.b[1], transTwo )[1];
  68. llec2xy = rotateX(ssec2x, ssec2y, transThree);
  69.  
  70. sssec2x = rotateX(tri1.c[0], tri1.c[1], transOne)[0];
  71. sssec2y = rotateX(tri1.c[0], tri1.c[1], transTwo )[1];
  72. lllec2xy = rotateX(sssec2x, sssec2y, transThree);
  73.  
  74. ctx.fillRect(200+lec2xy[0],200+lec2xy[1], 4, 4);
  75. ctx.fillStyle = "#00ff00";
  76. ctx.fillRect(200+llec2xy[0],200+llec2xy[1], 4, 4);
  77. ctx.fillStyle = "#0000ff";
  78. ctx.fillRect(200+lllec2xy[0],200+lllec2xy[1], 4, 4);
  79.  
  80. //ctx.fillRect(100+rotateX(tri1.b[0], tri1.b[1], toAng)[0], 100+rotateX(tri1.b[0], tri1.b[1], toAng)[1], 5, 5);
  81. //ctx.fillRect(100+rotateX(tri1.c[0], tri1.c[1], toAng)[0], 100+rotateX(tri1.c[0], tri1.c[1], toAng)[1], 5, 5);
  82.  
  83.  
  84.  
  85. /*
  86. ctx.fillStyle = "#0000ff";
  87. ctx.fillRect(tri2.a[0]+200, tri2.a[1]+200, 5, 5);
  88. ctx.fillRect(tri2.b[0]+200, tri2.b[1]+200, 5, 5);
  89. ctx.fillRect(tri2.c[0]+200, tri2.c[1]+200, 5, 5);
  90. */
  91.  
  92. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement