Guest User

Untitled

a guest
Jul 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Sierpinski Triangle</title>
  5. </head>
  6.  
  7. <body>
  8.  
  9. <canvas id="sierpinski">
  10. Oops! Your browser does not support HTML5 Canvas.
  11. </canvas>
  12.  
  13. <script type="text/javascript">
  14. width = 400;
  15. height = 400;
  16.  
  17. sierpinski = document.getElementById ('sierpinski');
  18. sierpinski.width = width;
  19. sierpinski.height = height;
  20.  
  21. context = sierpinski.getContext ('2d');
  22. context.fillStyle = "rgb(0,0,0)";
  23.  
  24. (function (x, y) {
  25. rand = Math.random();
  26.  
  27. if (rand > 0 && rand < 0.333) {
  28. x = (x + width)/2;
  29. y = y/2;
  30. } else if (rand >= 0.333 && rand < 0.666) {
  31. x = (x + width/2)/2;
  32. y = (y + height)/2;
  33. } else {
  34. x = x/2;
  35. y = y/2;
  36. }
  37.  
  38. context.fillRect (x, y, 1, 1);
  39.  
  40. setTimeout (arguments.callee, 5, x, y);
  41.  
  42. }) (100, 100);
  43.  
  44.  
  45. </script>
  46.  
  47. </body>
  48. </html>
Add Comment
Please, Sign In to add comment