Code: Select all
from microbit import *
import random
def unique(select, total):
chosen = []
for _ in range(select):
while True:
pick = random.randrange(total)
if not pick in chosen:
chosen.append(pick)
break
return chosen
one = unique(8, 10)
two = unique(4, 7)
for _ in range(2):
for i in range(32):
print('%d' % random.randrange(7), end = " ")
print('')
Code: Select all
6 6 5 4 2 1 3 1 3 1 6 0 1 3 4 0 2 2 1 5 1 5 4 6 6 4 6 5 2 4 2 5
4 2 5 2 4 3 2 5 4 1 5 4 5 0 3 1 0 3 3 2 1 4 0 2 1 2 1 6 1 4 2 1
Code: Select all
import microbit
import random
import neopixel
BUTTON = { 'up' : microbit.pin8,
'down' : microbit.pin14,
'left' : microbit.pin12,
'right' : microbit.pin13,
1 : microbit.pin15,
2 : microbit.pin16 }
IMAGE_BASE = (microbit.Image.HEART, microbit.Image.HAPPY,
microbit.Image.SAD, microbit.Image.DIAMOND,
microbit.Image.SQUARE, microbit.Image.SQUARE_SMALL,
microbit.Image.MUSIC_CROTCHET, microbit.Image.MUSIC_QUAVERS,
microbit.Image.UMBRELLA, microbit.Image.ARROW_N)
COLOURS = ((20, 0, 0), (0, 20, 0), # red green
(0, 0, 20), (20, 20, 0), # blue yellow
(0, 20, 20), (20, 0, 20), # cyan purple
(40, 20, 0) ) # orange
zip_led = neopixel.NeoPixel(microbit.pin0, 64)
board = []
cur_x = 4
cur_y = 3
def unique(select, total):
chosen = []
for _ in range(select):
while True:
pick = random.randrange(total)
if not pick in chosen:
chosen.append(pick)
break
return chosen
def main():
global board
global cur_x
global cur_y
symbols = unique(8, len(IMAGE_BASE))
colours = unique(4, len(COLOURS))
for s in symbols:
for c in colours:
board.append([0, s, c])
board += board
for i in range(len(board)):
item = board[i]
item[0] = random.randrange(len(COLOURS))
board[i] = item
for i in range(len(board)):
b , s, c = board[i]
print("%d" % b, end = " ")
if (i + 1) % 32 == 0:
print("")
main()
Code: Select all
1 2 1 3 5 5 0 3 3 2 5 0 3 0 0 2 6 4 0 2 2 3 0 5 6 6 5 1 3 5 5 0
1 2 1 3 5 5 0 3 3 2 5 0 3 0 0 2 6 4 0 2 2 3 0 5 6 6 5 1 3 5 5 0