ArrayList particles;PShape a;Twitter twitter;Query q;/*Mover[] movers = new Mover[190];Mover[] movers2 = new Mover[25];Mover[] movers3 = new Mover[7];*/color col;String[] terms = {"airandspace", "creativecourt", "ecosystems", "innovationlab", "rainforest" , "worldoflife"};int[] hues = {30, 25, 80, 60, 80};int index = 0;
//VOID SETUP////////////////////void setup() {size(800, 800);smooth();background(0);color(HSB, 100);frameRate(70);
//twitter stuffConfigurationBuilder cb = new ConfigurationBuilder();cb.setOAuthConsumerKey("PLmGEQtruhjtEDryFyx0rA");cb.setOAuthConsumerSecret("yN5ubhMXKkJjRF151m2M2awWQXmkaQzMgOkksyLtI");cb.setOAuthAccessToken("317405665-ojRo56DtA5KFvfujk39EM60g9Tk75DrE0f4VvO2N");cb.setOAuthAccessTokenSecret("oo2LazqjdMzYtiFUTlQWA3vzmifTOxUA3C8xzB11E");
twitter = new TwitterFactory(cb.build()).getInstance();
/*try{QueryResult result = twitter.search(q);ArrayList tweets = (ArrayList) result.getTweets();Tweet t = (Tweet) tweets.get(0);particles = new ArrayList();particles.add(new Mover(4, .07));println(t.getText());}catch(TwitterException te){}*/
particles = new ArrayList();col = color(hues[index], random(80, 100), random(60, 90));particles.add(new Mover(col, 4, .07));//Mover p = (Mover)particles.get(0);//println(p.msg);
a = loadShape("mos.svg");/*for (int i = 0; i < movers.length; i++) {movers[i] = new Mover(4, .07);}for (int i = 0; i < movers2.length; i++) {movers2[i] = new Mover(4, .13);}for (int i = 0; i < movers3.length; i++) {movers3[i] = new Mover(4, .2);}*/}
void draw(){noStroke();fill(255);rect(0, 0, width, height);
// create a timer to call createParticles();
for (int i=0; i<particles.size(); i++){Mover m = (Mover) particles.get(i);m.checkEdges();m.update();m.display();
if (m.finished()) {// Items can be deleted with remove()particles.remove(i);}}}
void mousePressed() {createParticles();}
void createParticles(){index = int(random(terms.length));col = color(hues[index], random(80, 90), random(90, 100));particles.add(new Mover(col, 4, .07));}
/*//VOID DRAW////////////////////void draw() {noStroke();fill(255);rect(0, 0, width, height);/*for (int i = 0; i < movers.length; i++) {movers[i].update();movers[i].checkEdges();if (!finished) movers[i].display();movers[i].fadeOut();}for (int i = 0; i < movers2.length; i++) {movers2[i].update();movers2[i].checkEdges();if (!finished) movers2[i].display();movers2[i].fadeOut();}for (int i = 0; i < movers3.length; i++) {movers3[i].update();movers3[i].checkEdges();if (!finished) movers3[i].display();movers3[i].fadeOut();}*///shape (a, -200, -200, 1200, 1200);//}
class Mover {
PVector location;PVector velocity;PVector acceleration;//fade out funtion; the larger the number, the longer////////////////////float life = 3550;float topspeed;int size;float multiplier;color col;String msg;
Mover(color tcol, int xsp, float xmu) {size = int(random(4, 1));location = new PVector(random(width), random(height));velocity = new PVector(random(width), random(height));topspeed = xsp;multiplier = xmu;msg = getMsg();int x = int(random(0, 255));
float c = random(0, 80);float m = random(0, 55);float y = random(0, 0);float k = random(0, 30);//col = convert(c, m, y, k);col = tcol;}
//fade out funtion////////////////////boolean finished() {// Balls fade outlife-=10;if (life < 0) {return true;}else {return false;}}
void fadeOut() {// Balls fade outlife--;}
//VOID UPDATE////////////////////void update() {PVector mouse = new PVector(width/2, height/2);PVector dir = PVector.sub(mouse, location);dir.normalize();dir.mult(multiplier);acceleration = dir;
velocity.add(acceleration);velocity.limit(topspeed);location.add(velocity);}
//COLOR//9*I;//////////////////color convert(float c, float m, float y, float k) {c = c / 100;m = m / 100;y = y / 100;k = k / 100;
c = ( c * ( 1 - k ) + k );m = ( m * ( 1 - k ) + k );y = ( y * ( 1 - k ) + k );
float r = ( 1 - c ) * 255;float g = ( 1 - m ) * 255;float b = ( 1 - y ) * 255;
return color(r, g, b);}
//VOID DISPLAY////////////////////void display() {noStroke();fill(col, life/10.0);ellipse(location.x, location.y, size, size);}
void checkEdges() {
if (location.x > width) {location.x = 0;}else if (location.x < 0) {location.x = width;}
if (location.y > height) {location.y = 0;}else if (location.y < 0) {location.y = height;}}
String getMsg(){try {q = new Query(terms[index]);q.setRpp(1);
QueryResult result = twitter.search(q);//Cast the list of tweets into an ArrayListArrayList tweets = (ArrayList) result.getTweets();
//and instead of a for loop, just get(0);//Pull out this particular Tweet object.Tweet t = (Tweet) tweets.get(0);return t.getText();
//println(usr+ ": " + msg + " ("+d+")");}catch(TwitterException te) {//println(te);return te.toString();}}}
ArrayList<String> particle = new ArrayList();PShape a;Twitter twitter;Query q;Mover[] movers = new Mover[190];Mover[] movers2 = new Mover[25];Mover[] movers3 = new Mover[7];
//VOID SETUP////////////////////void setup() {size(800, 800);smooth();background(0);frameRate(70);
//twitter stuffConfigurationBuilder cb = new ConfigurationBuilder();cb.setOAuthConsumerKey("PLmGEQtruhjtEDryFyx0rA");cb.setOAuthConsumerSecret("yN5ubhMXKkJjRF151m2M2awWQXmkaQzMgOkksyLtI");cb.setOAuthAccessToken("317405665-ojRo56DtA5KFvfujk39EM60g9Tk75DrE0f4VvO2N");cb.setOAuthAccessTokenSecret("oo2LazqjdMzYtiFUTlQWA3vzmifTOxUA3C8xzB11E");Twitter twitter = new TwitterFactory(cb.build()).getInstance();Query query = new Query("science");query.setRpp(1);particle = new ArrayList();
a = loadShape("mos.svg");for (int i = 0; i < movers.length; i++) {movers[i] = new Mover(4, .07);}for (int i = 0; i < movers2.length; i++) {movers2[i] = new Mover(4, .13);}for (int i = 0; i < movers3.length; i++) {movers3[i] = new Mover(4, .2);}}
//VOID DRAW////////////////////void draw() {noStroke();fill(255);rect(0, 0, width, height);
for (int i = 0; i < movers.length; i++) {movers[i].update();movers[i].checkEdges();movers[i].display();}for (int i = 0; i < movers2.length; i++) {movers2[i].update();movers2[i].checkEdges();movers2[i].display();}for (int i = 0; i < movers3.length; i++) {movers3[i].update();movers3[i].checkEdges();movers3[i].display();}shape (a, -200, -200, 1200, 1200);}
class Mover {
PVector location;PVector velocity;PVector acceleration;//fade out funtion////////////////////float life = 255;float topspeed;int size;float multiplier;color col;
//fade out funtion////////////////////boolean finished() {// Balls fade outlife--;if (life < 0) {return true;}else {return false;}}
Mover(int xsp, float xmu) {size = int(random(4, 9.5));location = new PVector(random(width), random(height));velocity = new PVector(random(width), random(height));topspeed = xsp;multiplier = xmu;int x = int(random(0, 255));
float c = random(0, 0);float m = random(0, 0);float y = random(0, 0);float k = random(0, 100);col = convert(c, m, y, k);}
//VOID UPDATE////////////////////void update() {
PVector mouse = new PVector(width/2, height/2);PVector dir = PVector.sub(mouse, location);dir.normalize();dir.mult(multiplier);acceleration = dir;
velocity.add(acceleration);velocity.limit(topspeed);location.add(velocity);}
//COLOR//9*I;//////////////////color convert(float c, float m, float y, float k) {c = c / 100;m = m / 100;y = y / 100;k = k / 100;
c = ( c * ( 1 - k ) + k );m = ( m * ( 1 - k ) + k );y = ( y * ( 1 - k ) + k );
float r = ( 1 - c ) * 255;float g = ( 1 - m ) * 255;float b = ( 1 - y ) * 255;
return color(r, g, b);}
//VOID DISPLAY////////////////////void display() {noStroke();fill(col);ellipse(location.x, location.y, size, size);}void checkEdges() {
if (location.x > width) {location.x = 0;}else if (location.x < 0) {location.x = width;}
if (location.y > height) {location.y = 0;}else if (location.y < 0) {location.y = height;}}}
for a personal project I'm rebranding science center, located in los angeles, california. this is overall my concept for my logo.
i changed the name of the museum to 'museum of science' for international aspirations. the museum of science can be abbreviated down to 'mos', pronounced as 'moss'. the logo consists of particles revolving and gravitating towards the 'o' of 'mos'. this structure was inspired by their iconic sculpture of hundreds of balls hanging from the ceiling above the entrance, which symbolized the connectivity of everything science. i decided to further work with the concept of 'connectivity'. once in a few months the museum of science houses a special exhibition, for example they're currently having an exhibition titled '1001 inventions, the golden age of muslim civilization'. the logo extracts twitter feeds that consist of key words of the exhibition; in this case the key words would be '1001', 'inventions', 'golden age', 'muslim', 'civilization', 'science' and 'museum'. once the logo extracts a twitter feed, a color coded particle appears. however, the particles have, for example, a 10-20 second life span, and fades away until it eventually disappears.
because I'm new to this program, i was wondering if you guys can help with the technical coding.
here are the problems that I'm encountering:
- how can i get twitter4j to pick up multiple twitter feeds that consist of key words (explained above)
- how can i set up the fade away function and tie it together with twitter4j?
- how can i color code the twitter feed particles?
i know this is a lot to ask, but please help me out. this is due friday morning and I'm panicking..
heres my code. if you want the full file that consists of additional files that tie into the code below, i can do that. thank you!
PShape a;
Mover[] movers = new Mover[190];
Mover[] movers2 = new Mover[25];
Mover[] movers3 = new Mover[7];
//VOID SETUP////////////////////
void setup() {
size(800, 800);
smooth();
background(0);
a = loadShape("mos.svg");
for (int i = 0; i < movers.length; i++) {
movers[i] = new Mover(4, .07);
}
for (int i = 0; i < movers2.length; i++) {
movers2[i] = new Mover(4, .13);
}
for (int i = 0; i < movers3.length; i++) {
movers3[i] = new Mover(4, .2);
}
}
//VOID DRAW////////////////////
void draw() {
noStroke();
fill(255);
rect(0, 0, width, height);
for (int i = 0; i < movers.length; i++) {
movers[i].update();
movers[i].checkEdges();
movers[i].display();
}
for (int i = 0; i < movers2.length; i++) {
movers2[i].update();
movers2[i].checkEdges();
movers2[i].display();
}
for (int i = 0; i < movers3.length; i++) {
movers3[i].update();
movers3[i].checkEdges();
movers3[i].display();
}
shape (a, -200, -200, 1200, 1200);
}
class Mover {
PVector location;
PVector velocity;
PVector acceleration;
float topspeed;
int size;
float multiplier;
color col;
Mover(int xsp, float xmu) {
size = int(random(4, 9.5));
location = new PVector(random(width), random(height));
velocity = new PVector(random(width), random(height));
topspeed = xsp;
multiplier = xmu;
int x = int(random(0, 255));
float c = random(0, 100);
float m = random(0, 100);
float y = random(0, 0);
float k = random(0, 0);
col = convert(c, m, y, k);
}
//VOID UPDATE////////////////////
void update() {
PVector mouse = new PVector(width/2, height/2);
PVector dir = PVector.sub(mouse, location);
dir.normalize();
dir.mult(multiplier);
acceleration = dir;
velocity.add(acceleration);
velocity.limit(topspeed);
location.add(velocity);
}
//COLOR//9*I;//////////////////
color convert(float c, float m, float y, float k) {
c = c / 100;
m = m / 100;
y = y / 100;
k = k / 100;
c = ( c * ( 1 - k ) + k );
m = ( m * ( 1 - k ) + k );
y = ( y * ( 1 - k ) + k );
float r = ( 1 - c ) * 255;
float g = ( 1 - m ) * 255;
float b = ( 1 - y ) * 255;
return color(r, g, b);
}
//VOID DISPLAY////////////////////
void display() {
noStroke();
fill(col);
ellipse(location.x, location.y, size, size);
}
void checkEdges() {
if (location.x > width) {
location.x = 0;
}
else if (location.x < 0) {
location.x = width;
}
if (location.y > height) {
location.y = 0;
}
else if (location.y < 0) {
location.y = height;
}
}
}