Guest User

Untitled

a guest
Jan 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. <style id="jsbin-css">
  8. canvas {
  9. width: 100%;
  10. height: 100%
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <canvas id="canvas"></canvas>
  16. <script id="jsbin-javascript">
  17. var canvas = document.getElementById("canvas");
  18. var ctx = canvas.getContext('2d');
  19. canvas.width = window.innerWidth;
  20. canvas.height = window.innerHeight;
  21. ctx.fillStyle = "red";
  22. var s = 1;
  23. var d = 0;
  24. setInterval(function() {
  25. ctx.clearRect(0, 0, canvas.width, canvas.height);
  26. d+=0.1;
  27. s = Math.sin(d)/2+0.5;
  28. for(var t=-Math.PI; t<Math.PI; t+=Math.PI/36) {
  29. var x = (1-s)*Math.cos(t)+s*Math.cos(t)*(1/Math.max(Math.abs(Math.sin(t)),Math.abs(Math.cos(t))));
  30. var y = (1-s)*Math.sin(t)+s*Math.sin(t)*(1/Math.max(Math.abs(Math.sin(t)),Math.abs(Math.cos(t))));
  31. ctx.fillRect(canvas.width/2+x*100, canvas.height/2+y*100, 5, 5);
  32. }
  33. }, 1000/30);
  34. </script>
  35.  
  36.  
  37. <script id="jsbin-source-css" type="text/css">canvas {
  38. width: 100%;
  39. height: 100%
  40. }</script>
  41.  
  42. <script id="jsbin-source-javascript" type="text/javascript">
  43. var canvas = document.getElementById("canvas");
  44. var ctx = canvas.getContext('2d');
  45. canvas.width = window.innerWidth;
  46. canvas.height = window.innerHeight;
  47. ctx.fillStyle = "red";
  48. var s = 1;
  49. var d = 0;
  50. setInterval(function() {
  51. ctx.clearRect(0, 0, canvas.width, canvas.height);
  52. d+=0.1;
  53. s = Math.sin(d)/2+0.5;
  54. for(var t=-Math.PI; t<Math.PI; t+=Math.PI/36) {
  55. var x = (1-s)*Math.cos(t)+s*Math.cos(t)*(1/Math.max(Math.abs(Math.sin(t)),Math.abs(Math.cos(t))));
  56. var y = (1-s)*Math.sin(t)+s*Math.sin(t)*(1/Math.max(Math.abs(Math.sin(t)),Math.abs(Math.cos(t))));
  57. ctx.fillRect(canvas.width/2+x*100, canvas.height/2+y*100, 5, 5);
  58. }
  59. }, 1000/30);</script></body>
  60. </html>
Add Comment
Please, Sign In to add comment