Skip to content

Instantly share code, notes, and snippets.

@terremoth
Created October 15, 2022 12:34
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 terremoth/8318583b0cfd74d9084b6f592608c143 to your computer and use it in GitHub Desktop.
Save terremoth/8318583b0cfd74d9084b6f592608c143 to your computer and use it in GitHub Desktop.
Mandelbrot Algorithm
let canvas = document.getElementById('universe').getContext('2d')
let atom = (x,y,c) => {canvas.fillStyle = c; canvas.fillRect(x,y,3,3)};
window.CP.PenTimer.MAX_TIME_IN_LOOP_WO_EXIT = 10000;
for (y=1; y < 1000; y++) {
for (x=1; x < 1000; x++) {
dx = (x-500)/200
dy = (y-500)/200
a = dx
b = dy
for (t = 1; t < 200; t++) {
d = (a*a) - (b*b) + dx
b = 2*(a*b) + dy
a = d
H = d > 200
if (H) {
atom(x,y, 'rgb('+t*5+','+t*2+','+ t*0.9 +')');
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment