1

I'm trying to find out how to draw a peano curve in tkinter. Should I use create_line?

My second question is how to start writing peano_curve function recursively: where to start drawing, setting steps, setting shutdown condition and so on. Can anyone help me to write this function? I haven't found anything useful on the Internet so far.

Michael Kristofik
  • 34,290
  • 15
  • 75
  • 125
anonf34
  • 313
  • 1
  • 3
  • 8

2 Answers2

1

Your distribution of Python should come with demo scripts which use tkinter (and the turtle module) to draw fractal curves. (Talk about batteries being included! :))

Running

python fractalcurves.py

draws the Hilbert curve:

enter image description here

You could study this code and modify it to draw the Peano curve.


On Ubuntu 11.10 the file is located at /usr/share/doc/python2.7/examples/Demo/turtle/tdemo_fractalcurves.py. If the demo scripts were not packaged with in your distribution of Python, you can also find it in the source code repository here.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
1

Drawing such curves is usually pretty easy. Use "turtle graphics" and L-Systems, and it should be fairly easy.

https://en.wikipedia.org/wiki/L-system

The Peano curve as L-System then just is this:

F -> F+F-F-F-F+F+F+F-F

with 90° rotations on + and -, and F either being recursion or drawing (at the desired level).

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194