[python/turtle] Fix unwanted dotted lines

Script:
fd(200)
left(90)
fd(10)
left(90)
fd(600)
The final line should be continuous but is dotted
This commit is contained in:
Léa Saviot
2019-02-05 16:54:50 +01:00
committed by EmilieNumworks
parent a021af46fe
commit a25b2a8ce5

View File

@@ -76,16 +76,23 @@ void Turtle::circle(mp_int_t radius, mp_float_t angle) {
bool Turtle::goTo(mp_float_t x, mp_float_t y) {
mp_float_t oldx = m_x;
mp_float_t oldy = m_y;
mp_float_t length = maxF(absF(floor(x) - floor(oldx)), absF(floor(y) - floor(oldy)));
mp_float_t xLength = absF(floor(x) - floor(oldx));
mp_float_t yLength = absF(floor(y) - floor(oldy));
bool principalDirectionIsX = xLength >= yLength;
mp_float_t length = principalDirectionIsX ? xLength : yLength;
if (length > 1) {
// Tweening function
for (int i = 1; i < length; i++) {
mp_float_t progress = i / length;
erase();
if (dot(x * progress + oldx * (1 - progress), y * progress + oldy * (1 - progress))
|| draw(false))
{
/* We make sure that each pixel along the principal direction is drawn. If
* the computation of the position on the principal coordinate is done
* using a barycenter, roundings might skip some pixels, which results in
* a dotted line. */
mp_float_t currentX = principalDirectionIsX ? oldx + (x > oldx ? i : -i) : x * progress + oldx * (1 - progress);
mp_float_t currentY = principalDirectionIsX ? y * progress + oldy * (1 - progress) : oldy + (y > oldy ? i : -i);
if (dot(currentX, currentY) || draw(false)) {
// Keyboard interruption. Return now to let MicroPython process it.
return true;
}