Skip to content
Permalink
old/np_simplel…
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
from np_simplelib import *
import random
import time
COLORS = [
(255, 255, 255),
(255, 0, 0 ),
(255, 255, 0 ),
(0, 255, 0 ),
(0, 255, 255),
(0, 0, 255),
(255, 0, 255),
]
DELAY = 0.01
color_idx = 0
FROM_END = True
LAST_COLOR = COLORS[0]
while True:
FROM_END = not FROM_END
target = range(NUM_PIXELS)
if FROM_END:
target = list(reversed(target))
for pixel in target:
# Choose a random color only some of the time
if random.random() > 0.5:
# Pick a defined color
#LAST_COLOR = random.choice(COLORS)
# Randomly generate an RGB color
LAST_COLOR = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
np.setPixelColorRGB(pixel, *LAST_COLOR)
time.sleep(DELAY)
np.show()
for pixel in target:
np.setPixelColorRGB(pixel, 0, 0, 0)
time.sleep(DELAY)
np.show()