コード例 #1
0
from openframeworks import *
from protopixel import Content

# color is the current color displayed
color = ofColor(255, 255, 255)

content = Content("Remote Interface Script")
size = 255

content.FBO_SIZE = (size, size)

# Here we specify where the remote interface (HTML) is.
# In this case, we have the index.html file in a folder
# called "remote_interface"
content.web_path('remote_interface')


@content.websocket.receive
def websocket(ws, data):
    """
    This function handles user input through a websocket, as provided in /pl.js library.
    Use content.websocket.receive decorator to define handles like this.
    In this case we send the accelerometer readings of the device (x,y,z).
    `ws` is a websocket, data the data comming through the websocket. You can send data
    with `ws.send()`.
    """
    global color
    r = normalize(data["x"])
    g = normalize(data["y"])
    b = normalize(data["z"])
    color = ofColor(r, g, b)
コード例 #2
0
from protopixel import Content
from openframeworks import *

X = 0.0
Y = 0.0

mode = 'rest'

content = Content('Orientation Script')
content.web_path('orientation')

content.FBO_SIZE = (500, 500)


class Autoscale(object):
    def __init__(self, min_value, max_value):
        self.min_out = min_value
        self.max_out = max_value
        self.spread_out = self.max_out - self.min_out
        self.min = self.max = None

    def __call__(self, val):
        if self.min is None:
            self.min = self.max = val
            return self.min_out + (self.spread_out) / 2.0

        self.min = min(self.min, val)
        self.max = max(self.max, val)

        return self.min_out + self.spread_out * ((val - self.min) /
                                                 (self.max - self.min))
コード例 #3
0
from openframeworks import *
from protopixel import Content

# color is the current color displayed
color = ofColor(255, 255, 255)

content = Content("Remote Interface Script")
size = 255

content.FBO_SIZE = (size, size)

# Here we specify where the remote interface (HTML) is.
# In this case, we have the index.html file in a folder
# called "remote_interface"
content.web_path('html-receive.html')


@content.websocket.receive
def websocket(ws, data):
    """
    This function handles user input through a websocket, as provided in /pl.js library.
    Use content.websocket.receive decorator to define handles like this.
    """
    global color
    r = data["R"]
    g = data["G"]
    b = data["B"]
    color = ofColor(r, g, b)


def draw():
コード例 #4
0
from protopixel import Content

content = Content('Remote Web Interface')

content.web_path('remote')  # directory relative to this file
コード例 #5
0
# This file is part of the ProtoPixel Library
from protopixel import Content
from openframeworks import *
from collections import namedtuple

content = Content('Paint')
content.add_parameter('size', value=300, min=0, max=1024)
content.add_parameter('clear', type='button')

firstrun = True
Finger = namedtuple('Finger', ['x', 'y', 'size', 'color'])
fingers = []

content.FBO_SIZE = (300, 300)
content.web_path('paint')


@content.parameter_changed('size')
def size_changed(size):
    content.FBO_SIZE = (size, size)


@content.websocket.receive
def websocket(ws, data):
    if data['event'] == "draw":
        getfinger(data['x'] * content.FBO_SIZE[0],
                  data['y'] * content.FBO_SIZE[1], data['color'])
    elif data['event'] == "clear":
        clear()