def fadeinout(): # f is the current step brightness and x/y to set LED in the grid: for f in range(10): for x in range(p.width): for y in range(p.height): p.pixel(x, y, f) badge.show(p) badge.tick(0.01) for f in range(10): for x in range(p.width): for y in range(p.height): p.pixel(x, y, 9 - f) badge.show(p) badge.tick(0.01)
def randomfuzz(density): # clear the screen for x in range(p.width): for y in range(p.height): p.pixel(x, y, 0) badge.show(p) # Generate (n) randomly positioned pixels for i in range(density): rx = randint(0, p.width) ry = randint(0, p.height) rb = randint(0, 16) p.pixel(rx, ry, rb) badge.show(p)
def randomdrops(): # clear the screen for x in range(p.width): for y in range(p.height): p.pixel(x, y, 0) badge.show(p) # store a random number for the next drop position drops = randint(0, (p.width - 1)) # Generate a random drop for i in range(p.height + 1): p.pixel(drops, i, (i + 1)) p.pixel(drops, (i - 1), 0) badge.show(p) badge.tick(0.01)
def randombar(): # clear the screen for x in range(p.width): for y in range(p.height): p.pixel(x, y, 0) badge.show(p) # store a random number for the next bar position bar = randint(0, (p.height - 1)) # Generate a random bar and fade over time for i in range(17): for x in range(p.width): p.pixel(x, bar, (16 - i)) badge.show(p) badge.tick(0.01)
def alternate(): # f is the current step brightness and x/y to set LED in the grid: # % modulo is used to alternate lines for f in range(10): for x in range(p.width): for y in range(p.height): if y % 2 == 0: p.pixel(x, y, f) else: p.pixel(x, y, 9 - f) badge.show(p) badge.tick(0.01) for f in range(10): for x in range(p.width): for y in range(p.height): if y % 2 == 0: p.pixel(x, y, 9 - f) else: p.pixel(x, y, f) badge.show(p) badge.tick(0.01)
def arrow(): # Clear the screen before the animation: for x in range(p.width): for y in range(p.height): p.pixel(x, y, 0) badge.show(p) # i is the length of the animation, 2 x screen width for i in range(p.width * 2): # Draw the middle vertical pixel, move horizontally with i p.pixel(i, int(p.height / 2), p.width) for f in range(i): # make a trail: if (p.width - 1) - f > -1: b = (p.width - 1) - f # b is for brightness p.pixel((i - f) - 1, int(p.height / 2), b) # Now make the wings of the arrow which dim as they spread: for n in range(i): if n < int(p.height / 2): ab = p.width - (n * 3) # ab is arrow wing brightness p.pixel(((i - n) - 1), (int(p.height / 2) + (n + 1)), ab) # upper wing p.pixel(((i - n) - 1), (int(p.height / 2) - (n + 1)), ab) # lower wing for z in range(i): # Make the arrow trails: if (ab - 1) - z > -1: atb = (ab - 1) - z p.pixel((((i - n) - z) - 1), (int(p.height / 2) + (n + 1)), atb) p.pixel((((i - n) - z) - 1), (int(p.height / 2) - (n + 1)), atb) badge.show(p) badge.tick(0.01)
def flashleftbar(): global l l = not l for y in range(11): p.pixel(3, y, l) #badge.show(p) def flashrightbar(): global r r = not r for y in range(11): p.pixel(10, y, r) #badge.show(p) while True: if (time.time() - t1) >= interval1: t1 = time.time() # update time sample 1 flashleftbar() if (time.time() - t2) >= interval2: t2 = time.time() # update time sample 2 flashrightbar() badge.show(p)
zoop_direction = 0 while True: badge.tick(0.05) # Move the text a little further to the left, until it's completely off # the screen if zoop_direction == 0: x_pos += 1 if x_pos > screen.width - 6: # Change direction, positionining the zoop prettily x_pos = screen.width - 3 zoop_direction = 1 # If we don't do this, the GC is sometimes too slow to collect # and leads to us running dangerously in/close to MemoryErrors gc.collect() else: x_pos -= 1 if x_pos < 1: # Change direction, positioning the zoop prettily x_pos = -4 zoop_direction = 0 # ...and draw the text block position 3 pixels below the top of screen, # and starting at the current x_pos # (blit draws the specified image in the given position on the screen) screen.blit(ZOOP[zoop_direction], x_pos, 5) badge.show(screen)
def cls(): for x in range(screen.width): for y in range(screen.height): screen.pixel(x, y, 0) badge.show(screen)
def update(xold, yold, xnew, ynew, bright): # set the old pixel to dark screen.pixel(xold, yold, 0) # and the new one to light screen.pixel(xnew, ynew, 10) badge.show(screen)