/home/ssingh6/NetBeansProjects/CS1/src/npw/AlternativeBalloons.java
  1 /*
  2  * To change this license header, choose License Headers in Project Properties.
  3  * To change this template file, choose Tools | Templates
  4  * and open the template in the editor.
  5  */
  6 package npw;
  7 import java.awt.Color;
  8 import java.util.Random;
  9 import javax.swing.SwingUtilities;
 10 import painter.SPainter;
 11 import shapes.SCircle;
 12 import shapes.SSquare;
 13 
 14 /**
 15  *
 16  * @author ssingh6
 17  */
 18 
 19 public class AlternativeBalloons {
 20  
 21      // REQUIRED INFRASTRUCTURE
 22      
 23      public AlternativeBalloons(){
 24          paintTheImage();
 25      }
 26      
 27      public static void main(String[] args) {
 28          SwingUtilities.invokeLater(new Runnable(){
 29              public void run(){
 30                  new AlternativeBalloons();
 31              }
 32          });
 33      }
 34      Color color1= randomColor();
 35      Color color2= randomColor();
 36      Color color3 =randomColor();
 37      Color color4= randomColor();
 38      Color color5= randomColor();
 39      Color color6= randomColor();
 40      
 41      // THE PAINTER DOING ITS THING
 42     
 43      private void paintTheImage(){
 44          SPainter painter = new SPainter("Balloons",600,600);
 45          paintSky(painter); // ask Netbeans to generate the stub
 46          int nrOfBalloons = 300;
 47          paintBalloons(painter,nrOfBalloons);
 48          // ask Netbeans to generate the stub
 49      }
 50 
 51      private void paintSky(SPainter painter) {
 52          painter.setColor(Color.BLUE);
 53          SSquare sky = new SSquare(2000);
 54          painter.paint(sky);
 55      }
 56  
 57      private void paintBalloons(SPainter painter, int nrOfBalloons) {
 58         int i = 1;
 59          while ( i <= nrOfBalloons ) {
 60              paintOneBalloon(painter); // ask Netbeans to generate the stub
 61              i = i + 1;
 62          }
 63      }
 64  
 65       private void paintOneBalloon(SPainter painter) {
 66          Random rgen = new Random();
 67           int rn = rgen.nextInt(6);
 68           if (rn == 0 ) {
 69              painter.setColor(color1);
 70         } else if ( rn == 1 ) {
 71               painter.setColor(color2);
 72           } else if ( rn == 2 ) {
 73              painter.setColor(color3);
 74           } else if ( rn == 3 ) {
 75               painter.setColor(color4);
 76           } else if ( rn == 4 ) {
 77               painter.setColor(color5);
 78           } else if ( rn == 5 ) {
 79               painter.setColor(color6);
 80           }
 81           painter.move();
 82           int balloonRadius = 30;
 83           SCircle balloon = new SCircle(balloonRadius);
 84           painter.paint(balloon);
 85           painter.setColor(Color.BLACK);
 86           painter.draw(balloon);
 87       }
 88 
 89     private Color randomColor() {
 90         int rv= (int) (Math.random()*256);
 91         int gv= (int) (Math.random()*256);
 92         int bv= (int) (Math.random()*256);
 93         Color color = new Color(rv,gv,bv);
 94         return color;
 95     }
 96      }
 97  
 98 
 99         
100