Loading...
Logo
Processing Forum
Hello everyone!

I'm trying to put a timeline text with twitter4j in this code. For the moment, i'm trying to make twitter4j working, but, i can't find the "twitter4j.jar" etc.

is someone can told me (or send me to my email adress) this twitter4j.jar (i'm trrying to use he latest stable version)
I know it is a little bit stupid...


... And the second question: I need to make every particule like different text. do you have any solution?

here the code:

Copy code
  1. import codeanticode.syphon.*;
    import controlP5.*;
    ControlP5 cp5;
    ControlWindow controlWindow;
    SyphonClient client;

    public int PersX = 100;
    public int PersY = 100;
    public float Zoom = 1.00;

    float Taille = 20;
    int num = 180;
    float RADIUS = 550;
    float SCALE = 450.0;
    float cameraZ= (height/2.0) / tan(PI*60.0/360.0);


    int globKonexID = 0;

    Neuron n[];

    void setup() {
      size(displayWidth, displayHeight, P3D);
      PFont maTypo = loadFont("Serif-30.vlw"); // choix de la typo
      textFont(maTypo, Taille);// Définition de la taille de la typo
      //////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);
    }



    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 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];


      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;
        float niah = 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);
               
                //HERE I'M TRYING TO CHANGE THE TEXT TO TWITTER TIMELINE
                if (niah == 1) {
                  text("hey ça va?", 0, 50);
                }
                if (niah == 2) {
                  text("bonjour", 0, 20);
                }
                if (niah == 3) {
                  text("t'as les plans?", 0, 30);
                }
                if (niah == 4) {
                  text("QUOI?", 0, 100);
                }
                if (niah == 5) {
                  text("tu charrettes?", 0, 54);
                }
                popStyle();
                popMatrix();
              }
              sig[i].step();
            }
          }
        }

        stroke(lerpColor(#3300FF, #FFFFFF, norm(val, 10, 200)), 50); // Couleurs traits
        drawConnections();
        strokeWeight(4); //Epaisseur de traits
      }
    }

    ////////////////////////// >>

    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--");
          }
        }
      }
    }
     




Replies(17)



http://twitter4j.org/en/index.html#download

or another one:
http://mccv.github.com/processing-tweet-stream/



make every particle like different text.
do you mean different color (use random 3x and fill())
or do you mean different font? Use font()

Greetings, Chrisir      


P.S.
Sorry, stating the obvious...




Thanks

Not the color, i just need different words in every particules: like,  for the moment you have only one phrase, and i want different phrases in every particules ^^, different quotes from the timeline.

u no what i mean?
You can get Twitter4j from here:  twitter4j.org
1) You need to drag and drop the file twitter4j-core-3.0.2.jar to your Processing window, so it will be copied to your sketchdir (or manually copy it to a folder called "code" inside your new sketch directory).

2) To authorize, you need an API key, register here:  https://dev.twitter.com/apps/new (You need to be locked in for this with your twitter account)
3) When you got your API key, generate an access token (scroll down).
4) Enter your API and Access token String in the code below (with secrets)

Copy code
  1. import twitter4j.*;

  2. void setup() {
  3.   ConfigurationBuilder cb = new ConfigurationBuilder();
  4.   cb.setDebugEnabled(true)
  5.     .setOAuthConsumerKey("***")
  6.       .setOAuthConsumerSecret("***")
  7.         .setOAuthAccessToken("***")
  8.           .setOAuthAccessTokenSecret("***");
  9.   TwitterFactory tf = new TwitterFactory(cb.build());
  10.   Twitter twitter = tf.getInstance();
  11.   List<Status> statuses = null;
  12.   try {
  13.     statuses = twitter.getHomeTimeline();
  14.   }
  15.   catch(TwitterException e) {
  16.     e.printStackTrace();
  17.   }
  18.   System.out.println("Showing home timeline.");
  19.   if (statuses != null) {
  20.     for (Status status : statuses) {
  21.       System.out.println(status.getUser().getName() + ":" +
  22.         status.getText());
  23.     }
  24.   }
  25. }
THAAAAANNNNNNNKS

really!!!


in some cases you really need to

You need to drag and drop the file twitter4j-core-3.0.2.jar to your Processing window
and not only use

manually copy it to a folder called "code" inside your new sketch directory




See How to Install a Contributed Library
Moved from Programming Questions.
Okay, now i can use the twitter librairy (i'm like "it'as aliiiiive")... But i just need to fix the problem like i need different quotes from the timelines...

... like the one with the word sandwich^^ Every people who speak about it, everywhere.
I don't understand what's the problem.
if you use this code, you will see that there is the same word writen everywhere, i want different words.

Do you want me to make drawing?
I'm sorry for my english, i'm... french (sooorry :D).
Heeeeee... not working for the moment, i will told you after for the part2

... just another little things. When i want to change the getStatus to something that can get every messages with a specific word...
And the problem is: in every example i see the "qwery" thing... and that's not working on prossessing.

Is there is a lilttle command for it? I will do it by myself after...
something like this, but it's not working so i don't know how to use it.

Twitter myTwitter;

void setup() {
  myTwitter = new TwitterFactory().getInstance();
  try {

    Query query = new Query("sandwich");
    query.setRpp(100);
    QueryResult result = myTwitter.search(query);

    ArrayList tweets = (ArrayList) result.getTweets();

    for (int i = 0; i < tweets.size(); i++) {
      Tweet t = (Tweet) tweets.get(i);
      String user = t.getFromUser();
      String msg = t.getText();
      Date d = t.getCreatedAt();
      println("Tweet by " + user + " at " + d + msg);
    };

  }
  catch (TwitterException te) {
    println("Couldn't connect: " + te);
  };
};

void draw() {

};
Here's the code to search something:

Copy code
  1. import twitter4j.*;
  2. import java.util.List;

  3. Twitter twitter;

  4. void setup() {
  5.   twitter = initTwitter();
  6.   printSearch(twitter, "@yarnaudio"); 
  7. }

  8. Twitter initTwitter() {
  9.   ConfigurationBuilder cb = new ConfigurationBuilder();
  10.   cb.setDebugEnabled(true)
  11.     .setOAuthConsumerKey("***")
  12.       .setOAuthConsumerSecret("***")
  13.         .setOAuthAccessToken("***")
  14.           .setOAuthAccessTokenSecret("***");
  15.   TwitterFactory tf = new TwitterFactory(cb.build());
  16.   return tf.getInstance();
  17. }

  18. void printTimeline(Twitter twitter) {
  19.   List<Status> statuses = null;
  20.   try {
  21.     statuses = twitter.getHomeTimeline();
  22.   }
  23.   catch(TwitterException e) {
  24.     e.printStackTrace();
  25.   }
  26.   System.out.println("Showing home timeline.");
  27.   if (statuses != null) {
  28.     for (Status status : statuses) {
  29.       System.out.println(status.getUser().getName() + ":" +
  30.         status.getText());
  31.     }
  32.   }
  33. }

  34. void printSearch(Twitter t, String sQuery) {
  35.   try {
  36.     Query query = new Query(sQuery);
  37.     QueryResult result;
  38.     do {
  39.       result = twitter.search(query);
  40.       List<Status> tweets = result.getTweets();
  41.       for (Status tweet : tweets) {
  42.         System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
  43.       }
  44.     } 
  45.     while ( (query = result.nextQuery ()) != null);
  46.     System.exit(0);
  47.   } 
  48.   catch (TwitterException te) {
  49.     te.printStackTrace();
  50.     System.out.println("Failed to search tweets: " + te.getMessage());
  51.     System.exit(-1);
  52.   }
  53. }

For more infos what you can do with a Status object have a look at the reference.

i'm fighting with it, it's working, now i'm trying to put it in my code....

for the moment i'm here (i notice the part where i'm triyng to put the text from twitter), i'm triyng different things (i'm architect, so sorry if i'm a little bit stupid with processing >.<):

Copy code

  1. 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 = 450.0;
    float cameraZ= (height/2.0) / tan(PI*60.0/360.0);


    int globKonexID = 0;

    Neuron n[];

    void setup() {
      size(displayWidth, displayHeight, P3D);
      PFont maTypo = loadFont("Serif-30.vlw"); // choix de la typo
      textFont(maTypo, Taille);// Définition de la taille de la typo



      //////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
    Twitter initTwitter() {
      ConfigurationBuilder cb = new ConfigurationBuilder();
      cb.setDebugEnabled(true)
        .setOAuthConsumerKey("**************")
          .setOAuthConsumerSecret("**************")
            .setOAuthAccessToken("**************")
              .setOAuthAccessTokenSecret("**************");
      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 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];


      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;
        float niah = 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);

                text("TWITTER TEXT", 0, 50);

                popStyle();
                popMatrix();
              }
              sig[i].step();
            }
          }
        }

        stroke(lerpColor(#3300FF, #FFFFFF, norm(val, 10, 200)), 50); // Couleurs traits
        drawConnections();
        strokeWeight(4); //Epaisseur de traits
      }
    }

    ////////////////////////// >>

    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--");
          }
        }
      }
    }
     


okay... i'really... a noob >_<

Please, would you tell me where i can put the "void printSearch(Twitter t, String sQuery)" to change the text with the twitter's text.
I tried to run your code and it crashed. Don't have the time to find the error...
In this line you get the twitter messages:
Copy code
  1. System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());


Thanks^^

I was testing it and i make a special class for twitter, i send you my code. The twitter codes come from a special profile so i let you the "secret codes" in my skteche.

http://codelab.fr/attachment.php?item=1028



or his one


http://dl.free.fr/getfile.pl?file=/C3FktJ39

I hope you can download it?