Created
September 30, 2022 12:09
-
-
Save rusith/ab19e1da8530c95ef3580d3c6dd6d0f9 to your computer and use it in GitHub Desktop.
Mandelbrot.html
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> | |
| <canvas id="display" width="1000" height="1000"></canvas> | |
| <script> | |
| const canvas = document.getElementById('display') | |
| .getContext('2d'); | |
| const atom = (x, y, c) => { | |
| canvas.fillStyle = c; | |
| canvas.fillRect(x, y, 3, 3) | |
| } | |
| for (let y = 1; y < 1000; y++) { | |
| for (let x = 1; x < 1000; x++) { | |
| const dx = (x - 500) / 10000 - 0.23; | |
| const dy = (y - 500) / 10000 - 0.68; | |
| let a = dx; | |
| let b = dy | |
| for (let t = 1; t < 200; t++) { | |
| const d = (a * a) - (b * b) + dx | |
| b = 2 * (a * b) + dy | |
| a = d | |
| const h = d > 200 | |
| if (h) { | |
| atom(x, y, `rgb(${t*3}, ${t}, ${t* 0.5} )`); | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment