spawn from different directions outside the screen
              in 
             Programming Questions 
              •  
              1 years ago    
            
 
            
            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(); 
  
}
}
                  | 
               
 
              
              1  
            
 
            