.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/gallery_hilbert.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_gallery_hilbert.py: Hilbert curve ============= .. figure:: /../../_static/figures/auto_examples/hilbert/hilbert.jpg :width: 100% :alt: An image of the embroidery machine making the Hilbert curve. .. GENERATED FROM PYTHON SOURCE LINES 11-42 .. image-sg:: /auto_examples/images/sphx_glr_gallery_hilbert_001.png :alt: hilbert.png :srcset: /auto_examples/images/sphx_glr_gallery_hilbert_001.png :class: sphx-glr-single-img .. code-block:: default from turtlethread import Turtle def draw_hilbertkurve(needle, step_length, recursion_level, angle=90): if recursion_level == 0: return needle.right(angle) draw_hilbertkurve(needle, step_length, recursion_level-1, -angle) needle.forward(step_length) needle.left(angle) draw_hilbertkurve(needle, step_length, recursion_level-1, angle) needle.forward(step_length) draw_hilbertkurve(needle, step_length, recursion_level-1, angle) needle.left(angle) needle.forward(step_length) draw_hilbertkurve(needle, step_length, recursion_level-1, -angle) needle.right(angle) needle = Turtle() with needle.running_stitch(20): draw_hilbertkurve(needle, 20, 5) needle.save("hilbert.jef") needle.save("hilbert.png") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.094 seconds) .. _sphx_glr_download_auto_examples_gallery_hilbert.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: gallery_hilbert.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: gallery_hilbert.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_