------------------------------------------------------------------- Generating a list of co-ordinates inside the Mandelbrot Set --------------------------------------------------------------------- Get values from cmdline (for interaction with Lisp)
offset := [val(command_line(1)), val(command_line(2))];
scale := val(command_line(3));
iterations := val(command_line(4));
-- get a list of image co-ordinates inside the bound
-- box of -2 to 2 on both axis
image := [];
for x in [offset(1)..(offset(1)+500)] loop;
for y in [offset(2)..(offset(2)+500)] loop;
image +:= [[x/scale, y/scale]];
end loop;
end loop;
-- Mandelbrot Set
M := {[(c(1)*scale)-offset(1),(c(2)*scale)-offset(2)] : c in image | forall num in {0..iterations} | cabs(pofc(c, num)) <= 2};
print(M);
----------------------------- Procedures ------------------------------- P(C) := z^2 + C
-- N iterations of P(C)
proc pofc(C, N);
z := [0, 0];
for x in [0..N] loop;
z := ctimes(z, z);
z(1) +:= C(1);
z(2) +:= C(2);
end loop;
return z;
end proc;
-- Complex Operator: Multiplication
proc ctimes(compa, compb);
outa := (compa(1) * compb(1)) - (compa(2) * compb(2));
outb := (compa(2) * compb(1)) + (compa(1) * compb(2));
return [outa, outb];
end proc;
-- Complex Operator: Absolute Value
proc cabs(comp);
return sqrt((comp(1) ** 2) + (comp(2) ** 2));
end proc;
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.