URGENT---> Twitter is blocked!!!
in
Contributed Library Questions
•
9 months ago
Helloooo everyone
So i make this little program and, i don't know why... Twitter block everything when the AGENT class is activated...
... Please, would you help me to fix it?
Thanks to all of you who can help!
CLASS AGENT :
AND NEURON :
So i make this little program and, i don't know why... Twitter block everything when the AGENT class is activated...
... Please, would you help me to fix it?
Thanks to all of you who can help!
- import controlP5.*;
- ControlP5 cp5;
- ControlWindow controlWindow;
- import twitter4j.*;
- import java.util.List;
- Twitter twitter;
- public int PersX = 100;
- public int PersY = 100;
- public float Zoom = 1.00;
- float Taille = 20;
- int num = 180;
- float RADIUS = 550;
- float SCALE = 150.0;
- float cameraZ= (height/2.0) / tan(PI*60.0/360.0);
- int globKonexID = 0;
- int nbAgent = 1;
- Neuron n[];
- Agent Particules[];
- void setup() {
- size(displayWidth, displayHeight, P3D);
- twitter = initTwitter();
- //////INTERFACE CONTROL
- cp5 = new ControlP5(this);
- controlWindow = cp5.addControlWindow("controlP5window", 100, 100, 300, 200)
- .hideCoordinates()
- .setBackground(color(150))
- ;
- cp5.addSlider("PersX")
- .setRange(0, 200)
- .setPosition(40, 40)
- .setSize(200, 20)
- .setWindow(controlWindow)
- ;
- cp5.addSlider("PersY")
- .setRange(0, 200)
- .setPosition(40, 80)
- .setSize(200, 20)
- .setWindow(controlWindow)
- ;
- cp5.addSlider("Zoom")
- .setRange(0, 2)
- .setPosition(40, 120)
- .setSize(200, 20)
- .setWindow(controlWindow)
- ;
- n = new Neuron[num];
- for (int i = 0;i<n.length;i++) {
- n[i] = new Neuron(i);
- }
- for (int i = 0;i<n.length;i++) {
- n[i].makeConnections();
- }
- noSmooth();
- stroke(1.0);
- for (int i = 0;i<n[0].k.length;i++)
- n[0].makeSignal(i);
- }
- Twitter initTwitter() {
- ConfigurationBuilder cb = new ConfigurationBuilder();
- cb.setDebugEnabled(true)
- .setOAuthConsumerKey("pPPRbR3XMdzt0K9zc0Xp1w")
- .setOAuthConsumerSecret("Wx4at79icYfxlETpJ8ELQ3L4ll094K4AgoRT6lM4o")
- .setOAuthAccessToken("105489042-wwGThZOa2B98Nl6V2pkJhDPyqErZLLLVXdEQ733X")
- .setOAuthAccessTokenSecret("7tu9xIuaU6fheGqt7U1VmlzL7ysifyxhup6uJQEqZ7c");
- TwitterFactory tf = new TwitterFactory(cb.build());
- return tf.getInstance();
- }
- void draw() {
- float time = millis()*0.001;
- background(0);
- camera( 2550, -1850, 100, 0, 0, 0, 0, 10, 0 ); // Cammera
- ///PERSPECTIVE
- float fov = PI/4.0;
- float cameraZ = (height/2.0) / tan(fov/2.0);
- perspective(fov*Zoom, float(width*PersX)/float(height*PersY), cameraZ/100.0, cameraZ*100.0);
- ////
- rotate (-time*.2, time*.1, -time*.0, -time*.1); //ROTATION DU TOUT
- for (int i = 0;i<n.length;i++) {
- n[i].draw();
- }
- }
- ////////////////////////// >>
CLASS AGENT :
- class Agent {
- public void printSearch(Twitter t, String sQuery) {
- printSearch(twitter, "@ENSAV");
- try {
- Query query = new Query(sQuery);
- QueryResult result;
- do {
- result = twitter.search(query);
- List<Status> tweets = result.getTweets();
- for (Status tweet : tweets) {
- //System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
- text("@" + tweet.getUser().getScreenName() + " - " + tweet.getText(), 0, 20);
- }
- }
- while ( (query = result.nextQuery ()) != null);
- }
- catch (TwitterException te) {
- te.printStackTrace();
- System.out.println("Failed to search tweets: " + te.getMessage());
- }
- }
- }
- ////////////////////////// >>
- class Konexe {
- int A, B, id;
- float weight = 1.5;
- Konexe(int _A, int _B) {
- A = _A;
- B = _B;
- id = globKonexID++;
- weight = random(50, 100)/SCALE;
- }
- }
- class Signal {
- Konexe base;
- int cyc = 0;
- float x, y, z, lx, ly, lz;
- float speed = 10.1;
- boolean running = false;
- boolean visible = true;
- boolean moving = false;
- int deadnum = 2000;
- int deadcount = 0;
- Signal(Konexe _base) {
- base = _base;
- lx = x = n[base.A].x;
- ly = y = n[base.A].y;
- lz = z = n[base.A].z;
- speed *= base.weight;
- }
- void step() {
- running = true;
- if (abs(lx-x)>.1||abs(ly-y)>.1||abs(lz-z)>.1)
- moving = true;
- else
- moving = false;
- lx = x;
- ly = y;
- lz = z;
- if (!n[base.A].imobile) {
- x += (n[base.B].xx-x) / speed*0.5;//(speed+(dist(n[base.A].x,n[base.A].y,n[base.B].x,n[base.B].y)+1)/100.0);
- y += (n[base.B].yy-y) / speed*0.5;//(speed+(dist(n[base.A].x,n[base.A].y,n[base.B].x,n[base.B].y)+1)/100.0);
- z += (n[base.B].zz-z) / speed*0.5;
- }
- n[base.A].val+=(0-n[base.A].val)/5000.0;
- if (dist(x, y, z, n[base.B].xx, n[base.B].yy, n[base.B].zz)<1.0) {
- if (deadcount<500000) {
- deadcount = deadnum;
- //deadnum += (int)random(-1,1);
- //println("run "+base.A+" : "+base.B);
- running = false;
- for (int i = 0; i < n[base.B].k.length;i++) {
- if (!n[base.B].sig[i].running && base.A!=n[base.B].sig[i].base.B) {
- n[base.B].makeSignal(i);
- n[base.B].sig[i].base.weight += (base.weight-n[base.B].sig[i].base.weight)/((dist(x, y, z, n[base.A].xx, n[base.A].yy, n[base.A].zz)+1.0)/200.0);
- }
- }
- //base.weight = random(1001,3000) / 1000.0;
- if (n[base.A].id!=1) {
- n[base.A].xx+=((n[base.B].x-n[base.A].x)/1.1)*noise((frameCount+n[base.A].id)/18.0);
- ;
- n[base.A].yy+=((n[base.B].y-n[base.A].y)/1.1)*noise((frameCount+n[base.A].id)/17.0);
- n[base.A].zz+=((n[base.B].z-n[base.A].z)/1.1)*noise((frameCount+n[base.A].id)/16.0);
- n[base.A].xx-=((n[base.B].x-n[base.A].x)/1.1)*noise((frameCount+n[base.B].id)/18.2);
- ;
- n[base.A].yy-=((n[base.B].y-n[base.A].y)/1.1)*noise((frameCount+n[base.B].id)/17.2);
- n[base.A].zz-=((n[base.B].z-n[base.A].z)/1.1)*noise((frameCount+n[base.B].id)/16.2);
- }
- lx = n[base.A].x;
- ly = n[base.A].y;
- lz = n[base.A].z;
- n[base.A].val+=(255-n[base.A].val)/10.0;
- }
- else {
- println("deadcount--");
- }
- }
- }
- }
AND NEURON :
- class Neuron {
- float x, y, z, radius, xx, yy, zz, val;
- int id;
- boolean imobile = false;
- Konexe k[] = new Konexe[0];
- Signal sig[] = new Signal[0];
- Agent Particules[] ;
- Neuron(int _id) {
- xx = x = random(-width/2, width/2);
- yy = y = random(-width/2, width/2);
- zz = z = random(-width/2, width/2);
- id= _id;
- radius = RADIUS;
- val = 0;
- if (id==1)imobile = true;
- }
- void makeConnections() {
- k = new Konexe[0];
- sig = new Signal[0];
- for (int i = 0 ;i<n.length;i++) {
- if (i!=id && dist(x, y, z, n[i].x, n[i].y, n[i].z) < radius) {
- k = (Konexe[])expand(k, k.length+1);
- k[k.length-1] = new Konexe(id, i);
- sig = (Signal[])expand(sig, sig.length+1);
- sig[sig.length-1] = new Signal(k[sig.length-1]);
- }
- }
- }
- void makeSignal(int which) {
- int i = which;
- sig[i].x = xx;
- sig[i].y = yy;
- sig[i].z = zz;
- sig[i].running = true;
- }
- void drawConnections() {
- for (int i = 0 ;i<k.length;i++) {
- line(xx, yy, zz, n[k[i].B].xx, n[k[i].B].yy, n[k[i].B].zz);
- }
- }
- void draw() {
- float time = millis()*0.1;
- xx += (x-xx) / 100.0;
- yy += (y-yy) / 100.0;
- zz += (z-zz) / 100.0;
- if (sig.length>0) {
- for (int i = 0;i<sig.length;i+=1) {
- if (sig[i].running) {
- if (sig[i].moving) {
- pushMatrix();
- pushStyle();
- strokeWeight(0);
- fill(time*.4, random(0, 255), random(0, 255)); // COULEUR BOITES
- //line(sig[i].x, sig[i].y, sig[i].z, sig[i].lx, sig[i].ly, sig[i].lz);
- translate(sig[i].x, sig[i].y, sig[i].z);
- Particules[1] = new Agent();
- popStyle();
- popMatrix();
- }
- sig[i].step();
- }
- }
- }
- stroke(lerpColor(#3300FF, #FFFFFF, norm(val, 10, 200)), 50); // Couleurs traits
- drawConnections();
- strokeWeight(4); //Epaisseur de traits
- }
- }
1