Skip to content
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

Correction CIRCLE avec angle négatif (correct circle with negative angle) #294

Open
wants to merge 4 commits into
base: upsilon-dev
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions python/port/mod/turtle/turtle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,22 @@ void Turtle::left(mp_float_t angle) {
void Turtle::circle(mp_int_t radius, mp_float_t angle) {
mp_float_t oldHeading = heading();
mp_float_t length = std::fabs(angle * k_headingScale * radius);
int direction = 1; // 1=fwd, -1=backward
fmOOmf marked this conversation as resolved.
Show resolved Hide resolved
if (angle < 0) { direction =-1; }
if (length > 1) {
for (int i = 1; i < length; i++) {
mp_float_t progress = i / length;
// Move the turtle forward
if (forward(1)) {
if (forward(direction)) {
// Keyboard interruption. Return now to let MicroPython process it.
return;
}
setHeadingPrivate(oldHeading+std::copysign(angle*progress, radius));
setHeadingPrivate(oldHeading+std::copysign(angle*progress, direction*radius));
}
forward(1);
setHeading(oldHeading+angle);
forward(direction);
setHeading(oldHeading+std::copysign(angle, direction*radius));
}

}

bool Turtle::goTo(mp_float_t x, mp_float_t y) {
Expand Down