Guest User

Main FIle

a guest
Jan 20th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. particle[] elec = new particle[5];
  2.  
  3. boolean record = false;
  4.  
  5. void setup(){
  6.   float x=0,y=0;
  7.   int i,j;
  8.   float diam = 100;
  9.  
  10.   size(800,400);
  11.  
  12.   //Initialising the particle objects
  13.   for (int k = 0; k < elec.length; k++){
  14.     x = random(width/10, width/1.2);
  15.     y = random(height/10, height/1.2);
  16.     elec[k] = new particle(x,y);
  17.   }
  18.  
  19.   //Spawning at random places
  20.   for ( i = 0; i < elec.length; i++){
  21.  
  22.    if (i!=0){
  23.      
  24.      for (  j = 0; j < elec.length; j ++){
  25.  
  26.        if (dist(x,y,elec[j].getX(),elec[j].getY()) <= diam){
  27.          x = random(width/10, width/1.2);
  28.          y = random(height/10, height/1.2);
  29.          j = -1;
  30.        }
  31.      }
  32.   }
  33.    
  34.     elec[i] = new particle(x,y,diam,4,4,2);
  35.    
  36.    
  37.   }
  38.  
  39.  
  40. }
  41. void draw(){
  42.   background(0);
  43.  
  44.   for (int i = 0; i < elec.length; i++){
  45.     elec[i].update(elec);
  46.     elec[i].move();
  47.     elec[i].bounce();
  48.     if(record){
  49.       saveFrame("collide_#####.png");
  50.       fill(255,0,0);
  51.     } else {
  52.       fill(0,255,0);
  53.     }
  54.    
  55.     ellipse(width/1.01, height/1.01,5,5);
  56.   }
  57.  
  58. }
  59.  
  60. void keyPressed(){
  61.   if (key =='r' || key =='R'){
  62.     record = !record;
  63.   }
  64. }
  65.  
  66. //float getdistance(float x, float y, float x1, float y1){
  67. //  return pow(pow((x-x1),2)+pow((y-y1),2),0.5);
  68. //}
Add Comment
Please, Sign In to add comment