Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Sierpinski Triangle</title>
- </head>
- <body>
- <canvas id="sierpinski">
- Oops! Your browser does not support HTML5 Canvas.
- </canvas>
- <script type="text/javascript">
- width = 400;
- height = 400;
- sierpinski = document.getElementById ('sierpinski');
- sierpinski.width = width;
- sierpinski.height = height;
- context = sierpinski.getContext ('2d');
- context.fillStyle = "rgb(0,0,0)";
- (function (x, y) {
- rand = Math.random();
- if (rand > 0 && rand < 0.333) {
- x = (x + width)/2;
- y = y/2;
- } else if (rand >= 0.333 && rand < 0.666) {
- x = (x + width/2)/2;
- y = (y + height)/2;
- } else {
- x = x/2;
- y = y/2;
- }
- context.fillRect (x, y, 1, 1);
- setTimeout (arguments.callee, 5, x, y);
- }) (100, 100);
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment