601 lines
65 KiB
HTML
601 lines
65 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>main — fractal 0.0.1 documentation</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
<link rel="index" title="Index" href="../genindex.html" />
|
|
<link rel="search" title="Search" href="../search.html" />
|
|
|
|
|
|
<script src="../_static/js/modernizr.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav">
|
|
|
|
|
|
<div class="wy-grid-for-nav">
|
|
|
|
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-scroll">
|
|
<div class="wy-side-nav-search">
|
|
|
|
|
|
|
|
<a href="../index.html" class="icon icon-home"> fractal
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div role="search">
|
|
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<p class="caption"><span class="caption-text">Contents:</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="../documentation.html">function documentation</a></li>
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
|
|
|
|
|
<nav class="wy-nav-top" aria-label="top navigation">
|
|
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="../index.html">fractal</a>
|
|
|
|
</nav>
|
|
|
|
|
|
<div class="wy-nav-content">
|
|
|
|
<div class="rst-content">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
|
|
|
<ul class="wy-breadcrumbs">
|
|
|
|
<li><a href="../index.html">Docs</a> »</li>
|
|
|
|
<li><a href="index.html">Module code</a> »</li>
|
|
|
|
<li>main</li>
|
|
|
|
|
|
<li class="wy-breadcrumbs-aside">
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
<div itemprop="articleBody">
|
|
|
|
<h1>Source code for main</h1><div class="highlight"><pre>
|
|
<span></span><span class="kn">import</span> <span class="nn">cmath</span>
|
|
<span class="kn">from</span> <span class="nn">math</span> <span class="k">import</span> <span class="n">atan</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">pi</span>
|
|
|
|
<span class="kn">from</span> <span class="nn">PIL</span> <span class="k">import</span> <span class="n">Image</span><span class="p">,</span> <span class="n">ImageDraw</span>
|
|
|
|
<span class="sd">"""</span>
|
|
<span class="sd">A lib to draw fractals on pillow image.</span>
|
|
|
|
<span class="sd">>>> img = Image.new('RGB', (5000, 5000), (0, 0, 0))</span>
|
|
<span class="sd">>>> figures = Figures(im=img)</span>
|
|
<span class="sd">>>> figures.von_koch_curve_flake((2500, 2500), 2000,6)</span>
|
|
<span class="sd">>>> img.save("test.bmp")</span>
|
|
<span class="sd">"""</span>
|
|
|
|
|
|
<div class="viewcode-block" id="State"><a class="viewcode-back" href="../documentation.html#main.State">[docs]</a><span class="k">class</span> <span class="nc">State</span><span class="p">:</span>
|
|
<span class="sd">"""State of Lsystem"""</span>
|
|
<span class="n">width</span><span class="p">:</span> <span class="nb">int</span>
|
|
<span class="n">color</span><span class="p">:</span> <span class="nb">tuple</span>
|
|
<span class="n">angle</span><span class="p">:</span> <span class="nb">int</span>
|
|
<span class="n">y</span><span class="p">:</span> <span class="nb">int</span>
|
|
<span class="n">x</span><span class="p">:</span> <span class="nb">int</span>
|
|
|
|
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="sd">"""Initialisation of state</span>
|
|
|
|
<span class="sd"> >>> State().x</span>
|
|
<span class="sd"> 0</span>
|
|
<span class="sd"> >>> State().y</span>
|
|
<span class="sd"> 0</span>
|
|
<span class="sd"> >>> State().angle</span>
|
|
<span class="sd"> 0</span>
|
|
<span class="sd"> >>> State().color</span>
|
|
<span class="sd"> (255, 255, 255)</span>
|
|
<span class="sd"> >>> State().width</span>
|
|
<span class="sd"> 0"""</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="mi">0</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="mi">0</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">angle</span> <span class="o">=</span> <span class="mi">0</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="mi">255</span><span class="p">,</span> <span class="mi">255</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">width</span> <span class="o">=</span> <span class="mi">0</span></div>
|
|
|
|
|
|
<div class="viewcode-block" id="Lsystem"><a class="viewcode-back" href="../documentation.html#main.Lsystem">[docs]</a><span class="k">class</span> <span class="nc">Lsystem</span><span class="p">(</span><span class="n">ImageDraw</span><span class="o">.</span><span class="n">ImageDraw</span><span class="p">):</span>
|
|
<span class="sd">"""Draw a L system"""</span>
|
|
<span class="n">state</span><span class="p">:</span> <span class="n">State</span>
|
|
<span class="n">states</span><span class="p">:</span> <span class="nb">list</span>
|
|
|
|
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
|
<span class="sd">"""Initialisation</span>
|
|
|
|
<span class="sd"> Parameters are the same than ImageDraw.__init__"""</span>
|
|
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">states</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">state</span> <span class="o">=</span> <span class="n">State</span><span class="p">()</span>
|
|
|
|
<div class="viewcode-block" id="Lsystem._right"><a class="viewcode-back" href="../documentation.html#main.Lsystem._right">[docs]</a> <span class="k">def</span> <span class="nf">_right</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">angle</span><span class="p">):</span>
|
|
<span class="sd">"""Turn pen to right of angle</span>
|
|
|
|
<span class="sd"> :param angle: Angle to rotate</span>
|
|
<span class="sd"> :type angle: float</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">angle</span> <span class="o">-=</span> <span class="n">angle</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem._left"><a class="viewcode-back" href="../documentation.html#main.Lsystem._left">[docs]</a> <span class="k">def</span> <span class="nf">_left</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">angle</span><span class="p">):</span>
|
|
<span class="sd">"""Turn pen to left of angle</span>
|
|
|
|
<span class="sd"> :param angle: Angle to rotate</span>
|
|
<span class="sd"> :type angle: float</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">angle</span> <span class="o">+=</span> <span class="n">angle</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem._forward"><a class="viewcode-back" href="../documentation.html#main.Lsystem._forward">[docs]</a> <span class="k">def</span> <span class="nf">_forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">distance</span><span class="p">):</span>
|
|
<span class="sd">"""Forward pen of distance</span>
|
|
|
|
<span class="sd"> :param distance: Distance to forward</span>
|
|
<span class="sd"> :type distance: float</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">x_2</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="p">(</span><span class="n">distance</span> <span class="o">*</span> <span class="n">cos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">angle</span><span class="p">))</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">x</span>
|
|
<span class="n">y_2</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="p">(</span><span class="n">distance</span> <span class="o">*</span> <span class="n">sin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">angle</span><span class="p">))</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">y</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">line</span><span class="p">(((</span><span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">y</span><span class="p">),</span> <span class="p">(</span><span class="n">x_2</span><span class="p">,</span> <span class="n">y_2</span><span class="p">)),</span> <span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">color</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">width</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">x_2</span><span class="p">,</span> <span class="n">y_2</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem._backward"><a class="viewcode-back" href="../documentation.html#main.Lsystem._backward">[docs]</a> <span class="k">def</span> <span class="nf">_backward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">distance</span><span class="p">):</span>
|
|
<span class="sd">"""Backward pen of distance</span>
|
|
|
|
<span class="sd"> :param distance: Distance to backward</span>
|
|
<span class="sd"> :type distance: float</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">_forward</span><span class="p">(</span><span class="o">-</span><span class="n">distance</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem._save"><a class="viewcode-back" href="../documentation.html#main.Lsystem._save">[docs]</a> <span class="k">def</span> <span class="nf">_save</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="sd">"""Save state of pen"""</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">states</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem._restore"><a class="viewcode-back" href="../documentation.html#main.Lsystem._restore">[docs]</a> <span class="k">def</span> <span class="nf">_restore</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="sd">"""Restore last pen state"""</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">state</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">states</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
|
|
<span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">states</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem.draw_l"><a class="viewcode-back" href="../documentation.html#main.Lsystem.draw_l">[docs]</a> <span class="k">def</span> <span class="nf">draw_l</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">replacement</span><span class="p">,</span> <span class="n">constants</span><span class="p">,</span> <span class="n">nb_recursive</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="mi">255</span><span class="p">,</span> <span class="mi">255</span><span class="p">),</span> <span class="n">width</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
|
<span class="sd">"""Draw a L system</span>
|
|
|
|
<span class="sd"> :param start: Axiome</span>
|
|
<span class="sd"> :param replacement: Dictionary which contain replacement values (F->F+F-F-F+F)</span>
|
|
<span class="sd"> :param constants: Dictionary which contain all elements with there function</span>
|
|
<span class="sd"> :param nb_recursive: Number of recursion</span>
|
|
<span class="sd"> :param color: Color to use for the drawing</span>
|
|
<span class="sd"> :param width: The line width, in pixels</span>
|
|
<span class="sd"> :type start: str</span>
|
|
<span class="sd"> :type replacement: dict</span>
|
|
<span class="sd"> :type constants: dict</span>
|
|
<span class="sd"> :type nb_recursive: int</span>
|
|
<span class="sd"> :type color: tuple</span>
|
|
<span class="sd"> :type width: int</span>
|
|
<span class="sd"> """</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="n">color</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">width</span> <span class="o">=</span> <span class="n">width</span>
|
|
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nb_recursive</span><span class="p">):</span>
|
|
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">replacement</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
|
|
<span class="n">start</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
|
|
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">start</span><span class="p">:</span>
|
|
<span class="n">constants</span><span class="p">[</span><span class="n">item</span><span class="p">]()</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem.right"><a class="viewcode-back" href="../documentation.html#main.Lsystem.right">[docs]</a> <span class="k">def</span> <span class="nf">right</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">angle</span><span class="p">):</span>
|
|
<span class="sd">"""Return a lambda function which make pen turning of angle radians to right</span>
|
|
|
|
<span class="sd"> :param angle: Angle to build function</span>
|
|
<span class="sd"> :type angle: float</span>
|
|
|
|
<span class="sd"> :return: lambda function to make pen turning right</span>
|
|
<span class="sd"> :rtype: lambda"""</span>
|
|
<span class="k">return</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_right</span><span class="p">(</span><span class="n">angle</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem.left"><a class="viewcode-back" href="../documentation.html#main.Lsystem.left">[docs]</a> <span class="k">def</span> <span class="nf">left</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">angle</span><span class="p">):</span>
|
|
<span class="sd">"""Return a lambda function which make pen turning of angle radians to left</span>
|
|
|
|
<span class="sd"> :param angle: Angle to build function</span>
|
|
<span class="sd"> :type angle: float</span>
|
|
|
|
<span class="sd"> :return: lambda function to make pen turning left</span>
|
|
<span class="sd"> :rtype: lambda"""</span>
|
|
<span class="k">return</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_left</span><span class="p">(</span><span class="n">angle</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem.forward"><a class="viewcode-back" href="../documentation.html#main.Lsystem.forward">[docs]</a> <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">distance</span><span class="p">):</span>
|
|
<span class="sd">"""Return a lambda function which make pen forward of distance</span>
|
|
|
|
<span class="sd"> :param distance: Distance to build function</span>
|
|
<span class="sd"> :type distance: float</span>
|
|
|
|
<span class="sd"> :return: lambda function to make pen forward</span>
|
|
<span class="sd"> :rtype: lambda"""</span>
|
|
<span class="k">return</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_forward</span><span class="p">(</span><span class="n">distance</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem.backward"><a class="viewcode-back" href="../documentation.html#main.Lsystem.backward">[docs]</a> <span class="k">def</span> <span class="nf">backward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">distance</span><span class="p">):</span>
|
|
<span class="sd">"""Return a lambda function which make pen backward of distance</span>
|
|
|
|
<span class="sd"> :param distance: Distance to build function</span>
|
|
<span class="sd"> :type distance: float</span>
|
|
|
|
<span class="sd"> :return: lambda function to make pen backward</span>
|
|
<span class="sd"> :rtype: lambda"""</span>
|
|
<span class="k">return</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_backward</span><span class="p">(</span><span class="n">distance</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem.save"><a class="viewcode-back" href="../documentation.html#main.Lsystem.save">[docs]</a> <span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="sd">"""Return a lambda function which save state of pen</span>
|
|
|
|
<span class="sd"> :return: lambda function to save pen state</span>
|
|
<span class="sd"> :rtype: lambda"""</span>
|
|
<span class="k">return</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_save</span><span class="p">()</span></div>
|
|
|
|
<div class="viewcode-block" id="Lsystem.restore"><a class="viewcode-back" href="../documentation.html#main.Lsystem.restore">[docs]</a> <span class="k">def</span> <span class="nf">restore</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="sd">"""Return a lambda function which restore state of pen</span>
|
|
|
|
<span class="sd"> :return: lambda function to restore pen state</span>
|
|
<span class="sd"> :rtype: lambda"""</span>
|
|
<span class="k">return</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_restore</span><span class="p">()</span></div></div>
|
|
|
|
|
|
<div class="viewcode-block" id="Figures"><a class="viewcode-back" href="../documentation.html#main.Figures">[docs]</a><span class="k">class</span> <span class="nc">Figures</span><span class="p">(</span><span class="n">ImageDraw</span><span class="o">.</span><span class="n">ImageDraw</span><span class="p">):</span>
|
|
<span class="sd">"""A lot of function to create some well-know shapes"""</span>
|
|
|
|
<div class="viewcode-block" id="Figures.point_to_complex"><a class="viewcode-back" href="../documentation.html#main.Figures.point_to_complex">[docs]</a> <span class="nd">@staticmethod</span>
|
|
<span class="k">def</span> <span class="nf">point_to_complex</span><span class="p">(</span><span class="n">point</span><span class="p">):</span>
|
|
<span class="sd">"""Transform tuple to complex</span>
|
|
|
|
<span class="sd"> :param point: Point to convert</span>
|
|
<span class="sd"> :type point: tuple</span>
|
|
|
|
<span class="sd"> :return: Complex representation of point</span>
|
|
<span class="sd"> :rtype: complex"""</span>
|
|
<span class="k">return</span> <span class="nb">complex</span><span class="p">(</span><span class="n">point</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">point</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span></div>
|
|
|
|
<div class="viewcode-block" id="Figures.complex_to_point"><a class="viewcode-back" href="../documentation.html#main.Figures.complex_to_point">[docs]</a> <span class="nd">@staticmethod</span>
|
|
<span class="k">def</span> <span class="nf">complex_to_point</span><span class="p">(</span><span class="n">point</span><span class="p">):</span>
|
|
<span class="sd">"""Transform tuple to complex</span>
|
|
|
|
<span class="sd"> :param point: Point to convert</span>
|
|
<span class="sd"> :type point: complex</span>
|
|
|
|
<span class="sd"> :return: tuple representation of point</span>
|
|
<span class="sd"> :rtype: tuple"""</span>
|
|
<span class="k">return</span> <span class="n">point</span><span class="o">.</span><span class="n">real</span><span class="p">,</span> <span class="n">point</span><span class="o">.</span><span class="n">imag</span></div>
|
|
|
|
<div class="viewcode-block" id="Figures.rotation"><a class="viewcode-back" href="../documentation.html#main.Figures.rotation">[docs]</a> <span class="k">def</span> <span class="nf">rotation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="mi">0</span><span class="n">j</span><span class="p">,</span> <span class="n">angle</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
|
<span class="sd">"""Rotate point in complex plane</span>
|
|
|
|
<span class="sd"> :param point: point (or list of point) to rotate</span>
|
|
<span class="sd"> :type point: tuple or complex</span>
|
|
<span class="sd"> :param center: center of rotation</span>
|
|
<span class="sd"> :type center: tuple or complex</span>
|
|
<span class="sd"> :param angle: angle of rotation</span>
|
|
<span class="sd"> :type angle: float</span>
|
|
|
|
<span class="sd"> :return: Rotated point (or list of rotated points)</span>
|
|
<span class="sd"> :rtype: tuple or list of tuples"""</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">center</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">complex</span><span class="p">:</span>
|
|
<span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_to_complex</span><span class="p">(</span><span class="n">center</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">point</span><span class="p">)</span> <span class="o">==</span> <span class="nb">list</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">rotation</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">center</span><span class="p">,</span> <span class="n">angle</span><span class="p">)</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">point</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">point</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">complex</span><span class="p">:</span>
|
|
<span class="n">point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_to_complex</span><span class="p">(</span><span class="n">point</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">complex_to_point</span><span class="p">(</span><span class="n">cmath</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="nb">complex</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="o">*</span> <span class="n">angle</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">point</span> <span class="o">-</span> <span class="n">center</span><span class="p">)</span> <span class="o">+</span> <span class="n">center</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Figures.homothety"><a class="viewcode-back" href="../documentation.html#main.Figures.homothety">[docs]</a> <span class="k">def</span> <span class="nf">homothety</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="mi">0</span><span class="n">j</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
|
<span class="sd">"""Homothety of point in complex plane</span>
|
|
|
|
<span class="sd"> :param point: point (or list of point) to make homothety</span>
|
|
<span class="sd"> :type point: tuple or complex</span>
|
|
<span class="sd"> :param center: center of homothety</span>
|
|
<span class="sd"> :type center: tuple or complex</span>
|
|
<span class="sd"> :param size: size of homothety</span>
|
|
<span class="sd"> :type size: float</span>
|
|
|
|
<span class="sd"> :return: Homothety of point (or list of homothety of points)</span>
|
|
<span class="sd"> :rtype: tuple or list of tuples"""</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">center</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">complex</span><span class="p">:</span>
|
|
<span class="n">center</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_to_complex</span><span class="p">(</span><span class="n">center</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">point</span><span class="p">)</span> <span class="o">==</span> <span class="nb">list</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">homothety</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">center</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">point</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">point</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">complex</span><span class="p">:</span>
|
|
<span class="n">point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_to_complex</span><span class="p">(</span><span class="n">point</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">complex_to_point</span><span class="p">(</span><span class="n">size</span> <span class="o">*</span> <span class="p">(</span><span class="n">point</span> <span class="o">-</span> <span class="n">center</span><span class="p">)</span> <span class="o">+</span> <span class="n">center</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Figures.translation"><a class="viewcode-back" href="../documentation.html#main.Figures.translation">[docs]</a> <span class="k">def</span> <span class="nf">translation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">vect</span><span class="p">):</span>
|
|
<span class="sd">"""Translate point in complex plane</span>
|
|
|
|
<span class="sd"> :param point: point (or list of point) to translate</span>
|
|
<span class="sd"> :type point: tuple or complex</span>
|
|
<span class="sd"> :param vect: vector of translation</span>
|
|
<span class="sd"> :type vect: tuple or complex</span>
|
|
|
|
<span class="sd"> :return: Translated point (or list of translated points)</span>
|
|
<span class="sd"> :rtype: tuple or list of tuples"""</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">vect</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">complex</span><span class="p">:</span>
|
|
<span class="n">vect</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_to_complex</span><span class="p">(</span><span class="n">vect</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">point</span><span class="p">)</span> <span class="o">==</span> <span class="nb">list</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">translation</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">vect</span><span class="p">)</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">point</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">point</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">complex</span><span class="p">:</span>
|
|
<span class="n">point</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">point_to_complex</span><span class="p">(</span><span class="n">point</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">complex_to_point</span><span class="p">(</span><span class="n">point</span> <span class="o">+</span> <span class="n">vect</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Figures.blanc_manger"><a class="viewcode-back" href="../documentation.html#main.Figures.blanc_manger">[docs]</a> <span class="k">def</span> <span class="nf">blanc_manger</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">origin</span><span class="p">,</span> <span class="n">finish</span><span class="p">,</span> <span class="n">iterations</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
|
<span class="sd">"""Trace blanc manger curve</span>
|
|
|
|
<span class="sd"> :param origin: coordinate of the starting point</span>
|
|
<span class="sd"> :param finish: coordinate of the ending point</span>
|
|
<span class="sd"> :param iterations: iterations for the drawings</span>
|
|
<span class="sd"> :param color: color to use for the lines</span>
|
|
<span class="sd"> :param width: the line width, in pixels</span>
|
|
<span class="sd"> :type origin: tuple</span>
|
|
<span class="sd"> :type finish: tuple</span>
|
|
<span class="sd"> :type iterations: int</span>
|
|
<span class="sd"> :type color: tuple</span>
|
|
<span class="sd"> :type width: int"""</span>
|
|
<span class="n">lenght_theoric</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">**</span> <span class="n">iterations</span>
|
|
<span class="n">length</span> <span class="o">=</span> <span class="p">(((</span><span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">finish</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="p">(</span><span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">finish</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span> <span class="o">**</span> <span class="mf">0.5</span><span class="p">)</span>
|
|
|
|
<span class="k">def</span> <span class="nf">sawtooth</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
|
|
<span class="n">d</span> <span class="o">=</span> <span class="n">x</span> <span class="o">-</span> <span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">d</span> <span class="o"><=</span> <span class="mi">1</span> <span class="o">/</span> <span class="mi">2</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">d</span>
|
|
<span class="k">return</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">d</span>
|
|
|
|
<span class="k">def</span> <span class="nf">blanc_manger</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">iterations</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
|
|
<span class="k">return</span> <span class="nb">sum</span><span class="p">([</span><span class="mi">1</span> <span class="o">/</span> <span class="p">(</span><span class="mi">2</span> <span class="o">**</span> <span class="n">k</span><span class="p">)</span> <span class="o">*</span> <span class="n">sawtooth</span><span class="p">((</span><span class="mi">2</span> <span class="o">**</span> <span class="n">k</span><span class="p">)</span> <span class="o">*</span> <span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">iterations</span><span class="p">)])</span>
|
|
|
|
<span class="n">points</span> <span class="o">=</span> <span class="p">[</span>
|
|
<span class="p">((</span><span class="n">i</span> <span class="o">/</span> <span class="n">lenght_theoric</span><span class="p">)</span> <span class="o">*</span> <span class="n">length</span><span class="p">,</span>
|
|
<span class="p">(</span><span class="n">blanc_manger</span><span class="p">(</span><span class="n">i</span> <span class="o">/</span> <span class="n">lenght_theoric</span><span class="p">,</span> <span class="n">iterations</span><span class="p">))</span> <span class="o">*</span> <span class="n">length</span><span class="p">)</span>
|
|
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">lenght_theoric</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)]</span>
|
|
|
|
<span class="n">points</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rotation</span><span class="p">(</span><span class="n">points</span><span class="p">,</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">pi</span> <span class="o">/</span> <span class="mi">4</span><span class="p">)</span>
|
|
<span class="n">points</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">translation</span><span class="p">(</span><span class="n">points</span><span class="p">,</span> <span class="n">origin</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">line</span><span class="p">(</span><span class="n">points</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Figures.von_koch_curve_flake"><a class="viewcode-back" href="../documentation.html#main.Figures.von_koch_curve_flake">[docs]</a> <span class="k">def</span> <span class="nf">von_koch_curve_flake</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">origin</span><span class="p">,</span> <span class="n">radius</span><span class="p">,</span> <span class="n">iterations</span><span class="p">,</span> <span class="n">angle</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
|
<span class="sd">"""Draw thee von koch flake on image.</span>
|
|
|
|
<span class="sd"> :param origin: coordinate of the center of circumscribed circle of main triangle</span>
|
|
<span class="sd"> :param radius: radius of circumscribed circle of main triangle</span>
|
|
<span class="sd"> :param iterations: iterations for the drawings</span>
|
|
<span class="sd"> :param angle: rotation of main triangle</span>
|
|
<span class="sd"> :param color: color to use for the lines</span>
|
|
<span class="sd"> :param width: the line width, in pixels</span>
|
|
<span class="sd"> :type radius: float</span>
|
|
<span class="sd"> :type origin: tuple</span>
|
|
<span class="sd"> :type iterations: int</span>
|
|
<span class="sd"> :type angle: float</span>
|
|
<span class="sd"> :type color: tuple</span>
|
|
<span class="sd"> :type width: int"""</span>
|
|
<span class="n">angle</span> <span class="o">=</span> <span class="n">angle</span> <span class="o">+</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">2</span>
|
|
<span class="n">summit_1</span> <span class="o">=</span> <span class="p">(</span><span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">angle</span><span class="p">)</span> <span class="o">*</span> <span class="n">radius</span><span class="p">,</span> <span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">angle</span><span class="p">)</span> <span class="o">*</span> <span class="n">radius</span><span class="p">)</span>
|
|
<span class="n">summit_2</span> <span class="o">=</span> <span class="p">(</span><span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">angle</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span> <span class="o">*</span> <span class="n">pi</span><span class="p">)</span> <span class="o">*</span> <span class="n">radius</span><span class="p">,</span> <span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">angle</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span> <span class="o">*</span> <span class="n">pi</span><span class="p">)</span> <span class="o">*</span> <span class="n">radius</span><span class="p">)</span>
|
|
<span class="n">summit_3</span> <span class="o">=</span> <span class="p">(</span><span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">angle</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span> <span class="o">*</span> <span class="n">pi</span><span class="p">)</span> <span class="o">*</span> <span class="n">radius</span><span class="p">,</span> <span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">angle</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span> <span class="o">*</span> <span class="n">pi</span><span class="p">)</span> <span class="o">*</span> <span class="n">radius</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">von_koch_curve</span><span class="p">(</span><span class="n">summit_2</span><span class="p">,</span> <span class="n">summit_1</span><span class="p">,</span> <span class="n">iterations</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">von_koch_curve</span><span class="p">(</span><span class="n">summit_3</span><span class="p">,</span> <span class="n">summit_2</span><span class="p">,</span> <span class="n">iterations</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">von_koch_curve</span><span class="p">(</span><span class="n">summit_1</span><span class="p">,</span> <span class="n">summit_3</span><span class="p">,</span> <span class="n">iterations</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="Figures._int"><a class="viewcode-back" href="../documentation.html#main.Figures._int">[docs]</a> <span class="nd">@staticmethod</span>
|
|
<span class="k">def</span> <span class="nf">_int</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
|
|
<span class="sd">"""Make a tuple of float coordinate into tuple of int coordinate</span>
|
|
|
|
<span class="sd"> :param value: Tuple to convert</span>
|
|
<span class="sd"> :type value: tuple</span>
|
|
|
|
<span class="sd"> :return: new tuple with int values</span>
|
|
<span class="sd"> :rtype: tuple(int, int)"""</span>
|
|
<span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span></div>
|
|
|
|
<div class="viewcode-block" id="Figures.von_koch_curve"><a class="viewcode-back" href="../documentation.html#main.Figures.von_koch_curve">[docs]</a> <span class="k">def</span> <span class="nf">von_koch_curve</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">origin</span><span class="p">,</span> <span class="n">finish</span><span class="p">,</span> <span class="n">iterations</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
|
|
<span class="sd">"""Draw thee von koch flake on image.</span>
|
|
|
|
<span class="sd"> :param origin: coordinate of the starting point</span>
|
|
<span class="sd"> :param finish: coordinate of the ending point</span>
|
|
<span class="sd"> :param iterations: iterations for the drawings</span>
|
|
<span class="sd"> :param color: color to use for the lines</span>
|
|
<span class="sd"> :param width: the line width, in pixels</span>
|
|
<span class="sd"> :type origin: tuple</span>
|
|
<span class="sd"> :type finish: tuple</span>
|
|
<span class="sd"> :type iterations: int</span>
|
|
<span class="sd"> :type color: tuple</span>
|
|
<span class="sd"> :type width: int"""</span>
|
|
<span class="n">third</span> <span class="o">=</span> <span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="n">finish</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">*</span> <span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span><span class="p">,</span> <span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="n">finish</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span>
|
|
<span class="n">two_third</span> <span class="o">=</span> <span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="n">finish</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span><span class="p">,</span> <span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="n">finish</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span>
|
|
|
|
<span class="n">length</span> <span class="o">=</span> <span class="p">(((</span><span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">finish</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="p">(</span><span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">finish</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span> <span class="o">**</span> <span class="mf">0.5</span><span class="p">)</span> <span class="o">/</span> <span class="mi">3</span>
|
|
<span class="n">angle</span> <span class="o">=</span> <span class="n">atan</span><span class="p">((</span><span class="n">finish</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">origin</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="p">(</span><span class="n">finish</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
|
|
<span class="n">angle_total</span> <span class="o">=</span> <span class="n">angle</span> <span class="o">+</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">3</span>
|
|
<span class="k">if</span> <span class="n">origin</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">></span> <span class="n">finish</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
|
|
<span class="n">angle_total</span> <span class="o">+=</span> <span class="n">pi</span>
|
|
<span class="n">summit</span> <span class="o">=</span> <span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="n">angle_total</span><span class="p">)</span> <span class="o">*</span> <span class="n">length</span> <span class="o">+</span> <span class="n">third</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">sin</span><span class="p">(</span><span class="n">angle_total</span><span class="p">)</span> <span class="o">*</span> <span class="n">length</span> <span class="o">+</span> <span class="n">third</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
|
|
<span class="k">if</span> <span class="n">iterations</span> <span class="o"><=</span> <span class="mi">1</span><span class="p">:</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">line</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">origin</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">third</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">summit</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">two_third</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">finish</span><span class="p">)],</span>
|
|
<span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">von_koch_curve</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">origin</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">third</span><span class="p">),</span> <span class="n">iterations</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">von_koch_curve</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">third</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">summit</span><span class="p">),</span> <span class="n">iterations</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">von_koch_curve</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">summit</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">two_third</span><span class="p">),</span> <span class="n">iterations</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">von_koch_curve</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">two_third</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_int</span><span class="p">(</span><span class="n">finish</span><span class="p">),</span> <span class="n">iterations</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span></div></div>
|
|
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
<span class="n">img</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="s1">'RGB'</span><span class="p">,</span> <span class="p">(</span><span class="mi">5000</span><span class="p">,</span> <span class="mi">5000</span><span class="p">),</span> <span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="mi">255</span><span class="p">,</span> <span class="mi">255</span><span class="p">))</span>
|
|
<span class="sd">"""figures = Figures(im=img)</span>
|
|
<span class="sd"> figures.blanc_manger((2000, 2000), (3000, 3000), 7, color=(0, 0, 0), width=2)"""</span>
|
|
<span class="n">figures</span> <span class="o">=</span> <span class="n">Lsystem</span><span class="p">(</span><span class="n">im</span><span class="o">=</span><span class="n">img</span><span class="p">)</span>
|
|
<span class="n">figures</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">figures</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="mi">4000</span><span class="p">,</span> <span class="mi">4000</span>
|
|
|
|
<span class="n">figures</span><span class="o">.</span><span class="n">draw_l</span><span class="p">(</span><span class="s2">"F"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"F"</span><span class="p">:</span> <span class="s2">"F+F-F"</span><span class="p">,</span> <span class="p">},</span>
|
|
|
|
<span class="p">{</span><span class="s2">"+"</span><span class="p">:</span> <span class="n">figures</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span><span class="p">),</span> <span class="s1">'-'</span><span class="p">:</span> <span class="n">figures</span><span class="o">.</span><span class="n">right</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span><span class="p">),</span>
|
|
<span class="s2">"F"</span><span class="p">:</span> <span class="n">figures</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="p">},</span> <span class="mi">7</span><span class="p">,</span>
|
|
|
|
<span class="p">(</span><span class="mi">255</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="mi">2</span><span class="p">)</span>
|
|
|
|
<span class="n">figures</span><span class="o">.</span><span class="n">_left</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>
|
|
|
|
<span class="n">figures</span><span class="o">.</span><span class="n">draw_l</span><span class="p">(</span><span class="s2">"F"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"F"</span><span class="p">:</span> <span class="s2">"F+F-F"</span><span class="p">,</span> <span class="p">},</span>
|
|
|
|
<span class="p">{</span><span class="s2">"+"</span><span class="p">:</span> <span class="n">figures</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span><span class="p">),</span> <span class="s1">'-'</span><span class="p">:</span> <span class="n">figures</span><span class="o">.</span><span class="n">right</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span><span class="p">),</span>
|
|
<span class="s2">"F"</span><span class="p">:</span> <span class="n">figures</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="p">},</span> <span class="mi">7</span><span class="p">,</span>
|
|
|
|
<span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">255</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
|
|
|
|
<span class="n">figures</span><span class="o">.</span><span class="n">_left</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>
|
|
|
|
<span class="n">figures</span><span class="o">.</span><span class="n">draw_l</span><span class="p">(</span><span class="s2">"F"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"F"</span><span class="p">:</span> <span class="s2">"F+F-F"</span><span class="p">,</span> <span class="p">},</span>
|
|
|
|
<span class="p">{</span><span class="s2">"+"</span><span class="p">:</span> <span class="n">figures</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span><span class="p">),</span> <span class="s1">'-'</span><span class="p">:</span> <span class="n">figures</span><span class="o">.</span><span class="n">right</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">/</span> <span class="mi">3</span><span class="p">),</span>
|
|
<span class="s2">"F"</span><span class="p">:</span> <span class="n">figures</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="p">},</span> <span class="mi">7</span><span class="p">,</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="mi">255</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
|
|
<span class="n">img</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s2">"D:</span><span class="se">\\</span><span class="s2">Users</span><span class="se">\\</span><span class="s2">louis chauvet</span><span class="se">\\</span><span class="s2">Documents</span><span class="se">\\</span><span class="s2">GitHub</span><span class="se">\\</span><span class="s2">fractale</span><span class="se">\\</span><span class="s2">test.bmp"</span><span class="p">)</span>
|
|
</pre></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
<footer>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>
|
|
© Copyright 2019, Les Collaborateurs Illégitimes.
|
|
|
|
</p>
|
|
</div>
|
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT:'../',
|
|
VERSION:'0.0.1',
|
|
LANGUAGE:'None',
|
|
COLLAPSE_INDEX:false,
|
|
FILE_SUFFIX:'.html',
|
|
HAS_SOURCE: true,
|
|
SOURCELINK_SUFFIX: '.txt'
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="../_static/jquery.js"></script>
|
|
<script type="text/javascript" src="../_static/underscore.js"></script>
|
|
<script type="text/javascript" src="../_static/doctools.js"></script>
|
|
<script type="text/javascript" src="../_static/language_data.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="../_static/js/theme.js"></script>
|
|
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.Navigation.enable(true);
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |