{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "1abfc7de-3ced-4407-b38e-3fc276b6a133", "metadata": {}, "outputs": [], "source": [ "import math\n", "import json\n", "from pathlib import Path\n", "\n", "import plotly.io as pio\n", "import plotly.graph_objects as go\n", "from coloraide import Color\n", "\n", "import gamut_3d_plotly as diagrams\n", "\n", "pio.renderers\n", "pio.renderers.default = \"notebook_connected\"\n", "\n", "\n", "def face_radial_plane(fig, theta_deg, r=2.5, tilt_deg=0):\n", " # normal in xy\n", " nx = -math.sin(math.radians(theta_deg))\n", " ny = math.cos(math.radians(theta_deg))\n", "\n", " # allow optional tilt up/down so it's not perfectly horizontal\n", " tilt = math.radians(tilt_deg) # 0 => horizontal view, positive looks slightly downward\n", " ex = r * nx * math.cos(tilt)\n", " ey = r * ny * math.cos(tilt)\n", " ez = r * math.sin(tilt)\n", "\n", " fig.update_layout(\n", " scene_camera=dict(\n", " eye=dict(x=ex, y=ey, z=ez),\n", " center=dict(x=0, y=0, z=0),\n", " up=dict(x=0, y=0, z=1)\n", " )\n", " )\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "642b3763-f250-4e24-bd4c-2a080772467d", "metadata": {}, "outputs": [], "source": [ "PALETTE_DIR = \"palettes\"\n", "\n", "with Path(PALETTE_DIR, \"monobiome-v111-oklch.json\").open(\"rb\") as f:\n", " mb_v111_dict = json.load(f)\n", "with Path(PALETTE_DIR, \"monobiome-vUCC-oklch.json\").open(\"rb\") as f:\n", " mb_vUCC_dict = json.load(f)\n", "with Path(PALETTE_DIR, \"monobiome-vMCL-oklch.json\").open(\"rb\") as f:\n", " mb_vMCL_dict = json.load(f)\n", "with Path(PALETTE_DIR, \"monobiome-vQBR-oklch.json\").open(\"rb\") as f:\n", " mb_vQBR_dict = json.load(f)\n", "with Path(PALETTE_DIR, \"monobiome-vQBRsn-oklch.json\").open(\"rb\") as f:\n", " mb_vQBRsn_dict = json.load(f)" ] }, { "cell_type": "code", "execution_count": 3, "id": "0e778a92-78fa-40eb-8b4f-51fbbbc9eb0a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "===> Generating oklch model...\n" ] }, { "data": { "text/html": [ " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "name = 'oklch'\n", "gamut = 'srgb'\n", "title = f'{name} color space'\n", "\n", "# elev=45\n", "# azim=-60.0\n", "elev=45\n", "azim=29.0\n", "width = 600\n", "height = 400\n", "\n", "print(f'===> Generating {name} model...')\n", "fig = diagrams.plot_gamut_in_space(\n", " name,\n", " gamuts={\n", " gamut: {\n", " 'opacity': 0.2,\n", " # 'edges': 'black',\n", " # 'faces': True,\n", " }\n", " },\n", " # dark=True,\n", " gmap={'method': 'raytrace'},\n", " title=title,\n", " size=(width, height),\n", " camera={'a': azim, 'e': elev, 'r': 2.5},\n", " projection='orthographic',\n", ")\n", "\n", "fig.update_layout(\n", " margin=dict(l=0, r=0, t=0, b=0)\n", ")\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": 4, "id": "ed02f2b8-ea4e-43f1-bec6-914b1b3ccccf", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# trajectory = [Color(c_str) for c_str in mb_dict[\"badlands\"].values()]\n", "trajectories = [ [Color(c_str) for c_str in c_str_dict.values()] for c_str_dict in mb_v111_dict.values()] \n", "\n", "tmp_fig = go.Figure(fig)\n", "\n", "for trajectory in trajectories:\n", " diagrams.plot_trajectory(\n", " tmp_fig,\n", " space=\"oklab\",\n", " trajectory_colors=trajectory,\n", " gmap={'method': 'raytrace'},\n", " filters=(),\n", " connect_line=True,\n", " marker_size=2,\n", " line_width=2,\n", " # simulate_alpha=False\n", " )\n", "\n", "face_radial_plane(tmp_fig, 29)\n", "tmp_fig.show()" ] }, { "cell_type": "code", "execution_count": 5, "id": "e2c781cc-f8a9-49f0-9488-e380897f5c9a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# trajectory = [Color(c_str) for c_str in mb_dict[\"badlands\"].values()]\n", "trajectories = [ [Color(c_str) for c_str in c_str_dict.values()] for c_str_dict in mb_vUCC_dict.values()] \n", "\n", "tmp_fig = go.Figure(fig)\n", "\n", "for trajectory in trajectories:\n", " diagrams.plot_trajectory(\n", " tmp_fig,\n", " space=\"oklab\",\n", " trajectory_colors=trajectory,\n", " gmap={'method': 'raytrace'},\n", " filters=(),\n", " connect_line=True,\n", " marker_size=2,\n", " line_width=2,\n", " # simulate_alpha=False\n", " )\n", "\n", "tmp_fig.show()" ] }, { "cell_type": "code", "execution_count": 6, "id": "521ce16e-82bc-4169-8a1b-65a353f9acea", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# trajectory = [Color(c_str) for c_str in mb_dict[\"badlands\"].values()]\n", "trajectories = [ [Color(c_str) for c_str in c_str_dict.values()] for c_str_dict in mb_vMCL_dict.values()] \n", "\n", "tmp_fig = go.Figure(fig)\n", "\n", "for trajectory in trajectories:\n", " diagrams.plot_trajectory(\n", " tmp_fig,\n", " space=\"oklab\",\n", " trajectory_colors=trajectory,\n", " gmap={'method': 'raytrace'},\n", " filters=(),\n", " connect_line=True,\n", " marker_size=2,\n", " line_width=2,\n", " # simulate_alpha=False\n", " )\n", "\n", "tmp_fig.show()" ] }, { "cell_type": "code", "execution_count": 7, "id": "4c088f0e-74d1-4bab-bf40-b0e9af5713bd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# trajectory = [Color(c_str) for c_str in mb_dict[\"badlands\"].values()]\n", "trajectories = [ [Color(c_str) for c_str in c_str_dict.values()] for c_str_dict in mb_vQBR_dict.values()] \n", "\n", "tmp_fig = go.Figure(fig)\n", "\n", "for trajectory in trajectories:\n", " diagrams.plot_trajectory(\n", " tmp_fig,\n", " space=\"oklab\",\n", " trajectory_colors=trajectory,\n", " gmap={'method': 'raytrace'},\n", " filters=(),\n", " connect_line=True,\n", " marker_size=2,\n", " line_width=2,\n", " # simulate_alpha=False\n", " )\n", "\n", "face_radial_plane(tmp_fig, 29)\n", "tmp_fig.show()" ] }, { "cell_type": "code", "execution_count": 10, "id": "32f3f70d-2ce7-4bdb-ad75-58a9193ca491", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# trajectory = [Color(c_str) for c_str in mb_dict[\"badlands\"].values()]\n", "trajectories = [ [Color(c_str) for c_str in c_str_dict.values()] for c_str_dict in mb_vQBRsn_dict.values()] \n", "\n", "tmp_fig = go.Figure(fig)\n", "\n", "for trajectory in trajectories:\n", " diagrams.plot_trajectory(\n", " tmp_fig,\n", " space=\"oklab\",\n", " trajectory_colors=trajectory,\n", " gmap={'method': 'raytrace'},\n", " filters=(),\n", " connect_line=True,\n", " marker_size=2,\n", " line_width=2,\n", " opacity=0.5,\n", " # simulate_alpha=True\n", " )\n", "\n", "face_radial_plane(tmp_fig, 29)\n", "tmp_fig.show()" ] }, { "cell_type": "code", "execution_count": 9, "id": "9f5ac6ad-dde8-4570-ae6c-43dfa28f655c", "metadata": {}, "outputs": [], "source": [ "#import plotly.graph_objects as go\n", "# tmp_fig = go.Figure(base_fig) with open(f'{name}-space.png', 'wb') as f:\n", "# f.write(fig.to_image(format='png', width=width, height=height))\n", "# print('[complete]')" ] } ], "metadata": { "kernelspec": { "display_name": "monobiome", "language": "python", "name": "monobiome" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.0" } }, "nbformat": 4, "nbformat_minor": 5 }