X-Git-Url: https://git-public.kairo.at/?p=mandelbrot.git;a=blobdiff_plain;f=xulapp%2Fchrome%2Fmandelbrot%2Fcontent%2Fmandelbrot.js;h=02654971e238b88020bf35a64a7046f7c1132de7;hp=7762362591c4664798a8f9344df9865b91d59fae;hb=eceff1c913ed3ce42776db2b5b1cf69e44f0b921;hpb=6403d662069799da869e77b1a426a29ccbc85a44 diff --git a/xulapp/chrome/mandelbrot/content/mandelbrot.js b/xulapp/chrome/mandelbrot/content/mandelbrot.js index 7762362..0265497 100644 --- a/xulapp/chrome/mandelbrot/content/mandelbrot.js +++ b/xulapp/chrome/mandelbrot/content/mandelbrot.js @@ -55,34 +55,75 @@ function drawImage() { document.getElementById("statusLabel").value = document.getElementById("mbrotBundle").getString("statusDrawing"); + let Cr_min = -2.0; + let Cr_max = 1.0; + try { + Cr_min = parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_min")); + Cr_max = parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_max")); + } + catch (e) { } + if ((Cr_min < -2) || (Cr_min > 2) || + (Cr_max < -2) || (Cr_max > 2) || (Cr_min >= Cr_max)) { + Cr_min = -2.0; Cr_max = 1.0; + } + gPref.setCharPref("mandelbrot.last_image.Cr_min", Cr_min); + gPref.setCharPref("mandelbrot.last_image.Cr_max", Cr_max); + + let Ci_min = -1.5; + let Ci_max = 1.5; + try { + Ci_min = parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_min")); + Ci_max = parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_max")); + } + catch (e) { } + if ((Ci_min < -2) || (Ci_min > 2) || + (Ci_max < -2) || (Ci_max > 2) || (Ci_min >= Ci_max)) { + Ci_min = -2.0; Ci_max = 1.0; + } + gPref.setCharPref("mandelbrot.last_image.Ci_min", Ci_min); + gPref.setCharPref("mandelbrot.last_image.Ci_max", Ci_max); + let iterMax = gPref.getIntPref("mandelbrot.iteration_max"); let algorithm = gPref.getCharPref("mandelbrot.use_algorithm"); - context.fillStyle = "rgb(255, 255, 255)"; + let iWidth = 0; + try { + iWidth = gPref.getIntPref("mandelbrot.image.width"); + } + catch (e) { } + if ((iWidth < 10) || (iWidth > 5000)) { + iWidth = 300; + gPref.setIntPref("mandelbrot.image.width", iWidth); + } + let iHeight = 0; + try { + iHeight = gPref.getIntPref("mandelbrot.image.height"); + } + catch (e) { } + if ((iHeight < 10) || (iHeight > 5000)) { + iHeight = 300; + gPref.setIntPref("mandelbrot.image.height", iHeight); + } + + canvas.width = iWidth; + canvas.height = iHeight; + + context.fillStyle = "rgba(255, 255, 255, 127)"; context.fillRect(0, 0, canvas.width, canvas.height); gStartTime = new Date(); - drawLine(0, canvas, context, iterMax, algorithm); + drawLine(0, [Cr_min, Cr_max, Ci_min, Ci_max], + canvas, context, iterMax, algorithm); } -function drawLine(line, canvas, context, iterMax, algorithm) { - let Cr_min = -2.0; - let Cr_max = 1.0; - try { - Cr_min = gPref.getCharPref("mandelbrot.last_image.Cr_min"); - Cr_max = gPref.getCharPref("mandelbrot.last_image.Cr_max"); - } - catch (e) { } +function drawLine(line, dimensions, canvas, context, iterMax, algorithm) { + let Cr_min = dimensions[0]; + let Cr_max = dimensions[1]; let Cr_scale = Cr_max - Cr_min; - let Ci_min = -1.5; - let Ci_max = 1.5; - try { - Cr_min = gPref.getCharPref("mandelbrot.last_image.Ci_min"); - Cr_max = gPref.getCharPref("mandelbrot.last_image.Ci_max"); - } - catch (e) { } + let Ci_min = dimensions[2]; + let Ci_max = dimensions[3]; let Ci_scale = Ci_max - Ci_min; let pixels = []; @@ -95,7 +136,7 @@ function drawLine(line, canvas, context, iterMax, algorithm) { context.putImageData({width: canvas.width, height: pixels.length/4/canvas.width, data: pixels}, 0, line); if (img_y < canvas.height) - setTimeout(drawLine, 0, img_y, canvas, context, iterMax, algorithm); + setTimeout(drawLine, 0, img_y, dimensions, canvas, context, iterMax, algorithm); else EndCalc(); }