diff --git a/juliabrot-zoom.ipynb b/juliabrot-zoom.ipynb index 1c0837a..d2fce17 100644 --- a/juliabrot-zoom.ipynb +++ b/juliabrot-zoom.ipynb @@ -186,7 +186,7 @@ "# Change some of the preview grid settings, for example size. Fractal will generate below cell\n", "# Max dimensions are 16K x 16K, beware PS memory is limited and large images may have issues when coloring\n", "# Note: cannot override kernel_mode unless overlay is reloaded!\n", - "big_grid.set_size(1920,1080)\n", + "big_grid.set_size(1920, 1080)\n", "big_grid.settings.max_iterations = int(jui.iter_slider.value)\n", "big_tile = jui.juliabrot.compute(big_grid.tile_list[0], True)" ] @@ -282,8 +282,15 @@ "outputs": [], "source": [ "# Create the canvas, push the data to it\n", - "canvas_full = jui.Canvas(width=big_tile.sizeX, height=big_tile.sizeY)\n", - "canvas_full.sync_image_data = True\n", + "canvas_full = jui.Canvas(width=big_tile.sizeX, height=big_tile.sizeY, sync_image_data=True)\n", + "def save_canvas_to_file(*args, **kwargs):\n", + " # Uncomment the following line to write image data from canvas to PNG file\n", + " #canvas_full.to_file('./user-images/fractal.png')\n", + " pass\n", + "\n", + "# Listen to changes on the ``image_data`` trait and call ``save_to_file`` when it changes.\n", + "canvas_full.observe(save_canvas_to_file, 'image_data')\n", + "\n", "with jui.hold_canvas(canvas_full) :\n", " canvas_full.put_image_data(rgb, 0, 0)\n", " canvas_full.fill_style=\"#ffffff\" # Set text color\n", @@ -311,16 +318,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Save the above canvas as an 8-bit PNG file, canvas.to_file() can have issues for large 4K sized images, use the 2nd method if it does" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "canvas_full.to_file('./user-images/fractal.png')" + "Save the above canvas as an 8-bit PNG file, canvas.to_file() can have issues for large 4K sized images" ] }, { @@ -329,9 +327,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Uncomment alternative and slower method to save to png (but it won't have the text)\n", - "#from skimage.io import imsave\n", - "#imsave('./user-images/fractal.png', rgb.astype(np.uint8)) # rgb is 64-bit float and scaled for 8-bit color" + "# Uncomment alternative and slower method to save to png (but it won't have the ipycanvas text)\n", + "from skimage.io import imsave\n", + "imsave('./user-images/fractal-sk.png', rgb.astype(np.uint8)) # rgb is 64-bit float and scaled for 8-bit color" ] }, {