示例#1
0
from cube_simulator import Pixel, rgb, Cube
import random, math, time, png
from sys import argv

#Check for simulation vs real cube
cube_type = None
if len(argv) > 1:
    cube_type = argv[1]

#Create cube and a list to hold all 12 images
cube = Cube()
all_pixels = []
image_count = 12

#Load all 12 images into list
for ii in range(1, image_count + 1):
    filename = '../resources/mario/mario_' + str(ii) + '.png'
    with open(filename, 'rb') as fid:
        fid_png = png.Reader(file=fid)
        raw_data = fid_png.read()
        width = raw_data[0]
        height = raw_data[1]
        planes = raw_data[3]['planes']
        pixels = list(raw_data[2])
        blank_pixels = [[Pixel(255, 255, 255)] * 64 for ii in range(0, 64)]
        for row in range(0, min(height, 64)):
            for col in range(0, width * planes, planes):
                blank_pixels[row][col // planes] = Pixel(
                    pixels[row][col], pixels[row][col + 1],
                    pixels[row][col + 2])
        all_pixels.append(blank_pixels)
示例#2
0
from cube_simulator import Pixel, rgb, Cube
import random
from sys import argv

#Check for simulation vs real cube
cube_type = None
if len(argv) > 1:
    cube_type = argv[1]

#Create cube and list of colors
cube = Cube()
colors = [
    rgb.white, rgb.red, rgb.green, rgb.blue, rgb.yellow, rgb.magenta, rgb.aqua,
    rgb.salmon, rgb.silver, rgb.lawn_green, rgb.purple, rgb.navy
]

#Change a col of leds on each face to a random color
for face in range(0, 6):
    for col in range(0, 64):
        select = random.randint(0, len(colors) - 1)
        cube.set_col_face_color(col, face, colors[select])

#Update cube simulation with new colors
cube.update(cube_type)
示例#3
0
from cube_simulator import Pixel, rgb, Cube
import random
from sys import argv

#Check for simulation vs real cube
cube_type = None
if len(argv) > 1:
	cube_type = argv[1]

#Create cube and list of colors
cube = Cube()
colors = [rgb.white,rgb.red,rgb.green,rgb.blue,rgb.yellow,rgb.magenta,rgb.aqua,rgb.salmon,rgb.silver,rgb.lawn_green,rgb.purple,rgb.navy]

#Select different size radii and color for each circle 
circle_radi = [random.randint(5,31) for ii in range(0,6)]
circle_color = [random.randint(0,len(colors)-1) for ii in range(0,len(colors)-1)]

#Only change leds that fit within the circle radius on each face
for face in range(0,6):
	for row in range(0,64):
		for col in range(0,64):
			if (row-31.5)**2 + (col-31.5)**2 <= circle_radi[face]**2:
				index = row*64*6 + face*64 + col
				cube.set_led(index,colors[circle_color[face]])

#Update cube simulation with new colors
cube.update(cube_type)
示例#4
0
from cube_simulator import Pixel, rgb, Cube
import random, math, time
from sys import argv

#Check for simulation vs real cube
cube_type = None
if len(argv) > 1:
    cube_type = argv[1]

#Create cube and the shades of red, green, blue in the equalizer bar
#Each bar is 5 leds wide and starts out green and then yellow to red
#as the bar gets taller
cube = Cube()
red = [round(ii * 7.968) for ii in range(1, 33)] + [255] * 32
green = [255] * 32 + [round(ii * 7.968) for ii in range(32, 0, -1)]
blue = [0] * 64

#Equalizer bar properties
mag = 40
bar_width = 5
step = 0.2244

#Run animation for 30 seconds
start_time = time.time()
while time.time() - start_time <= 30:
    #Turn all leds back to black
    cube.reset()

    #Using sin waves, create random equalizer bars on each face
    for face in range(1, 5):
        baseline = random.randint(0, 30)
示例#5
0
from cube_simulator import Pixel, rgb, Cube
import random
from sys import argv

#Check for simulation vs real cube
cube_type = None
if len(argv) > 1:
    cube_type = argv[1]

#Create cube and list of colors
cube = Cube()
colors = [
    rgb.white, rgb.red, rgb.green, rgb.blue, rgb.yellow, rgb.magenta, rgb.aqua,
    rgb.salmon, rgb.silver, rgb.lawn_green, rgb.purple, rgb.navy
]

#Create a list of the 4 corners on every face
indices = [0, 383, 24192, 24575]
for ii in range(64, 384, 64):
    indices += [ii - 1, ii]
    indices += [ii + 24191, ii + 24192]

#Set each corner to a random color
for index in indices:
    select = random.randint(0, len(colors) - 1)
    cube.set_led(index, colors[select])

#Update cube simulation with new colors
cube.update(cube_type)
示例#6
0
from cube_simulator import Pixel, rgb, Cube
import random
from sys import argv

#Check for simulation vs real cube
cube_type = None
if len(argv) > 1:
    cube_type = argv[1]

#Create cube and list of colors
cube = Cube()
colors = [
    rgb.white, rgb.red, rgb.green, rgb.blue, rgb.yellow, rgb.magenta, rgb.aqua,
    rgb.salmon, rgb.silver, rgb.lawn_green, rgb.purple, rgb.navy
]

#Change a row of leds on each face to a solid color
for face in range(0, 6):
    for row in range(0, 64):
        select = random.randint(0, len(colors) - 1)
        cube.set_row_face_color(row, face, colors[select])

#Update cube simulation with new colors
cube.update(cube_type)
示例#7
0
from cube_simulator import Pixel, rgb, Cube
import random, math, time
import subprocess as sp
from sys import argv

#Check for simulation vs real cube
cube_type = None
if len(argv) > 1:
    cube_type = argv[1]

#Create cube and list of colors
cube = Cube()

#Comminucate with ffmpeg to process the video through python pipes
FFMPEG_BIN = 'ffmpeg'
command = [
    FFMPEG_BIN, '-i', '../resources/movies/BigBuckBunny_320x180.mp4', '-f',
    'image2pipe', '-pix_fmt', 'rgb24', '-vf', 'scale=106:60', '-vcodec',
    'rawvideo', '-'
]
pipe = sp.Popen(command, stdout=sp.PIPE, bufsize=10**8)

#Movie properties, will need to change for a different video
mov_depth = 3
mov_width = 106
mov_height = 60

#Run through a specfic number of frames in movie, adjust as needed
for jj in range(0, 10000):
    #Grab pixels from ffmpeg pipe
    pixels = [