mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[python] add bgcolor to turtule module (#367)
* add bgcolor to turtul module * add bgcolor to toolbox and a minor fix * ok is ok now i hope however * Submodule Omega-Kawaii-Theme remove
This commit is contained in:
@@ -262,3 +262,4 @@ PythonFileReadable = "Kann Datei gelesen werden?"
|
||||
PythonFileWritable = "Kann Datei geschrieben werden?"
|
||||
PythonImportUtils = "Importieren von ulab.utils"
|
||||
PythonUtilsFunction = "Funktionspräfix des utils-Moduls"
|
||||
PythonTurtleBgcolor = "Ändern Sie die Hintergrundfarbe"
|
||||
|
||||
@@ -262,3 +262,4 @@ PythonFileReadable = "Tells if read can be used on a file"
|
||||
PythonFileWritable = "Tells if write can be used on a file"
|
||||
PythonImportUtils = "Importing ulab.utils"
|
||||
PythonUtilsFunction = "utils module function prefix"
|
||||
PythonTurtleBgcolor = "Change the background color"
|
||||
|
||||
@@ -262,3 +262,4 @@ PythonFileReadable = "Tells if read can be used on a file"
|
||||
PythonFileWritable = "Tells if write can be used on a file"
|
||||
PythonImportUtils = "Importando ulab.utils"
|
||||
PythonUtilsFunction = "prefijo de función del módulo utils"
|
||||
PythonTurtleBgcolor = "Cambiar el color de fondo"
|
||||
|
||||
@@ -212,6 +212,7 @@ PythonTurtleBackward = "Recule de x pixels"
|
||||
PythonTurtleCircle = "Cercle de rayon r pixels"
|
||||
PythonTurtleColor = "Modifie la couleur du tracé"
|
||||
PythonTurtleColorMode = "Met le mode de couleur à 1.0 ou 255"
|
||||
PythonTurtleBgcolor = "Modifie la couleur du fond"
|
||||
PythonTurtleForward = "Avance de x pixels"
|
||||
PythonTurtleFunction = "Préfixe fonction du module turtle"
|
||||
PythonTurtleGoto = "Va au point de coordonnées (x,y)"
|
||||
|
||||
@@ -262,3 +262,4 @@ PythonKeyAns = "ANS kulcs"
|
||||
PythonKeyExe = "EXE kulcs"
|
||||
PythonImportUtils = "Az ulab.utils importálása"
|
||||
PythonUtilsFunction = "utils modul függvény előtagja"
|
||||
PythonTurtleBgcolor = "Módosítsa a háttérszínt"
|
||||
|
||||
@@ -262,3 +262,4 @@ PythonFileReadable = "Dice se si può leggere sul file"
|
||||
PythonFileWritable = "Dice se si può scrivere sul file"
|
||||
PythonImportUtils = "Importazione di ulab.utils"
|
||||
PythonUtilsFunction = "Prefisso funzione del modulo utils"
|
||||
PythonTurtleBgcolor = "Cambia il colore dello sfondo"
|
||||
|
||||
@@ -263,3 +263,4 @@ PythonFileReadable = "Tells if read can be used on a file"
|
||||
PythonFileWritable = "Tells if write can be used on a file"
|
||||
PythonImportUtils = "Ulab.utils importeren"
|
||||
PythonUtilsFunction = "utils module functie prefix"
|
||||
PythonTurtleBgcolor = "Verander de achtergrondkleur"
|
||||
|
||||
@@ -262,3 +262,4 @@ PythonFileReadable = "Tells if read can be used on a file"
|
||||
PythonFileWritable = "Tells if write can be used on a file"
|
||||
PythonImportUtils = "Importando ulab.utils"
|
||||
PythonUtilsFunction = "prefixo de função do módulo utils"
|
||||
PythonTurtleBgcolor = "Alterar a cor de fundo"
|
||||
|
||||
@@ -404,6 +404,7 @@ PythonTurtleCommandBackward = "backward(x)"
|
||||
PythonTurtleCommandCircle = "circle(r)"
|
||||
PythonTurtleCommandColor = "color('c')"
|
||||
PythonTurtleCommandColorMode = "colormode(x)"
|
||||
PythonTurtleCommandBgcolor = "bgcolor('c')"
|
||||
PythonTurtleCommandForward = "forward(x)"
|
||||
PythonTurtleCommandGoto = "goto(x,y)"
|
||||
PythonTurtleCommandHeading = "heading()"
|
||||
|
||||
@@ -338,6 +338,7 @@ const ToolboxMessageTree TurtleModuleChildren[] = {
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonTurtleCommandHideturtle, I18n::Message::PythonTurtleHideturtle, false),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonTurtleCommandColor, I18n::Message::PythonTurtleColor),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonTurtleCommandColorMode, I18n::Message::PythonTurtleColorMode),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonTurtleCommandBgcolor, I18n::Message::PythonTurtleBgcolor),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandColorBlue, I18n::Message::PythonColorBlue, false),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandColorRed, I18n::Message::PythonColorRed, false),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandColorGreen, I18n::Message::PythonColorGreen, false),
|
||||
@@ -542,6 +543,7 @@ const ToolboxMessageTree catalogChildren[] = {
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandCmathFunction, I18n::Message::PythonCmathFunction, false, I18n::Message::PythonCommandCmathFunctionWithoutArg),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandColor, I18n::Message::PythonColor),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonTurtleCommandColorMode, I18n::Message::PythonTurtleColorMode),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonTurtleCommandBgcolor, I18n::Message::PythonTurtleBgcolor),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandComplex, I18n::Message::PythonComplex),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandCopySign, I18n::Message::PythonCopySign),
|
||||
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandCos, I18n::Message::PythonCos),
|
||||
|
||||
@@ -520,6 +520,7 @@ Q(pensize)
|
||||
Q(width)
|
||||
Q(isdown)
|
||||
Q(pencolor)
|
||||
Q(bgcolor)
|
||||
Q(reset)
|
||||
Q(showturtle)
|
||||
Q(st)
|
||||
|
||||
@@ -20,6 +20,7 @@ void modturtle_view_did_disappear() {
|
||||
|
||||
mp_obj_t modturtle___init__() {
|
||||
sTurtle = Turtle();
|
||||
sTurtle.drawBg();
|
||||
/* Note: we don't even bother writing a destructor for Turtle because this
|
||||
* init function is called once, and only once, per MicroPython init cycle.
|
||||
* When the previous Turtle object is destroyed, its VM is long gone. */
|
||||
@@ -165,6 +166,38 @@ mp_obj_t modturtle_pencolor(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t modturtle_bgcolor(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
// bgcolor()
|
||||
KDColor c = sTurtle.colorBg();
|
||||
mp_obj_t mp_col[3];
|
||||
if(sTurtle.colorMode() == MicroPython::Color::Mode::MaxIntensity255){
|
||||
mp_col[0] = mp_obj_new_int_from_uint(c.red());
|
||||
mp_col[1] = mp_obj_new_int_from_uint(c.green());
|
||||
mp_col[2] = mp_obj_new_int_from_uint(c.blue());
|
||||
} else {
|
||||
mp_col[0] = mp_obj_new_float(uint8tColorToDouble(c.red()));
|
||||
mp_col[1] = mp_obj_new_float(uint8tColorToDouble(c.green()));
|
||||
mp_col[2] = mp_obj_new_float(uint8tColorToDouble(c.blue()));
|
||||
}
|
||||
return mp_obj_new_tuple(3, mp_col);
|
||||
}
|
||||
if (n_args == 2) {
|
||||
mp_raise_TypeError("bgcolor() takes 0, 1 or 3 arguments");
|
||||
return mp_const_none;
|
||||
}
|
||||
mp_obj_t color;
|
||||
if (n_args == 1) {
|
||||
color = args[0];
|
||||
} else {
|
||||
assert(n_args == 3);
|
||||
color = mp_obj_new_tuple(n_args, args);
|
||||
}
|
||||
sTurtle.setColorBg(MicroPython::Color::Parse(color, sTurtle.colorMode()));
|
||||
sTurtle.drawBg();
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t modturtle_colormode(size_t n_args, const mp_obj_t *args) {
|
||||
if(n_args == 0){
|
||||
return mp_obj_new_int_from_uint(static_cast<int>(sTurtle.colorMode()));
|
||||
|
||||
@@ -26,6 +26,7 @@ mp_obj_t modturtle_isvisible();
|
||||
mp_obj_t modturtle_write(mp_obj_t s);
|
||||
|
||||
mp_obj_t modturtle_pencolor(size_t n_args, const mp_obj_t *args);
|
||||
mp_obj_t modturtle_bgcolor(size_t n_args, const mp_obj_t *args);
|
||||
mp_obj_t modturtle_colormode(size_t n_args, const mp_obj_t *args);
|
||||
|
||||
mp_obj_t modturtle_showturtle();
|
||||
|
||||
@@ -18,6 +18,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modturtle_pensize_obj, 0, 1, modturtl
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modturtle_isdown_obj, modturtle_isdown);
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modturtle_pencolor_obj, 0, 3, modturtle_pencolor);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modturtle_bgcolor_obj, 0, 3, modturtle_bgcolor);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modturtle_colormode_obj, 0, 1, modturtle_colormode);
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modturtle_reset_obj, modturtle_reset);
|
||||
@@ -66,6 +67,7 @@ STATIC const mp_rom_map_elem_t modturtle_module_globals_table[] = {
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_color), (mp_obj_t)&modturtle_pencolor_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pencolor), (mp_obj_t)&modturtle_pencolor_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_bgcolor), (mp_obj_t)&modturtle_bgcolor_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_colormode), (mp_obj_t)&modturtle_colormode_obj },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset), (mp_obj_t)&modturtle_reset_obj },
|
||||
|
||||
@@ -33,6 +33,7 @@ void Turtle::reset() {
|
||||
m_y = 0;
|
||||
m_heading = 0;
|
||||
m_color = k_defaultColor;
|
||||
m_bgcolor = k_defaultColorBG;
|
||||
m_penDown = true;
|
||||
m_visible = true;
|
||||
m_speed = k_defaultSpeed;
|
||||
@@ -40,6 +41,7 @@ void Turtle::reset() {
|
||||
m_mileage = 0;
|
||||
|
||||
// Draw the turtle
|
||||
drawBg();
|
||||
draw(true);
|
||||
}
|
||||
|
||||
@@ -202,6 +204,19 @@ bool Turtle::isOutOfBounds() const {
|
||||
return absF(x()) > k_maxPosition || absF(y()) > k_maxPosition;
|
||||
};
|
||||
|
||||
void Turtle::drawBg() {
|
||||
MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox();
|
||||
|
||||
KDContext * ctx = KDIonContext::sharedContext();
|
||||
|
||||
KDRect bg = KDRect(
|
||||
0,
|
||||
0,
|
||||
320,
|
||||
229);
|
||||
ctx->fillRect(bg, m_bgcolor);
|
||||
}
|
||||
|
||||
// Private functions
|
||||
|
||||
void Turtle::setHeadingPrivate(mp_float_t angle) {
|
||||
@@ -406,4 +421,4 @@ void Turtle::erase() {
|
||||
KDContext * ctx = KDIonContext::sharedContext();
|
||||
ctx->fillRectWithPixels(iconRect(), m_underneathPixelBuffer, nullptr);
|
||||
m_drawn = false;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ extern "C" {
|
||||
#include <kandinsky.h>
|
||||
#include <math.h>
|
||||
#include <python/port/port.h>
|
||||
#include <escher/palette.h>
|
||||
|
||||
/* We check for keyboard interruptions using micropython_port_vm_hook_loop and
|
||||
* micropython_port_interruptible_msleep, but even if we catch an interruption,
|
||||
@@ -30,6 +31,7 @@ public:
|
||||
m_y(0),
|
||||
m_heading(0),
|
||||
m_color(k_defaultColor),
|
||||
m_bgcolor(k_defaultColorBG),
|
||||
m_colorMode(MicroPython::Color::Mode::MaxIntensity255),
|
||||
m_penDown(true),
|
||||
m_visible(true),
|
||||
@@ -67,11 +69,18 @@ public:
|
||||
void setVisible(bool visible);
|
||||
|
||||
KDColor color() const { return m_color; }
|
||||
KDColor colorBg() const { return m_bgcolor; }
|
||||
void setColor(KDColor c) {
|
||||
m_color = c;
|
||||
}
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
m_color = KDColor::RGB888(r, g, b);
|
||||
}
|
||||
void setColorBg(KDColor c) {
|
||||
m_bgcolor = c;
|
||||
}
|
||||
void setColorBg(uint8_t r, uint8_t g, uint8_t b) {
|
||||
m_bgcolor = KDColor::RGB888(r, g, b);
|
||||
}
|
||||
MicroPython::Color::Mode colorMode() const {return m_colorMode; }
|
||||
void setColorMode(MicroPython::Color::Mode colorMode){
|
||||
@@ -88,6 +97,7 @@ public:
|
||||
* when out of bound, and can prevent text that would have been visible to be
|
||||
* drawn. We use very large bounds to temper these effects. */
|
||||
bool isOutOfBounds() const;
|
||||
void drawBg();
|
||||
|
||||
private:
|
||||
static constexpr mp_float_t k_headingScale = M_PI / 180;
|
||||
@@ -99,6 +109,7 @@ private:
|
||||
static constexpr uint8_t k_defaultSpeed = 8;
|
||||
static constexpr uint8_t k_maxSpeed = 10;
|
||||
static constexpr KDColor k_defaultColor = KDColorBlack;
|
||||
static constexpr KDColor k_defaultColorBG = Palette::CodeBackground;
|
||||
static constexpr uint8_t k_defaultPenSize = 1;
|
||||
static constexpr const KDFont * k_font = KDFont::LargeFont;
|
||||
static constexpr mp_float_t k_maxPosition = KDCOORDINATE_MAX * 0.75f;
|
||||
@@ -152,6 +163,7 @@ private:
|
||||
mp_float_t m_heading;
|
||||
|
||||
KDColor m_color;
|
||||
KDColor m_bgcolor;
|
||||
MicroPython::Color::Mode m_colorMode;
|
||||
bool m_penDown;
|
||||
bool m_visible;
|
||||
|
||||
Reference in New Issue
Block a user