def ready(now): pixels.fill(OFF) k = int(now) % 2 for color, idx in OPTIONS.values(): pixels[idx] = color if k else OFF after(0.2, ready) pixels.show()
def finish(now): pixels.fill(OFF) for idx, value in enumerate(state.results): if value: pixels[idx] = REWARD[value] pixels.show() state.reset() after(3, main)
def finish(now): pixels.fill(OFF) for idx, value in enumerate(State.results): if value: pixels[idx] = REWARD[value] pixels.show() State.reset() after(3, main)
def play(now): if not state.ready: return good = 1 if state.pos == 7 else 0 pixels.fill(REWARD[good]) pixels[state.pos] = REWARD[not good] pixels.show() state.results[state.round] = good state.round += 1 state.pos = random.randint(0, 9) after(0.5, main)
def play(now): if not State.ready: return good = 1 if State.pos == 7 else 0 pixels.fill(REWARD[good]) pixels[State.pos] = REWARD[not good] pixels.show() State.results[State.round] = good State.round += 1 State.pos = random.randint(0, 9) after(0.5, main)
def main(now): if not state.ready: pixels.fill(OFF) pixels[2] = FLASH[int(now) % 2] pixels.show() return after(0.1, main) if state.round >= ROUNDS: return after(0, finish) after(SPEEDS[state.round], main) state.pos += 1 if state.pos >= 10: state.pos = 0 render()
def main(now): if not State.ready: pixels.fill(OFF) pixels[2] = FLASH[int(now) % 2] pixels.show() return after(0.1, main) if State.round >= ROUNDS: return after(0, finish) after(SPEEDS[State.round], main) State.pos += 1 if State.pos >= 10: State.pos = 0 render()
def fail(now): print("fail") state.phase = FAIL pixels.fill(RED) pixels.show() if state.pos < 1: after(0.5, clear) after(1, fail) state.pos = 1 else: after(0.5, clear) after(1, begin)
def show(now): if state.pos < len(state.sequence): name = state.sequence[state.pos] print("show {}".format(name)) render(name) state.pos += 1 after(0.5, clear) after(0.75, show) else: clear() state.watch() after(TIMEOUT, fail)
def press(now, color): if state.phase == READY: state.begin() cancel(ready) render(color, sound=False) after(0.1, clear) after(1, show) elif state.phase == WATCH: if color == state.sequence[state.pos]: render(color) after(0.5, clear) state.pos += 1 if state.pos == len(state.sequence): state.show() after(1, show) cancel(fail) else: after(TIMEOUT, fail) else: after(0, fail)
def begin(now): state.reset() enable_speaker(state.sound) after(0.5, ready) print("ready")