mandel_canvas = {
let xmin = -2;
let xmax = 0.6;
let ymin = -1.3;
let ymax = 1.3;
let w = 0.5 * width;
let canvas = d3
.create('canvas')
.attr('width', w)
.attr('height', w);
draw_mandelbrot_set(canvas.node(), xmin, xmax, ymin, ymax);
let context = canvas.node().getContext("2d");
context.fillStyle = "#f30";
let ij = xy_to_ij([-1, 0], xmin, xmax, ymin, ymax, w);
context.fillRect(ij[0] + 1, ij[1] - 1, 3, 3);
const render = function(ij) {
let xy = ij_to_xy(ij, xmin, xmax, ymin, ymax, w);
draw_mandelbrot_set(canvas.node(), xmin, xmax, ymin, ymax);
context.fillRect(ij[0] + 1, ij[1] - 1, 3, 3);
d3.select(julia_svg)
.attr('c', ij_to_xy(ij, xmin, xmax, ymin, ymax, w))
.select('image')
.attr('xlink:href', generate_julia_im_url({ re: xy[0], im: xy[1] }));
c.html(`c = ${d3.format('.2f')(xy[0])} + ${d3.format('.2f')(xy[1])} i`);
};
let clicked = false;
canvas.on('mousedown', function() {
clicked = true;
render(d3.mouse(this));
});
canvas.on('mousemove', function() {
if (clicked) render(d3.mouse(this));
});
canvas.on('mouseup', function() {
clicked = false;
});
return canvas;
}