コード例 #1
0
def importAni():
    global leds
    global frame_number
    with open('animation8x4.py') as ll:
        line_count = sum(1 for _ in ll)
    ll.close()

    #animation = {}
    frame_number = 1
    file = open('animation8x4.py')
    for r in range(4):
        file.readline()

    for frame  in range(line_count-9):
        buff = file.readline()

        load_frame = buff.split('], [')
        #print(load_frame)
        counter = 1
        uh_leds =[]
        for f in load_frame:

            if counter == 1:
                f = f[3:]
            elif counter == 64:
                f = f[:-5]
            elif counter%8 == 0 and counter != 64:
                f = f[:-1]
            elif (counter-1)%8 == 0:
                f = f[1:]

            y = int((counter-1)/8)
            x = int((counter-1)%8)
            #print(counter,x,y)


            led = LED(radius=20,pos=(x, y))
            #print(' x= ' + str(led.pos_x) + ' y= ' + str(led.pos_y))

            #print(f)
            if f == '0, 0, 0':
                led.lit = False

            else:
                led.lit = True
                f_colours = f.split(',')
                #print(f_colours)
                led.color = [int(f_colours[0]),int(f_colours[1]),int(f_colours[2])]
            uh_leds.append(led)

            counter+=1
        leds = []
        for pp in range(32):
                        leds.append(uh_leds[pp])

        animation[frame_number] = copy.deepcopy(leds)
        frame_number+=1
        counter+=1

    file.close()
コード例 #2
0
def importAni():
    global leds
    global frame_number
    with open('animation8x8.py') as ll:
        line_count = sum(1 for _ in ll)
    ll.close()

    #animation = {}
    frame_number = 1
    file = open('animation8x8.py')
    for r in range(3):
        file.readline()

    for frame in range(line_count - 8):
        buff = file.readline()

        load_frame = buff.split('], [')
        #print load_frame
        counter = 1
        leds = []
        for f in load_frame:

            if counter == 1:
                f = f[3:]
            elif counter == 64:
                f = f[:-5]
            elif counter % 8 == 0 and counter != 64:
                f = f[:-1]
            elif (counter - 1) % 8 == 0:
                f = f[1:]

            y = int((counter - 1) / 8)
            x = int((counter - 1) % 8)
            #print(counter,x,y)

            #print(str(counter) + ' ' + f + ' x= ' + str(x) + ' y= ' + str(y))
            led = LED(radius=20, pos=(x, y))
            if f == '0, 0, 0':
                led.lit = False

            else:
                led.lit = True
                f_colours = f.split(',')
                #print(f_colours)
                led.color = [
                    int(f_colours[0]),
                    int(f_colours[1]),
                    int(f_colours[2])
                ]
            leds.append(led)
            counter += 1
        animation[frame_number] = copy.deepcopy(leds)
        frame_number += 1
        counter += 1

    file.close()
コード例 #3
0
def importAni():
    global leds
    global frame_number
    with open('animation8x8.py') as ll:
        line_count = sum(1 for _ in ll)
    ll.close()

# start of actual good code

    #animation = {}
    frame_number = 1
    file = open('animation8x8.py')
    for r in range(line_count):
        buff = file.readline()
        if (buff[:2] == '[['):
            load_frame = buff.split('], [')
            counter = 1
            leds =[]
            for f in load_frame:

                if counter == 1:
                    f = f[2:]
                elif counter == 64:

                    f = f[:-4]

                y = int((counter-1)/8)
                x = int((counter-1)%8)

                #print(str(counter) + ' ' + f + ' x= ' + str(x) + ' y= ' + str(y))
                led = LED(radius=20,pos=(x, y))
                if f == '0, 0, 0':
                    led.lit = False

                else:
                    led.lit = True
                    f_colours = f.split(',')
                    #print(f_colours)
                    led.color = [int(f_colours[0]),int(f_colours[1]),int(f_colours[2])]
                leds.append(led)
                counter+=1
            animation[frame_number] = copy.deepcopy(leds)
            frame_number+=1
            counter+=1


##### end of actual good code



    file.close()
コード例 #4
0
def exportAni():

    global saved
    FILE=open('animation8x8.py','w')
    FILE.write('from sense_emu import SenseHat\n')
    FILE.write('import time\n')
    FILE.write('sh=SenseHat()\n')
    FILE.write('FRAMES = [\n')
    global leds
    global frame_number
    animation[frame_number] = copy.deepcopy(leds)
    #print 'length of ani is ' + str(len(animation))
    for playframe in range(1,(len(animation)+1)):
        #print(playframe)
        leds =[]
        for x in range(0, 8):
            for y in range(0, 8):
                led = LED(radius=20,pos=(x, y))
                leds.append(led)
            for saved_led in animation[playframe]:
                if saved_led.lit:
                    for led in leds:
                        if led.pos == saved_led.pos:
                            led.color = saved_led.color
                            led.lit = True
        grid, png_grid = buildGrid()

        FILE.write(str(grid))
        FILE.write(',\n')
    FILE.write(']\n')
    FILE.write('for x in FRAMES:\n')
    FILE.write('\t sh.set_pixels(x)\n')
    FILE.write('\t time.sleep('+ str(1.0/fps) + ')\n')
    FILE.close()
    saved = True
コード例 #5
0
def exportAni():

    global saved
    FILE=open('animation8x8.py','w')
    FILE.write('from sense_hat import SenseHat\n')
    FILE.write('import time\n')
    FILE.write('sh=SenseHat()\n')
    FILE.write('FRAMES = [\n')
    global leds
    global frame_number
    animation[frame_number] = copy.deepcopy(leds)
    #print 'length of ani is ' + str(len(animation))
    for playframe in range(1,(len(animation)+1)):
        #print(playframe)
        leds =[]
        for x in range(0, 8):
            for y in range(0, 8):
                led = LED(radius=20,pos=(x, y))
                leds.append(led)
            for saved_led in animation[playframe]:
                if saved_led.lit:
                    for led in leds:
                        if led.pos == saved_led.pos:
                            led.color = saved_led.color
                            led.lit = True
        grid, png_grid = buildGrid()

        FILE.write(str(grid))
        FILE.write(',\n')
    FILE.write(']\n')
    FILE.write('for x in FRAMES:\n')
    FILE.write('\t sh.set_pixels(x)\n')
    FILE.write('\t time.sleep('+ str(1.0/fps) + ')\n')
    FILE.close()
    saved = True
コード例 #6
0
def exportAni():

    global saved
    FILE = open("animation8x8.py", "wb")
    FILE.write("from astro_pi import AstroPi\n")
    FILE.write("import time\n")
    FILE.write("ap=AstroPi()\n")
    FILE.write("FRAMES = [\n")
    global leds
    global frame_number
    animation[frame_number] = copy.deepcopy(leds)
    # print 'length of ani is ' + str(len(animation))
    for playframe in range(1, (len(animation) + 1)):
        # print(playframe)
        leds = []
        for x in range(0, 8):
            for y in range(0, 8):
                led = LED(pos=(x, y))
                leds.append(led)
            for saved_led in animation[playframe]:
                if saved_led.lit:
                    for led in leds:
                        if led.pos == saved_led.pos:
                            led.color = saved_led.color
                            led.lit = True
        grid, png_grid = buildGrid()

        FILE.write(str(grid))
        FILE.write(",\n")
    FILE.write("]\n")
    FILE.write("for x in FRAMES:\n")
    FILE.write("\t ap.set_pixels(x)\n")
    FILE.write("\t time.sleep(" + str(1.0 / fps) + ")\n")
    FILE.close()
    saved = True
コード例 #7
0
def importAni():
    global leds
    global frame_number
    with open('animation8x8.py') as ll:
        line_count = sum(1 for _ in ll)
    ll.close()

    #animation = {}
    frame_number = 1
    file = open('animation8x8.py')
    for r in range(4):
        file.readline()

    for frame  in range(line_count-8):
        buff = file.readline()

        load_frame = buff.split('], [')
        counter = 1
        leds =[]
        for f in load_frame:

            if counter == 1:
                f = f[2:]
            elif counter == 64:

                f = f[:-4]

            y = int((counter-1)/8)
            x = int((counter-1)%8)

            #print(str(counter) + ' ' + f + ' x= ' + str(x) + ' y= ' + str(y))
            led = LED(radius=20,pos=(x, y))
            if f == '0, 0, 0':
                led.lit = False

            else:
                led.lit = True
                f_colours = f.split(',')
                #print(f_colours)
                led.color = [int(f_colours[0]),int(f_colours[1]),int(f_colours[2])]
            leds.append(led)
            counter+=1
        animation[frame_number] = copy.deepcopy(leds)
        frame_number+=1
        counter+=1

    file.close()
コード例 #8
0
def play():
	
	global leds
	global frame_number
	animation[frame_number] = copy.deepcopy(leds)
	#print 'length of ani is ' + str(len(animation))
	for playframe in range(1,(len(animation)+1)):
		#print(playframe) 
		leds =[]
		for x in range(0, 8):
			for y in range(0, 8):
				led = LED(pos=(x, y))
				leds.append(led)
			for saved_led in animation[playframe]:
				if saved_led.lit:
					for led in leds:
						if led.pos == saved_led.pos:
							led.color = saved_led.color
							led.lit = True
		piLoad()
		time.sleep(1.0/fps)
コード例 #9
0
def play():

	global leds
	global frame_number
	animation[frame_number] = copy.deepcopy(leds)
	#print 'length of ani is ' + str(len(animation))
	for playframe in range(1,(len(animation)+1)):
		#print(playframe)
		leds =[]
		for x in range(0, 8):
			for y in range(0, 8):
				led = LED(radius=20,pos=(x, y))
				leds.append(led)
			for saved_led in animation[playframe]:
				if saved_led.lit:
					for led in leds:
						if led.pos == saved_led.pos:
							led.color = saved_led.color
							led.lit = True
		piLoad()
		time.sleep(1.0/fps)
コード例 #10
0
def start_animation():
	global animation_process
	global saved
	FILE=open('/home/pi/RPi_8x8GridDraw/animation8x8.py','wb')
	FILE.write('from sense_hat import AstroPi\n')
	FILE.write('import time\n')
	FILE.write('ap=AstroPi()\n')
	FILE.write('FRAMES = [\n')
	global leds
	global frame_number
	animation[frame_number] = copy.deepcopy(leds)
	#print 'length of ani is ' + str(len(animation))
	for playframe in range(1,(len(animation)+1)):
		#print(playframe) 
		leds =[]
		for x in range(0, 8):
			for y in range(0, 8):
				led = LED(pos=(x, y))
				leds.append(led)
			for saved_led in animation[playframe]:
				if saved_led.lit:
					for led in leds:
						if led.pos == saved_led.pos:
							led.color = saved_led.color
							led.lit = True
		grid, png_grid = buildGrid()
		
		FILE.write(str(grid))
		FILE.write(',\n')
	FILE.write(']\n')
	FILE.write('while True:\n')
	FILE.write('\tfor x in FRAMES:\n')
	FILE.write('\t\tap.set_pixels(x)\n')
	FILE.write('\t\ttime.sleep('+ str(1.0/fps) + ')\n')
	FILE.close()
	saved = True
	if animation_process is not None:
		animation_process.terminate()
	animation_process = subprocess.Popen(["python", "/home/pi/RPi_8x8GridDraw/animation8x8.py"])