Estoy tratando de crear el conjunto de Mandelbrot y otros Conjuntos de Julia en JavaScript para un proyecto escolar. Revisé mi código y parece que sigue la fórmula correctamente, pero mi conjunto de Mandelbrot no se dibuja correctamente. ¿Algún consejo sobre lo que está mal?
<!DOCTYPE html> <html> <head> </head> <body> <canvas id="canvas" width="600" height="600" style="background-color: black;"></canvas> <script> //center the canvas at the coordinate plane var canvas = document.getElementById("canvas"); const width = canvas.width; const height = canvas.height; const scalingFactor = width / 4; var graphics = canvas.getContext("2d"); function mandelbrotDraw(iterations) { //multiply by 4 in order to get the scaling right for (var i = 0; i <= width; i++) { for (var j = 0; j <= height; j++) { var x = 0; var y = 0; var re = (i - width / 2) / scalingFactor; var im = (j - height / 2) / scalingFactor; var k = 0; while (x * x + y * y <= 4 && k < iterations) { x = x * x - y * y + re; y = 2 * x * y + im; k++; } if (k < iterations) { graphics.fillStyle = "black"; graphics.fillRect(i, j, 1, 1); } else { graphics.fillStyle = "white"; graphics.fillRect(i, j, 1, 1); } } } } mandelbrotDraw(25); </script> </body> </html>