I want this snippet of my code to generate a random order of 4 RGB lists:
Code: Select all
colors = [[255 , 0 , 0] , [255 , 255 , 0] , [255 , 0 , 255] , [0 , 255 , 0]]I have tried printing the color it comes out with but it just says 0 for all of them.
Here's my code:
Code: Select all
from astro_pi import AstroPi
import random , math
from time import time
from time import sleep
ap = AstroPi()
ap.clear()
#o = ap.get_orientation()
#pitch = o["pitch"]
#roll = o["roll"]
O = [0 , 0 , 0]
up = 0
down = 0
right = 0
left = 0
def color():
loop = 1
while loop <= 4:
colors = [[255 , 0 , 0] , [255 , 255 , 0] , [255 , 0 , 255] , [0 , 255 , 0]]
choice = random.choice(colors)
running = True
while running:
if choice == up or choice == down or choice == right or choice == left:
choice = random.choice(colors)
else:
running = False
if loop == 1:
choice = up
elif loop == 2:
choice = down
elif loop == 3:
choice = right
elif loop == 4:
choice = left
print(str(up + down + right + left))
loop += 1
ap.clear()
L = [0 , 0 , 0]
side = [
L, L, L, L, L, L, L, L,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O
]
color()
L = up
ap.set_pixels(side)
ap.set_rotation(0)
sleep(3)
ap.clear()
L = right
ap.set_pixels(side)
ap.set_rotation(90)
sleep(3)
ap.clear()
L = down
ap.set_pixels(side)
ap.set_rotation(180)
sleep(3)
ap.clear()
L = left
ap.set_pixels(side)
ap.set_rotation(270)
sleep(3)
ap.clear()
generation = random.random()
generation = generation * 10
sleep(generation)
R = [0 , 0 , 0]
dot = [
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, R, R, O, O, O,
O, O, O, R, R, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O
]
ap.set_pixels(dot)
starttime = time()
run = True
#while run == True:
# if mode == 1:
# elif mode == 2:
# elif mode == 3:
# elif mode == 4:
presstime = time()
timetaken = presstime - starttime