Created
December 15, 2010 23:36
-
-
Save johnciacia/742783 to your computer and use it in GitHub Desktop.
Sierpinski's Triangle IFS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment