def setupTextures(self): content = Content("Aurora") ch1_file = content.add_asset('iChannel0.png') ch2_file = content.add_asset('iChannel1.png') self.img = ofImage(ch1_file) self.img2 = ofImage(ch2_file) self.fbo2 = ofFbo() self.fbo2.allocate(self.width, self.height) self.fbo2.begin() self.img2.draw(0, 0, self.width, self.height) self.fbo2.end()
from protopixel import Content from openframeworks import * import os.path from tempfile import mkdtemp content = Content("Noise") side = 256 content.FBO_SIZE = (side, side) shaderfile = content.add_asset('shader') shader = ofShader() temp_dir = mkdtemp() frag_file = os.path.join(temp_dir, 's.frag') vert_file = os.path.join(temp_dir, 's.vert') shader_file_of = os.path.join(temp_dir, 's') #a global variable color = ofColor(255) elapsedTime = 0.0 startColorIndex = 1 endColorIndex = 2 scaleFactor = 10 currentTime = 0 timeFactor = 0.5 speedFactor = 2.0 content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255))
from openframeworks import * from protopixel import Content from tempfile import mkdtemp import os.path from random import randint import imp content = Content("IngoSchusterAurora") aurora_file = content.add_asset("Aurora.py") aurora = imp.load_source('aurora',aurora_file) print "IngoSchusterSunset" #a global variable num_modes = 3 elapsedTime = 0.0 change_time = 350 width = 600 height= 100 content.FBO_SIZE = (width,height) #optional: define size of FBO, default=(100,100) targetAlpha = 1.0 currentAlpha = 0.0 energy = 1.0 fbo = ofFbo() fboVisuals = ofFbo() shader = ofShader() mode = 0 content.add_parameter("gamma", min=0.0, max=1.0, value=0.85)
from random import randint import math print "Strobe" #a global variable color = ofColor(255) elapsedTime = 0.0 startColorIndex = 1 endColorIndex = 2 brightness = 0 scaleFactor = 10.0 currentSpeed = 0.1 speedFactor = 7 content = Content("Strobe") content.FBO_SIZE = (170, 170) #optional: define size of FBO, default=(100,100) content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True) content.add_parameter("color_speed", min=0.00, max=1.0, value=0.1) content.add_parameter("speed", min=0.0, max=1.0, value=0.1) content.add_parameter("stage_mode", value=False) @content.parameter_changed('change_hue') def parameter_changed(value): """ This function is called every time a a_integer is changed.
from openframeworks import * from protopixel import Content from random import randint import math print "BlackoutSections" #a global variable size = 170 currentTransparency = [] targetTransparency = [] numSections = 5 onTransparency = 10 content = Content("BlackoutSections") content.FBO_SIZE = (170, 170) #optional: define size of FBO, default=(100,100) content.add_parameter("_1", value=False) content.add_parameter("_2", value=False) content.add_parameter("_3", value=False) content.add_parameter("_4", value=False) content.add_parameter("_5", value=False) @content.parameter_changed('_1') def parameter_changed(value): global targetTransparency, onTransparency if value == True: targetTransparency[0] = 255
from protopixel import Content from openframeworks import * import os.path from tempfile import mkdtemp #a global variable color = ofColor(255) elapsedTime = 0.0 startColorIndex = 1 endColorIndex = 2 scaleFactor = 10.0 currentTime = 0 timeFactor = 5.0 content = Content("Shader") side = 256 content.FBO_SIZE = (side, side) shaderfile = content.add_asset('shader') shader = ofShader() temp_dir = mkdtemp() frag_file = os.path.join(temp_dir, 's.frag') vert_file = os.path.join(temp_dir, 's.vert') shader_file_of = os.path.join(temp_dir, 's') content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True)
from openframeworks import * from protopixel import Content from tempfile import mkdtemp import os.path from random import randint import imp content = Content("ProtoPixeFrames") print "ProtoPixeFrames" color = ofColor(255) shader = ofShader() targetAlpha = 1.0 currentAlpha = 0.0 size = 10 content.FBO_SIZE = (size, size) content.add_parameter("gamma", min=0.0, max=1.0, value=0.9) content.add_parameter("Color", type="color", value=ofColor(255, 255, 255)) rainbow_file = content.add_asset("rainbow.py") rainbow = imp.load_source('rainbow', rainbow_file) square_file = content.add_asset("square.py") square = imp.load_source('square', square_file) def setup(): """ This will be called at the beggining, you set your stuff here
from openframeworks import * from protopixel import Content from tempfile import mkdtemp import os.path from random import randint import imp content = Content("IngoSchuster") sunset_file = content.add_asset("Sunset.py") sunset = imp.load_source('sunset', sunset_file) clouds_file = content.add_asset("Clouds.py") clouds = imp.load_source('clouds', clouds_file) aurora_file = content.add_asset("Aurora.py") aurora = imp.load_source('clouds', aurora_file) print "IngoSchuster" #a global variable num_modes = 3 elapsedTime = 0.0 change_time = 350 width = 600 height = 100 content.FBO_SIZE = (width, height ) #optional: define size of FBO, default=(100,100) targetAlpha = 1.0 currentAlpha = 0.0 energy = 1.0
from protopixel import Content from random import randint import math print "Pulse" #a global variable color = ofColor(255) elapsedTime = 0.0 startColorIndex = 1 endColorIndex = 2 brightness = 0.0 scaleFactor = 10 speedFactor = 20 content = Content("Pulse") content.FBO_SIZE = (170, 170) #optional: define size of FBO, default=(100,100) content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True) content.add_parameter("color_speed", min=0.00, max=1.0, value=0.1) content.add_parameter("speed", min=0.0, max=1.0, value=0.1) content.add_parameter("stage_mode", value=False) @content.parameter_changed('change_hue') def parameter_changed(value): """ This function is called every time a a_integer is changed.
from protopixel import Content from random import randint import math print "CircleAnimation" #a global variable color = ofColor(255) elapsedTime = 0.0 startColorIndex = 1 endColorIndex = 2 scaleFactor = 10 size = 170 content = Content("CircleAnimation") content.FBO_SIZE = (size,size) #optional: define size of FBO, default=(100,100) content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True) content.add_parameter("color_speed", min=0.00, max=1.0, value=0.1) content.add_parameter("speed", min=0.0, max=1.0, value=0.2) content.add_parameter("circle_num", min=1, max=20, value=1) content.add_parameter("stage_mode", value=False) class Circle: frameSize = 170
from openframeworks import * from protopixel import Content from tempfile import mkdtemp import os.path from random import randint import imp from OSC import OSCClient, OSCMessage content = Content("ProtoPixelDress") sparkle_file = content.add_asset("sparkle.py") sparkles = imp.load_source('sparkles', sparkle_file) rainbow_file = content.add_asset("rainbow.py") rainbow = imp.load_source('rainbow', rainbow_file) fade_file = content.add_asset("fade.py") fade = imp.load_source('fade', fade_file) waves_file = content.add_asset("waves.py") waves = imp.load_source('waves', waves_file) circles_file = content.add_asset("circles.py") circles = imp.load_source('circles', circles_file) OSC_DEST_IP = "localhost" OSC_BROADCAST_IP = "192.168.8.255" OSC_BROADCAST_PORT = 2346 OSC_DEST_PORT = 2345
from openframeworks import * from protopixel import Content from random import randint import math print "Blackout" #a global variable size = 170 currentTransparency = 0 targetTransparency = 0 content = Content("Blackout") content.FBO_SIZE = (170, 170) #optional: define size of FBO, default=(100,100) content.add_parameter("On", value=False) @content.parameter_changed('On') def parameter_changed(value): """ This function is called every time a a_integer is changed. We get the new value as an argument """ global targetTransparency if value == True: targetTransparency = 255 print "Global Blackout ON " else: targetTransparency = 0
from openframeworks import * import numpy as np from protopixel import Content # You can paint directly your light points by using numpy arrays content = Content('Pixel Draw Script') content.FBO_SIZE = (170, 170) # we can precalculate this center = np.array(content.FBO_SIZE) / 2 def draw_pixels(position_array, colors_array): """ This function is called at every frame, with two arguments: * position_array is an array of 2D positions of all our lights * colors_array is an array of RGBA color components that we have to fill in order to "paint" our leds Please note that we have to CHANGE the contents of colors_array, not to assign a new array to the variable: >>> colors_array[:] = computed_colors # Correct >>> colors_array = computed_colors # Incorrect """ t = ofGetElapsedTimef() dx = position_array[:, 0] - center[ 0] # position_array[:,0] is all x positions dy = position_array[:, 1] - center[ 1] # position_array[:,1] is all y positions
size = 170 yPos = - 170 xPos = 0 animationType = 3 width = size height = size color = ofColor(255) elapsedTime = 0.0 startColorIndex = 1 endColorIndex = 2 scaleFactor = 10 speedFactor = 300 yOffset = 0 xOffset = 0 content = Content("SwipeAnimation") content.FBO_SIZE = (size,size) #optional: define size of FBO, default=(100,100) content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True) content.add_parameter("color_speed", min=0.00, max=1.0, value=0.1) content.add_parameter("speed", min=0.0, max=1.0, value=0.2) content.add_parameter("stage_mode", value=False) @content.parameter_changed('change_hue') def parameter_changed(value): """ This function is called every time a a_integer is changed. We get the new value as an argument
from openframeworks import * from protopixel import Content import numpy as np content = Content("Assets example Script") # If you want to use an external asset inside a script # you can declare it like this: cat_file = content.add_asset('cat.jpeg') # This could be a file or a folder. # This serves two different purposes: # - It is equivalent to os.path.join(os.path.dirname(__file__),'cat.jpeg'), # so it allows you to get a valid path for an asset that is relative to # the script, but is easier to write. # - It tells ProtoPixel Create about these files, so it can pack them when # exporting a project. def setup(): global image image = ofImage(cat_file) content.FBO_SIZE = (int(image.getWidth()), int(image.getHeight())) def draw(): image.draw(0,0)
from openframeworks import * from protopixel import Content from random import randint import math print "Colors" #a global variable color = ofColor(255) elapsedTime = 0.0 startColorIndex = 1 endColorIndex = 2 scaleFactor = 10 content = Content("Colors") content.FBO_SIZE = (170, 170) #optional: define size of FBO, default=(100,100) content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True) content.add_parameter("color_speed", min=0.00, max=1.0, value=0.1) content.add_parameter("stage_mode", value=False) @content.parameter_changed('change_hue') def parameter_changed(value): """ This function is called every time a a_integer is changed. We get the new value as an argument """
from protopixel import Content from openframeworks import * import os.path from tempfile import mkdtemp content = Content("Ripple") side = 256 content.FBO_SIZE = (side,side) shaderfile = content.add_asset('shader') shader = ofShader() temp_dir = mkdtemp() frag_file = os.path.join(temp_dir,'s.frag') vert_file = os.path.join(temp_dir,'s.vert') shader_file_of = os.path.join(temp_dir,'s') content.add_parameter("speed", min=0.01, max=1.0, value=0.033) def setup(): if content['shader path']: shader_path_changed(content['shader path']) with open(frag_file,'w') as f: f.write(frag_contents_prefix) f.write(frag_contents) f.write(frag_contents_suffix) with open(vert_file,'w') as f: f.write(vert_contents) shader.load(shader_file_of)
#a global variable size = 570 width = size height = size color = ofColor(255) elapsedTime = 0.0 elapsedTimeLines = 0.0 startColorIndex = 1 endColorIndex = 2 scaleFactor = 10.0 lineScaleFactor = 10.0 rows = [ 0.0069, 0.055, 0.102, 0.151, 0.234926, 0.284, 0.331, 0.38, 0.479, 0.528, 0.575, 0.625, 0.707, 0.756, 0.803, 0.899, 0.948, 0.994] cols = [ 0.026, 0.107, 0.186, 0.268089, 0.35, 0.428, 0.508, 0.591, 0.67, 0.751, 0.831, 0.912, 0.99] content = Content("MinimalLines") content.FBO_SIZE = (size,size) #optional: define size of FBO, default=(100,100) content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True) content.add_parameter("color_speed", min=0.00, max=1.0, value=0.1) content.add_parameter("speed", min=0.0, max=1.0, value=0.1) content.add_parameter("num_lines", min=0, max=10, value=1) content.add_parameter("stage_mode", value=False) class Line: size = 570
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))
col4 = [ 0.268089, 0.35, 0.428, 0.508, 0.591, 0.67, 0.751] col5 = [ 0.268089, 0.35, 0.428, 0.508, 0.591, 0.67, 0.751] cols.append(col1) cols.append(col2) cols.append(col3) cols.append(col4) cols.append(col5) #rows = [ 0.0069, 0.055, 0.102, 0.151, 0.234926, 0.284, 0.331, 0.38, 0.479, 0.528, 0.575, 0.625, 0.707, 0.756, 0.803, 0.899, 0.948, 0.994] #cols = [ 0.026, 0.107, 0.186, 0.268089, 0.35, 0.428, 0.508, 0.591, 0.67, 0.751, 0.831, 0.912, 0.99] squares = [] content = Content("RandomSquares") content.FBO_SIZE = (size,size) #optional: define size of FBO, default=(100,100) content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True) content.add_parameter("color_speed", min=0.00, max=1.0, value=0.1) content.add_parameter("speed", min=0.0, max=1.0, value=0.1) content.add_parameter("num_squares", min=0, max=20, value=1) content.add_parameter("stage_mode", value=False) @content.parameter_changed('change_hue') def parameter_changed(value): """ This function is called every time a a_integer is changed.
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)
# Activating/deactivating contents by OSC or button # In this scenario we have two contents that we want to control, their names are "content1" and "content2" from protopixel import Content # We need to change the configuration of other contents from protopixel.core import setConfContent # Create ProtoPixel Create content content = Content('OSC and button Content enabler example') # content.add_button decorator adds a button on the GUI that executes the decorated function # content.OSC decorator let's you define an OSC entry point for a given address. In this case # '/scene1' address with no arguments will execute this function @content.add_button('scene1') @content.OSC('/scene1') def enable_scene1(): # When we receive an OSC packet in '/scene1' or click on 'scene1' button, we activate content1 # and deactivate content2 setConfContent('content1','enabled',True) setConfContent('content2','enabled',False) @content.add_button('scene2') @content.OSC('/scene2') def enable_scene2(): # When we receive an OSC packet in '/scene2' or click on 'scene2' button, we activate content2 # and deactivate content1 setConfContent('content1','enabled',False) setConfContent('content2','enabled',True)
from openframeworks import * from protopixel import Content from random import randint import math print "Hello ProtoPixel" content = Content("Simple Script") content.FBO_SIZE = (170,170) #optional: define size of FBO, default=(100,100) #a global variable counter = 0 amplitudes = [] # None of the following functions are mandatory, they can be omitted def setup(): global x_spacing, wave_width, theta, period, dx, max_amplitude, amplitudes ofBackground(255, 255, 255) ofSetFrameRate(25) ofEnableAlphaBlending() ofEnableSmoothing() # distance between each horizontal point (in pixels) x_spacing = 5 # width of the wave wave_width = 170 # current angle theta = 0.0
from openframeworks import * from protopixel import Content import numpy as np content = Content("Audio Script") def draw(): """ To pocess audio input, we can use the audio input buffer. >>> content.get_sound_buffer() #get audio buffer as a numpy array """ buffer = content.get_sound_buffer() # get the absolute values buffer = np.abs(buffer) # get the sum of all values, to measure the energy energy = int(buffer.sum()) # we use the energy to change the color ofClear(min(255, energy), 0, 0, 255)
from openframeworks import * from protopixel import Content import numpy as np # We neeed access to low level API calls for communication with core from protopixel.core import setConfContent, callParameterContent content = Content("Video Script") def setup(): print "setup player" def draw(): pass @content.OSC('/column2P/1') def video_play(action): """ This function handles OSC user input in address "/acc", with 3 arguments: x,y,z. Use pl.OSC decorator to define handles like this. Multiple scripts can listen to the same address simultaneously. """ print("WORKING!") print action if action == True: callParameterContent("outro2", "params:resume") print "Play"
from openframeworks import * from protopixel import Content from tempfile import mkdtemp import os.path from random import randint import imp content = Content("IngoSchusterclouds") clouds_file = content.add_asset("Clouds.py") clouds = imp.load_source('clouds', clouds_file) print "IngoSchusterSunset" #a global variable num_modes = 3 elapsedTime = 0.0 change_time = 350 width = 600 height = 100 content.FBO_SIZE = (width, height ) #optional: define size of FBO, default=(100,100) targetAlpha = 1.0 currentAlpha = 0.0 energy = 1.0 fbo = ofFbo() fboVisuals = ofFbo() shader = ofShader() mode = 0 content.add_parameter("gamma", min=0.0, max=1.0, value=0.9)
from protopixel import Content from openframeworks import * import os.path from tempfile import mkdtemp content = Content("SnowFlakes") side = 256 content.FBO_SIZE = (side, side) shaderfile = content.add_asset('shader') shader = ofShader() temp_dir = mkdtemp() frag_file = os.path.join(temp_dir, 's.frag') vert_file = os.path.join(temp_dir, 's.vert') shader_file_of = os.path.join(temp_dir, 's') #a global variable color = ofColor(255) elapsedTime = 0.0 startColorIndex = 1 endColorIndex = 2 scaleFactor = 10 speedFactor = 0.6 content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True) content.add_parameter("color_speed", min=0.00, max=1.0, value=0.1)
from openframeworks import * from protopixel import Content from protopixel.core import (getContents, getWorkSpaceItems, getConfContent, setConfContent) size = 255 # color is the current color displayed, # color2 is the last color received color = ofColor(255, 255, 255) color2 = ofColor(255, 255, 255) content = Content('Custom OSC Script') content.FBO_SIZE = (size, size) def update(): """ As we receive these messages at a lower rate than the framerate, we use a running average to interpolate between values. """ pass def draw(): """ We use r,g,b to draw the three bars. """ pass
width = size height = size color = ofColor(255) elapsedTime = 0.0 elapsedTimeSquares = 0.0 startColorIndex = 1 endColorIndex = 2 scaleFactor = 10 squareScaleFactor = 2.0 rows = [ 0.0069, 0.055, 0.102, 0.151, 0.234926, 0.284, 0.331, 0.38, 0.479, 0.528, 0.575, 0.625, 0.707, 0.756, 0.803, 0.899, 0.948, 0.994] cols = [ 0.026, 0.107, 0.186, 0.268089, 0.35, 0.428, 0.508, 0.591, 0.67, 0.751, 0.831, 0.912, 0.99] content = Content("MinimalSquares") content.FBO_SIZE = (size,size) #optional: define size of FBO, default=(100,100) content.add_parameter("color1", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color2", type="color", value=ofColor(255, 255, 255)) content.add_parameter("color3", type="color", value=ofColor(255, 255, 255)) content.add_parameter("change_hue", value=True) content.add_parameter("color_speed", min=0.00, max=1.0, value=0.1) content.add_parameter("speed", min=0.0, max=1.0, value=0.1) content.add_parameter("num_squares", min=0, max=20, value=1) content.add_parameter("stage_mode", value=False) class Square: size = 570 height = 4
from protopixel import Content content = Content('Remote Web Interface') content.web_path('remote') # directory relative to this file