On 3/1/2020 4:54 AM, Giuseppe wrote:
Hi,

I am new to Python.
I already tried turtle and it works well for my needs.

I would like to draw fractals using turtle module. There are many ways to do that but I would like to use multiple turtles drawing in parallel but I don't know how.

My first idea is to use clones as I do with Scratch (the problem with Scratch is the maximum number of simultaneous clones is set to 300) : each clone draw a part of the fractal and each clone (before being deleted) create clones who do the same thing and so on and so on...

1/ Is it possible to clone turtles ?
2/ Is it possible to make them work simultaneously ?
3/ Should I use multiple turtles instead ?
4/ Are there special things I should read first ?

1 & 3. I don't know what a Scratch clone is so I don't know the difference between 1 and 3. I suspect the answer is 3. Note that turtle provides a default turtle. Then one can create more with Turtle().

2. Truly in parallel? no. Turtle module uses a tk Canvas and one can only draw to a canvas from one process. One can instead rotate among turtles so it looks like they move 'simultaneously'.

4. Run 'python -m turtle' and watch the two demos, especially the last part of the second. Then read demo2() starting with

        tri = getturtle()  # Default turtle, chaser.
        tri.resizemode("auto")  # New turtle, chased.
# ... and loop.
        while tri.distance(turtle) > 4:
            turtle.fd(3.5)
            turtle.lt(0.6)
            tri.setheading(tri.towards(turtle))
            tri.fd(4)

For your purpose, you should, for instance, make a Turtle subclass with additional data and an extra 'tick' method to move according to the extra instance data. Remember that modifying collections while iterating through them is either prohibited or tricky.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to