first processing sketches fsor visuals
parent
9f9e731a75
commit
d11aadd03b
|
@ -3,7 +3,7 @@ import netP5.*;
|
|||
|
||||
OscP5 oscP5;
|
||||
NetAddress myRemoteLocation;
|
||||
int x1,x2,fil;
|
||||
int x1,x2,m1, m2;
|
||||
void setup() {
|
||||
fullScreen();
|
||||
//size(400,400);
|
||||
|
@ -15,7 +15,9 @@ void setup() {
|
|||
//sc3p5
|
||||
oscP5.plug(this,"sc3p5","/sc3p5");
|
||||
oscP5.plug(this,"test","/test");
|
||||
oscP5.plug(this,"col","/col");
|
||||
oscP5.plug(this,"mother1","/mother1");
|
||||
oscP5.plug(this,"mother2","/mother2");
|
||||
|
||||
}
|
||||
|
||||
void sc3p5(int theA, int theB) {
|
||||
|
@ -25,12 +27,18 @@ void sc3p5(int theA, int theB) {
|
|||
x2= theB;
|
||||
}
|
||||
|
||||
void col(int theC) {
|
||||
fil= theC;
|
||||
void mother1(int theC) {
|
||||
m1= theC;
|
||||
}
|
||||
|
||||
void mother2(int theC) {
|
||||
m2= theC;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
ellipse(fil,10,10,10);
|
||||
rect(random(0,width),random(0,height),50+x1,50+x2);
|
||||
rect(m1,0 ,5,height);
|
||||
rect(0,m2,width, 5);
|
||||
|
||||
//rect(random(0,width),random(0,height),50+x1,50+x2);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
@ -1,13 +1,60 @@
|
|||
|
||||
import oscP5.*;
|
||||
import netP5.*;
|
||||
import http.requests.*;
|
||||
|
||||
|
||||
OscP5 oscP5;
|
||||
|
||||
float x; // global variable
|
||||
float y;
|
||||
float z;
|
||||
|
||||
float ry;
|
||||
int[] r = {3,5,8,13,21};
|
||||
|
||||
PShape chickenfoot;
|
||||
//String urosC02;
|
||||
|
||||
import http.requests.*;
|
||||
JSONObject json; // this is the full json object including the headers
|
||||
JSONArray totalData; // this is the array in the feeds part
|
||||
JSONObject record; // this is each one of the small json objects in the array
|
||||
int id; // this is just a counter provided by Thingspeak that increments with each new posted data point. It is an int
|
||||
String timeStamp; // this is the full time stamp provided by Thingspeak. It could be parsed to extract specific information for visualization
|
||||
int temp; // this is the data point that I uploaded from my arduino
|
||||
// (a TMP36 analog temperature sensor --> Arduino Uno --> Ethernet Shield --> Thingspeak) using a standard arduino upload program
|
||||
int co2;
|
||||
float humidity;
|
||||
|
||||
PFont liberation;
|
||||
|
||||
|
||||
|
||||
// https://api.thingspeak.com/channels/1724587/fields/3.json?results=1
|
||||
void setup() {
|
||||
size(400, 300);
|
||||
|
||||
// UROS DATA FROM THINGSPEAK
|
||||
json = loadJSONObject("https://api.thingspeak.com/channels/1724587/feeds.json");
|
||||
totalData = json.getJSONArray("feeds");
|
||||
for (int i = 0; i < totalData.size(); i++) { // step through the array, one record at a time
|
||||
record = totalData.getJSONObject(i); // remember the items in the array are also JSON objects
|
||||
id = record.getInt("entry_id"); // the key "entry_id" is given by Thingspeak. This is essentially a counter
|
||||
timeStamp = record.getString("created_at"); // the key "created_at" is also given by Thingspeak. I will write a parser to unpack it into a Date class soon.
|
||||
temp = int(record.getString("field1")); // Thingspeak stored this as a string so I have to convert it to an int for visualisation
|
||||
co2 = int(record.getString("field3")); // Thingspeak stored this as a string so I have to convert it to an int for visualisation
|
||||
humidity = int(record.getString("field4"));
|
||||
println(id + ", " + timeStamp + ", " + temp +", co2 level ppm: " + co2); // Just checking that it is all there.
|
||||
}
|
||||
|
||||
liberation = createFont("LiberationMono-Bold.ttf", 45);
|
||||
|
||||
chickenfoot = loadShape("chicken.obj");
|
||||
fullScreen(P3D);
|
||||
|
||||
//size(400, 300);
|
||||
frameRate(24);
|
||||
background(0);
|
||||
//background(0);
|
||||
smooth();
|
||||
|
||||
OscProperties properties = new OscProperties();
|
||||
|
@ -19,16 +66,82 @@ void oscEvent(OscMessage msg) {
|
|||
if (msg.checkAddrPattern("/sc3p5")) {
|
||||
x = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
if (msg.checkAddrPattern("/mother2")) {
|
||||
y = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
if (msg.checkAddrPattern("/rotation")) {
|
||||
z = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
}
|
||||
|
||||
void drawTarget(float xloc, float yloc, float size, float num) {
|
||||
float grayvalues = 255/num;
|
||||
float steps = size/num;
|
||||
ellipseMode(CENTER);
|
||||
for (int i = 0; i < num; i++) {
|
||||
fill(i*grayvalues);
|
||||
ellipse(xloc, yloc, size - i*steps, size - i*steps);
|
||||
}
|
||||
}
|
||||
//https://forum.processing.org/two/discussion/4448/downloading-data-from-thingspeak.html
|
||||
|
||||
void draw() {
|
||||
background(x, x, x);
|
||||
|
||||
if (y == 3){
|
||||
background(0);
|
||||
} else { background(255); }
|
||||
|
||||
// DISPLAY UROS DATA /////////////////
|
||||
|
||||
textSize(22);
|
||||
fill(0, 111);
|
||||
textFont(liberation);
|
||||
|
||||
text("Time: " + timeStamp, width*0.5, height/4);
|
||||
text("Temperature (Celsius): " + temp, width*0.5, height/5);
|
||||
text("CO2 PPM: " + co2, width*0.5, height/6);
|
||||
text("Humidity (%rel): " + humidity, width*0.5, height/7);
|
||||
|
||||
|
||||
/////////////////
|
||||
|
||||
lights();
|
||||
|
||||
println("rotation: ", z);
|
||||
//rectMode(CORNERS);
|
||||
drawTarget(width/6 , (height/8) *-y + random(0,10) +height*0.7 , random(60, 1200), (y%8)+2);
|
||||
//scale(7.5);
|
||||
//rotateX(PI*z/6);
|
||||
|
||||
//drawTarget(width/12 * x, height/2, 222, x);
|
||||
//drawTarget(width*0.75, y, 120, 6);
|
||||
//background(x, x, x);
|
||||
println("POST: ", x);
|
||||
// draw rect
|
||||
stroke(256-x/2, 256-x*abs(sin(x)), 256-x/4);
|
||||
strokeWeight(4);
|
||||
//stroke(256-x/2, 256-x*abs(sin(x)), 256-x/4);
|
||||
//sdtkeWeight(random(12));
|
||||
fill(256-x/2, 256-x, 256-x*abs(sin(x)));
|
||||
translate(width/2, height/2);
|
||||
rotate(x%64);
|
||||
rect(x%64, x%64, x*abs(sin(x))%128, x*abs(sin(x))%128, 6);
|
||||
//translate(width/2, height/2);
|
||||
//rotate(-x); //make recieve osc
|
||||
//rect(x%64, x%64, x*abs(sin(x))%128, x*abs(sin(x))%128, 6);
|
||||
//fill(random(255));
|
||||
rect(width/12 * x, 0, r[int(random(2))], height, 6);
|
||||
//translate(width/2, 0);
|
||||
if (y == 4){
|
||||
rotateX(PI*z/2);
|
||||
} else {
|
||||
rotateX(0);
|
||||
}
|
||||
|
||||
//rotateX(0.5);
|
||||
fill(255);
|
||||
rect(0, (height/8) *-y +height*0.7 , width, random(0, 22), 6);
|
||||
translate(width/2, height/2 + 100, -200);
|
||||
rotateZ(PI);
|
||||
rotateY(ry);
|
||||
scale(8);
|
||||
fill(255, 255,0);
|
||||
shape(chickenfoot);
|
||||
|
||||
ry += 0.03;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
@ -0,0 +1,206 @@
|
|||
import oscP5.*;
|
||||
import netP5.*;
|
||||
import http.requests.*;
|
||||
import peasy.*;
|
||||
|
||||
PeasyCam cam;
|
||||
OscP5 oscP5;
|
||||
|
||||
float x; // global variable
|
||||
float y;
|
||||
float z;
|
||||
|
||||
int col;
|
||||
float rot;
|
||||
|
||||
float rx;
|
||||
float ry;
|
||||
float rz;
|
||||
|
||||
int[] r = {3,5,8,13,21,34,55,89};
|
||||
|
||||
PShape chickenfoot;
|
||||
//String urosC02;
|
||||
|
||||
JSONObject json;
|
||||
JSONObject jsonchannel;
|
||||
|
||||
JSONArray totalData;
|
||||
JSONArray nameData;
|
||||
JSONArray chnameData;
|
||||
|
||||
JSONObject record;
|
||||
|
||||
int id;
|
||||
String name;
|
||||
|
||||
String timeStamp;
|
||||
int temp;
|
||||
int co2;
|
||||
float humidity;
|
||||
int s; // seconds counter
|
||||
|
||||
PFont liberation;
|
||||
PGraphics urosBuffer;
|
||||
boolean urosDisplayed;
|
||||
|
||||
void setup() {
|
||||
fullScreen(P3D);
|
||||
colorMode(HSB, 255);
|
||||
|
||||
//// CREATE GRAPHICS BUFFER FOR UROS DATA
|
||||
urosBuffer = createGraphics(600,300);
|
||||
chickenfoot = loadShape("chicken.obj");
|
||||
chickenfoot.setFill(color(200, 0, 0));
|
||||
|
||||
liberation = createFont("LiberationMono-Bold.ttf", 30);
|
||||
|
||||
frameRate(24);
|
||||
smooth();
|
||||
|
||||
// SET OSC LISTEN FROM SUPERCOLLIDER
|
||||
OscProperties properties = new OscProperties();
|
||||
properties.setListeningPort(47120); // osc receive port (from sc)
|
||||
oscP5 = new OscP5(this, properties);
|
||||
}
|
||||
|
||||
// SET OSC RECEIVE HANDLES (FROM SUPERCOLLIDER PATTERNS)
|
||||
void oscEvent(OscMessage msg) {
|
||||
println("message: " + msg);
|
||||
if (msg.checkAddrPattern("/mother1")) {
|
||||
x = msg.get(0).floatValue(); // receive floats from sc
|
||||
println("xxxx: " + x);
|
||||
}
|
||||
if (msg.checkAddrPattern("/mother2")) {
|
||||
y = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
if (msg.checkAddrPattern("/rotation1")) {
|
||||
z = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
}
|
||||
|
||||
// UROS DATA ////////////////////////////////////////
|
||||
void getUROS() {
|
||||
// UROS DATA FROM THINGSPEAK
|
||||
json = loadJSONObject("https://api.thingspeak.com/channels/1724587/feeds.json");
|
||||
jsonchannel = loadJSONObject("https://api.thingspeak.com/channels/1724587channel.json");
|
||||
|
||||
totalData = json.getJSONArray("feeds");
|
||||
for (int i = 0; i < totalData.size(); i++) {
|
||||
record = totalData.getJSONObject(i);
|
||||
id = record.getInt("entry_id");
|
||||
timeStamp = record.getString("created_at");
|
||||
temp = int(record.getString("field1"));
|
||||
co2 = int(record.getString("field3"));
|
||||
humidity = int(record.getString("field4")); }
|
||||
}
|
||||
|
||||
void urosDrawData() {
|
||||
//draw data direct to the buffer
|
||||
//urosBuffer.scale(2);
|
||||
urosBuffer.beginDraw();
|
||||
urosBuffer.clear();
|
||||
//size(222,111);
|
||||
urosBuffer.background(0,0,0, 0.5);
|
||||
urosBuffer.noFill();
|
||||
//urosBuffer.fill(111);
|
||||
//urosBuffer.rect(0,0, width/5, height/5);
|
||||
urosBuffer.fill(0);
|
||||
urosBuffer.textFont(liberation);
|
||||
urosBuffer.text("Location: " + name, 30, 50);
|
||||
urosBuffer.text("Time: " + timeStamp, 30, 100);
|
||||
urosBuffer.text("Temperature (Celsius): " + temp, 30, 150);
|
||||
urosBuffer.text("CO2 PPM: " + co2, 30, 200);
|
||||
urosBuffer.text("Humidity (%rel): " + humidity, 30, 250);
|
||||
urosBuffer.endDraw();
|
||||
}
|
||||
|
||||
void drawTarget(float xloc, float yloc, float size, float num) {
|
||||
float grayvalues = 255/num;
|
||||
float steps = size/num;
|
||||
ellipseMode(CENTER);
|
||||
for (int i = 0; i < num; i++) {
|
||||
fill(i*grayvalues);
|
||||
ellipse(xloc, yloc, size - i*steps, size - i*steps);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void draw() {
|
||||
|
||||
if (y >= 5 ){
|
||||
background(255, 0, 0);
|
||||
stroke(0);
|
||||
//background(123,44,234);
|
||||
//background(0);
|
||||
} else {
|
||||
background(0);
|
||||
stroke(255); }
|
||||
|
||||
// UROS
|
||||
int s = second();
|
||||
s = s - 60; // countdown timer
|
||||
if (s==-1) { // every minute
|
||||
thread("getUROS"); // threaded pull of UROS data from thingspeak
|
||||
}
|
||||
|
||||
// scale(3);
|
||||
//urosDrawData(); // draw the data into a imagebuffer
|
||||
//if(urosDisplayed) { // use boolean to draw or not
|
||||
//image(urosBuffer,0,0); // display the imageBuffer
|
||||
// }
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
//lights();
|
||||
|
||||
|
||||
strokeWeight(2);
|
||||
fill(255);
|
||||
pushMatrix();
|
||||
//translate(width/2, 0);
|
||||
//rotateX(radians(22));
|
||||
rect(width/12 * x, 0, r[int(random(8))], height, 6); // MOTHER 1 VERTICAL
|
||||
popMatrix();
|
||||
|
||||
// if (y == 4){
|
||||
//rotateX(PI*z/2);
|
||||
// } else {
|
||||
// rotateX(0);
|
||||
//}
|
||||
|
||||
// VERTICAL SCALE DEGREE TRACKER
|
||||
|
||||
fill(255);
|
||||
pushMatrix();
|
||||
//rotateY(radians(45));
|
||||
strokeWeight(2);
|
||||
rect(0, (height/8) *-y +height*0.7 , width, r[int(random(8))], 6);
|
||||
popMatrix();
|
||||
|
||||
// SPHERE //////////////////////////
|
||||
|
||||
pushMatrix();
|
||||
translate(width *0.5, height * 0.5, 0);
|
||||
rotateX(radians( ry ));
|
||||
rotateY(radians( ry ));
|
||||
rotateZ(radians( ry ));
|
||||
strokeWeight(col % 2000 / 10);
|
||||
noFill();
|
||||
stroke(col%255, 100, 200);
|
||||
sphereDetail(5);
|
||||
sphere((col%1000 /10) * 150);
|
||||
popMatrix();
|
||||
|
||||
// COUNTERS
|
||||
|
||||
ry += 0.06;
|
||||
rx += 0.025;
|
||||
rz += 0.5;
|
||||
col += 4;
|
||||
rot += 0.5;
|
||||
|
||||
}
|
||||
// END //////////////////////////
|
||||
////////////////////////////////////////////////////
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
@ -0,0 +1,198 @@
|
|||
|
||||
import oscP5.*;
|
||||
import netP5.*;
|
||||
import http.requests.*;
|
||||
import peasy.*;
|
||||
|
||||
PeasyCam cam;
|
||||
OscP5 oscP5;
|
||||
|
||||
float x; // global variable
|
||||
float y;
|
||||
float z;
|
||||
|
||||
float rx;
|
||||
float ry;
|
||||
float rz;
|
||||
|
||||
int[] r = {3,5,8,13,21};
|
||||
|
||||
PShape chickenfoot;
|
||||
//String urosC02;
|
||||
|
||||
JSONObject json;
|
||||
JSONObject jsonchannel;
|
||||
|
||||
JSONArray totalData;
|
||||
JSONArray nameData;
|
||||
JSONArray chnameData;
|
||||
|
||||
JSONObject record;
|
||||
|
||||
int id;
|
||||
String name;
|
||||
|
||||
String timeStamp;
|
||||
int temp;
|
||||
int co2;
|
||||
float humidity;
|
||||
int s; // seconds counter
|
||||
|
||||
PFont liberation;
|
||||
PGraphics urosBuffer;
|
||||
boolean urosDisplayed;
|
||||
|
||||
void setup() {
|
||||
fullScreen(P3D);
|
||||
//cam = new PeasyCam(this, 100);
|
||||
//cam.setMinimumDistance(50);
|
||||
//cam.setMaximumDistance(500);
|
||||
|
||||
//// CREATE GRAPHICS BUFFER FOR UROS DATA
|
||||
urosBuffer = createGraphics(600,300);
|
||||
chickenfoot = loadShape("chicken.obj");
|
||||
chickenfoot.setFill(color(200, 0, 0));
|
||||
liberation = createFont("LiberationMono-Bold.ttf", 30);
|
||||
|
||||
frameRate(24);
|
||||
smooth();
|
||||
|
||||
// SET OSC LISTEN FROM SUPERCOLLIDER
|
||||
OscProperties properties = new OscProperties();
|
||||
properties.setListeningPort(47120); // osc receive port (from sc)
|
||||
oscP5 = new OscP5(this, properties);
|
||||
}
|
||||
|
||||
// SET OSC RECEIVE HANDLES (FROM SUPERCOLLIDER PATTERNS)
|
||||
void oscEvent(OscMessage msg) {
|
||||
if (msg.checkAddrPattern("/sc3p5")) {
|
||||
x = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
if (msg.checkAddrPattern("/mother2")) {
|
||||
y = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
if (msg.checkAddrPattern("/rotation")) {
|
||||
z = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
}
|
||||
|
||||
// UROS DATA ////////////////////////////////////////
|
||||
|
||||
void getUROS() {
|
||||
// UROS DATA FROM THINGSPEAK
|
||||
json = loadJSONObject("https://api.thingspeak.com/channels/1724587/feeds.json");
|
||||
jsonchannel = loadJSONObject("https://api.thingspeak.com/channels/1724587channel.json");
|
||||
|
||||
totalData = json.getJSONArray("feeds");
|
||||
for (int i = 0; i < totalData.size(); i++) {
|
||||
record = totalData.getJSONObject(i);
|
||||
id = record.getInt("entry_id");
|
||||
timeStamp = record.getString("created_at");
|
||||
temp = int(record.getString("field1"));
|
||||
co2 = int(record.getString("field3"));
|
||||
humidity = int(record.getString("field4")); }
|
||||
}
|
||||
|
||||
void urosDrawData() {
|
||||
//draw data direct to the buffer
|
||||
//urosBuffer.scale(2);
|
||||
|
||||
urosBuffer.beginDraw();
|
||||
urosBuffer.clear();
|
||||
//size(222,111);
|
||||
urosBuffer.background(0,0,0, 0.5);
|
||||
urosBuffer.noFill();
|
||||
//urosBuffer.fill(111);
|
||||
//urosBuffer.rect(0,0, width/5, height/5);
|
||||
urosBuffer.fill(0);
|
||||
urosBuffer.textFont(liberation);
|
||||
urosBuffer.text("Location: " + name, 30, 50);
|
||||
urosBuffer.text("Time: " + timeStamp, 30, 100);
|
||||
urosBuffer.text("Temperature (Celsius): " + temp, 30, 150);
|
||||
urosBuffer.text("CO2 PPM: " + co2, 30, 200);
|
||||
urosBuffer.text("Humidity (%rel): " + humidity, 30, 250);
|
||||
urosBuffer.endDraw();
|
||||
}
|
||||
|
||||
void drawTarget(float xloc, float yloc, float size, float num) {
|
||||
float grayvalues = 255/num;
|
||||
float steps = size/num;
|
||||
ellipseMode(CENTER);
|
||||
for (int i = 0; i < num; i++) {
|
||||
fill(i*grayvalues);
|
||||
ellipse(xloc, yloc, size - i*steps, size - i*steps);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void draw() {
|
||||
|
||||
if (y == 3){
|
||||
background(0);
|
||||
} else {
|
||||
background(255);
|
||||
}
|
||||
|
||||
// UROS
|
||||
int s = second();
|
||||
s = s - 60; // countdown timer
|
||||
if (s==-1) { // every minute
|
||||
thread("getUROS"); // threaded pull of UROS data from thingspeak
|
||||
}
|
||||
|
||||
// scale(3);
|
||||
urosDrawData(); // draw the data into a imagebuffer
|
||||
//if(urosDisplayed) { // use boolean to draw or not
|
||||
image(urosBuffer,0,0); // display the imageBuffer
|
||||
// }
|
||||
//////////////////////////////////////
|
||||
//scale(-3);
|
||||
|
||||
lights();
|
||||
|
||||
//println("rotation: ", z);
|
||||
//rectMode(CORNERS);
|
||||
//drawTarget(width/6 , (height/8) *-y + random(0,10) +height*0.7 , random(60, 1200), (y%8)+2);
|
||||
//scale(7.5);
|
||||
//rotateX(PI*z/6);
|
||||
|
||||
//drawTarget(width/12 * x, height/2, 222, x);
|
||||
//drawTarget(width*0.75, y, 120, 6);
|
||||
//background(x, x, x);
|
||||
//println("POST: ", x);
|
||||
// draw rect
|
||||
//stroke(256-x/2, 256-x*abs(sin(x)), 256-x/4);
|
||||
//sdtkeWeight(random(12));
|
||||
fill(256-x/2, 256-x, 256-x*abs(sin(x)));
|
||||
//translate(width/2, height/2);
|
||||
//rotate(-x); //make recieve osc
|
||||
//rect(x%64, x%64, x*abs(sin(x))%128, x*abs(sin(x))%128, 6);
|
||||
//fill(random(255));
|
||||
//rect(width/12 * x, 0, r[int(random(2))], height, 6);
|
||||
//translate(width/2, 0);
|
||||
|
||||
if (y == 4){
|
||||
rotateX(PI*z/2);
|
||||
} else {
|
||||
rotateX(0);
|
||||
}
|
||||
|
||||
//rotateX(0.5);
|
||||
fill(255);
|
||||
//rect(0, (height/8) *-y +height*0.7 , width, random(0, 22), 6);
|
||||
translate(width/2, height/2 + 100, -200);
|
||||
rotateX(radians(rz));
|
||||
rotateY(ry);
|
||||
//rotateZ(rz);
|
||||
|
||||
scale(8);
|
||||
fill(255, 255,0);
|
||||
shape(chickenfoot);
|
||||
|
||||
ry += 0.02;
|
||||
rx += 0.025;
|
||||
rz += 0.15;
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
@ -0,0 +1,219 @@
|
|||
import oscP5.*;
|
||||
import netP5.*;
|
||||
import http.requests.*;
|
||||
import peasy.*;
|
||||
|
||||
PeasyCam cam;
|
||||
OscP5 oscP5;
|
||||
|
||||
float x; // global variable
|
||||
float y;
|
||||
float z;
|
||||
|
||||
int col;
|
||||
|
||||
float rx;
|
||||
float ry;
|
||||
float rz;
|
||||
|
||||
int[] r = {3,5,8,13,21,34,55,89};
|
||||
|
||||
PShape chickenfoot;
|
||||
//String urosC02;
|
||||
|
||||
JSONObject json;
|
||||
JSONObject jsonchannel;
|
||||
|
||||
JSONArray totalData;
|
||||
JSONArray nameData;
|
||||
JSONArray chnameData;
|
||||
|
||||
JSONObject record;
|
||||
|
||||
int id;
|
||||
String name;
|
||||
|
||||
String timeStamp;
|
||||
int temp;
|
||||
int co2;
|
||||
float humidity;
|
||||
int s; // seconds counter
|
||||
|
||||
PFont liberation;
|
||||
PGraphics urosBuffer;
|
||||
boolean urosDisplayed;
|
||||
|
||||
void setup() {
|
||||
fullScreen(P3D);
|
||||
colorMode(HSB, 255);
|
||||
|
||||
//cam = new PeasyCam(this, 100);
|
||||
//cam.setMinimumDistance(50);
|
||||
//cam.setMaximumDistance(500);
|
||||
|
||||
//// CREATE GRAPHICS BUFFER FOR UROS DATA
|
||||
urosBuffer = createGraphics(600,300);
|
||||
chickenfoot = loadShape("chicken.obj");
|
||||
chickenfoot.setFill(color(200, 0, 0));
|
||||
|
||||
liberation = createFont("LiberationMono-Bold.ttf", 30);
|
||||
|
||||
frameRate(24);
|
||||
smooth();
|
||||
|
||||
// SET OSC LISTEN FROM SUPERCOLLIDER
|
||||
OscProperties properties = new OscProperties();
|
||||
properties.setListeningPort(47120); // osc receive port (from sc)
|
||||
oscP5 = new OscP5(this, properties);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// SET OSC RECEIVE HANDLES (FROM SUPERCOLLIDER PATTERNS)
|
||||
void oscEvent(OscMessage msg) {
|
||||
if (msg.checkAddrPattern("/sc3p5")) {
|
||||
x = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
if (msg.checkAddrPattern("/mother2")) {
|
||||
y = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
if (msg.checkAddrPattern("/rotation")) {
|
||||
z = msg.get(0).floatValue(); // receive floats from sc
|
||||
}
|
||||
}
|
||||
|
||||
// UROS DATA ////////////////////////////////////////
|
||||
void getUROS() {
|
||||
// UROS DATA FROM THINGSPEAK
|
||||
json = loadJSONObject("https://api.thingspeak.com/channels/1724587/feeds.json");
|
||||
jsonchannel = loadJSONObject("https://api.thingspeak.com/channels/1724587channel.json");
|
||||
|
||||
totalData = json.getJSONArray("feeds");
|
||||
for (int i = 0; i < totalData.size(); i++) {
|
||||
record = totalData.getJSONObject(i);
|
||||
id = record.getInt("entry_id");
|
||||
timeStamp = record.getString("created_at");
|
||||
temp = int(record.getString("field1"));
|
||||
co2 = int(record.getString("field3"));
|
||||
humidity = int(record.getString("field4")); }
|
||||
}
|
||||
|
||||
void urosDrawData() {
|
||||
//draw data direct to the buffer
|
||||
//urosBuffer.scale(2);
|
||||
urosBuffer.beginDraw();
|
||||
urosBuffer.clear();
|
||||
//size(222,111);
|
||||
urosBuffer.background(0,0,0, 0.5);
|
||||
urosBuffer.noFill();
|
||||
//urosBuffer.fill(111);
|
||||
//urosBuffer.rect(0,0, width/5, height/5);
|
||||
urosBuffer.fill(0);
|
||||
urosBuffer.textFont(liberation);
|
||||
urosBuffer.text("Location: " + name, 30, 50);
|
||||
urosBuffer.text("Time: " + timeStamp, 30, 100);
|
||||
urosBuffer.text("Temperature (Celsius): " + temp, 30, 150);
|
||||
urosBuffer.text("CO2 PPM: " + co2, 30, 200);
|
||||
urosBuffer.text("Humidity (%rel): " + humidity, 30, 250);
|
||||
urosBuffer.endDraw();
|
||||
}
|
||||
|
||||
void drawTarget(float xloc, float yloc, float size, float num) {
|
||||
float grayvalues = 255/num;
|
||||
float steps = size/num;
|
||||
ellipseMode(CENTER);
|
||||
for (int i = 0; i < num; i++) {
|
||||
fill(i*grayvalues);
|
||||
ellipse(xloc, yloc, size - i*steps, size - i*steps);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void draw() {
|
||||
|
||||
if (y == 3){
|
||||
background(123,44,234);
|
||||
//background(0);
|
||||
} else {
|
||||
background(255);
|
||||
}
|
||||
|
||||
// UROS
|
||||
int s = second();
|
||||
s = s - 60; // countdown timer
|
||||
if (s==-1) { // every minute
|
||||
thread("getUROS"); // threaded pull of UROS data from thingspeak
|
||||
}
|
||||
|
||||
// scale(3);
|
||||
//urosDrawData(); // draw the data into a imagebuffer
|
||||
//if(urosDisplayed) { // use boolean to draw or not
|
||||
//image(urosBuffer,0,0); // display the imageBuffer
|
||||
// }
|
||||
//////////////////////////////////////
|
||||
|
||||
|
||||
lights();
|
||||
|
||||
//println("rotation: ", z);
|
||||
//rectMode(CORNERS);
|
||||
//drawTarget(width/6 , (height/8) *-y + random(0,10) +height*0.7 , 300, (y%8)+2);
|
||||
//scale(7.5);
|
||||
//rotateX(PI*z/6);
|
||||
|
||||
//drawTarget(width/12 * x, height/2, 222, x);
|
||||
//drawTarget(width*0.75, y, 120, 6);
|
||||
//background(x, x, x);
|
||||
//println("POST: ", x);
|
||||
// draw rect
|
||||
//stroke(256-x/2, 256-x*abs(sin(x)), 256-x/4);
|
||||
//sdtkeWeight(random(12));
|
||||
fill(256-x/2, 256-x, 256-x*abs(sin(x)));
|
||||
//translate(width/2, height/2);
|
||||
//rotate(-x); //make recieve osc
|
||||
//rect(x%64, x%64, x*abs(sin(x))%128, x*abs(sin(x))%128, 6);
|
||||
//fill(random(255));
|
||||
pushMatrix();
|
||||
rotateX(radians(22));
|
||||
rect(width/12 * x, 0, r[int(random(8))], height, 6);
|
||||
//translate(width/2, 0);
|
||||
popMatrix();
|
||||
|
||||
// if (y == 4){
|
||||
//rotateX(PI*z/2);
|
||||
// } else {
|
||||
// rotateX(0);
|
||||
//}
|
||||
|
||||
//rotateX(0.5);
|
||||
fill(255);
|
||||
pushMatrix();
|
||||
rotateY(radians(45));
|
||||
|
||||
rect(0, (height/8) *-y +height*0.7 , width, random(0, 322), 6);
|
||||
popMatrix();
|
||||
|
||||
translate(width/2, height/2 + 100, -200);
|
||||
|
||||
//rotateX(radians(rz));
|
||||
//rotateY(ry);
|
||||
//rotateZ(rz);
|
||||
//scale(6);
|
||||
//fill(255, 255,0);
|
||||
//chickenfoot.setFill(color(col%256));
|
||||
|
||||
//shape(chickenfoot);
|
||||
pushMatrix();
|
||||
translate(ry, 0, 0);
|
||||
rotateY(y);
|
||||
noFill();
|
||||
box(160);
|
||||
popMatrix();
|
||||
|
||||
ry += 0.02;
|
||||
rx += 0.025;
|
||||
rz += 0.015;
|
||||
col += 1;
|
||||
|
||||
}
|
Loading…
Reference in New Issue