-
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
Adding arc() method to Turtle #100
Conversation
Hello! Thanks for adding this method! Also, congrats on getting issue/PR number #100! That's a big milestone for the project! 🎉 My apologies for not getting back to your issue comment. I saw it, thought of my response, and then must have forgotten to actually send it. 😅 Your implementation is a good start and I'd like to see how it behaves when it is used in a drawing. Could you add an example to the examples directory that uses this function to draw a couple of different arcs? In particular it would be good to try it with different pen thicknesses to see what happens. Try drawing parts of circles, entire circles, and then do bigger angles like 800 or something. This will probably bring out some interesting edge cases and will help me verify the implementation. I have some other review comments that I will add later when I have a chance to look at this PR in more detail. My response above should give you something to work on in the meantime. Thanks again for adding this method! Let me know if you have any questions about any of this. 😄 |
Hey @sunjay ! Ive added a simple example that draws the beats logo. I did notice some issues while working with different pen sizes. For example the below code let mut turtle = Turtle::new();
turtle.drawing_mut().set_background_color("black");
let _radius= 50.0;
turtle.set_pen_size(100.0);
turtle.set_pen_color("light blue");
turtle.arc(_radius, None); seems to generate this weird pattern. I've notice this becomes more evident as the pen size approaches radius. Radius = 2.0 let mut turtle = Turtle::new();
turtle.drawing_mut().set_background_color("black");
let _radius= 2.0;
turtle.set_pen_size(100.0);
turtle.set_pen_color("light blue");
turtle.arc(_radius, None); Radius = 15.0 let mut turtle = Turtle::new();
turtle.drawing_mut().set_background_color("black");
let _radius= 15.0;
turtle.set_pen_size(100.0);
turtle.set_pen_color("light blue");
turtle.arc(_radius, None); Radius = 25.0 let mut turtle = Turtle::new();
turtle.drawing_mut().set_background_color("black");
let _radius= 25.0;
turtle.set_pen_size(100.0);
turtle.set_pen_color("light blue");
turtle.arc(_radius, None); Any ideas on what could be causing this behavior? Cheers |
Hello! Thanks for continuing to work on this! 😄
Yes! This is actually exactly why I wanted you to test with different line thicknesses. I had a suspicion that we would run into this issue. Check out this code in the Rust logo example: Lines 136 to 143 in 05a5fa1
I suggest you try to replace those two movements in that code example with a single movement ExplanationThe problem is that when turtle draws, it takes very small steps. If the pen thickness is very large, these steps become very wide but still only go forward a short distance. This ends up resulting in the turtle drawing several very thin lines perpendicular to itself. That's what you're seeing in the screenshots that you provided. Potential SolutionThe solution to this is to make our approach a little more sophisticated. Instead of drawing individual lines, we should probably use something like a BackgroundTo give you an idea of what we would have to do, let's look at how This is the source code of that method: Lines 118 to 120 in 05a5fa1
This calls the method with the same name on Lines 127 to 159 in 05a5fa1
This method calculates the start, end, and duration of the movement animation, starts a timer, and then begins to play that animation synchronously. Lines 67 to 90 in 05a5fa1
The animation is driven by the If the animation is still running, we pass in a Lines 184 to 200 in 05a5fa1
These paths are sent to the renderer process to be drawn by the renderer via a drawing command: Lines 25 to 36 in 05a5fa1
The drawing commands are processed in the following: Lines 153 to 166 in 05a5fa1
Then, the temporary path and each stored path are rendered in the renderer: Lines 200 to 246 in 05a5fa1
The result of all of this is the lines that show up on your screen! Mentoring InstructionsTo implement Looking at all of this, it is actually a pretty monumental task to get arc support setup! I'm so sorry I didn't see this sooner! It took your experimenting for me to realize that a more complicated solution is actually necessary. If you would like to continue working on this, I can take you there step by step through a series of smaller PRs. This is too big to be done in a single contribution. That being said, the size and scope of this task has suddenly gotten quite big so I totally understand if you don't have the time to work on it. :) Let me know what you are willing to do (and have time for). Sorry again for not anticipating this sooner. |
Hey @sunjay Thanks for the detailed explanation about what causes the issue. Regarding further course of action the changes necessary could be broken down into smaller issues which can be picked up as time permits. |
Thank you for being understanding! I will add more information to the original issue and close this PR for the time being. I really appreciate you investing your time and my apologies for not realizing the complexity of this issue sooner. |
Fixes #82