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

[python] Turtle module #748

Merged
merged 59 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
464c1a5
[python] Initial turtle module
boricj Oct 27, 2018
0a05b94
[python] Turtle module improvements
boricj Oct 28, 2018
ca589b9
[python] Fix turtle icon dependency
boricj Oct 28, 2018
3a7ae27
[python] Fix turtle icon dependency (for real)
boricj Oct 28, 2018
9e24370
[python] Clean up turtle code and samples
boricj Oct 28, 2018
0c94f44
[python] Return value for turtle.pensize()
boricj Oct 30, 2018
fcf7cc3
[python] Implement turtle.position()
boricj Oct 30, 2018
c89a369
[python] Add getters for turtle module
boricj Oct 30, 2018
34f5aba
[python] Add turtle toolbox
boricj Oct 30, 2018
efaa87d
Merge branch 'master' into python_turtle
Ecco Nov 16, 2018
82f0b71
[python/turtle] Use micropython_port_interruptible_msleep
Ecco Nov 16, 2018
22a39a2
[python/turtle] Use a dedicated folder
Ecco Nov 16, 2018
fe076d0
[python/turtle] Use mp_float_t
Ecco Nov 16, 2018
a9091c9
[python/turtle] Use a Turtle class
Ecco Nov 16, 2018
7fc34fe
[python/turtle] Use an init method to reset the turtle
Ecco Nov 16, 2018
5748521
[python/turtle] Try to play well with uPy's GC
Ecco Nov 16, 2018
467ae9c
[python/turtle] Fix small typos
Ecco Nov 16, 2018
05a2491
[python/turtle] Fix the heading
Ecco Nov 16, 2018
49e8a50
[python] Fix micropython_port_interruptible_msleep
LeaNumworks Dec 5, 2018
1e78f20
[python] Return after interruption in possibly long turtle methods
LeaNumworks Dec 6, 2018
4b3ce7a
[python/turtle] Fix Turtle::setSpeed
LeaNumworks Dec 6, 2018
e769255
[python/turtle] Default pen size is 1
LeaNumworks Dec 6, 2018
d530637
[python/turtle] Fix speed type
LeaNumworks Dec 6, 2018
432e259
[python/turtle] Speed max and min should produce the same behavior
LeaNumworks Dec 6, 2018
3ca1790
[python/turtle] The Y axis is oriented upwards
LeaNumworks Dec 6, 2018
9c9355d
[python/turtle] Use Escher::Metric values instead of copying them
LeaNumworks Dec 6, 2018
cc3beb6
[python/turtle] Turtle::reset() method
LeaNumworks Dec 6, 2018
c8a5972
[python/turtle] Turtle::circle(radius, angle)
LeaNumworks Dec 7, 2018
e836593
[kandinsky] In KDContext::getPixels: beware of rects crossing the screen
LeaNumworks Dec 7, 2018
c95e291
[python/turtle] First icon redesign
LeaNumworks Dec 7, 2018
3b33425
[python/turlte] Move the turtle paws to mimic crawling
LeaNumworks Dec 10, 2018
3249ccb
[python/turtle] "back()" shortcut for "backwards()"
LeaNumworks Dec 10, 2018
fa0e93e
[python/turtle] Fix Turtle::circle for negative angles
LeaNumworks Dec 10, 2018
7efb48a
[python/turtle] Turtle::circle's angle argument is optional
LeaNumworks Dec 10, 2018
d545c45
[python/turtle] When speed = 0, do not draw the turtle during "goTo"
LeaNumworks Dec 10, 2018
23e3038
[python/turtle] Remove waitForVBlank before drawings
LeaNumworks Dec 10, 2018
62cda01
[python/turtle] color and pencolor can take various arguments
LeaNumworks Dec 11, 2018
3bd3e64
[python/turtle] Order the qstr
LeaNumworks Dec 11, 2018
99d71bb
[python/turtle] Clean Turtle::setColor
LeaNumworks Dec 12, 2018
8ac6098
[python/turtle] Remove old turtle icon
LeaNumworks Dec 12, 2018
91c4fea
[python/turtle] Clean Turtle::PawPosition
LeaNumworks Dec 12, 2018
306869e
[python/turtle] Tune values of the turtle speed
LeaNumworks Dec 11, 2018
609740b
[apps/code] Order catalog.universal.i18n
LeaNumworks Dec 17, 2018
8a3aa1a
[apps/code] Add turtle functions in th python toolbox
LeaNumworks Dec 17, 2018
b058b02
[apps/code] Add turtle functions in the toolbox catalog
LeaNumworks Dec 17, 2018
b3c11f2
[apps/code] Put turtle module higher in Python toolbox
LeaNumworks Dec 17, 2018
62de89c
[apps/code] Fix 'blue', 'red', ... python command insertion
LeaNumworks Dec 17, 2018
101370c
[escher] Change ToolboxMessageTree constructors
LeaNumworks Dec 17, 2018
ad745f7
[python/turtle] Add speed() methods without args
LeaNumworks Dec 17, 2018
ed19d19
Merge branch 'master' into python_turtle
LeaNumworks Dec 17, 2018
4b30679
[python/turtle] Turtle::m_drawn is false if sandbox not displayed
LeaNumworks Dec 17, 2018
de6646a
[build/emscripten] Add turtle symbols to the whitelist
LeaNumworks Dec 18, 2018
5a941bc
[python/turtle] Clean circle code
LeaNumworks Dec 21, 2018
c2dbe9f
[python/turtle] Fix line drawing glitches
LeaNumworks Dec 21, 2018
df2b9c4
[escher/apps] Get children count via template in ToolboxMessageTree::…
LeaNumworks Dec 21, 2018
03f300a
[python/turtle] Add showturtle and hideturtle to the toolbox
LeaNumworks Dec 27, 2018
384fa04
[apps/code] Change the default scripts: squares instead of factorial
LeaNumworks Dec 27, 2018
9b07f19
[apps/code] Squares script template: start by resetting the turtle
LeaNumworks Jan 3, 2019
4f4ae4e
Merge branch 'master' into python_turtle
LeaNumworks Jan 8, 2019
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
14 changes: 14 additions & 0 deletions apps/code/catalog.de.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ PythonImportCmath = "Import cmath module"
PythonImportKandinsky = "Import kandinsky module"
PythonImportRandom = "Import random module"
PythonImportMath = "Import math module"
PythonImportTurtle = "Import turtle module"
PythonImportFromCmath = "Import cmath module"
PythonImportFromKandinsky = "Import kandinsky module"
PythonImportFromRandom = "Import random module"
PythonImportFromMath = "Import math module"
PythonImportFromTurtle = "Import turtle module"
PythonInput = "Prompt a value"
PythonInt = "Convert x to an integer"
PythonIsFinite = "Check if x is finite"
Expand Down Expand Up @@ -92,4 +94,16 @@ PythonSum = "Sum the items of a list"
PythonTan = "Tangent"
PythonTanh = "Hyperbolic tangent"
PythonTrunc = "x truncated to an integer"
PythonTurtleFunction = "turtle module function prefix"
PythonTurtleForward = "Move the turtle forward"
PythonTurtleBackward = "Move the turtle backward"
PythonTurtleLeft = "Turn turtle to the left"
PythonTurtleRight = "Turn turtle to the right"
PythonTurtlePosition = "Get turtle position"
PythonTurtleSetposition = "Set turtle position"
PythonTurtleHeading = "Get turtle angle"
PythonTurtleSetheading = "Set turtle angle"
PythonTurtleSpeed = "Set turtle speed"
PythonTurtlePencolor = "Set pen color"
PythonTurtlePensize = "Get/Set pen width"
PythonUniform = "Floating point number in [a,b]"
14 changes: 14 additions & 0 deletions apps/code/catalog.en.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ PythonImportCmath = "Import cmath module"
PythonImportKandinsky = "Import kandinsky module"
PythonImportRandom = "Import random module"
PythonImportMath = "Import math module"
PythonImportTurtle = "Import turtle module"
PythonImportFromCmath = "Import cmath module"
PythonImportFromKandinsky = "Import kandinsky module"
PythonImportFromRandom = "Import random module"
PythonImportFromMath = "Import math module"
PythonImportFromTurtle = "Import turtle module"
PythonInput = "Prompt a value"
PythonInt = "Convert x to an integer"
PythonIsFinite = "Check if x is finite"
Expand Down Expand Up @@ -92,4 +94,16 @@ PythonSum = "Sum the items of a list"
PythonTan = "Tangent"
PythonTanh = "Hyperbolic tangent"
PythonTrunc = "x truncated to an integer"
PythonTurtleFunction = "turtle module function prefix"
PythonTurtleForward = "Move the turtle forward"
PythonTurtleBackward = "Move the turtle backward"
PythonTurtleLeft = "Turn turtle to the left"
PythonTurtleRight = "Turn turtle to the right"
PythonTurtlePosition = "Get turtle position"
PythonTurtleSetposition = "Set turtle position"
PythonTurtleHeading = "Get turtle angle"
PythonTurtleSetheading = "Set turtle angle"
PythonTurtleSpeed = "Set turtle speed"
PythonTurtlePencolor = "Set pen color"
PythonTurtlePensize = "Get/Set pen width"
PythonUniform = "Floating point number in [a,b]"
14 changes: 14 additions & 0 deletions apps/code/catalog.es.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ PythonImportCmath = "Import cmath module"
PythonImportKandinsky = "Import kandinsky module"
PythonImportRandom = "Import random module"
PythonImportMath = "Import math module"
PythonImportTurtle = "Import turtle module"
PythonImportFromCmath = "Import cmath module"
PythonImportFromKandinsky = "Import kandinsky module"
PythonImportFromRandom = "Import random module"
PythonImportFromMath = "Import math module"
PythonImportFromTurtle = "Import turtle module"
PythonInput = "Prompt a value"
PythonInt = "Convert x to an integer"
PythonIsFinite = "Check if x is finite"
Expand Down Expand Up @@ -92,4 +94,16 @@ PythonSum = "Sum the items of a list"
PythonTan = "Tangent"
PythonTanh = "Hyperbolic tangent"
PythonTrunc = "x truncated to an integer"
PythonTurtleFunction = "turtle module function prefix"
PythonTurtleForward = "Move the turtle forward"
PythonTurtleBackward = "Move the turtle backward"
PythonTurtleLeft = "Turn turtle to the left"
PythonTurtleRight = "Turn turtle to the right"
PythonTurtlePosition = "Get turtle position"
PythonTurtleSetposition = "Set turtle position"
PythonTurtleHeading = "Get turtle angle"
PythonTurtleSetheading = "Set turtle angle"
PythonTurtleSpeed = "Set turtle speed"
PythonTurtlePencolor = "Set pen color"
PythonTurtlePensize = "Get/Set pen width"
PythonUniform = "Floating point number in [a,b]"
14 changes: 14 additions & 0 deletions apps/code/catalog.fr.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ PythonImportCmath = "Importation du module cmath"
PythonImportKandinsky = "Importation du module kandinsky"
PythonImportRandom = "Importation du module random"
PythonImportMath = "Importation du module math"
PythonImportTurtle = "Importation du module turtle"
PythonImportFromCmath = "Importation du module cmath"
PythonImportFromKandinsky = "Importation du module kandinsky"
PythonImportFromRandom = "Importation du module random"
PythonImportFromMath = "Importation du module math"
PythonImportFromTurtle = "Importation du module turtle"
PythonInput = "Entrer une valeur"
PythonInt = "Conversion en entier"
PythonIsFinite = "Teste si x est fini"
Expand Down Expand Up @@ -92,4 +94,16 @@ PythonSum = "Somme des éléments d'une liste"
PythonTan = "Tangente"
PythonTanh = "Tangente hyperbolique"
PythonTrunc = "Troncature entière"
PythonTurtleFunction = "Préfixe fonction du module math"
PythonTurtleForward = "Avance la tortue"
PythonTurtleBackward = "Recule la tortue"
PythonTurtleLeft = "Tourne la tortue à gauche"
PythonTurtleRight = "Tourne la tortue à droite"
PythonTurtlePosition = "Position de la tortue"
PythonTurtleSetposition = "Positionne la tortue"
PythonTurtleHeading = "Direction de la tortue"
PythonTurtleSetheading = "Tourne la tortue"
PythonTurtleSpeed = "Vitesse de la tortue"
PythonTurtlePencolor = "Couleur du crayon"
PythonTurtlePensize = "Largeur du crayon"
PythonUniform = "Nombre décimal dans [a,b]"
14 changes: 14 additions & 0 deletions apps/code/catalog.pt.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ PythonImportCmath = "Import cmath module"
PythonImportKandinsky = "Import kandinsky module"
PythonImportRandom = "Import random module"
PythonImportMath = "Import math module"
PythonImportTurtle = "Import turtle module"
PythonImportFromCmath = "Import cmath module"
PythonImportFromKandinsky = "Import kandinsky module"
PythonImportFromRandom = "Import random module"
PythonImportFromMath = "Import math module"
PythonImportFromTurtle = "Import turtle module"
PythonInput = "Prompt a value"
PythonInt = "Convert x to an integer"
PythonIsFinite = "Check if x is finite"
Expand Down Expand Up @@ -92,4 +94,16 @@ PythonSum = "Sum the items of a list"
PythonTan = "Tangent"
PythonTanh = "Hyperbolic tangent"
PythonTrunc = "x truncated to an integer"
PythonTurtleFunction = "turtle module function prefix"
PythonTurtleForward = "Move the turtle forward"
PythonTurtleBackward = "Move the turtle backward"
PythonTurtleLeft = "Turn turtle to the left"
PythonTurtleRight = "Turn turtle to the right"
PythonTurtlePosition = "Get turtle position"
PythonTurtleSetposition = "Set turtle position"
PythonTurtleHeading = "Get turtle angle"
PythonTurtleSetheading = "Set turtle angle"
PythonTurtleSpeed = "Set turtle speed"
PythonTurtlePencolor = "Set pen color"
PythonTurtlePensize = "Get/Set pen width"
PythonUniform = "Floating point number in [a,b]"
15 changes: 15 additions & 0 deletions apps/code/catalog.universal.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ PythonCommandImportFromCmath = "from cmath import *"
PythonCommandImportFromMath = "from math import *"
PythonCommandImportFromKandinsky = "from kandinsky import *"
PythonCommandImportFromRandom = "from random import *"
PythonCommandImportFromTurtle = "from turtle import *"
PythonCommandHex = "hex(x)"
PythonCommandImportCmath = "import cmath"
PythonCommandImportKandinsky = "import kandinsky"
PythonCommandImportRandom = "import random"
PythonCommandImportMath = "import math"
PythonCommandImportTurtle = "import turtle"
PythonCommandInput = "input(\"text\")"
PythonCommandInt = "int(x)"
PythonCommandIsFinite = "isfinite(x)"
Expand Down Expand Up @@ -96,6 +98,19 @@ PythonCommandSorted = "sorted(list)"
PythonCommandSqrt = "sqrt(x)"
PythonCommandSqrtComplex = "sqrt(z)"
PythonCommandSum = "sum(list)"
PythonCommandTurtleFunction = "turtle.function"
PythonCommandTurtleFunctionWithoutArg = "turtle.ø"
PythonTurtleCommandForward = "forward(d)"
PythonTurtleCommandBackward = "backward(d)"
PythonTurtleCommandLeft = "left(a)"
PythonTurtleCommandRight = "right(a)"
PythonTurtleCommandPosition = "position()"
PythonTurtleCommandSetposition = "setposition(x, [y])"
PythonTurtleCommandHeading = "heading()"
PythonTurtleCommandSetheading = "setheading(a)"
PythonTurtleCommandSpeed = "speed(s)"
PythonTurtleCommandPencolor = "pencolor(r, g, b)"
PythonTurtleCommandPensize = "pensize([w])"
PythonCommandTan = "tan(x)"
PythonCommandTanh = "tanh(x)"
PythonCommandTrunc = "trunc(x)"
Expand Down
7 changes: 7 additions & 0 deletions apps/code/console_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ void ConsoleController::displaySandbox() {
stackViewController()->push(&m_sandboxController);
}

void ConsoleController::resetSandbox() {
if (!m_sandboxIsDisplayed) {
return;
}
m_sandboxController.reset();
}

/* printText is called by the Python machine.
* The text argument is not always null-terminated. */
void ConsoleController::printText(const char * text, size_t length) {
Expand Down
1 change: 1 addition & 0 deletions apps/code/console_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ConsoleController : public ViewController, public ListViewDataSource, publ

// MicroPython::ExecutionEnvironment
void displaySandbox() override;
void resetSandbox() override;
void printText(const char * text, size_t length) override;
const char * inputText(const char * prompt) override;

Expand Down
24 changes: 22 additions & 2 deletions apps/code/python_toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ static constexpr int MathModuleChildrenCount = 43;
static constexpr int KandinskyModuleChildrenCount = 7;
static constexpr int CMathModuleChildrenCount = 13;
static constexpr int RandomModuleChildrenCount = 10;
static constexpr int TurtleModuleChildrenCount = 14;

static constexpr int conditionsChildrenCount = 9;
static constexpr int forLoopChildrenCount = 4;
static constexpr int functionsChildrenCount = 2;
static constexpr int ifStatementChildrenCount = 5;
static constexpr int loopsAndTestsChildrenCount = 4;
static constexpr int menuChildrenCount = 4;
static constexpr int modulesChildrenCount = 4;
static constexpr int modulesChildrenCount = 5;
static constexpr int whileLoopChildrenCount = 1;


Expand Down Expand Up @@ -138,11 +140,29 @@ const ToolboxMessageTree CMathModuleChildren[CMathModuleChildrenCount] = {
ToolboxMessageTree(I18n::Message::PythonCommandCosComplex, I18n::Message::PythonCos, I18n::Message::PythonCommandCos),
ToolboxMessageTree(I18n::Message::PythonCommandSinComplex, I18n::Message::PythonSin, I18n::Message::PythonCommandSin)};

const ToolboxMessageTree TurtleModuleChildren[TurtleModuleChildrenCount] = {
ToolboxMessageTree(I18n::Message::PythonCommandImportTurtle, I18n::Message::PythonImportTurtle, I18n::Message::PythonCommandImportTurtle),
ToolboxMessageTree(I18n::Message::PythonCommandImportFromTurtle, I18n::Message::PythonImportFromTurtle, I18n::Message::PythonCommandImportFromTurtle),
ToolboxMessageTree(I18n::Message::PythonCommandTurtleFunction, I18n::Message::PythonTurtleFunction, I18n::Message::PythonCommandTurtleFunctionWithoutArg),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandForward, I18n::Message::PythonTurtleForward, I18n::Message::PythonTurtleCommandForward),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandBackward, I18n::Message::PythonTurtleBackward, I18n::Message::PythonTurtleCommandBackward),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandLeft, I18n::Message::PythonTurtleLeft, I18n::Message::PythonTurtleCommandLeft),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandRight, I18n::Message::PythonTurtleRight, I18n::Message::PythonTurtleCommandRight),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandPosition, I18n::Message::PythonTurtlePosition, I18n::Message::PythonTurtleCommandPosition),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandSetposition, I18n::Message::PythonTurtleSetposition, I18n::Message::PythonTurtleCommandSetposition),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandHeading, I18n::Message::PythonTurtleHeading, I18n::Message::PythonTurtleCommandHeading),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandSetheading, I18n::Message::PythonTurtleSetheading, I18n::Message::PythonTurtleCommandSetheading),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandSpeed, I18n::Message::PythonTurtleSpeed, I18n::Message::PythonTurtleCommandSpeed),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandPencolor, I18n::Message::PythonTurtlePencolor, I18n::Message::PythonTurtleCommandPencolor),
ToolboxMessageTree(I18n::Message::PythonTurtleCommandPensize, I18n::Message::PythonTurtlePensize, I18n::Message::PythonTurtleCommandPensize)};


const ToolboxMessageTree modulesChildren[modulesChildrenCount] = {
ToolboxMessageTree(I18n::Message::MathModule, I18n::Message::Default, I18n::Message::Default, MathModuleChildren, MathModuleChildrenCount),
ToolboxMessageTree(I18n::Message::CmathModule, I18n::Message::Default, I18n::Message::Default, CMathModuleChildren, CMathModuleChildrenCount),
ToolboxMessageTree(I18n::Message::RandomModule, I18n::Message::Default, I18n::Message::Default, RandomModuleChildren, RandomModuleChildrenCount),
ToolboxMessageTree(I18n::Message::KandinskyModule, I18n::Message::Default, I18n::Message::Default, KandinskyModuleChildren, KandinskyModuleChildrenCount)};
ToolboxMessageTree(I18n::Message::KandinskyModule, I18n::Message::Default, I18n::Message::Default, KandinskyModuleChildren, KandinskyModuleChildrenCount),
ToolboxMessageTree(I18n::Message::TurtleModule, I18n::Message::Default, I18n::Message::Default, TurtleModuleChildren, TurtleModuleChildrenCount)};

const ToolboxMessageTree catalogChildren[catalogChildrenCount] = {
ToolboxMessageTree(I18n::Message::PythonCommandPound, I18n::Message::PythonPound, I18n::Message::PythonCommandPound),
Expand Down
11 changes: 10 additions & 1 deletion apps/code/sandbox_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ StackViewController * SandboxController::stackViewController() {
return static_cast<StackViewController *>(parentResponder());
}

void SandboxController::reset() {
m_solidColorView.reload();
redrawWindow();
}

void SandboxController::viewWillAppear() {
static_cast<AppsContainer *>(const_cast<Container *>(app()->container()))->redrawWindow();
redrawWindow();
}

bool SandboxController::handleEvent(Ion::Events::Event event) {
Expand All @@ -28,4 +33,8 @@ bool SandboxController::handleEvent(Ion::Events::Event event) {
return true;
}

void SandboxController::redrawWindow() {
static_cast<AppsContainer *>(const_cast<Container *>(app()->container()))->redrawWindow();
}

}
2 changes: 2 additions & 0 deletions apps/code/sandbox_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SandboxController : public ViewController {
public:
SandboxController(Responder * parentResponder);
StackViewController * stackViewController();
void reset();

// ViewController
View * view() override { return &m_solidColorView; }
Expand All @@ -20,6 +21,7 @@ class SandboxController : public ViewController {
ViewController::DisplayParameter displayParameter() override { return ViewController::DisplayParameter::WantsMaximumSpace; }

private:
void redrawWindow();
SolidColorView m_solidColorView;
};
}
Expand Down
2 changes: 2 additions & 0 deletions apps/code/script_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ ScriptStore::ScriptStore()
addScriptFromTemplate(ScriptTemplate::Factorial());
addScriptFromTemplate(ScriptTemplate::Mandelbrot());
addScriptFromTemplate(ScriptTemplate::Polynomial());
addScriptFromTemplate(ScriptTemplate::Spiral());
addScriptFromTemplate(ScriptTemplate::Koch());
}

void ScriptStore::deleteAllScripts() {
Expand Down
41 changes: 41 additions & 0 deletions apps/code/script_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ def roots(a,b,c):
else:
return None)");

constexpr ScriptTemplate spiralScriptTemplate("spiral.py", "\x01" R"(from turtle import *
def spiral(N_iteration):
N_iteration *= 25
for i in range(N_iteration):
# Change pen color
gray=255-(i*255/N_iteration)
pencolor(int(gray),int(gray*0.75),int(gray*0.25))
# Draw a segment of the spiral
forward(i*0.1)
left(10))");

constexpr ScriptTemplate kochScriptTemplate("koch.py", "\x01" R"(from turtle import *
def koch(N_iteration):
# Save pencil size and set it to 1
prevSize = pensize()
pensize(1)
# Define inner function for recursion
def _koch(n, l):
if n == 1:
forward(l)
else:
_koch(n-1,l/3)
left(60)
_koch(n-1,l/3)
right(120)
_koch(n-1,l/3)
left(60)
_koch(n-1,l/3)
# Call inner function
_koch(N_iteration,140)
# Restore pencil size
pensize(prevSize))");

const ScriptTemplate * ScriptTemplate::Empty() {
return &emptyScriptTemplate;
}
Expand All @@ -80,6 +113,14 @@ const ScriptTemplate * ScriptTemplate::Polynomial() {
return &polynomialScriptTemplate;
}

const ScriptTemplate * ScriptTemplate::Spiral() {
return &spiralScriptTemplate;
}

const ScriptTemplate * ScriptTemplate::Koch() {
return &kochScriptTemplate;
}

}


2 changes: 2 additions & 0 deletions apps/code/script_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ScriptTemplate {
static const ScriptTemplate * Fibonacci();
static const ScriptTemplate * Mandelbrot();
static const ScriptTemplate * Polynomial();
static const ScriptTemplate * Spiral();
static const ScriptTemplate * Koch();
const char * name() const { return m_name; }
const char * content() const { return m_value+1; }
const char * value() const { return m_value; }
Expand Down
1 change: 1 addition & 0 deletions apps/code/toolbox.universal.i18n
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MathModule = "math"
CmathModule = "cmath"
KandinskyModule = "kandinsky"
TurtleModule = "turtle"
ForLoopMenu = "For"
IfStatementMenu = "If"
WhileLoopMenu = "While"
Expand Down
2 changes: 1 addition & 1 deletion build/toolchain.emscripten.mak
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ _fun_bc_call \
_fun_builtin_var_call \
_main \
_micropython_port_interruptible_msleep \
_micropython_port_should_interrupt \
_micropython_port_interrupt_if_needed \
_micropython_port_vm_hook_loop \
_mp_builtin___import__ \
_mp_builtin_input \
Expand Down
2 changes: 2 additions & 0 deletions escher/include/escher/palette.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Palette {
constexpr static KDColor Orange = KDColor::RGB24(0xfe871f);
constexpr static KDColor Green = KDColor::RGB24(0x50c102);
constexpr static KDColor GreenLight = KDColor::RGB24(0x52db8f);
constexpr static KDColor Brown = KDColor::RGB24(0x8d7350);
constexpr static KDColor Purple = KDColor::RGB24(0x6e2d79);
constexpr static KDColor DataColor[] = {Red, Blue, Green, YellowDark};
constexpr static KDColor DataColorLight[] = {RedLight, BlueLight, GreenLight, YellowLight};
};
Expand Down
Loading