Hi! I’m a processing novice and only have a limited understanding of coding, but I’m putting together a sketch for my final project in class.
I have the basic code where every time the mouse is pressed, orbs spawn in a 3D space, but I want it so the orbs are spawn every time someone tweets out #addmetothelistonTheNetworkArchivalProject (thus accumulating the number of orbs). This will send a picture of the sketch and uploads it to my twitter account.
I am using the simpletweet library from the processing wiki.
//Built off of JRafner code:
import gohai.simpletweet.*;
import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Status;
import twitter4j.TwitterException;
import twitter4j.User;
SimpleTweet simpletweet;
ArrayList<Status> tweets;
import peasy.*;
PeasyCam camera;
PVector position;
PVector velocity;
PVector acceleration;
float r;
float maxforce; // Maximum steering force
float maxspeed; // Maximum speed
int i;
float angle;
PGraphics pg;
PShape texture;
PShader texlightShader;
ArrayList<Bird> birds = new ArrayList<Bird>();
int sphereRotate;
PImage img;
PShader blur;
//_____________________________________________________________________________
void setup() {
//size(1000, 1000, P3D);
fullScreen(P3D);
frameRate(60);
colorMode(HSB, 360);
lights();
sphereRotate = 0;
//camera = new PeasyCam(this, 0, 0, 0, 0);
//camera = new PeasyCam(this, width/2, height/2, 0, 560);
simpletweet = new SimpleTweet(this);
simpletweet.setOAuthConsumerKey("...");
simpletweet.setOAuthConsumerSecret("...");
simpletweet.setOAuthAccessToken("...");
simpletweet.setOAuthAccessTokenSecret("...");
tweets = search("#addmetothelistonTheNetworkArchivalProject");
}
//_____________________________________________________________________________
void draw() {
background(0);
lights();
for (Bird b : birds) {
b.render();
b.step();
}
Status current = tweets.get(frameCount % tweets.size());
String message = current.getText();
User user = current.getUser();
String username = user.getScreenName();
text(message + "by @" + username, 0, height/2);
}
//_____________________________________________________________________________
ArrayList<Status> search(String keyword) {
// request 100 results
Query query = new Query(keyword);
query.setCount(100);
try {
QueryResult result = simpletweet.twitter.search(query);
ArrayList<Status> tweets = (ArrayList)result.getTweets();
// return an ArrayList of Status objects
return tweets;
} catch (TwitterException e) {
println(e.getMessage());
return new ArrayList<Status>();
}
}
//_____________________________________________________________________________
void mousePressed(){
for (int i = 0; i < 2; i++) {
birds.add(new Bird());
}
String tweet = simpletweet.tweetImage(get(), "Made with Processing");
println("Posted" + tweet);
}
//_____________________________________________________________________________
class Bird {
PVector position = new PVector(random(width), random(height), random(height));
PVector direction = new PVector(random(-10, 10), random(-10, 10), random(-10, 10));
void render() {
pushMatrix();
translate(position.x, position.y, position.z);
rotateY(angle);
angle += 0.05;
beginShape(QUADS);
normal(0, 0, 1);
noStroke();
//stroke(360);
//noFill();
fill(random(360), random(360), random(360));
sphere(3);
endShape();
popMatrix();
}
//_____________________________________________________________________________
void light(Bird plan) {
lightSpecular(0, 0, 0);
pointLight(70, 70, 60, plan.position.x, plan.position.y, plan.position.z);
}
//_____________________________________________________________________________
void step() {
//find closest Bird
Bird closestBird = null;
float closestDistance = 10000;
for (Bird b : birds) {
if (this != b) {
float distance = position.dist(b.position);
if (distance < closestDistance) {
closestDistance = distance;
closestBird = b;
}
}
}
//average directions so they converge to the same direction
direction = new PVector((direction.x+closestBird.direction.x)/2, (direction.y+closestBird.direction.y)/2, (direction.z+closestBird.direction.z)/2);
position.add(direction);
if (position.x <100) {
position.x = width-100;
}
if (position.x > width-100) {
position.x = 100;
}
if (position.y < 100) {
position.y = height-100;
}
if (position.y > height-100) {
position.y = 100;
}
if (position.z < 100) {
position.z = height-100;
}
if (position.z > height-100) {
position.z = 100;
}
}
}
//_____________________________________________________________________________
void update() {
// Update velocity
velocity.add(acceleration);
// Limit speed
velocity.limit(maxspeed);
position.add(velocity);
// Reset accelertion to 0 each cycle
acceleration.mult(1);
}
//_____________________________________________________________________________
// A method that calculates and applies a steering force towards a target
// STEER = DESIRED MINUS VELOCITY
PVector seek(PVector target) {
PVector desired = PVector.sub(target, position); // A vector pointing from the position to the target
// Scale to maximum speed
desired.normalize();
desired.mult(maxspeed);
// Steering = Desired minus Velocity
PVector steer = PVector.sub(desired, velocity);
steer.limit(maxforce); // Limit to maximum steering force
return steer;
}
//_____________________________________________________________________________
//_____________________________________________________________________________
I’m having trouble visualizing real-time data from twitter into my processing sketch.
If anyone could help me understand or put together the basic code to get the sketch to work that would be greatly appreciated!