Skip to content

Instantly share code, notes, and snippets.

@LuxXx
Created April 8, 2017 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuxXx/6ed3ac8081d606e79c50e1901a9ae961 to your computer and use it in GitHub Desktop.
Save LuxXx/6ed3ac8081d606e79c50e1901a9ae961 to your computer and use it in GitHub Desktop.
the sierpinski carpet
<!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