Created
May 2, 2019 00:09
-
-
Save fernando-gzz-mtz/021ac5852d05d974145140f1944d458a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://processing.org/examples/easing.html | |
import processing.serial.*; | |
import oscP5.*; | |
import netP5.*; | |
// OSC PARAMETERS & PORTS | |
int recvPort = 5555; | |
OscP5 oscP5; | |
//float[] xys = {250, 250, 250, 250}; | |
//float[] eegStream = {0, 0, 0, 0}; | |
float accelX, accelY; | |
int colorChecker, jawClench; | |
int red = 0, blue = 0, green = 0; | |
float mx, my; | |
float easing = 0.05; | |
int radius = 24; | |
int edge = 0; | |
int inner = edge + radius; | |
float rngColor = 255; | |
void setup() { | |
size(1360, 700); | |
frameRate(60); | |
noStroke(); | |
/* start oscP5, listening for incoming messages at recvPort */ | |
oscP5 = new OscP5(this, recvPort); | |
ellipseMode(RADIUS); | |
rectMode(CORNERS); | |
background(255); | |
fill(255); | |
rect(edge, edge, width, height); | |
} | |
void draw() { | |
//background(0); | |
if (abs(accelX - mx) > 0.1) { | |
mx = mx + (accelX + 550 - mx) * easing; | |
} | |
if (abs(accelY - my) > 0.1) { | |
my = my + (accelY + 400 - my) * easing; | |
} | |
mx = constrain(mx, inner, width - inner); | |
my = constrain(my, inner, height - inner); | |
//fill(0); | |
//rect(edge, edge, width, height); | |
fill(red, blue, green); | |
ellipse(mx, my, radius, radius); | |
} | |
//Works for Accelerometer data | |
//Uncomment for acc data | |
void oscEvent(OscMessage msg) { | |
//System.out.println("### got a message " + msg); | |
if (msg.checkAddrPattern("/muse/acc")==true) { | |
//for(int i = 0; i < 4; i++) { | |
//System.out.print("EEG on channel " + i + ": " + msg.get(i).floatValue() + "\n"); | |
accelY = msg.get(0).floatValue()*0.8; | |
accelX = msg.get(2).floatValue(); | |
//} | |
} | |
if (msg.checkAddrPattern("/muse/elements/blink")==true) { | |
colorChecker = msg.get(0).intValue(); | |
//System.out.print(msg.get(0)); | |
if (colorChecker == 1){ | |
red = round(random(0,255)); | |
blue = round(random(0,255)); | |
green = round(random(0,255)); | |
} | |
} | |
//if (msg.checkAddrPattern("/muse/elements/jaw_clench")==true) { | |
// jawClench = msg.get(0).intValue(); | |
// if (jawClench == 1){ | |
// fill(red,green,blue); | |
// ellipse(mx,my,50,50); | |
// } | |
//} | |
} | |
void keyPressed() | |
{ | |
// If the key is between 'A'(65) to 'Z' and 'a' to 'z'(122) | |
if((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z')) { | |
if(key == 'R' || key == 'r') { | |
background(255); | |
fill(255); | |
rect(edge, edge, width, height); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment