194 lines
12 KiB
HTML
194 lines
12 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
|
||
|
||
<title>Navigation — boxes.py 0.1 documentation</title>
|
||
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/nature.css" />
|
||
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
|
||
<script src="_static/jquery.js"></script>
|
||
<script src="_static/underscore.js"></script>
|
||
<script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
|
||
<script src="_static/doctools.js"></script>
|
||
<script src="_static/sphinx_highlight.js"></script>
|
||
<link rel="shortcut icon" href="_static/favicon.ico"/>
|
||
<link rel="index" title="Index" href="genindex.html" />
|
||
<link rel="search" title="Search" href="search.html" />
|
||
<link rel="next" title="Parts" href="api_parts.html" />
|
||
<link rel="prev" title="Generator Arguments" href="api_arguments.html" />
|
||
</head><body>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="api_parts.html" title="Parts"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="api_arguments.html" title="Generator Arguments"
|
||
accesskey="P">previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="index.html">boxes.py 0.1 documentation</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="apidoc.html" accesskey="U">Using the Boxes.py API</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">Navigation</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="navigation">
|
||
<h1>Navigation<a class="headerlink" href="#navigation" title="Permalink to this heading">¶</a></h1>
|
||
<p>The back end can both move the origin and the current point from
|
||
which the next line is going to start. Boxes.py hides this by using
|
||
Turtle Graphics commands that also move the origin to the end of the
|
||
last line. Other drawing commands restore the current position after
|
||
they are finished.</p>
|
||
<p>Moving the origin like this allows ignoring the absolute coordinates
|
||
and do all movement and drawing to be relative to the current
|
||
position. The current positions does not only consist of a point on
|
||
the drawing canvas but also a direction.</p>
|
||
<p>To move the origin to a different location there are these to methods:</p>
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="boxes.Boxes.moveTo">
|
||
<span class="sig-prename descclassname"><span class="pre">Boxes.</span></span><span class="sig-name descname"><span class="pre">moveTo</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">degrees</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/boxes.html#Boxes.moveTo"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#boxes.Boxes.moveTo" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Move coordinate system to given point</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>x</strong> – </p></li>
|
||
<li><p><strong>y</strong> – (Default value = 0.0)</p></li>
|
||
<li><p><strong>degrees</strong> – (Default value = 0)</p></li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="boxes.Boxes.moveArc">
|
||
<span class="sig-prename descclassname"><span class="pre">Boxes.</span></span><span class="sig-name descname"><span class="pre">moveArc</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">angle</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">r</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.0</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/boxes.html#Boxes.moveArc"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#boxes.Boxes.moveArc" title="Permalink to this definition">¶</a></dt>
|
||
<dd><dl class="field-list simple">
|
||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>angle</strong> – </p></li>
|
||
<li><p><strong>r</strong> – (Default value = 0.0)</p></li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<p>Often it is necessary to return to a position e.g. after placing a
|
||
row of parts. This can be done with the following context manager:</p>
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="boxes.Boxes.saved_context">
|
||
<span class="sig-prename descclassname"><span class="pre">Boxes.</span></span><span class="sig-name descname"><span class="pre">saved_context</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/boxes.html#Boxes.saved_context"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#boxes.Boxes.saved_context" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Generator: for saving and restoring contexts.</p>
|
||
</dd></dl>
|
||
|
||
<p>It can be used with the following code pattern:</p>
|
||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">saved_context</span><span class="p">():</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">rectangularWall</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">move</span><span class="o">=</span><span class="s2">"right"</span><span class="p">)</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">rectangularWall</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">move</span><span class="o">=</span><span class="s2">"right"</span><span class="p">)</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">rectangularWall</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">move</span><span class="o">=</span><span class="s2">"right"</span><span class="p">)</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">rectangularWall</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">move</span><span class="o">=</span><span class="s2">"right"</span><span class="p">)</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">rectangularWall</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">move</span><span class="o">=</span><span class="s2">"up only"</span><span class="p">)</span>
|
||
|
||
<span class="c1"># continue above the row</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Parts of the code still directly use the back end primitives <strong>Boxes.ctx.save()</strong>
|
||
and <strong>Boxes.ctx.restore()</strong>. But this has several disadvantages and is
|
||
discouraged. For one it requires matchiung calls. It also does not
|
||
reset the starting point of the next line. This is “healed” by a
|
||
follow up <strong>.moveTo()</strong>. Use <strong>.moveTo(0, 0)</strong> if in doubt.</p>
|
||
</section>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<p class="logo"><a href="index.html">
|
||
<img class="logo" src="_static/boxes-logo.svg" alt="Logo"/>
|
||
</a></p>
|
||
<div>
|
||
<h3><a href="index.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">Navigation</a><ul>
|
||
<li><a class="reference internal" href="#boxes.Boxes.moveTo"><code class="docutils literal notranslate"><span class="pre">Boxes.moveTo()</span></code></a></li>
|
||
<li><a class="reference internal" href="#boxes.Boxes.moveArc"><code class="docutils literal notranslate"><span class="pre">Boxes.moveArc()</span></code></a></li>
|
||
<li><a class="reference internal" href="#boxes.Boxes.saved_context"><code class="docutils literal notranslate"><span class="pre">Boxes.saved_context()</span></code></a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="api_arguments.html"
|
||
title="previous chapter">Generator Arguments</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="api_parts.html"
|
||
title="next chapter">Parts</a></p>
|
||
</div>
|
||
<div role="note" aria-label="source link">
|
||
<h3>This Page</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="_sources/api_navigation.rst.txt"
|
||
rel="nofollow">Show Source</a></li>
|
||
</ul>
|
||
</div>
|
||
<div id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<script>document.getElementById('searchbox').style.display = "block"</script>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="api_parts.html" title="Parts"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="api_arguments.html" title="Generator Arguments"
|
||
>previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="index.html">boxes.py 0.1 documentation</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="apidoc.html" >Using the Boxes.py API</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">Navigation</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2016, Florian Festi.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
|
||
</div>
|
||
</body>
|
||
</html> |