diff --git a/apps/code/script_template.cpp b/apps/code/script_template.cpp index 8bbcf1d34..a9d352272 100644 --- a/apps/code/script_template.cpp +++ b/apps/code/script_template.cpp @@ -30,22 +30,17 @@ def fibo2(n): constexpr ScriptTemplate mandelbrotScriptTemplate("mandelbrot.py", R"(# This script draws a Mandelbrot fractal set # N_iteration: degree of precision import kandinsky -N_iteration = 10 -def drawMandlebrot(): +def mandelbrot(N_iteration): for x in range(320): for y in range(222): # Compute the mandelbrot sequence for the point c = (c_r, c_i) with start value z = (z_r, z_i) - z_r = 0 - z_i = 0 + z = complex(0,0) # Rescale to fit the drawing screen 320x222 - c_r = 2.7*x/319-2.1 - c_i = -1.87*y/221+0.935 + c = complex(3.5*x/319-2.5, -2.5*y/221+1.25) i = 0 - while (i < N_iteration) and ((z_r * z_r) + (z_i * z_i) < 4): + while (i < N_iteration) and abs(z) < 2: i = i + 1 - stock = z_r - z_r = z_r * z_r - z_i * z_i + c_r - z_i = 2 * stock * z_i + c_i + z = z*z+c # Choose the color of the dot from the Mandelbrot sequence rgb = int(255*i/N_iteration) col = kandinsky.color(int(rgb),int(rgb*0.75),int(rgb*0.25))