Toggle Navigation
Hatchery
Eggs
Bouncing Ball
__init__.py
Login
Register
__init__.py
Content
import display import time import random import ugfx import samd # Screen width and height (W, H) = display.size() def action_exit(pushed): if (pushed): # go back to the home screen system.home() def bounce(axis): if axis == 'x': samd.buzzer(10, 1) elif axis == 'y': samd.buzzer(1, 1) def main(): ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_START, action_exit) r = 5 # radius of the ball r2 = r/2 # half of the radius # Random starting position x = random.randint(r,W-r) y = random.randint(r,H-r) # Speed vx = 2 vy = 2 while True: if x + vx - r2 < 0 or x + vx + r2 > W: vx *= -1 bounce('x') if y + vy - r2 < 0 or y + vy + r2 > H: vy *= -1 bounce('y') x = x + vx y = y + vy display.drawFill(0x000000) display.drawCircle(x, y, r, 0, 360, True, 0xFFFFFF) display.flush() sys.stdin.read(1) action_exit(True) main()