Back to index

wims  3.65+svn20090927
Public Member Functions | Package Attributes | Static Private Attributes
SplashPanel Class Reference
Inheritance diagram for SplashPanel:
Inheritance graph
[legend]
Collaboration diagram for SplashPanel:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SplashPanel (Plinko plinko)
void start ()
void run ()
void dropBall ()
void setup ()
void paintComponent (Graphics graphics)
void increment (PlinkoBall ball)
void drawBackground (int W, int H)
void mouseClicked (MouseEvent me)
void mouseEntered (MouseEvent me)
void mouseExited (MouseEvent me)
void mousePressed (MouseEvent me)
void mouseReleased (MouseEvent me)

Package Attributes

Plinko plinko
double w
double h
int TOTAL
int[] HIST
double MAX
Point[][] PINS
double DIST
double BALL_RAD
int PIN_RAD
int BINS = 20
PlinkoBall FIRST_BALL
int BALL_COUNT
int BOTTOM_MARGIN = 5
Image[] IMAGES
boolean newBackground = true
boolean active = true
Thread thread
Image background
Graphics2D backGraphics
int FUDGE = 200

Static Private Attributes

static final int hx = 15
static final int hy = 15
static final int bgGrey = 192

Detailed Description

Definition at line 7 of file SplashPanel.java.


Constructor & Destructor Documentation

SplashPanel.SplashPanel ( Plinko  plinko) [inline]

Definition at line 30 of file SplashPanel.java.

                                          {
              setBackground( Color.white );
              addMouseListener( this );   
              this.plinko = plinko;
              for ( int i = 0; i<25; i++ ){
                     dropBall();
                     FIRST_BALL.ROW = 10+(int)(10*Math.random());
                     FIRST_BALL.COL = (int)(FIRST_BALL.ROW*Math.random());
                     FIRST_BALL.C = 10;
                     FIRST_BALL.t = i%11;
              }
              start();
       }

Here is the call graph for this function:


Member Function Documentation

void SplashPanel.drawBackground ( int  W,
int  H 
) [inline]

Definition at line 217 of file SplashPanel.java.

                                              {
              Point p;

              Graphics2D backgroundgraphics = (Graphics2D) background.getGraphics();
              backgroundgraphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
              backgroundgraphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
              backgroundgraphics.setColor(Color.white);
              backgroundgraphics.fillRect( 0, 0, W, H );
              backgroundgraphics.setColor(Color.black);
              Image img = PlinkoBoard.getBall( PIN_RAD, Color.black );

              // draw pins
              for (int i=0; i<BINS-1; i++){
                     for (int j=0;j<=i;j++){
                            p = PINS[i][j];
                            //backgroundgraphics.fillOval(p.x-PIN_RAD,p.y-PIN_RAD,2*PIN_RAD,2*PIN_RAD);
                     backgroundgraphics.drawImage(img, (int)(p.x-PIN_RAD),(int)(p.y-PIN_RAD),this );
                     }
              }
              repaint();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SplashPanel.dropBall ( ) [inline]

Definition at line 65 of file SplashPanel.java.

Here is the caller graph for this function:

void SplashPanel.increment ( PlinkoBall  ball) [inline]

Definition at line 160 of file SplashPanel.java.

                                            {
              // if ball has landed on pin, reset t to 0 and pick a direction
              if ( ball.t == ball.C && ball.ROW < BINS-2 ){
                     ball.ROW++;
                     ball.COL += ball.DIR;
                     ball.t = 0;
                     ball.DIR = 0;
                     if ( Math.random() < 0.5 ) ball.DIR = 1;

                     ball.C = 10;
                     
                     //if ( C>1 ) C += spaz;
              }

              double dx = DIST*ball.t*(2*ball.DIR - 1)/ball.C;

              if ( ball.ROW < 0 ){ // ball falling onto top pin
                     ball.X = PINS[0][0].x;
                     dx = Math.abs(dx);
                     ball.Y = PINS[0][0].y - DIST + DIST*ball.t*ball.t/(ball.C*ball.C);
              } else if ( ball.ROW < BINS-2 ) {
                     ball.X = PINS[ball.ROW][ball.COL].x + dx;
                     dx = Math.abs(dx);
                     //Y = PlinkoBoard.PINS[ROW][COL].y - (int)(dx*(A*dx/PlinkoBoard.DIST+B));
                     ball.Y = PINS[ball.ROW][ball.COL].y - DIST*PlinkoBoard.DYS[ball.C][ball.t];
              } else { // ball falling into bin
                     ball.X = PINS[ball.ROW][ball.COL].x + dx;
                     if ( dx>0 ){ 
                            ball.X = Math.min(ball.X,PINS[ball.ROW][ball.COL].x + 2*DIST - BALL_RAD );
                     } else {
                            ball.X = Math.max(ball.X,PINS[ball.ROW][ball.COL].x - 2*DIST + BALL_RAD + 1);
                     }
                     dx = Math.abs(dx);
                     ball.Y = PINS[ball.ROW][ball.COL].y  - dx*(ball.A*dx/DIST+ball.B);
              }

              ball.t++;

              if ( ball.Y > h - BOTTOM_MARGIN - PIN_RAD ){
                     if ( ball.previousBall != null && ball.nextBall != null){
                            ball.previousBall.nextBall = ball.nextBall;
                            ball.nextBall.previousBall = ball.previousBall;
                     } else if ( ball.previousBall != null && ball.nextBall == null ) {
                            ball.previousBall.nextBall = null;
                     } else if ( ball.previousBall == null && ball.nextBall != null ) {
                            ball.nextBall.previousBall = null;
                            FIRST_BALL = ball.nextBall;
                     } else  {
                            FIRST_BALL = null;
                            //plinko.bins.setEnabled( true );
                     }

                     BALL_COUNT--;
              }
    }

Here is the caller graph for this function:

void SplashPanel.mouseClicked ( MouseEvent  me) [inline]

Definition at line 240 of file SplashPanel.java.

                                                {
              active = false;
              plinko.showFrame();
       }

Here is the call graph for this function:

void SplashPanel.mouseEntered ( MouseEvent  me) [inline]

Definition at line 246 of file SplashPanel.java.

                                                {
       }
void SplashPanel.mouseExited ( MouseEvent  me) [inline]

Definition at line 250 of file SplashPanel.java.

                                               {
       }
void SplashPanel.mousePressed ( MouseEvent  me) [inline]

Definition at line 254 of file SplashPanel.java.

                                                {
       }
void SplashPanel.mouseReleased ( MouseEvent  me) [inline]

Definition at line 258 of file SplashPanel.java.

                                               {
       }
void SplashPanel.paintComponent ( Graphics  graphics) [inline]

Definition at line 117 of file SplashPanel.java.

                                                      {
              // have a copy of the background on which to draw
              w = getWidth();
              h = getHeight();
              
              w = Math.max( getWidth(),getHeight() ) + FUDGE;
              h = w;

              Graphics2D g = (Graphics2D)graphics;
              g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

              if ( background == null || background.getWidth(this) != h || background.getHeight(this) != w ){
                     setup();
                     background = createImage( (int)w, (int)h );
                     drawBackground((int)w,(int)h);
              }

              g.drawImage( background, 0, 0, this );

              // run through all active balls and draw them on the image
              PlinkoBall ball = FIRST_BALL;

              int red;
              int green;
              int blue;
              while ( ball != null ){
                     graphics.drawImage( IMAGES[ball.spaz], (int)(ball.X - BALL_RAD),  (int)(ball.Y - 2*BALL_RAD - PIN_RAD + 1), this );
                     if ( active ) increment( ball );
                     ball = ball.nextBall;
              }
              //g.drawImage(image,0,0,this);

              w = getWidth();
              h = getHeight();
              g.setColor( new Color( 128,128,128,220 ) );
              g.setFont( new Font("Helvetica",Font.BOLD,plinko.font_size) );
              //String str = "CLICK ANYWHERE TO BEGIN";
              String str = plinko.click_text;
              
              g.drawString( str, (int)(w-g.getFontMetrics().stringWidth(str)-5), (int)(h-5) );
       }

Here is the call graph for this function:

void SplashPanel.run ( ) [inline]

Definition at line 51 of file SplashPanel.java.

                        {
           while ( active ){
              if ( Math.random() < 0.4 ){
                  dropBall();
                  FIRST_BALL.ROW = 11;
                  FIRST_BALL.COL = (int)(FIRST_BALL.ROW*Math.random());
                  FIRST_BALL.C = 10;
              }
              repaint();
              try {Thread.sleep(100);} catch (InterruptedException e){}
           }
       }

Here is the call graph for this function:

void SplashPanel.setup ( ) [inline]

Definition at line 81 of file SplashPanel.java.

                       {
              if(plinko.wims_exercise == true){ FUDGE = 100;}
              if ( h-BOTTOM_MARGIN<h/2 ){
                     DIST = (double)(h-BOTTOM_MARGIN)/BINS;
              } else {
                     DIST = (double)(w-10)/(2*BINS);
              }

              PIN_RAD = (int)DIST/9 + 1;
              BALL_RAD = Math.max(2*DIST/7,2.0) + 1;

              // create images of colored balls
              IMAGES = new Image[ PlinkoBoard.COLORS.length ];
              Graphics2D g;
              int red;
              int green;
              int blue;
              for ( int i=0; i<PlinkoBoard.COLORS.length; i++ ){
                     IMAGES[i] = PlinkoBoard.getBall( BALL_RAD, PlinkoBoard.COLORS[i] );
              }

              PINS = new Point[BINS][];
              for (int i=0; i<BINS; i++){
                     PINS[i] = new Point[i+1];
                     for (int j=0; j<=i; j++){
                            PINS[i][j]= new Point((int)(DIST*(2*j-i)+w/2)-FUDGE/2,(int)(DIST*(i+1))-(FUDGE-15));
                     }
              }             
              
              // pins at the base of each bin
              for (int i=0; i<BINS; i++){
                     PINS[BINS-1][i]= new Point((int)(DIST*(2*i-BINS+1)+w/2),(int)(h-30-BALL_RAD));
              }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SplashPanel.start ( ) [inline]

Definition at line 44 of file SplashPanel.java.

                          {
              active = true;
              thread = new Thread(this);
              thread.start();
       }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 28 of file SplashPanel.java.

Graphics2D SplashPanel.backGraphics [package]

Definition at line 78 of file SplashPanel.java.

Image SplashPanel.background [package]

Definition at line 77 of file SplashPanel.java.

int SplashPanel.BALL_COUNT [package]

Definition at line 20 of file SplashPanel.java.

double SplashPanel.BALL_RAD [package]

Definition at line 16 of file SplashPanel.java.

final int SplashPanel.bgGrey = 192 [static, private]

Definition at line 25 of file SplashPanel.java.

int SplashPanel.BINS = 20 [package]

Definition at line 18 of file SplashPanel.java.

int SplashPanel.BOTTOM_MARGIN = 5 [package]

Definition at line 21 of file SplashPanel.java.

double SplashPanel.DIST [package]

Definition at line 15 of file SplashPanel.java.

Definition at line 19 of file SplashPanel.java.

int SplashPanel.FUDGE = 200 [package]

Definition at line 79 of file SplashPanel.java.

double SplashPanel.h [package]

Definition at line 10 of file SplashPanel.java.

int [] SplashPanel.HIST [package]

Definition at line 12 of file SplashPanel.java.

final int SplashPanel.hx = 15 [static, private]

Definition at line 23 of file SplashPanel.java.

final int SplashPanel.hy = 15 [static, private]

Definition at line 24 of file SplashPanel.java.

Image [] SplashPanel.IMAGES [package]

Definition at line 26 of file SplashPanel.java.

double SplashPanel.MAX [package]

Definition at line 13 of file SplashPanel.java.

Definition at line 27 of file SplashPanel.java.

int SplashPanel.PIN_RAD [package]

Definition at line 17 of file SplashPanel.java.

Point [][] SplashPanel.PINS [package]

Definition at line 14 of file SplashPanel.java.

Definition at line 8 of file SplashPanel.java.

Thread SplashPanel.thread [package]

Definition at line 29 of file SplashPanel.java.

int SplashPanel.TOTAL [package]

Definition at line 11 of file SplashPanel.java.

double SplashPanel.w [package]

Definition at line 9 of file SplashPanel.java.


The documentation for this class was generated from the following file: