def animate(fb, fps=5, img=HEART, colour=1, start_x=0, start_y=0, scale=4, repeat=False): fb.fill((colour + 1) % 2) show_pic(fb, img=img, colour=colour, start_x=start_x, start_y=start_y, scale=scale, repeat=repeat) fb.show() quokka.sleep(1000 // fps) fb.fill((colour + 1) % 2) show_pic(fb, img=img, colour=colour, start_x=start_x + scale**2, start_y=start_y + scale**2, scale=scale // 2, repeat=repeat) fb.show() quokka.sleep(1000 // fps)
def scroll(string, stringScale=2, charWidth=8, scWidth=128, charHeight=8, scHeight=64, startx=5, starty=5, textColour=1): numchars = (scWidth - startx) // (charWidth * stringScale) while string: quokka.display.fill(1 - textColour) quokka.display.text(string[:numchars], startx, starty, textColour, scale=stringScale) quokka.display.show() if len(string) > 1: string = string[1:] else: string = "" quokka.sleep(200) quokka.display.fill(1 - textColour)
def start_sequence(): for word in start_statements: quokka.display.fill(1) quokka.display.text(word, 5, 5, 0) quokka.display.show() quokka.sleep(1000) quokka.display.fill(1) quokka.display.show()
def turn_reset(): quokka.sleep(timer * 1000) r = 0 g = 0 b = 0 quokka.display.fill(1) quokka.display.show() quokka.neopixels.clear() quokka.neopixels.show() timer = timer * 0.8 quokka.sleep(500)
def colour_show(current_colour, r, g, b): if current_colour == 'RED': r = 255 if current_colour == 'GREEN': g = 255 if current_colour == 'YELLOW': r = 255 g = 150 if current_colour == 'BLUE': b = 255 quokka.neopixels.clear() for i in range(8): quokka.neopixels.set_pixel(i, r, g, b) quokka.neopixels.show() quokka.sleep(5)
import quokka while True: for i in range(4): if quokka.buttons[i].is_pressed(): quokka.leds[i].on() else: quokka.leds[i].off() quokka.sleep(50)
import quokka quokka.display.fill(0) quokka.display.text(quokka.radio.version(), 0, 0, 1) quokka.display.show() quokka.sleep(1000) while True: quokka.display.fill(0) quokka.neopixels.clear() if quokka.buttons.a.is_pressed(): quokka.display.text('a', 5, 5, 1) quokka.neopixels.set_pixel(0, 255, 0, 0) if quokka.buttons.b.is_pressed(): quokka.display.text('b', 20, 5, 1) quokka.neopixels.set_pixel(1, 255, 0, 0) if quokka.buttons.c.is_pressed(): quokka.display.text('c', 35, 5, 1) quokka.neopixels.set_pixel(2, 255, 0, 0) if quokka.buttons.d.is_pressed(): quokka.display.text('d', 50, 5, 1) quokka.neopixels.set_pixel(3, 255, 0, 0) if quokka.buttons.usr.is_pressed(): quokka.display.text('u', 65, 5, 1) quokka.display.show() quokka.sleep(50)
# colour show and select current_colour = random.choice(colours) colour_show(current_colour, r, g, b) #temporary body: current_limb = random.choice(limbs) current_side = random.choice(sides) body_show(current_side, current_limb) start_time = quokka.running_time() elapse_time = quokka.running_time() - start_time while elapse_time < 5000: msg = quokka.radio.receive() if current_colour == "RED": quokka.sleep(2000) points += 1 break if msg: try: protocol, cmd, array = msg.split(":") if protocol == "tw" and cmd == "btn": buttons = [] for line in array.split(';'): buttons.append(line.split(",")) except ValueError: continue # list of integers, showing num of buttons pressed in each row #if current_colour
skip_collision = True if ball_nx_y < 0 or ball_nx_y > 64: v_y = -0.8 * v_y skip_collision = True if skip_collision: return # Determine the types of walls that the ball will pass through to get to ball_nx and deflect off them v_wall, h_wall = wall_type(wall_map, ball_nx_x, ball_nx_y) if v_wall: v_x = -0.8 * v_x if h_wall: v_y = -0.8 * v_y if not (v_wall) and not (h_wall): # No collision. Advance ball ball_x = ball_nx_x ball_y = ball_nx_y t_old = pyb.millis() while True: if render_tick: render_tick = False render_method() if physics_tick: physics_method() physics_tick = False quokka.sleep(1)
import quokka import radio import sys v = radio.version() if not v: quokka.display.print('bad radio') quokka.display.show() sys.exit(0) radio.on() radio.config(channel=40) while True: if quokka.button_a.is_pressed(): quokka.display.print('send a') #quokka.neopixels.set_pixel(0, 64, 0, 0) radio.send("duck") elif quokka.button_b.is_pressed(): radio.send("giraffe") #quokka.neopixels.set_pixel(0, 0, 64, 0) else: radio.send("clear") #quokka.neopixels.set_pixel(0, 0, 0, 64) quokka.sleep(10)
import quokka from load_image import load_image fb = load_image('NCSS-logo-68x50.qimz') quokka.display.fill(1) quokka.display.blit(fb, 30, 7) quokka.display.show() c = 1 while True: quokka.sleep(1500) quokka.display.invert(c) quokka.display.show() c = (c + 1) % 2