Loading...
Logo
Processing Forum
lobj10's Profile
8 Posts
5 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message


    Is a defender game searching for information against twitter. It search active  for tweets containing keywords like 2012 and search in those results after END n such. It converts tweets into comets that spawns randomly outside the sketch, aimin at the center..
     Your job as starfleet captain commander Buck is to save the earthlings against confusion AND mass destruction.
    Achieve this by crashing your spaceship into every comet possible...


    It's working but need som few tweaks and a mutch cleaner code.

    1: 
    How do I make the comets "lag" their way towards earth? 
    (as In  old 8 bit "grid"-games and as in;" low frame rate", like the movement of the spaceship in this sketch)
    Can i fake it in some kind of way?

    2:
     Please look it thru and se if you find any superbig mistakes (exept the "press H for help"- loop, that's under construction).





      MAIN SKETCH

      1. //import liberaries
      2. import ddf.minim.*;
      3. import ddf.minim.signals.*;
      4. import ddf.minim.analysis.*;
      5. import ddf.minim.effects.*;

      6. PImage gameover;
      7. PImage skull;
      8. PImage jorden;
      9. PImage heart;
      10. import simpleML.*;
      11. int e = 0;
      12. //boolean showComet;


      13. ArrayList kometer = new ArrayList();

      14. int y = 0;
      15. int x = 0;
      16. int douche = 0;
      17. int i1 = 503;
      18. int i2 = 245;
      19. int i3 = 62;
      20. int i = 0;
      21. int rx = 100;
      22. int ry = 50;
      23. int hp = 10;
      24. int kills = 0;
      25. int sqx = 500;
      26. int sqy = 250;
      27. int sqr = 20;

      28. komet k;

      29. PFont Font;


      30. XMLRequest xmlRequest;
      31. int startTime;     // for the timer to make request ever N seconds
      32. String html = "";  // String to hold data from request

      33. import ddf.minim.*;
      34. Minim minim;
      35. AudioPlayer groove;


      36. void setup() {
      37.   // Music
      38.   minim = new Minim(this);
      39.   groove = minim.loadFile("test_rymd2.mp3", 512);
      40.   groove.loop();
      41.   // Creating and starting the request
      42.   xmlRequest = new XMLRequest(this, "http://search.twitter.com/search.rss?q=2012");
      43.   xmlRequest.makeRequest();
      44.   size(height = 1000, width = 500);
      45.   smooth();

      46.   //showComet = true;
      47. }

      48. void draw() {

      49.   background(0);  
      50.   ellipse(i1, i2, i3*2, i3*2);
      51.   fill(255, 255, 255);

      52.   // Every 5 seconds, make a new request
      53.   int now = millis();
      54.   if (now - startTime > 5000) {
      55.     xmlRequest.makeRequest();
      56.     println("Making request!");
      57.     startTime = now;
      58.   }

      59.   jorden = loadImage("earth.png"); //Bilden
      60.   imageMode(CENTER);
      61.   image(jorden, 500, 250);



      62.   for (int i = 0; i < kometer.size(); i++) {
      63.     komet k = (komet)kometer.get(i);
      64.     k.smart();
      65.   }

      66.   Font = loadFont("PressStartK-25.vlw"); //text corners
      67.   textFont(Font, 25);
      68.   text(hp, 15, 40);
      69.   text("H=help", 835, 485);
      70.   text(kills, 150, 40);
      71.   //  text(kills, 15, 485);

      72.   heart = loadImage("heart2.png");     //hp heart
      73.   imageMode(CENTER);
      74.   image(heart, 90, 29);

      75.   skull = loadImage("skull.png");     //hp heart
      76.   imageMode(CENTER);
      77.   image(skull, 220, 28);
      78.   // image(skull, 80, 475);


      79.   fill(255, 255, 255);
      80.   if (hp < 5) {
      81.     fill(255, 255, 0);
      82.   }
      83.   if (hp < 2) {
      84.     fill(255, 0, 0);
      85.   }

      86.   if (hp < 1) {
      87.     gameover = loadImage("gameover.png");
      88.     imageMode(CENTER);
      89.     image(gameover, 500, 250);
      90. //    groove = minim.loadFile("gameover2.mp3", 512);
      91. //    groove.loop(0);
      92.   }     
      93.   jorden = loadImage("ship10.png"); //Bilden
      94.   imageMode(CENTER);
      95.   image(jorden, sqx, sqy);

      96.   //  ellipse(sqx,sqy,sqr*2,sqr*2);

      97.   if (sqx > 980) {
      98.     sqx = 980;
      99.   } 
      100.   if (sqy < 20) {
      101.     sqy = 20;
      102.   }
      103.   if (sqx < 20) {
      104.     sqx = 20;
      105.   }
      106.   if (sqy > 480) {
      107.     sqy = 480;
      108.   }
      109. }


      110. void stop() {
      111.   groove.close();
      112.   minim.stop();
      113.   super.stop();
      114. }


      115. // When the request is complete
      116. void netEvent(XMLRequest ml) {
      117.   // Retrieving an array of all XML elements inside "<title*>" tags
      118.   String[] headlines = ml.getElementArray("title");
      119.   for (int i = 0; i < headlines.length; i++) {
      120.     // println(headlines[i]);
      121.   }

      122.   for (String html: headlines) {  
      123.     if (html.toLowerCase().contains("end")) {    
      124.       douche++;      
      125.       println(douche);     


      126.       switch ((int) random(4)) {
      127.       case 0:
      128.         // top edge
      129.         k = new komet( random(width), -10 );
      130.         break;
      131.       case 1:
      132.         // right edge
      133.         k = new komet( width+10, random(height) );
      134.         break;
      135.       case 2:
      136.         // left edge
      137.         k = new komet( -10, random(height) );
      138.         break;
      139.       case 3:
      140.         // bot edge
      141.         k = new komet( random(width), height+10 );
      142.         break;
      143.       }
      144.       kometer.add(k);
      145.     }
      146.   }
      147. }
      148. void keyPressed() {
      149.   if (keyPressed);
      150.   if (key == ('r') && (hp <= 10)) {
      151.     hp = 10;
      152.     kills = 0;  

      153.     println("RESTART");
      154.   }
      155.   if (key == CODED) {              //Gamepad
      156.     if (keyCode == RIGHT) {
      157.       sqx = sqx + 10;
      158.     }
      159.     if (keyCode == LEFT) {
      160.       sqx = sqx - 10;
      161.     }
      162.     if (keyCode == UP) {
      163.       sqy = sqy - 10;
      164.     }
      165.     if (keyCode == DOWN) {
      166.       sqy = sqy + 10;
      167.     }
      168.   }  
      169.   if (key == 'h') {                                                                                          //////////////HELP ME HERE
      170.     Font = loadFont("PressStartK-12.vlw");
      171.     textFont(Font, 12);
      172.     text(" A info-defender game, searching active \n for tweets containing keywords like 2012 / END  \n & spawn thoose as comets. Your job as  \n starfleet  captain BUCK is  to defend earth \n against confusion. \n \n R = restart \n arrows = move ", 410, 30);
      173.     println("HELP");
      174.   }
      175. }



      KOMET CLASS


      1. PImage kometen;
      2. PImage jorden2;
      3. PFont Font2;


      4. class komet {

      5.   int a = 15;
      6.   int b = 15;
      7.   float x = 0;
      8.   float y = 0;
      9.   float komet1, komet2;
      10.   boolean show = true;

      11.   komet(float _x, float _y) {
      12.     x = _x;
      13.     y = _y;
      14.     float speed = 2;
      15.     float ang = atan2(height/2-y, width/2-x);
      16.     komet1 = cos(ang)*speed;
      17.     komet2 = sin(ang)*speed;
      18.   }
      19.   void movement() {
      20.     x +=komet1;
      21.     y +=komet2;
      22.   }
      23.   void kometer() {
      24.     if (show) {
      25.       kometen = loadImage("komet5.png");
      26.       imageMode(CENTER);
      27.       image(kometen, x, y);
      28.     }
      29.   }        
      30.   void collision() {  
      31.     if (show) {
      32.       if ( dist(x, y, i1, i2) < i3) {            
      33.       
      34.         groove = minim.loadFile("hithit_earth.mp3", 512);
      35.         groove.loop(0);
      36.         
      37.         show = false;

      38.         

      39.         println("HIT");  //Räknar träffar
      40.         hp--;
      41.         rx--;

      42.         kometen = loadImage("testar3.png");
      43.         imageMode(CENTER);
      44.         image(kometen, x, y);
      45.       }
      46.     
      47.         if ( dist(x, y, sqx, sqy) < sqr) {  
      48.         
      49.         groove = minim.loadFile("hit_comet.mp3", 512);
      50.         groove.loop(0);
      51.         
      52.         show = false;
      53.         
      54.         kills++;
      55.     
      56.         kometen = loadImage("testar3.png");
      57.         imageMode(CENTER);
      58.         image(kometen, x, y);
      59.     }
      60.   }
      61. }  
      62.   void smart() {
      63.     movement();
      64.     kometer();
      65.     collision(); 
      66.   }  
      67. }



      >>>> <<<<>>>>  <<<<
      erase all that belong so minim lib and all mp3's and change font, if you want to test it and the speedyshare timed out... all images found above

      Hi.
      First of a big thanks to "jbum" who have helped me with half of my coding..

      Now...



      I have a comet (komet.png) that I'm throwing at  earth (earth.png)

      On collision i want my comet to disapear  and display tha word BOOOM 
      on the impact location.



      For the moment Im sending the comet outside the screen, but I assume it will create LAG
      when I spawn more and more comets...


      How do I erase or kill an object in a simple way (on impact:) and can I do this in just "void collision"?


      looks like this right now:




        void collision(){  
          if ( dist(x, y, i1, i2) < i3) {
            println("hit");            
          //  x = 1000000;
          //  y = 1000000;      
            i++;
              Font2 = loadFont("PressStartK-12.vlw");
              textFont(Font,12);
             text("BOOOM",x,y);
          }
      I want my "comet5.png"  to explode on inpact with earth.png


      I have tried the "explode" tutorial, but it seems I cant solve it...


      The image doesnt need to explode ,  i figure, i can spawn 4 pieces of the picture
      on the same location as the impact and throw the pieces in different directions...  but it's probably easier to learn how to explode thinks from the start.

      somebody who wants to save my night?






      1. PImage kometen;
      2. class komet{

      3.   int a = 15;
      4.   int b = 15;
      5.   float x = 0;
      6.   float y = 0;
      7.   float komet1,komet2;
      8.   
      9.   
      10.   komet(float _x, float _y){
      11.     x = _x;
      12.     y = _y;
      13.     float speed = 1;
      14.     float ang = atan2(height/2-y, width/2-x);
      15.     komet1 = cos(ang)*speed;
      16.     komet2 = sin(ang)*speed;
      17.   }
      18.   void movement(){
      19.     x +=komet1;
      20.     y +=komet2;
      21.   }
      22.   void kometer(){
      23.    kometen = loadImage("komet5.png");
      24.    imageMode(CENTER);
      25.    image(kometen, x, y);

      26.    noStroke();
      27.  
      28.   }        
      29.   void collision(){  
      30.     if ( dist(x, y, i1, i2) < i3) {
      31.       println("traff");            
      32.       x = 1000000;
      33.       y = 1000000;      
      34.       i++;
      35.     }
      36.   }  
      37. void smart(){
      38.    movement();
      39.    kometer();       
      40.    collision();  
      41. }
      42. }


      Hello!

      Im pretty new to processing so bare with me..
      I want to create a tail on a simple .png file that symbols a comet...
      I saw somebody do something similar by creating a "bleed" from the picture that faded away ..

      Do somebody know how to fix that?

      here's my code    prethanks!











      1. PImage jorden;
      2. import simpleML.*;
      3. int e = 0;

      4. ArrayList kometer = new ArrayList();

      5. int x = 0;
      6. int y = 0;
      7. int douche = 0;
      8. int i1 = 503;
      9. int i2 = 245;
      10. int i3 = 62;
      11. int i = 0;

      12. komet k;

      13. PFont Font;


      14. XMLRequest xmlRequest;
      15. int startTime;     // for the timer to make request ever N seconds
      16. String html = "";  // String to hold data from request




      17. void setup() {

      18.   // Creating and starting the request
      19.   xmlRequest = new XMLRequest(this, "http://search.twitter.com/search.rss?q=end");
      20.   xmlRequest.makeRequest();
      21.   size(height = 1000, width = 500);
      22.   
      23.   smooth();
      24. }



      25. void draw() {

      26.   background(0);  
      27.   ellipse(i1, i2, i3*2, i3*2);
      28.   fill(227, 222, 181);

      29.   // Every 5 seconds, make a new request
      30.   int now = millis();
      31.   if (now - startTime > 2000) {
      32.     xmlRequest.makeRequest();
      33.     println("Making request!");
      34.     startTime = now;
      35.   }
      36.   jorden = loadImage("earth.png"); //Bilden
      37.   imageMode(CENTER);
      38.   image(jorden, 500, 250);


      39.   for (int i = 0; i < kometer.size(); i++) {
      40.     komet k = (komet)kometer.get(i);

      41.     k.smart();
      42.   }
      43.   Font = loadFont("PressStartK-48.vlw");
      44.   textFont(Font,48);
      45.   text(i, 25, 75);
      46. }





      47. // When the request is complete
      48. void netEvent(XMLRequest ml) {
      49.   // Retrieving an array of all XML elements inside "<title*>" tags
      50.   String[] headlines = ml.getElementArray("title");
      51.   for (int i = 0; i < headlines.length; i++) {
      52.     // println(headlines[i]);
      53.   }

      54.   for (String html: headlines) {  
      55.     if (html.toLowerCase().contains("2012")) {    
      56.       douche++;      
      57.       println(douche);     


      58.       switch ((int) random(4)) {
      59.       case 0:
      60.         // top edge
      61.         k = new komet( random(width), -10 );
      62.         break;
      63.       case 1:
      64.         // right edge
      65.         k = new komet( width+10, random(height) );
      66.         break;
      67.       case 2:
      68.         // left edge
      69.         k = new komet( -10, random(height) );
      70.         break;
      71.       case 3:
      72.         // bot edge
      73.         k = new komet( random(width), height+10 );
      74.         break;
      75.       }
      76.       kometer.add(k);
      77.     }
      78.   }
      79. }
      80. ------------------------------------classss------------------------------------------------------

      81. class komet{

      82.   int a = 15;
      83.   int b = 15;
      84.   float x = 0;
      85.   float y = 0;
      86.   float komet1,komet2;
      87.   
      88.   
      89.   komet(float _x, float _y){
      90.     x = _x;
      91.     y = _y;
      92.     float speed = 1;
      93.     float ang = atan2(height/2-y, width/2-x);
      94.     komet1 = cos(ang)*speed;
      95.     komet2 = sin(ang)*speed;
      96.   }
      97.   void movement(){
      98.     x +=komet1;
      99.     y +=komet2;
      100.   }
      101.   void kometer(){
      102.    rect(x,y,a,b);

      103.    noStroke();
      104.  
      105.   }        
      106.   void collision(){  
      107.     if ( dist(x, y, i1, i2) < i3) {
      108.       println("traff");            
      109.       x = 1000000;
      110.       y = 1000000;      
      111.       i++;
      112.     }
      113.   }  
      114. void smart(){
      115.    movement();
      116.    kometer();       
      117.    collision();  
      118. }
      119. }
      Hello.

      I want a rectangle to spin around it's on center.

      my rect is spawning outside the screen and will aim at the center.
      I want it to rotate all the way...   can figure it out, please help me.

      Best to do this in the class or in main?




      1. class komet{

      2.   int a = 15;
      3.   int b = 15;
      4.   float x = 0;
      5.   float y = 0;
      6.   float komet1,komet2;
      7.   
      8.   
      9.   komet(float _x, float _y){
      10.     x = _x;
      11.     y = _y;
      12.     float speed = 1;
      13.     float ang = atan2(height/2-y, width/2-x);
      14.     komet1 = cos(ang)*speed;
      15.     komet2 = sin(ang)*speed;
      16.   }
      17.   void movement(){
      18.     x +=komet1;
      19.     y +=komet2;
      20.   }
      21.   void kometer(){
      22.    rect(x,y,a,b);
      23.    noStroke();
      24.  
      25.   }        
      26.   void collision(){  
      27.     if ( dist(x, y, i1, i2) < i3) {
      28.       println("traff");            
      29.       x = 1000000;
      30.       y = 1000000;      
      31.       i++;
      32.     }
      33.   }  
      34. void smart(){
      35.    movement();
      36.    kometer();       
      37.    collision();  
      38. }
      39. }


      this is my mainer



      1. PImage jorden;
      2. import simpleML.*;
      3. int e = 0;

      4. ArrayList kometer = new ArrayList();

      5. int x = 0;
      6. int y = 0;
      7. int douche = 0;
      8. int i1 = 503;
      9. int i2 = 245;
      10. int i3 = 62;
      11. int i = 0;

      12. komet k;

      13. PFont Font;


      14. XMLRequest xmlRequest;
      15. int startTime;     // for the timer to make request ever N seconds
      16. String html = "";  // String to hold data from request




      17. void setup() {

      18.   // Creating and starting the request
      19.   xmlRequest = new XMLRequest(this, "http://search.twitter.com/search.rss?q=end");
      20.   xmlRequest.makeRequest();
      21.   size(height = 1000, width = 500);
      22.   
      23.   smooth();
      24. }



      25. void draw() {

      26.   background(0);  
      27.   ellipse(i1, i2, i3*2, i3*2);
      28.   fill(227, 222, 181);

      29.   // Every 5 seconds, make a new request
      30.   int now = millis();
      31.   if (now - startTime > 2000) {
      32.     xmlRequest.makeRequest();
      33.     println("Making request!");
      34.     startTime = now;
      35.   }
      36.   jorden = loadImage("earth.png"); //Bilden
      37.   imageMode(CENTER);
      38.   image(jorden, 500, 250);


      39.   for (int i = 0; i < kometer.size(); i++) {
      40.     komet k = (komet)kometer.get(i);

      41.     k.smart();
      42.   }
      43.   Font = loadFont("PressStartK-48.vlw");
      44.   textFont(Font,48);
      45.   text(i, 25, 75);
      46. }





      47. // When the request is complete
      48. void netEvent(XMLRequest ml) {
      49.   // Retrieving an array of all XML elements inside "<title*>" tags
      50.   String[] headlines = ml.getElementArray("title");
      51.   for (int i = 0; i < headlines.length; i++) {
      52.     // println(headlines[i]);
      53.   }

      54.   for (String html: headlines) {  
      55.     if (html.toLowerCase().contains("2012")) {    
      56.       douche++;      
      57.       println(douche);     


      58.       switch ((int) random(4)) {
      59.       case 0:
      60.         // top edge
      61.         k = new komet( random(width), -10 );
      62.         break;
      63.       case 1:
      64.         // right edge
      65.         k = new komet( width+10, random(height) );
      66.         break;
      67.       case 2:
      68.         // left edge
      69.         k = new komet( -10, random(height) );
      70.         break;
      71.       case 3:
      72.         // bot edge
      73.         k = new komet( random(width), height+10 );
      74.         break;
      75.       }
      76.       kometer.add(k);
      77.     }
      78.   }
      79. }


      I also want to explode the rectangle when it hits my "earth.png"
      Hello.
      Is it possible to import a simple animated gif 
      as I import a ordinary image file? (PImage)

      I want this dot to symbolize a comet.



      Or is it just stupid=?
      Perhaps it's quicker to animate inside
      processing?

      Can somebody point me in right direction please?



      hey !
        I'm about to   make   a program including   " meteors " that spawns  randomly   from different directions ou tside the   scetch, aiming for a certain point in center of screen.
      How do i do that?
      (For the moment they'r spawning randomly  but not outside sketch and not aiming for the center... and also in just one direction :)


      Code so far:


      PImage jorden;
      import simpleML.*;
      int e = 0;
      
      ArrayList kometer = new ArrayList();
      
      int x = 0;
      int y = 0;
      int douche = 0;
      
      
      XMLRequest xmlRequest;
      int startTime;     // for the timer to make request ever N seconds
      String html = "";  // String to hold data from request
      
      
      
      void setup() {
      
        // Creating and starting the request
        xmlRequest = new XMLRequest(this, "http://search.twitter.com/search.rss?q=end");
        xmlRequest.makeRequest();
        size(height = 1000, width = 500);
        ellipse(503, 245, 125, 125);
      }
      
      void draw() {
        background(0);
        // Every 5 seconds, make a new request
        int now = millis();
        if (now - startTime > 2000) {
          xmlRequest.makeRequest();
          println("Making request!");
          startTime = now;
        }
        jorden = loadImage("earth.jpg"); //Bilden
        imageMode(CENTER);
        image(jorden, 500, 250);
      
      
        for (int i = 0; i < kometer.size(); i++) {
          komet k = (komet)kometer.get(i);
          
          k.smart();
        }
      }
      
      
      
      // When the request is complete
      void netEvent(XMLRequest ml) {
        // Retrieving an array of all XML elements inside "<title*>" tags
        String[] headlines = ml.getElementArray("title");
        for (int i = 0; i < headlines.length; i++) {
          // println(headlines[i]);
        }
      
        for (String html: headlines) {  
          if (html.toLowerCase().contains("2012")) {    
            douche++;      
            println(douche);     
      
            kometer.add( new komet(random(0, width), random(0, height)));
          }
        }
      }
      
      ///////////////////////////////CLASS KOMET/////////////////////////////////////
      
      class komet{
      
        float x = 0;
        float y = 0;
        int komet1 = 10;
        int komet2 = 1;
        
        komet(float _x, float _y){
          x = _x;
          y = _y;
        }
        void movement(){
          x +=komet1;
          y +=komet2;
        }
        void kometer(){
          ellipse(x,y,25,25);
        }    
      
        void smart(){
        movement();
        kometer(); 
        
      
      }
      
      
      }
      HI!

      I work with   a program that   will be able to  read   different   keywords in   twitter   and then report   how   many of the specific   word I   have chosen I   want   to do this   in real time.

      So for   every new   Twitter   messages   that contain   the specific   word , a new   icon appears in my  sketch .


      I'm not a   veteran of the   processing ,   but I 've added   twitter4j
      and   got   processing   to report   the last 100   posts   that contain
      the word   "economy "   but as I said , I   want it in   real time.

      Please help me!

      edit:   
      I got 2 questions:
       
      1:
      How do I get my program to search in intervalls and fetch just the last entry, but not if the last entry is the same as previous serch?

      2: I want processing to display the results as either coloured boxes or icons in an grid.
      I'll have 4 keywords represented with 4 colors or icons. When somebody "tweet", a new color/icon will pop up next the "old"-one   eventually creating a pattern across the screen.
      How do I do this in the best way?