Toggle Navigation
Hatchery
Eggs
fact
__init__.py
Login
Register
__init__.py
Content
import system, sys, ugfx n = 0 def action_exit(pushed): if (pushed): system.home() def draw_number(): global n ugfx.area(0, 0, 300, 300, ugfx.WHITE) ugfx.string(0, 0, "n = {}".format(n), "Roboto_Regular12", ugfx.BLACK) ugfx.string(0, 15, "Press up/down to", "Roboto_Regular12", ugfx.BLACK) ugfx.string(0, 30, "increase/decrease n", "Roboto_Regular12", ugfx.BLACK) ugfx.flush() def draw_factorial(pushed): if (pushed): global n ugfx.area(0, 0, 300, 300, ugfx.WHITE) ugfx.string(0, 0, "n! = {}".format(factorial(n)), "Roboto_Regular12", ugfx.BLACK) ugfx.string(0, 15, "Press up/down to", "Roboto_Regular12", ugfx.BLACK) ugfx.string(0, 30, "increase/decrease n", "Roboto_Regular12", ugfx.BLACK) ugfx.flush() def increase_n(pushed): global n if (pushed): n += 1 draw_number() def decrease_n(pushed): global n if (pushed and n > 0): n -= 1 draw_number() def factorial(n): ret = 1; for i in range(1, n + 1): ret *= i return ret def main(): ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_START, draw_factorial) ugfx.input_attach(ugfx.JOY_UP, increase_n) ugfx.input_attach(ugfx.JOY_DOWN, decrease_n) draw_number() sys.stdin.read(1) action_exit(True) main()