-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undo/Redo #105
Comments
The L-systems workshop mentioned in this issue is slightly different from the undo/redo functionality. In the example the turtle is extended with a push and pop function. Push pushes the current state of the turtle, i.e. it's position and heading, onto a stack. Pop set the state of the turtle to whatever comes of the stack. The functionality is shown below fn push(&mut self) {
let position = self.turtle.position();
let heading = self.turtle.heading();
let state = State::new(position, heading);
self.stack.push(state);
}
fn pop(&mut self) {
let state_option = self.stack.pop();
if state_option.is_some() {
let state = state_option.unwrap();
self.turtle.pen_up();
self.turtle.go_to(state.position);
self.turtle.set_heading(state.heading);
self.turtle.pen_down();
} |
Ah! That makes sense! Undo/redo is definitely different from that. I wonder if a feature like the push/pop you implemented is useful as part of the turtle crate or better as an extension like the one you implemented. The undo/redo feature described in this issue is still definitely important. I am happy to provide mentoring for anyone interested in working on it. 😄 |
If push/pop is worthwhile is for you to decide 😃 |
Yes! I'll have to think about it more. Thanks for clarifying 😄 |
No, don't use push/pop. Record all state changes in append-only history. If you know the speed of the turtle, you can calculate key frames.
To display the turtle at any given time, you can find two nearest key frames and use linear interpolation to calculate precise location. PoC: https://github.com/buckle2000/turtle-playback The following struct supports fd, bk, lt, rt, pu, pd. |
As part of the new architecture in #173, I made it so that each turtle keeps a list of all the drawings it has created. Those lists of drawings will become the foundation upon which we implement undo/redo. Since multiple turtles are all adding to the display list, we can't just remove the last time and hope it was from the right turtle. These lists give us a way to know exactly which drawing primitive should be removed or re-added. The work involved in this issue is a bit more complicated now, but definitely still doable if anyone is interested in working on it! |
https://docs.python.org/2/library/turtle.html#turtle.undo
A per-turtle way to support undoing and then potentially redoing the last actions of a given turtle. Since we only have one turtle per drawing right now, it is fine to maintain just a single undo stack, but the idea is that this feature will eventually work well with multiple turtles (#16) as well.
We can also add something called a "save point" to return an identifier to a particular point in the turtle's state. This can be used to undo/redo the drawing back to a particular point. Then, instead of an undo stack, we could even make an undo graph/tree where you can go back and forth to any arbitrary point in history. Modeling it as a graph is probably a much later extension to what can start as a simpler feature.
This undo/redo functionality is related to the Push & Pop functionality added to this L-systems workshop that uses turtle.The text was updated successfully, but these errors were encountered: