示例#1
0
from Canopto import Canopto
import pygame
from pygame import *
from pygame.locals import *
from pygame.transform import *
import time
from random import randint
from random import random
from colorsys import *
import sys
from tween import *
from itertools import chain

display_size = (8, 8)
cans = Canopto (display_size[0], display_size[1], True, True)

def get_window_at_pos (baseImage, pos, windowSize=display_size):
	return baseImage.subsurface(((baseImage.get_width() - windowSize[0])*pos[0], (baseImage.get_height() - windowSize[1])*pos[1]), windowSize)

base_image = pygame.image.load("res/sunflowers1.jpg")

# Zoom in on a position within a larger image slowly
# Zoom back out
# Repeat with a new position

old_image = Surface(display_size)
while True:
	# Zoom in and out again
	pos = (random(), random())
	
示例#2
0
#!/bin/python3

from Canopto import Canopto
import pygame
from pygame.locals import *
import time
import random
from colorsys import *

c = Canopto(8, 8, True, True)
c.bs.clear()
c.bs.send_data(0)

while True:
	x = random.randint(0, c.width-1)
	last_x = x
	for y in range(0, c.height+1):
		# Write new position as a white snowflake
		#x = random.randint(0, c.width-1)
		if y < c.height:
			c.setPixel(x, y, (255, 255, 255))
			
		fade_time = 0.75
		if y > 0:
			# Fade out old position
			fade_step = 0.02
			old_pos_color = (1, 1, 0)
			while c.getPixel(last_x, y-1)[0] > 0:
				old_pos_color = (old_pos_color[0], max(old_pos_color[1] - 0.03, 0), old_pos_color[2])
				fading_color = (hls_to_rgb(*old_pos_color)[0]*255.0, hls_to_rgb(*old_pos_color)[1]*255.0, hls_to_rgb(*old_pos_color)[2]*255.0)
				c.setPixel(last_x, y-1, fading_color)
示例#3
0
#!/bin/python3

from Canopto import Canopto
import pygame
from pygame import *
from pygame.locals import *
import time
from random import randint
from random import random
from colorsys import *
import sys

display_size = (8, 8)
cans = Canopto (display_size[0], display_size[1], True, True)

# Create image of random colors with a constant lightness
# Fade it over the previous image
# Delay
# Repeat forever

old_image = Surface(display_size)
while True:
	new_image = Surface(display_size)
	for x in range (0, display_size[0]):
		for y in range (0, display_size[1]):
			# Show either gold or a random green
			rand_color = Color(0, 0, 0, 0)
			if (random() > 0.7):
				rand_color.hsla = (50, 100, 50, 100)
			else:
				# Green
示例#4
0
文件: cgol.py 项目: fenceFoil/canopto
#!/bin/python3

from Canopto import Canopto
import pygame
from pygame import *
from pygame.locals import *
import time
from random import randint
from colorsys import *
import sys
import numpy
import math


display_size = (8, 8)
cans = Canopto (display_size[0], display_size[1], True, True)

# Plays Conway's Game of Life over the display, fading in each new frame over the last
# Still life and cycle detection is provided by storing every frame of every simulation,
# and comparing each new frame to all the previous. If there are any matches, the
# game ends after a set number more frames are rendered (10-ish).

# Graphical plan: fade in each new frame on top of the last, showing the last dimly
# behind the current. When about to reset, pulse the background red or yellow. 
# Otherwise keep the background black.
# The foreground color will change with each simulation, always bright.

def randomize_frame (input_frame):
	input_frame = [[randint(0, 1)
		for x in range (len(input_frame[0]))] 
		for y in range (len(input_frame))]
示例#5
0
#!/bin/python3

from Canopto import Canopto
import pygame
from pygame import *
from pygame.locals import *
from pygame.transform import *
import time
from random import randint
from random import random
from colorsys import *
import sys
from tween import *

display_size = (8, 8)
cans = Canopto (display_size[0], display_size[1], True, True)

# Create image of random colors with a constant lightness
# Fade it over the previous image
# Delay
# Repeat forever

old_image = Surface(display_size)
while True:
	new_image = Surface(display_size)
	for x in range (0, display_size[0]):
		for y in range (0, display_size[1]):
			# Show either gold or a random green
			rand_color = Color(0, 0, 0, 0)
			if (random() > 0.9):
				rand_color.hsla = (50, 100, 50, 100)
示例#6
0
#!/bin/python3

from Canopto import Canopto
import pygame
from pygame import *
from pygame.locals import *
import time
from random import randint
from colorsys import *
import sys

display_size = (8, 8)
cans = Canopto (display_size[0], display_size[1], False, True)

# Create image of random colors with a constant lightness
# Fade it over the previous image
# Delay
# Repeat forever

colors = [Color(0, 0, 0, 255), Color(0, 255, 255, 0)]
curr_color = 0
cycle_fwd = True
while True:
	new_image = Surface(display_size)
	new_image.fill(colors[curr_color])
	
	hue = colors[1].hsla[0]
	if (cycle_fwd):
		hue = (hue + 2)
		if (hue >= 360):
			cycle_fwd = False
示例#7
0
def main():
    #Initialize Canopto Display
    display = Canopto(8, 8)
    Canopto.start(display)
    display.clear()

    CONFIG_PATH = '/home/aoi/code/canopto_config.json'
    # API KEYS FOUND HERE: https://www.twilio.com/user/account  (NOT  under DEV TOOLS > API KEYS)
    # Read API keys for Twilio from json config file (outside of git repository)
    # Or use environment variables as https://github.com/twilio/twilio-python suggests
    with open(CONFIG_PATH) as json_config:
        config = json.load(json_config)
        ACCOUNT_SID = config['twilio']['account_sid']
        AUTH_TOKEN = config['twilio']['auth_token']
        print("Successfuly read api information from config")

    client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

    processedMessages = []
    processedIDs = []

    startTime = datetime.datetime.now() + datetime.timedelta(hours=4)

    while (display.running): #display.tracker.running):
        #if tracker.frameCounter == 10:
            #tracker.resetToMotion = True
            #print "reset to motion"

        #Because of a conflict between timezones used to represent dates cannot limit by day since messages sent after
        #~10pm will, according to server, be sent tomorrow thereby not having them show up as new messages if limited by today
        #date_sent=datetime.datetime.today()
        messages = client.messages.list()
        for message in messages:
            if (message.direction == "inbound"):
                #New message from now onward that hasn't already been processed
                if message.sid not in processedIDs and message.date_created > startTime:
                    currentMessage = Message(message.sid, message.from_, message.to, message.body)
                    print "New Text Message:", currentMessage

                    #print(len(message.body))
                    #if len(message.body) > 70:         #Large text messages get split up, also blocks the display
                    #    continue

                    if (message.body.lower() == "reset" or message.body.lower() == "r") and display.mode == "text":
                        display.tracker.resetTrackingPosition()
                        display.drawSentence(str(display.tracker.reportPosition()) + "  ")
                        client.messages.create(to=message.from_, from_=message.to, body=str(display.tracker.reportPosition()))
                        #pass
                    elif (message.body.lower() == "print" or message.body.lower() == "p") and display.mode == "text":
                        display.drawSentence(str(display.tracker.reportPosition()) + "  ")
                        client.messages.create(to=message.from_, from_=message.to, body=str(display.tracker.reportPosition()))
                        #pass
                    elif (message.body.lower() == "clear"):
                        display.clear()
                    elif message.body.lower() == "crazy" and display.mode == "text":
                        display.crazyColorMode = not display.crazyColorMode     #Toggle Crazy Color Mode
                        if not display.crazyColorMode:
                            #reset colors to normal
                            display.resetColors()
                        client.messages.create(to=message.from_, from_=message.to, body="Crazy Mode: " + str(display.crazyColorMode))
                    elif message.body.lower() == "nocrazy":
                        display.crazyColorMode = False
                        client.messages.create(to=message.from_, from_=message.to, body="Crazy Mode: " + str(display.crazyColorMode))
                    elif message.body.lower()[0:5] == "speed" and len(message.body) > 6:
                        display.fps = int(message.body.split(' ')[1])
                        if display.mode == "text":
                            display.drawSentence("fps:" + str(display.fps))
                        client.messages.create(to=message.from_, from_=message.to, body="fps:" + str(display.fps))
                    elif message.body.lower() == "track":
                        display.mode = "track"
                        client.messages.create(to=message.from_, from_=message.to, body="Display Mode = track" )
                    elif message.body.lower() == "text":
                        display.mode = "text"
                        client.messages.create(to=message.from_, from_=message.to, body="Display Mode = text" )
                    elif (message.body[0] == "0"):
                        x, y = [int(x) for x in message.body[1:].split(',')]
                        display.tracker.setTrackingPosition(x,y,30,30)

                        display.drawSentence(str(display.tracker.reportPosition()) + "  ")
                    elif message.body.lower() == "reset to motion":
                        display.mode = "track"
                        client.messages.create(to=message.from_, from_=message.to, body="Refocusing to motion" )
                    elif message.body.lower() == "refocus":
                        display.mode = "track"
                        display.tracker.resetToMotion = True
                        client.messages.create(to=message.from_, from_=message.to, body="Refocusing to motion" )
                    elif message.body.lower()[0:6] == "bcolor":
                        rgb = [int(i) for i in message.body.lower().split(' ')[1].split(',')]
                        print "New background color:", rgb
                        display.backgroundColor = display.toGamma(rgb)
                        client.messages.create(to=message.from_, from_=message.to, body="Background color is now " + str(display.backgroundColor) )
                    elif message.body.lower()[0:6] == "fcolor":
                        rgb = [int(i) for i in message.body.lower().split(' ')[1].split(',')]
                        print "New font color:", rgb
                        display.fontColor = display.toGamma(rgb)
                        client.messages.create(to=message.from_, from_=message.to, body="Font color is now " + str(display.fontColor) )
                    elif message.body.lower()[0] == "w" and display.mode == "text":
                        display.drawSentence(message.body[1:] + " ")
                        client.messages.create(to=message.from_, from_=message.to, body="Writing: " + str(message.body[1:]) )
                    elif message.body.lower() == "resetbs":
                        display.tracker.resetBS = True
                        client.messages.create(to=message.from_, from_=message.to, body="Resetting background subtractor" )
                    elif message.body.lower() == "options" or message.body.lower() == "help":
                        client.messages.create(to=message.from_, from_=message.to, body="""if (message.body.lower() == "reset" or message.body.lower() == "r") and display.mode == "text":
                        elif (message.body.lower() == "print" or message.body.lower() == "p") and display.mode == "text":
                        elif (message.body.lower() == "clear"):
                        elif message.body.lower() == "crazy" and display.mode == "text":
                        elif message.body.lower() == "nocrazy":
                        elif message.body.lower()[0:5] == "speed" and len(message.body) > 6:
                        elif message.body.lower() == "track":
                        elif message.body.lower() == "text":
                        elif (message.body[0] == "0"): display.tracker.setTrackingPosition(x,y,30,30)
                        elif message.body.lower() == "reset to motion":
                        elif message.body.lower() == "refocus":
                        elif message.body.lower()[0:6] == "bcolor":
                        elif message.body.lower()[0:6] == "fcolor":
                        elif message.body.lower()[0] == "w" and display.mode == "text":
                        elif message.body.lower() == "resetbs":""")

                    processedIDs.append(message.sid)
                    processedMessages.append(currentMessage)
        time.sleep(1)

    #Close down the main loops of the threads
    #tracker.running = False
    display.clear()
    display.running = False