Last active
April 7, 2022 17:18
-
-
Save christophergorexyz/afb76b36ae21b34b0cadfbaf35527d11 to your computer and use it in GitHub Desktop.
an implementation of the sierpenski carpet
This file contains hidden or 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
| <html> | |
| <head> | |
| <title>sierpenski</title> | |
| </head> | |
| <body> | |
| <canvas id="sierpenski" width="2187" height="2187"></canvas> | |
| <script> | |
| let canvas = document.getElementById('sierpenski'); | |
| let context = canvas.getContext('2d'); | |
| context.fillStyle = 'black'; | |
| function sierpinski(size, x, y) { | |
| if (size > 1) { | |
| sierpinski(size / 3, x, y); | |
| sierpinski(size / 3, x + 2 * size / 3, y); | |
| sierpinski(size / 3, x + size / 3, y + size / 3); | |
| sierpinski(size / 3, x, y + 2 * size / 3); | |
| sierpinski(size / 3, x + 2 * size / 3, y + 2 * size / 3); | |
| } | |
| else { | |
| return context.fillRect(x, y, 1, 1); | |
| } | |
| } | |
| sierpinski(3 ** 7, 0, 0); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment