Skip to content

Support Multiple Turtles #16

@sunjay

Description

@sunjay

Very low priority until all the drawing methods are completed. Postponed in order to keep the library's implementation as simple as possible while we are still figuring everything out. This will involve refactoring quite a bit of the behind the scenes code in the codebase. We'll have to plan out what those changes should be to meet all the requirements of this feature.

The idea is that we would have an API that looks something like this:

let mut window = TurtleWindow::new();

let turtle1 = window.add_turtle();
let turtle2 = window.add_turtle();
turtle1.forward(100.0);
turtle2.right(90.0);
turtle2.forward(100.0);

The animations would still occur sequentially in this example (one turtle would move at a time). Ideally we would like the turtles to be able to run in multiple threads so that multiple turtles can be drawing on the screen at once.

This feature is excellent for teaching parallel and concurrent programming.

  • Add reset() and clear() methods to Drawing that clear all of the drawings. The turtle reset() and clear() methods only clear that turtle's drawings
  • Are turtles cloneable? Would clone copy the drawings of the turtle or just its current state? (Position, angle, pen, etc.)
  • Does dropping a turtle delete its drawings? (Answer is probably no since each turtle is just a "handle" to data represented in the renderer but still worth considering)
  • Turtle needs to be Send in order for each turtle to be moved into a separate thread, having Turtle be Sync is probably not desirable
  • Add a examples/maze_multiple example that uses multiple turtles to draw the maze concurrently
  • Document that wait_for_click does not work for multiple turtles because it consumes events from the global event pipe

Note that this feature has nothing to do with async. There is a separate issue (#17) open for that.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions