From 10aaf19204aaaf9312fe13f15083910bbddf1d69 Mon Sep 17 00:00:00 2001 From: janion Date: Wed, 5 Sep 2018 13:22:29 +0100 Subject: [PATCH] Updated Sketchy-Etch Added option to clear drawing, added initial dialog with instructions, added ability to create circles --- SketchyEtch/main.py | 46 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/SketchyEtch/main.py b/SketchyEtch/main.py index f9d3ef2..af66250 100644 --- a/SketchyEtch/main.py +++ b/SketchyEtch/main.py @@ -1,25 +1,40 @@ """Accidentally created etcher sketch...""" -___name___ = "Sketchy Etch" -___title___ = "Sketchy Etch" +___name___ = "Sketchy-Etch" +___title___ = "Sketchy-Etch" ___license___ = "MIT" -___dependencies___ = ["ugfx_helper"] +___dependencies___ = ["ugfx_helper", "dialogs"] ___categories___ = ["Games"] -import ugfx, ugfx_helper, app +import ugfx, ugfx_helper, app, dialogs from tilda import Buttons from time import sleep +i = 0 +j = 0 + +def reset(): + global i + global j + i = int(ugfx.width() / 2) + j = int(ugfx.height() / 2) + ugfx.area(0, 0, ugfx.width(), ugfx.height(), ugfx.BLACK) + ugfx.area((i - 1) if i > 0 else 0, (j - 1) if j > 0 else 0, 3 if (i > 0 and i < (ugfx.width() - 1)) else 2, 3 if (j > 0 and j < (ugfx.height() - 1)) else 2, ugfx.GREY) + ugfx_helper.init() ugfx.clear() -ugfx.area(0, 0, ugfx.width(), ugfx.height(), ugfx.BLACK) - +dialogs.notice("Draw with joystick arrows\nHold joystick centre for circle\nA to clear\nB to exit", title="Sketchy-Etch") -i = int(ugfx.width() / 2) -j = int(ugfx.height() / 2) -while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu)): +ugfx.area(0, 0, ugfx.width(), ugfx.height(), ugfx.BLACK) + + +circleSize = 3 +reset() +while not Buttons.is_pressed(Buttons.BTN_B): changed = False + oldI = i + oldJ = j if Buttons.is_pressed(Buttons.JOY_Right) and (i < (ugfx.width() - 1)): i += 1 @@ -34,9 +49,20 @@ while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(Button elif Buttons.is_pressed(Buttons.JOY_Up) and (j > 0): j -= 1 changed = True + + if Buttons.is_pressed(Buttons.JOY_Center): + circleSize += 1 + ugfx.fill_circle(i, j, circleSize, ugfx.WHITE) + changed = True + else: + circleSize = 3 + + if Buttons.is_pressed(Buttons.BTN_A): + reset() if changed: - ugfx.area((i - 1) if i > 0 else 0, (j - 1) if j > 0 else 0, 3 if (i > 0 and i < (ugfx.width() - 1)) else 2, 3 if (j > 0 and j < (ugfx.height() - 1)) else 2, ugfx.WHITE) + ugfx.area((oldI - 1) if oldI > 0 else 0, (oldJ - 1) if oldJ > 0 else 0, 3 if (oldI > 0 and oldI < (ugfx.width() - 1)) else 2, 3 if (oldJ > 0 and oldJ < (ugfx.height() - 1)) else 2, ugfx.WHITE) + ugfx.area((i - 1) if i > 0 else 0, (j - 1) if j > 0 else 0, 3 if (i > 0 and i < (ugfx.width() - 1)) else 2, 3 if (j > 0 and j < (ugfx.height() - 1)) else 2, ugfx.GREY) sleep(0.05)