gtr/visuals/sphere_degree_beats/sphere_degree_beats.pde

207 lines
4.7 KiB
Plaintext

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 //////////////////////////
////////////////////////////////////////////////////