Created
April 8, 2017 18:19
-
-
Save LuxXx/6ed3ac8081d606e79c50e1901a9ae961 to your computer and use it in GitHub Desktop.
the sierpinski carpet
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> | |
<meta charset="utf-8"> | |
<title>Sierpinski</title> | |
</head> | |
<body> | |
<canvas id="canvas" width="1000" height="1000" style="border:1px solid #FF0000;"></canvas> | |
<script type="text/javascript"> | |
let c = document.getElementById('canvas'); | |
let ctx = c.getContext('2d'); | |
let ds = ((x, y, s) => { | |
ctx.rect(x, y, s, s); | |
ctx.stroke(); | |
}); | |
let dsc = ((x, y, s) => { | |
if (s < 30) return; | |
s = s / 3; | |
ds(x + s, y + s, s); | |
dsc(x, y, s); | |
dsc(x + s, y, s); | |
dsc(x + 2*s, y, s); | |
dsc(x, y + s, s); | |
dsc(x, y + 2*s, s); | |
dsc(x + 2*s, y + s, s); | |
dsc(x + 2*s, y + 2*s, s); | |
dsc(x + s, y + 2*s, s); | |
}); | |
dsc(0,0, 1000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment