[python/turtle] Turtle::reset() method

This commit is contained in:
Léa Saviot
2018-12-06 16:07:57 +01:00
parent 9c9355deba
commit cc3beb6014
13 changed files with 71 additions and 11 deletions

View File

@@ -7,6 +7,7 @@ extern "C" {
#include "turtle_icon.h"
static constexpr KDSize k_iconSize = KDSize(9, 9);
constexpr KDColor Turtle::k_defaultColor;
template <typename T> static inline T * allocate(size_t count) {
/* We forward dynamic allocations to the Python GC so we don't have to bother
@@ -16,6 +17,25 @@ template <typename T> static inline T * allocate(size_t count) {
return static_cast<T*>(m_malloc(sizeof(T) * count));
}
void Turtle::reset() {
// Erase the drawing
MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->resetSandbox();
// Reset turtle values
m_x = 0;
m_y = 0;
m_heading = k_headingOffset;
m_color = k_defaultColor;
m_penDown = true;
m_visible = true;
m_speed = k_defaultSpeed;
m_penSize = k_defaultPenSize;
m_mileage = 0;
// Draw the turtle
draw();
}
void Turtle::forward(mp_float_t length) {
goTo(
m_x + length * sin(m_heading),