Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
abikesa committed Aug 22, 2024
1 parent 07fef2c commit ecd48bb
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 15 deletions.
48 changes: 40 additions & 8 deletions _sources/ipynb/logo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 10,
"metadata": {
"tags": [
"hide-input"
Expand All @@ -138,7 +138,7 @@
"\n",
"def add_fern_edges(G, start, depth, angle, scale):\n",
" if depth == 0:\n",
" return\n",
" return start\n",
" \n",
" end = (start[0] + scale * angle[0], start[1] + scale * angle[1])\n",
" \n",
Expand All @@ -147,21 +147,36 @@
" new_angle1 = (angle[0] * 0.6 - angle[1] * 0.4, angle[0] * 0.4 + angle[1] * 0.6)\n",
" new_angle2 = (angle[0] * 0.6 + angle[1] * 0.4, -angle[0] * 0.4 + angle[1] * 0.6)\n",
" \n",
" add_fern_edges(G, end, depth - 1, new_angle1, scale * 0.7)\n",
" add_fern_edges(G, end, depth - 1, new_angle2, scale * 0.7)\n",
" child1 = add_fern_edges(G, end, depth - 1, new_angle1, scale * 0.7)\n",
" child2 = add_fern_edges(G, end, depth - 1, new_angle2, scale * 0.7)\n",
" \n",
" return end\n",
"\n",
"def create_fern_graph(depth, scale=1):\n",
" G = nx.Graph()\n",
" start = (0, 0)\n",
" angle = (0, 1)\n",
" \n",
" add_fern_edges(G, start, depth, angle, scale)\n",
" child1 = add_fern_edges(G, start, depth, angle, scale)\n",
" \n",
" return G\n",
" return G, start, child1\n",
"\n",
"# Generate the fern graph\n",
"fern_depth = 7 # Adjust depth for more or fewer branches\n",
"fern_graph = create_fern_graph(fern_depth)\n",
"fern_graph, father, son = create_fern_graph(fern_depth)\n",
"\n",
"# Find the children of \"Father\"\n",
"children = list(fern_graph.neighbors(father))\n",
"\n",
"# Ensure there are at least two children\n",
"if len(children) >= 2:\n",
" # Label the edges as \"Son\" and \"HolySpirit\"\n",
" edge_labels = {\n",
" (father, children[0]): \"Son\",\n",
" (father, children[1]): \"HolySpirit\"\n",
" }\n",
"else:\n",
" edge_labels = {}\n",
"\n",
"# Define colors\n",
"leaf_color = '#5F9E54' # A green between lime and cabbage\n",
Expand All @@ -177,11 +192,28 @@
"pos = {node: node for node in fern_graph.nodes()}\n",
"nx.draw(fern_graph, pos, with_labels=False, node_size=0, edge_color=colors, width=2)\n",
"\n",
"# Draw edge labels if they exist\n",
"if edge_labels:\n",
" nx.draw_networkx_edge_labels(fern_graph, pos, edge_labels=edge_labels, font_size=12)\n",
"\n",
"plt.axis('off')\n",
"\n",
"# Save the image\n",
"# plt.savefig(\"/Users/apollo/Documents/rhythm/music/kitabo/ensi/figures/fern_fractal.png\", dpi=300, bbox_inches='tight')\n",
"plt.show()"
"plt.show()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```{figure} ../figures/blanche.*\n",
"---\n",
"width: 1\n",
"height: 1\n",
"---\n",
"_Extraordinary_. Parent is \"Father\" and children are \"Son\" and \"Holy Spirit\". Everything else springs from these two children: the wave-particle duality of the entire cosmos!\n",
"```"
]
},
{
Expand Down
37 changes: 31 additions & 6 deletions ipynb/logo.html
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ <h2> Contents </h2>

<span class="k">def</span> <span class="nf">add_fern_edges</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">depth</span><span class="p">,</span> <span class="n">angle</span><span class="p">,</span> <span class="n">scale</span><span class="p">):</span>
<span class="k">if</span> <span class="n">depth</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</span>
<span class="k">return</span> <span class="n">start</span>

<span class="n">end</span> <span class="o">=</span> <span class="p">(</span><span class="n">start</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">scale</span> <span class="o">*</span> <span class="n">angle</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">start</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">scale</span> <span class="o">*</span> <span class="n">angle</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

Expand All @@ -528,21 +528,36 @@ <h2> Contents </h2>
<span class="n">new_angle1</span> <span class="o">=</span> <span class="p">(</span><span class="n">angle</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.6</span> <span class="o">-</span> <span class="n">angle</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.4</span><span class="p">,</span> <span class="n">angle</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.4</span> <span class="o">+</span> <span class="n">angle</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.6</span><span class="p">)</span>
<span class="n">new_angle2</span> <span class="o">=</span> <span class="p">(</span><span class="n">angle</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.6</span> <span class="o">+</span> <span class="n">angle</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.4</span><span class="p">,</span> <span class="o">-</span><span class="n">angle</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.4</span> <span class="o">+</span> <span class="n">angle</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.6</span><span class="p">)</span>

<span class="n">add_fern_edges</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">depth</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">new_angle1</span><span class="p">,</span> <span class="n">scale</span> <span class="o">*</span> <span class="mf">0.7</span><span class="p">)</span>
<span class="n">add_fern_edges</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">depth</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">new_angle2</span><span class="p">,</span> <span class="n">scale</span> <span class="o">*</span> <span class="mf">0.7</span><span class="p">)</span>
<span class="n">child1</span> <span class="o">=</span> <span class="n">add_fern_edges</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">depth</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">new_angle1</span><span class="p">,</span> <span class="n">scale</span> <span class="o">*</span> <span class="mf">0.7</span><span class="p">)</span>
<span class="n">child2</span> <span class="o">=</span> <span class="n">add_fern_edges</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">depth</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">new_angle2</span><span class="p">,</span> <span class="n">scale</span> <span class="o">*</span> <span class="mf">0.7</span><span class="p">)</span>

<span class="k">return</span> <span class="n">end</span>

<span class="k">def</span> <span class="nf">create_fern_graph</span><span class="p">(</span><span class="n">depth</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
<span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>
<span class="n">start</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">angle</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>

<span class="n">add_fern_edges</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">depth</span><span class="p">,</span> <span class="n">angle</span><span class="p">,</span> <span class="n">scale</span><span class="p">)</span>
<span class="n">child1</span> <span class="o">=</span> <span class="n">add_fern_edges</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">depth</span><span class="p">,</span> <span class="n">angle</span><span class="p">,</span> <span class="n">scale</span><span class="p">)</span>

<span class="k">return</span> <span class="n">G</span>
<span class="k">return</span> <span class="n">G</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">child1</span>

<span class="c1"># Generate the fern graph</span>
<span class="n">fern_depth</span> <span class="o">=</span> <span class="mi">7</span> <span class="c1"># Adjust depth for more or fewer branches</span>
<span class="n">fern_graph</span> <span class="o">=</span> <span class="n">create_fern_graph</span><span class="p">(</span><span class="n">fern_depth</span><span class="p">)</span>
<span class="n">fern_graph</span><span class="p">,</span> <span class="n">father</span><span class="p">,</span> <span class="n">son</span> <span class="o">=</span> <span class="n">create_fern_graph</span><span class="p">(</span><span class="n">fern_depth</span><span class="p">)</span>

<span class="c1"># Find the children of &quot;Father&quot;</span>
<span class="n">children</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">fern_graph</span><span class="o">.</span><span class="n">neighbors</span><span class="p">(</span><span class="n">father</span><span class="p">))</span>

<span class="c1"># Ensure there are at least two children</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">children</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">2</span><span class="p">:</span>
<span class="c1"># Label the edges as &quot;Son&quot; and &quot;HolySpirit&quot;</span>
<span class="n">edge_labels</span> <span class="o">=</span> <span class="p">{</span>
<span class="p">(</span><span class="n">father</span><span class="p">,</span> <span class="n">children</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span> <span class="s2">&quot;Son&quot;</span><span class="p">,</span>
<span class="p">(</span><span class="n">father</span><span class="p">,</span> <span class="n">children</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span> <span class="s2">&quot;HolySpirit&quot;</span>
<span class="p">}</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">edge_labels</span> <span class="o">=</span> <span class="p">{}</span>

<span class="c1"># Define colors</span>
<span class="n">leaf_color</span> <span class="o">=</span> <span class="s1">&#39;#5F9E54&#39;</span> <span class="c1"># A green between lime and cabbage</span>
Expand All @@ -558,6 +573,10 @@ <h2> Contents </h2>
<span class="n">pos</span> <span class="o">=</span> <span class="p">{</span><span class="n">node</span><span class="p">:</span> <span class="n">node</span> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">fern_graph</span><span class="o">.</span><span class="n">nodes</span><span class="p">()}</span>
<span class="n">nx</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">fern_graph</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">with_labels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">node_size</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">edge_color</span><span class="o">=</span><span class="n">colors</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>

<span class="c1"># Draw edge labels if they exist</span>
<span class="k">if</span> <span class="n">edge_labels</span><span class="p">:</span>
<span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx_edge_labels</span><span class="p">(</span><span class="n">fern_graph</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">edge_labels</span><span class="o">=</span><span class="n">edge_labels</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>

<span class="n">plt</span><span class="o">.</span><span class="n">axis</span><span class="p">(</span><span class="s1">&#39;off&#39;</span><span class="p">)</span>

<span class="c1"># Save the image</span>
Expand All @@ -571,6 +590,12 @@ <h2> Contents </h2>
<img alt="../_images/6e3efdc487371d93e0c3060bb272eb87b38dbf6dc9b41975f1096a17b658416b.png" src="../_images/6e3efdc487371d93e0c3060bb272eb87b38dbf6dc9b41975f1096a17b658416b.png" />
</div>
</div>
<figure class="align-default" id="id2">
<a class="reference internal image-reference" href="../_images/blanche.png"><img alt="../_images/blanche.png" src="../_images/blanche.png" style="width: 1px; height: 1px;" /></a>
<figcaption>
<p><span class="caption-text"><em>Extraordinary</em>. Parent is “Father” and children are “Son” and “Holy Spirit”. Everything else springs from these two children: the wave-particle duality of the entire cosmos!</span><a class="headerlink" href="#id2" title="Permalink to this image">#</a></p>
</figcaption>
</figure>
<aside class="margin sidebar">
<p class="sidebar-title"></p>
<Details>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

0 comments on commit ecd48bb

Please sign in to comment.