Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0ba4b09
Clean up basic particle converge test
botmayank Jan 2, 2020
1390fac
Initialize movers with parameters for PM2.5 and PM10 particles
botmayank Jan 2, 2020
a256cae
Add basic AQI get request test
botmayank Jan 2, 2020
a710019
Get AQI data for a specific station
botmayank Jan 2, 2020
96af5a2
Refactor getAqi to return JSONObject
botmayank Jan 2, 2020
a7f6c4e
Add print method for aqi details
botmayank Jan 2, 2020
7a474ed
Add basic shader example with clouds
botmayank Jan 2, 2020
dbaf678
Slowly increasing fog
botmayank Jan 4, 2020
1d13879
Reorganize pollution sketches
botmayank Jan 4, 2020
3d0ef85
Rename final folders for dance to pollution
botmayank Jan 4, 2020
4ff4b81
Initialize movers with params
botmayank Jan 4, 2020
c1cb018
Add mouse mode to dance_aqi
botmayank Jan 4, 2020
4442b12
Add aqi methods
botmayank Jan 4, 2020
f291748
Change from array to ArrayList for Movers
botmayank Jan 4, 2020
bb41d0d
Add different particles initialized based on AQI
botmayank Jan 4, 2020
86cf9b4
Make pm25 particles stick to human in kinect mode
botmayank Jan 4, 2020
f8a7974
Pick up particle color based on AQI category
botmayank Jan 4, 2020
5e27234
Calculate num of gases based on AQI data
botmayank Jan 4, 2020
8e8da0d
Set min particles to skeletonbody points
botmayank Jan 25, 2020
cb721e7
Add city_list dict for text display
botmayank Jan 30, 2020
1c59361
Display city in bottom right
botmayank Jan 30, 2020
2c30869
Decouple body rendering from particles
botmayank Jan 30, 2020
d6618c0
Initialize pm10 and pm2.5 with aqi based radii
botmayank Jan 30, 2020
535f563
Add full HSB color lookup based on AQI
botmayank Jan 30, 2020
ec72866
Prevent particles from clustering when body exits
botmayank Jan 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions 1_pollution/0_basics/aqiget/aqiget.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Basic AQI JSON from waqi.info getting test based on jsonget example in http-requests library
https://github.com/acdean/HTTP-Requests-for-Processing
By: Mayank Joneja
Date: 02-01-2019
*/

import http.requests.*;

String AQI_TOKEN = "ENTER-TOKEN-HERE"; // Token generated from waqi.info
int POLLING_INTERVAL = 2; // Don't go faster than once per second preferably

//String city = "delhi"; //city name or @station-id
String city = "@2556"; //R.K. Puram

/*
To search for station-id, change the keyword field in:
https://api.waqi.info//search/?token=ENTER_TOKEN_HERE&keyword=rk puram
Take the "uid" parameter.
*/

public void setup()
{
size(400,400);
smooth();
println("Aqidata for " + city + " polled every " + POLLING_INTERVAL + " seconds:");
}

void draw() {
println("AQI value: " + getAqiVal(city));
printParticleVals(city);
delay(POLLING_INTERVAL * 1000); // milliseconds
}

JSONObject getAqiData(String city) {
String AQI_URL = "https://api.waqi.info/feed/" + city + "/?token=" + AQI_TOKEN;
GetRequest get = new GetRequest(AQI_URL);
get.send(); // program will wait untill the request is completed

JSONObject response = parseJSONObject(get.getContent());

String status = response.getString("status");
if(!status.equals("ok")) {
println("GET request to " + AQI_URL + " failed! Status: " + status);
println(response.getString("data"));
return null;
}

//println("response: " + get.getContent());

// Parsing of response
JSONObject aqidata = response.getJSONObject("data");
return aqidata;
}

int getAqiVal(String city) {
JSONObject aqidata = getAqiData(city);
if(aqidata != null){
return aqidata.getInt("aqi");
} else {
return -1;
}
}

void printParticleVals(String city) {
JSONObject aqidata = getAqiData(city);
if(aqidata != null){
JSONObject iaqi = aqidata.getJSONObject("iaqi");

String particles[] = {"pm25", "pm10", "co", "o3"};

println("===========AQI Details========");
for (String p : particles) {
float val = iaqi.getJSONObject(p).getFloat("v");
println(p + " value: " + val);
}
println("==============================");
}
}
150 changes: 111 additions & 39 deletions 1_pollution/0_basics/converge_2/converge_2.pde
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
private static boolean mode_kinect = true;
/*
Basic test for moving pollution particles based on processing's PVector tutorial: https://processing.org/tutorials/pvector/
Date: 02-01-2020
By: Mayank Joneja - [email protected]
*/


// Config
private static boolean mode_kinect = false; // true: Control with Kinect, false: Control with mouse

// Random movement mode (only used when mode_kinect = false)
//0: No randomness, exactly follows mouse
//1: Follows mouse with some randomness
//2: Disregards mouse, totally random target positions

static int random_mouse_mode = 2;

// types of particles
int NO_2_5_PARTICLES = 40, NO_10_PARTICLES = 10;
Mover[] pm2_5_particles = new Mover[NO_2_5_PARTICLES];
Mover[] pm10_particles = new Mover[NO_10_PARTICLES];

Mover[] movers = new Mover[20];

Expand All @@ -11,66 +31,120 @@ ArrayList <SkeletonData> bodies;
void setup(){
size(1440, 800, P3D);
background(0);
smooth();
smooth();
println("Running pollution particle test...");

float inertia, speed;
// Create new generic movers
for(int i = 0; i < movers.length; i++){
int gray = int(random(255));
movers[i] = new Mover();
//movers[i].col = color(gray, gray, gray);
//movers[i].orig_col = movers[i].col;
color col = color(random(50,255), random(10,90), 127);
float r = random(30.0, 90.0);
inertia = 15.0;
speed = 20.0;
movers[i] = new Mover(col, r, speed, inertia);
}

// PM 2.5 particles
float r_2_5 = 25.0;
inertia = 10.0; // 10.0 makes particles overshoot target a lot
speed = 20.0;
for(int i = 0; i < pm2_5_particles.length; i++){
color col = color(175, 71, 30);
pm2_5_particles[i] = new Mover(col, r_2_5, speed, inertia);
}

// PM 10 particles
float r_10 = 100.0;
inertia = 60.0;
speed = 10.0;
for(int i = 0; i < pm10_particles.length; i++){
color col = color(127, 173, 51);
pm10_particles[i] = new Mover(col, r_10, speed, inertia);
}

// Other initializations
if(mode_kinect) {
kinect = new Kinect(this);
bodies = new ArrayList<SkeletonData> ();
println("======Kinect mode====");
println("Move around in front of kinect to make particles follow!");
println("=====================");
} else {
println("======Mouse mode====");
println("Move around mouse to make particles follow!");
println("=====================");
}
kinect = new Kinect(this);
bodies = new ArrayList<SkeletonData> ();

println("Converging PSEQ2");

}

void draw(){
noStroke();
fill(0,20);
rect(0, 0, width, height);

//Kinect mode
if(mode_kinect){
//SkeletonData body;
//if body detected
if (bodies.size() != 0){
//Body detected
if (bodies.size() != 0){
int bodyIndex = bodies.size() - 1;
//for(SkeletonData body : bodies){
SkeletonData body = bodies.get(bodyIndex);
//PVector body_pos = body.position;
//println("Body x, y:");
//println(body.position.x);
//println(body.position.y);
updatePositionKinect(body);
//}
}
else{
}
// body not detected, buzz around
else{
int delta = 60;
for(int i = 0; i < movers.length; i++){
//movers[i].update(mouse_pos);
movers[i].checkEdges();
movers[i].display();
movers[i].topspeed = 0.5;
PVector goal = new PVector(random(movers[i].location.x-delta, movers[i].location.x+delta), random(movers[i].location.y-delta, movers[i].location.y+delta));
movers[i].update(goal);
}
//noStroke();
//noFill();
//background(0);
}
}
else{ // if mouse and not kinect
PVector mouse_pos = new PVector(mouseX,mouseY);
for(int i = 0; i < movers.length; i++){
movers[i].update(mouse_pos);
movers[i].checkEdges();
movers[i].display();
}
} // for loop
} // else
} // mode_kinect

// Mouse mode
else{
int target_x = 0, target_y = 0;
if(random_mouse_mode == 0){
// Follow mouse exactly
target_x = mouseX;
target_y = mouseY;
} else if(random_mouse_mode == 1) {
// Follow mouse with some randomness
target_x = mouseX + int(random(width/4));
target_y = mouseY + int(random(height/4));
} else {
// Totally random target position
target_x = int(random(width));
target_y = int(random(height));
}

PVector mouse_pos = new PVector(target_x, target_y);

// Normal Movers
//for(int i = 0; i < movers.length; i++){
// movers[i].update(mouse_pos);
// movers[i].checkEdges();
// movers[i].display();
//}

// PM 2.5 particles
for(int i = 0; i < pm2_5_particles.length; i++){
pm2_5_particles[i].update(mouse_pos);
pm2_5_particles[i].checkEdges();
pm2_5_particles[i].display();
}

// PM 10 particles
for(int i = 0; i < pm10_particles.length; i++){
pm10_particles[i].update(mouse_pos);
pm10_particles[i].checkEdges();
pm10_particles[i].display();
}
}
}

//Kinect events

void appearEvent(SkeletonData _s)
{
if (_s.trackingState == Kinect.NUI_SKELETON_NOT_TRACKED)
Expand Down Expand Up @@ -119,8 +193,6 @@ void moveEvent(SkeletonData _b, SkeletonData _a)
}

void updatePositionKinect(SkeletonData body){
//PVector body_pos = new PVector(body.position.x*width, body.position.y*height);
//PVector[] body_part_pos = body.skeletonPositions;
for(int i = 0; i < movers.length; i++){
PVector pos = new PVector(body.skeletonPositions[i%body.skeletonPositions.length].x*width, body.skeletonPositions[i%body.skeletonPositions.length].y*height);
fill(0,0,127);
Expand Down
30 changes: 10 additions & 20 deletions 1_pollution/0_basics/converge_2/mover.pde
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ class Mover {
float r; //Radius
boolean move;
int col_count = 1;
float overshoot_dist; //60.0 makes them stop too soon, 10.0 makes them overshoot

Mover(){
//location = new PVector(width/2, height/2);
Mover(color c, float radius, float max_speed, float inertia){
location = new PVector(random(width), random(height));
//velocity = new PVector(random(-2,2), random(-2,2));
velocity = new PVector(0, 0);
topspeed = 10;
col = color(random(50,255), random(10,90), 0);
r = random(30.0, 90.0);
//acceleration = new PVector(-0.001,0.01);
velocity = new PVector(random(-2,2), random(-2,2));
topspeed = max_speed;
col = c;
r = radius;
overshoot_dist = inertia;
}

void update(PVector destination){
//PVector mouse = new PVector(mouseX, mouseY);
PVector dir = PVector.sub(destination, location);
if(dir.mag() < 60.0){
if(dir.mag() < overshoot_dist){
move = false;
}
else{
Expand Down Expand Up @@ -66,14 +65,5 @@ class Mover {
location.y = height;
}

}

void setRed(){
if(col_count == 1){
col = color(random(127, 255), 0, 0);
}
col_count++;
}


}
}
} // class Mover
Binary file added 1_pollution/0_basics/shader_cloud/cloud1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1_pollution/0_basics/shader_cloud/cloud2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1_pollution/0_basics/shader_cloud/cloud3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions 1_pollution/0_basics/shader_cloud/shader_cloud.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Random clouds filling up screen like fog based on Shaders Tutorial 10.2
https://processing.org/tutorials/pshader/
By: Mayank Joneja
Date: 03-01-2020
*/

PShader pointShader;
PImage cloud1;
PImage cloud2;
PImage cloud3;

float weight = 100;
int target_x = 0, target_y = 0;
int y_margin = 50;
int frame_counter = 0;

void setup() {
size(1440, 960, P3D);

pointShader = loadShader("spritefrag.glsl", "spritevert.glsl");
pointShader.set("weight", weight);
cloud1 = loadImage("cloud1.png");
cloud2 = loadImage("cloud2.png");
cloud3 = loadImage("cloud3.png");
pointShader.set("sprite", cloud2);

strokeWeight(weight);
strokeCap(SQUARE);
stroke(255, 70);

background(0);
}

void draw() {

shader(pointShader, POINTS);
if(frame_counter <= 300) {
target_y = int(random(2 * height/3 + 100, height));
} else {
target_y = int(random(2 * height/3, height));
}

//target_x = int(random(width));

target_y = int(random(target_y - y_margin, target_y + y_margin));

target_x += 3;
if (target_x >= width) target_x = 0;
if(!mousePressed)
point(target_x, target_y);

frame_counter++;
}
14 changes: 14 additions & 0 deletions 1_pollution/0_basics/shader_cloud/spritefrag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

uniform sampler2D sprite;

varying vec4 vertColor;
varying vec2 texCoord;

void main() {
gl_FragColor = texture2D(sprite, texCoord) * vertColor;
}
Loading