# generates a barcode pattern on the scroll:bit that redraws randomly # ensure scrollbit.py is copied onto your micro:bit to avoid import errors import scrollbit import random import time # you can add another stripe variant here if you like. stripes = [0, 50, 255] # chose c for column and r for row but you could use x and y while True: for c in range (0, 17): brightness = random.choice(stripes) for r in range(0, 7): scrollbit.set_pixel(c, r, brightness) scrollbit.show() time.sleep(0.1) scrollbit.clear()
# Displays a dot on your scroll:bit, move it by tilting! # Flash this file your micro:bit, # then save this as scrollbit.py and transfer it to your micro:bit using the Files menu. ready = False try: import scrollbit ready = True except ImportError: print("Please copy the scrollbit.py library to your micro:bit") import microbit while ready: x = microbit.accelerometer.get_x() + 1024 x = max(0, min(2048, x)) / 2048.0 y = microbit.accelerometer.get_y() + 1024 y = max(0, min(2048, y)) / 2048.0 x = int((scrollbit.WIDTH - 1) * x) y = int((scrollbit.HEIGHT - 1) * y) scrollbit.clear() scrollbit.set_pixel(x, y, 255) scrollbit.show() microbit.sleep(50)
# code written by F, age 11, at one of our workshops # randomly turns pixels on or off, creating a game of life effect import scrollbit import random # picks a random pixel on the scrollbit # picks a second set of pixel coordinates # sets the first random pixel to full brightness # sets the second random pixel to off # shows the changes while True: col = random.randint(0, 16) row = random.randint(0, 6) newcol = random.randint(0, 16) newrow = random.randint(0, 6) scrollbit.set_pixel(col, row, 255) scrollbit.set_pixel(newcol, newrow, 0) scrollbit.show()
import scrollbit char = Image("00000:" "00000:" "00000:" "00900:" "09990:") ts = 0 cs = 5 bullets = [] bombs = [] score = 0 state = 0 while True: if state == 0: scrollbit.clear() scrollbit.set_pixel(ts, 0, 50) scrollbit.draw_icon(cs, 2, char, brightness=50) for b in bullets: scrollbit.set_pixel(b[0], b[1], 50) if b[1] == 0 and b[0] == ts: display.set_pixel(score % 5, score // 5, 5) score += 1 if score == 25: score = 0 ts = 0 b[1] -= 1 for b in bombs: scrollbit.set_pixel(b[0], b[1], 50) if b[1] == 6 and abs(b[0] - cs - 2) < 2:
def draw(x, y, b): set_pixel((x + shift) % 17, y, b)
X_MAX = 16 Y_MAX = 6 x = random.randint(0, X_MAX+1) y = random.randint(0, Y_MAX+1) x_direction = random.choice([-1, 1]) y_direction = random.choice([-1, 1]) while True: for x_ in range(0, X_MAX+1): for y_ in range(0, Y_MAX+1): brightness = scrollbit.get_pixel(x_, y_) if brightness: scrollbit.set_pixel(x_, y_, brightness-15) scrollbit.set_pixel(x, y, 255) scrollbit.show() x += x_direction y += y_direction if x < 0 or x > X_MAX: x_direction *= -1 x = 0 if x < 0 else X_MAX if y < 0 or y > Y_MAX: y_direction *= -1 y = 0 if y < 0 else Y_MAX