Package bouncingballs

Examples of bouncingballs.ManualBalls$Ball


        graphic = (Graphics2D)canvasImage.getGraphics();    
   
        balls = new ArrayList<Ball>();
       
        int numballs = 19;
      Ball ball;
     
      Color[] color = { Color.orange,  Color.gray,     Color.cyan,
                Color.green,   Color.lightGray,   Color.yellow,
                Color.magenta, Color.pink,     Color.red, 
                Color.white
              };
     
      int dx = 65;
      int dy = 65;
      int y = Config.MARGIN + 15;
      int x = Config.MARGIN + 15;
     
     // now generating the random balls
      for (int i=0;i<numballs;i++){
        int radius = 20 - ((int) Math.random() * 10);
        ball = new Ball(color[i%color.length], radius);
        ball.setCoords( x , y );
        x += dx;
        if( x > Config.WIDTH_E - dx){
          x = Config.MARGIN + 15;
          y += dy;
        }
        ball.setAngle(45 + Math.toRadians( (int) (Math.random() * 90) ));
        ball.setSpeed(1 + (int) (Math.random()*10));
        addBall(ball);
      }
     
      //run();
     
View Full Code Here


        }
    }
      graphic.setColor(antes);
      // now draw each ball
      for(Iterator<Ball> i= balls.iterator(); i.hasNext(); ) { 
        Ball b = (Ball) i.next();
        b.draw(graphic);
        // data from each ball
        if(Config.DEBUG)
        {
          graphic.drawString("a="+(int) Math.toDegrees(b.getAngle()), b.getX(), b.getY());
          graphic.drawString("s="+b.getSpeed(), b.getX(), b.getY()+15);
          graphic.drawString("r="+b.getRadius(), b.getX(), b.getY()+30);
         
        }
      }      
      repaint();
    }
View Full Code Here

          if(Config.DEBUG)
          System.out.print("V");
        }
      }
      for(Iterator<Ball> i= balls.iterator(); i.hasNext(); ) {  
        Ball b = ((Ball) i.next());
        if(b!=ball){
          int distance = ball.distance(b);
          int r2 = b.getRadius();
          if(distance <= r + r2){
            // two balls are bounced
            // we play with speeds, checked ball lost one point of speed
            // and crashed ball win one point of speed
            int v1 = ball.getSpeed();
            if(v1>3) ball.setSpeed(v1-1);
            int v2 = b.getSpeed();
            if(v2<10) b.setSpeed(v2+1);
            // check if the balls are mounted to calculate dist to separate them
            dist = distance<r+r2?r+r2-distance+1:dist;
            if(Config.DEBUG)
              System.out.println("distance: "+distance+",bounce between "+b.getNumber()+" & "+ball.getNumber());
            // now angle interchange except that balls goes in the same direction
            a = (180 + ang) % 360;
            b.setAngle(angle);
          }
        }
      }
      if(a!=9999){
        a = (360 + a) % 360;
View Full Code Here

      while(process){
        long t1 = System.currentTimeMillis();
        if(move// this is controlled by user with spacebar
          {
          for(Iterator<Ball> it = balls.iterator(); it.hasNext(); ) { 
            Ball b = (Ball) it.next();
            if(b.getNumber()==1 && dir>0) b.setAngle(0);
            if(b.getNumber()==1 && dir<0) b.setAngle(Math.PI);
            if(Config.DEBUG)
              System.out.println(">:"+b.getNumber());
            move(b);
          }
        }
        redraw();    
        long t2 = System.currentTimeMillis();
View Full Code Here

        graphic = (Graphics2D)canvasImage.getGraphics();    
   
        balls = new ArrayList<Ball>();
       
        int numballs = 9;
      Ball ball;
     
      Color[] color = { Color.orange,  Color.gray,     Color.cyan,
                Color.green,   Color.lightGray,   Color.yellow,
                Color.magenta, Color.pink,     Color.red, 
                Color.white
              };
     
      int dx = 65;
      int dy = 65;
      int y = Config.MARGIN + 15;
      int x = Config.MARGIN + 15;
     
     // now generating the random balls
      for (int i=0;i<numballs;i++){
        int radius = 20 - ((int) Math.random() * 10);
        ball = new Ball(color[i%color.length], radius);
        ball.setCoords( x , y );
        x += dx;
        if( x > Config.WIDTH_E - dx){
          x = Config.MARGIN + 15;
          y += dy;
        }
        ball.setAngle(45 + Math.toRadians( (int) (Math.random() * 90) ));
        ball.setSpeed(1 + (int) (Math.random()*10));
        addBall(ball);
      }
     
      //run();
     
View Full Code Here

        }
    }
      graphic.setColor(antes);
      // now draw each ball
      for(Iterator<Ball> i= balls.iterator(); i.hasNext(); ) { 
        Ball b = (Ball) i.next();
        b.draw(graphic);
        // data from each ball
        if(Config.DEBUG)
        {
          graphic.drawString("a="+(int) Math.toDegrees(b.getAngle()), b.getX(), b.getY());
          graphic.drawString("s="+b.getSpeed(), b.getX(), b.getY()+15);
          graphic.drawString("r="+b.getRadius(), b.getX(), b.getY()+30);
         
        }
      }      
      repaint();
    }
View Full Code Here

          if(Config.DEBUG)
          System.out.print("V");
        }
      }
      for(Iterator<Ball> i= balls.iterator(); i.hasNext(); ) {  
        Ball b = ((Ball) i.next());
        if(b!=ball){
          int distance = ball.distance(b);
          int r2 = b.getRadius();
          if(distance <= r + r2){
            // two balls are bounced
            // we play with speeds, checked ball lost one point of speed
            // and crashed ball win one point of speed
            int v1 = ball.getSpeed();
            if(v1>3) ball.setSpeed(v1-1);
            int v2 = b.getSpeed();
            if(v2<10) b.setSpeed(v2+1);
            // check if the balls are mounted to calculate dist to separate them
            dist = distance<r+r2?r+r2-distance+1:dist;
            if(Config.DEBUG)
              System.out.println("distance: "+distance+",bounce between "+b.getNumber()+" & "+ball.getNumber());
            // now angle interchange except that balls goes in the same direction
            a = (180 + ang) % 360;
            b.setAngle(angle);
          }
        }
      }
      if(a!=9999){
        a = (360 + a) % 360;
View Full Code Here

      while(process){
        long t1 = System.currentTimeMillis();
        if(move// this is controlled by user with spacebar
          {
          for(Iterator<Ball> it = balls.iterator(); it.hasNext(); ) { 
            Ball b = (Ball) it.next();
            if(b.getNumber()==1 && dir>0) b.setAngle(0);
            if(b.getNumber()==1 && dir<0) b.setAngle(Math.PI);
            if(Config.DEBUG)
              System.out.println(">:"+b.getNumber());
            move(b);
          }
        }
        redraw();    
        long t2 = System.currentTimeMillis();
View Full Code Here

TOP

Related Classes of bouncingballs.ManualBalls$Ball

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.