Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import processing.serial.*;
Serial myPort;
import codeanticode.syphon.*;
SyphonServer server;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
PImage YEL;
PImage BLUE;
float x;
float y;
float alpha;
ArrayList<PImage> yImg;
ArrayList<PImage> bImg;
float yPosition[][];
float bPosition[][];
int count1;
int count2;
boolean bState = false;
boolean yState = false;
boolean soundState = false;
void setup()
{
size(500, 800, P3D);
smooth();
minim = new Minim(this);
player = minim.loadFile("Frank_Sinatra-LOVE(mp3vip.eu).mp3", 2048);
yImg = new ArrayList<PImage>();
YEL = loadImage("yellow.png");
bImg = new ArrayList<PImage>();
BLUE = loadImage("blue.png");
yPosition = new float[20000][2];
bPosition = new float[20000][2];
println(Serial.list());
myPort = new Serial(this, Serial.list()[5], 9600);
myPort.bufferUntil('\n');
server = new SyphonServer(this, "Processing Syphon");
}
void draw()
{
background(0);
for (int n = 0; n < yImg.size (); n+=6)
{
image(yImg.get(n), yPosition[n][0], yPosition[n][1]);
yPosition[n][1] -= 3;
if (yPosition[n][0] > width /2)
{
//yPosition[n][0] -= .5;
}
if (yPosition[n][0] < width /2)
{
//yPosition[n][0] += .5;
}
}
for (int n = 0; n < bImg.size (); n+=6)
{
image(bImg.get(n), bPosition[n][0], bPosition[n][1]);
bPosition[n][1] -= 3;
if (bPosition[n][0] > width /2)
{
//bPosition[n][0] -= .5;
}
if (bPosition[n][0] < width /2)
{
//bPosition[n][0] += .5;
}
}
if (yState)
{
x = random(0, width);
y = height;
yImg.add(count1, YEL);
yPosition[count1][0] = x;
yPosition[count1][1] = y;
count1++;
}
if (bState)
{
x = random(0, width);
y = height;
bImg.add(count2, BLUE);
bPosition[count2][0] = x;
bPosition[count2][1] = y;
count2++;
}
server.sendScreen();
}
void serialEvent(Serial myPort)
{
String inString = myPort.readStringUntil('\n');
if (inString != null)
{
inString = trim(inString);
int inByte = int(inString);
println(inByte);
if ((inByte == 11) || (inByte == 111))
{
bState = true;
//println("wow");
soundState = true;
if (soundState)
{
player.play();
soundState = false;
}
} else if ((inByte == 22) || (inByte == 222))
{
yState = true;
//println("lol");
soundState = true;
if (soundState)
{
player.play();
soundState = false;
}
}
}
}
void keyPressed()
{
if (key == 'b')
{
bState = true;
}
if (key == 'y')
{
yState = true;
}
if (key == 'r')
{
//rState = true;
}
if (key == 'p')
{
player.play();
}
if (key =='s')
{
stop();
}
}
void play()
{
}
void stop()
{
player.close();
minim.stop();
super.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.