def test(): button.destroy() welcome_message.destroy() free.destroy() free2.destroy() instruction = Text(app, text="Push the red circle as soon as he appears") instruction.text_color = "white" board = Waffle(app, height=5, width=5, visible=True) board.pixel_size = 75 board.set_all("white") app.update() waitingTime = (random.randint(0, 10)) time.sleep(waitingTime) starttime = time.perf_counter() def ende(x, y): if board[x, y].dotty == True: board[x, y].dotty = False board.set_pixel(x, y, "white") end = time.perf_counter() timeused = round((end - starttime) * 1000) / 1000 timedisplay = Text(app, text="Your reaction-time: " + str(timeused) + "s") timedisplay.text_color = "white" timedisplay.font = "Impact" board.update_command(ende) x, y = random.randint(0, 4), random.randint(0, 4) board[x, y].dotty = True board.set_pixel(x, y, "red")
def test_set_get_all(): from itertools import chain a = App() w = Waffle(a) w.set_all("red") # turn 2d list into 1d list pixels = chain.from_iterable(zip(*w.get_all())) count = 0 for pixel in pixels: assert pixel == "red" count += 1 assert count == w.width * w.height a.destroy()
def balancetest(): m = 0 r = 255, m, 0 x_values = [] z_values = [] global sb, txt, qth, score sb.visible = False txt.visible = False stillx = 0.068 stillz = 0.064 rockx = 0.296 rockz = 0.228 bigrockx = 0.608 bigrockz = 0.849 panacake = Waffle(qth, height=1, width=10, dim=70) qth.update() for i in range(100): raw = s.get_accelerometer_raw() x_values.append(raw['x']) z_values.append(raw['z']) sleep(0.2) if i // 10 == i / 10: t = i / 10 print(t) panacake.set_pixel(int(t), 0, r) qth.update() m = m + 25 r = 255, m, 0 for i in range(4): panacake.set_all('green') qth.update() sleep(0.3) panacake.set_all('white') qth.update() sleep(0.3) panacake.set_all('green') qth.update() sleep(0.3) panacake.set_all('white') qth.update() sleep(0.3) panacake.set_all('green') qth.update() sleep(0.3) panacake.set_all('white') qth.update() sleep(0.3) panacake.visible = False xvalue = max(x_values) - min(x_values) zvalue = max(z_values) - min(z_values) if xvalue < 0.1 or xvalue < stillx and zvalue < 0.1 or zvalue < stillz: print('standing still : passed') score = score + 1 if xvalue > 0.1 and xvalue < 0.4 and zvalue > 0.1 and zvalue < 0.4: print('rocking slightly : failed') if xvalue > 0.4 and zvalue > 0.4: print('rocking alot : failed') if xvalue > 1 and zvalue > 1: print('u fell over') print('score is ' + str(score)) finalcheck()
from guizero import App, Waffle, PushButton def clicked(x, y): waffle.set_pixel(x, y, "red") print("{}.{}".format(x, y)) print(waffle.get_all()) waffle.width = 5 waffle.height = 5 waffle.pixel_size = 50 waffle.dotty = True waffle.pad = 25 waffle.color = "green" app = App() waffle = Waffle(app, command=clicked, height=15, width=15) waffle.bg = (255, 255, 0) waffle.set_all("red") waffle.set_pixel(0, 0, "blue") waffle.set_pixel(8, 1, "#00ff00") waffle.set_pixel(3, 4, "blue") waffle.pixel(1, 2).dotty = True print(waffle[8, 1].color) button = PushButton(app, command=waffle.reset) app.display()