Back to index

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

List of all members.

Public Member Functions

 PlinkoBoard (Plinko plinko)
void setup ()
void newHist ()
String ReadData ()
void LimitReached ()
void run ()
void kill ()
void dropBall (boolean sound)
void paintComponent (Graphics g)
void drawNormal ()
void increment (PlinkoBall ball)
void updateHist (int i)
void drawStats (Graphics g)
void drawHist (Graphics2D g)
void drawBackground ()
void drawBackground (int W, int H)
void keyTyped (KeyEvent ke)
void keyPressed (KeyEvent ke)
void keyReleased (KeyEvent ke)
void mouseReleased (MouseEvent me)
void mouseEntered (MouseEvent me)
void mouseExited (MouseEvent me)
void updatePercent ()
void mouseClicked (MouseEvent me)
void mousePressed (MouseEvent me)
void mouseDragged (MouseEvent me)
void mouseMoved (MouseEvent me)

Static Public Member Functions

static Image getBall (double R, Color color)

Package Attributes

double COUNT
double TOTAL
double TOTAL_SQUARES
long[] HIST
float MAX
double[][][] PINS
double DIST
double BALL_RAD
int PIN_RAD
int BINS
int W
int H
PlinkoBall FIRST_BALL
int BALL_COUNT
int BOTTOM_MARGIN = 5
int LEFT
int RIGHT
double PERCENT
int CURRENT_BIN = 0
int showstats = 0
int maximum_balls
String start_number = "0"
int incr = 1
Image[] IMAGES
Thread thread
boolean active
Image background
Image image
Graphics2D graphics
Plinko plinko

Static Package Attributes

static double[][] DYS
static Color[] COLORS = { Color.red, Color.magenta, Color.orange, Color.yellow, Color.green, Color.blue, Color.cyan }

Detailed Description

Definition at line 8 of file PlinkoBoard.java.


Constructor & Destructor Documentation

PlinkoBoard.PlinkoBoard ( Plinko  plinko) [inline]

Definition at line 61 of file PlinkoBoard.java.

                                       {
       super();
       this.plinko = plinko;
       setup();
       newHist();

       FIRST_BALL = null;
       BALL_COUNT = 0;
       active = false;

       DYS = new double[12][];

       for ( double i=0.0; i<12.0; i++ ){
           DYS[(int)i] = new double[ (int)i ];
           for ( double j=0.0; j<i; j++ ){
              DYS[(int)i][(int)j] = PlinkoBall.A*j*j/(i*i) + PlinkoBall.B*j/i;
           }
       }

       addKeyListener( this );
       addMouseListener( this );
       // jm.evers: if the applet is in an wims exercise...read appletparam and start buckets_number with 1 instead of 0
       maximum_balls=(int)plinko.total_balls - 1;
       if(plinko.wims_exercise == false){ showstats = 1;}else{ start_number="1"; incr=2; }
    }

Here is the call graph for this function:


Member Function Documentation

void PlinkoBoard.drawBackground ( ) [inline]

Definition at line 501 of file PlinkoBoard.java.

                                {
              drawBackground( getWidth(), getHeight() );
    }

Here is the caller graph for this function:

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

Definition at line 506 of file PlinkoBoard.java.

                                              {
              double[] 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 = 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.fill( new Ellipse2D.Double(p[0]-PIN_RAD,p[1]-PIN_RAD,2*PIN_RAD,2*PIN_RAD) );
                     backgroundgraphics.drawImage(img, (int)(p[0]-PIN_RAD),(int)(p[1]-PIN_RAD),this );
                     }
              }

              String s;
              backgroundgraphics.setFont( new Font("Helvetica",Font.BOLD,Math.min((int)(4*DIST)/3,50)) );
              FontMetrics fm = backgroundgraphics.getFontMetrics();
              // draw lines and numbers
              p = PINS[BINS-1][0];
              backgroundgraphics.draw( new Line2D.Double( p[0]-DIST,H-100-BOTTOM_MARGIN,p[0]-DIST,H-BOTTOM_MARGIN) );
              backgroundgraphics.setColor( Color.darkGray );
              backgroundgraphics.drawString(start_number,(int)(p[0] - fm.stringWidth("0")/2), H-100-BOTTOM_MARGIN+Math.min((int)(4*DIST)/3, 50) );
              for (int i=0; i<BINS-1; i++){
                     p = PINS[BINS-2][i];
                     s = ""+(i+incr);
                     backgroundgraphics.setColor( Color.darkGray );
                     backgroundgraphics.drawString(s,(int)(p[0] + DIST - fm.stringWidth(s)/2),H-100-BOTTOM_MARGIN+Math.min((int)(4*DIST)/3,50));
                     backgroundgraphics.setColor( Color.black );
                     backgroundgraphics.draw( new Line2D.Double( p[0],H-100-BOTTOM_MARGIN,p[0],H-BOTTOM_MARGIN) );
              }
              p = PINS[BINS-1][BINS-1];
              backgroundgraphics.draw( new Line2D.Double(p[0]+DIST,H-100-BOTTOM_MARGIN,p[0]+DIST,H-BOTTOM_MARGIN) );
              backgroundgraphics.draw( new Line2D.Double(0,H-BOTTOM_MARGIN,W,H-BOTTOM_MARGIN) );
              repaint();
    }

Here is the call graph for this function:

void PlinkoBoard.drawHist ( Graphics2D  g) [inline]

Definition at line 461 of file PlinkoBoard.java.

                                        {
              long h;
              double x0;
              double x1;
              String str;
              W = getWidth();
              H = getHeight();
              Rectangle2D rect;

              for (int i=0; i<BINS; i++){
                     if ( i==0 ){
                            x0 = PINS[BINS-1][0][0]-DIST;
                            x1 = PINS[BINS-2][0][0];
                     } else if ( i==BINS-1 ){
                            x0 = PINS[BINS-2][BINS-2][0];
                            x1 = PINS[BINS-1][BINS-1][0]+DIST;
                     } else {
                            x0 = PINS[BINS-2][i-1][0];
                            x1 = PINS[BINS-2][i][0];
                     }

                     //Draw bar
                     h = HIST[i];
                     if (MAX>100) h=(int)(100.0*h/MAX);
                     g.setColor( new Color(255,0,0,175) );
                     if ( i >= LEFT && i <= RIGHT ) g.setColor( new Color(0,255,0,175) );
                     rect = new Rectangle2D.Double(x0,H-h-BOTTOM_MARGIN,x1-x0,h);
                     g.fill( rect );
                     g.setColor(Color.black);
                     g.setStroke( new BasicStroke(1.0f) );
                     g.draw( rect );
              }
       
              // draw line under current bin
              g.setColor( Color.black );
              g.setStroke( new BasicStroke(3.0f) );
              g.draw( new Line2D.Double(PINS[BINS-1][CURRENT_BIN][0]-DIST,H-BOTTOM_MARGIN+3,PINS[BINS-1][CURRENT_BIN][0]+DIST,H-BOTTOM_MARGIN+3) );
    }

Here is the caller graph for this function:

void PlinkoBoard.drawNormal ( ) [inline]

Definition at line 330 of file PlinkoBoard.java.

                            {
    }
void PlinkoBoard.drawStats ( Graphics  g) [inline]

Definition at line 418 of file PlinkoBoard.java.

                                     {
    //jm.evers : if in a wims_exercise we show a limited amount of statistical data...
       if(showstats == 1){
           plinko.count.setText(plinko.label_count+ (int)COUNT);
           plinko.current_bin.setText(plinko.label_bin + CURRENT_BIN);
           plinko.current_bin_count.setText(plinko.label_bin_count + HIST[CURRENT_BIN]);
           if(COUNT > 0.0D){
              double d = TOTAL / COUNT;
               plinko.mean.setText(plinko.label_mean + (float)d);
               plinko.variance.setText(plinko.label_variance + (float)(TOTAL_SQUARES / COUNT - d * d));
              plinko.current_bin_prob.setText(plinko.label_bin_probability + (float)((double)(int)((double)(0x186a0L * HIST[CURRENT_BIN]) / COUNT) / 1000D) + "%");
              if(LEFT < BINS){
                  if(LEFT == RIGHT){
                     plinko.confidence.setText(plinko.label_confidence + (float)((double)(int)((100000D * PERCENT) / COUNT) / 1000D) + plinko.some_text + LEFT + ".");
                  } 
                  else 
                  {
                     plinko.confidence.setText(plinko.label_confidence + (float)((double)(int)((100000D * PERCENT) / COUNT) / 1000D) + plinko.some_text + LEFT + plinko.through + RIGHT + ".");
                  }
              } 
              else
              {
                  plinko.confidence.setText(plinko.label_confidence );
              }
           } 
           else
           {
              plinko.mean.setText(plinko.label_mean );
               plinko.variance.setText(plinko.label_variance);
               plinko.current_bin_prob.setText(plinko.label_bin_probability);
               plinko.confidence.setText(plinko.label_confidence);
           }
       }
       else
       {
       // just the total COUNT and "balls per active bin" 
           plinko.count.setText(plinko.label_count+ (int)COUNT);
           plinko.current_bin.setText(plinko.label_bin + (CURRENT_BIN+1));
           plinko.current_bin_count.setText(plinko.label_bin_count + HIST[CURRENT_BIN]);
       }
    }

Here is the caller graph for this function:

void PlinkoBoard.dropBall ( boolean  sound) [inline]

Definition at line 271 of file PlinkoBoard.java.

                                         {
       BALL_COUNT++;
       // jm.evers : I don't know of another/better way to get the system to stop at a given [param] number of balls...
       if(COUNT == maximum_balls ){LimitReached();}
       if ( FIRST_BALL == null ){
           FIRST_BALL = new PlinkoBall();
           FIRST_BALL.sound = sound;
       } else {
           FIRST_BALL.previousBall = new PlinkoBall();
           FIRST_BALL.previousBall.sound = sound;
           FIRST_BALL.previousBall.nextBall = FIRST_BALL;
           FIRST_BALL = FIRST_BALL.previousBall;
       }

       try { Thread.sleep(0);} catch (InterruptedException e){}
           
       if ( !active ){
           active = true;
           thread = new Thread(this);
           thread.start();
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static Image PlinkoBoard.getBall ( double  R,
Color  color 
) [inline, static]

Definition at line 151 of file PlinkoBoard.java.

                                                           {
              BufferedImage image = new BufferedImage( (int)(2*R+2), (int)(2*R+2), BufferedImage.TYPE_INT_ARGB);
                                          
              int red;
              int grn;
              int blu;
              double[] n = new double[3];
              double[] e = new double[3];
              double[] l = {-5,5,10};
              double ll = Math.sqrt(150);
              double F;
              double G;

              for ( int i=0; i<(int)(2*R+2); i++ ){
                     for ( int j=0; j<(int)(2*R+2); j++ ){
                            if ( (R-i)*(R-i) + (R-j)*(R-j) <= (R-1)*(R-1) ){        
                                   // vector normal to sphere
                                   n[0] = (i - R)/R;
                                   n[1] = (R - j)/R;
                                   n[2] = Math.sqrt(1 - n[0]*n[0] - n[1]*n[1]);
                                   
                                   F = (n[0]*l[0] + n[1]*l[1] + n[2]*l[2])/Math.sqrt(l[0]*l[0] + l[1]*l[1] + l[2]*l[2]);
                                   F = (1+F)/2;
                                   G = Math.pow(F,20.0);

                                   red = (int)(color.getRed()*(F-G) + G*255);
                                   grn = (int)(color.getGreen()*(F-G) + G*255);
                                   blu = (int)(color.getBlue()*(F-G) + G*255);

                                   image.setRGB(i,j, (255<<24) + (red<<16) + (grn<<8) + blu );
                            } else if ( (R-i)*(R-i) + (R-j)*(R-j) <= (R+1)*(R+1) ){
                                   red = 0;
                                   grn = 0;
                                   blu = 0;
                                   
                                   for ( double di = -0.33; di<0.5; di+=0.33 ){
                                          for ( double dj = -0.33; dj<0.5; dj+=0.33 ){
              
                                                 if ( (R-(i+di))*(R-(i+di)) + (R-(j+dj))*(R-(j+dj)) <= R*R ){
                                                        n[0] = (i + dj - R)/R;
                                                        n[1] = (R - (j+dj))/R;
                                                        n[2] = Math.sqrt(1 - n[0]*n[0] - n[1]*n[1]);

                                                        F = (n[0]*l[0] + n[1]*l[1] + n[2]*l[2])/ll;
                                                        F = (1+F)/2;
                                                        G = Math.pow(F,20.0);
                                                 } else {
                                                        F = 1;
                                                        G = 1;
                                                 }
                                                 red += (int)(color.getRed()*(F-G) + G*255);
                                                 grn += (int)(color.getGreen()*(F-G) + G*255);
                                                 blu += (int)(color.getBlue()*(F-G) + G*255);

                                          }
                                   }
       
                                   red /= 9;
                                   grn /= 9;
                                   blu /= 9;
                                   
                                   image.setRGB(i,j, ((255-(red+grn+blu)/3)<<24) + (red<<16) + (grn<<8) + blu );
                            }
                     }
              }
              return image;
       }

Here is the caller graph for this function:

void PlinkoBoard.increment ( PlinkoBall  ball) [inline]

Definition at line 334 of file PlinkoBoard.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;
                     
                     // pick a new direction
                     
                     // jm.evers: reading controls or applet param...plinko.chance is parameter
                     if(plinko.wims_exercise == false){
                         if ( Math.random() < ((Double)plinko.prob.getValue()).doubleValue() ) ball.DIR = 1;
                     }
                     else
                     {
                         if ( Math.random() <  plinko.chance ){ ball.DIR = 1;}
                     }

                     // update speed
                     ball.C = 11-((Integer)plinko.rate.getValue()).intValue();
                     
                     if ( ball.sound ) Plinko.ping.play();
              }

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

              if ( ball.ROW < 0 ){ 
                     // ball falling onto top pin
                     ball.X = PINS[0][0][0];
                     dx = Math.abs(dx);
                     ball.Y = PINS[0][0][1] - DIST + DIST*ball.t*ball.t/(ball.C*ball.C);
              } else if ( ball.ROW < BINS-2 ) {
                     ball.X = PINS[ball.ROW][ball.COL][0] + dx;
                     dx = Math.abs(dx);
                     ball.Y = PINS[ball.ROW][ball.COL][1] - DIST*DYS[ball.C][ball.t];
              } else { 
                     // ball falling into bin
                     // dx = DIST*ball.t*(2*ball.DIR - 1)/10.0;
                     ball.X = PINS[ball.ROW][ball.COL][0] + dx;
                     if ( dx>0 ){ 
                            ball.X = Math.min(ball.X,PINS[ball.ROW][ball.COL][0] + 2*DIST - BALL_RAD );
                     } else {
                            ball.X = Math.max(ball.X,PINS[ball.ROW][ball.COL][0] - 2*DIST + BALL_RAD + 1);
                     }
                     dx = Math.abs(dx);
                     ball.Y = PINS[ball.ROW][ball.COL][1]  - 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--;
                     updateHist(ball.COL+ball.DIR);
                     if ( ball.sound ) Plinko.click.play();
              }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void PlinkoBoard.keyPressed ( KeyEvent  ke) [inline]

Definition at line 554 of file PlinkoBoard.java.

                                         {
              int code = ke.getKeyCode();
              char key = ke.getKeyChar();

              if ( key >= '0' && key <= '4' ){
                     int x = key - '0';
                     int n = 1;
                     for (int i=0; i<x; i++ ){
                            n *= 10;
                     }/*
                     plinko.countdown = n;
                     if ( !plinko.active ){
                            plinko.start();
                            plinko.bins.setEnabled( false );
                            plinko.thread = new Thread(plinko);
                            plinko.thread.start();
                            //start.setText("Stop");
                     }*/
                     for (int i=0; i<n; i++){
                            dropBall( n == 1 );
                     }
              } else if ( code == 37 ){  // left arrow
                     CURRENT_BIN--;
                     if ( CURRENT_BIN<0 ) CURRENT_BIN = BINS - 1;
                     updatePercent();
                     repaint();
              } else if ( code == 39 ){  // right arrow
                     CURRENT_BIN++;
                     if ( CURRENT_BIN>BINS-1 ) CURRENT_BIN = 0;
                     updatePercent();
                     repaint();
              } else if ( code == KeyEvent.VK_ENTER ){ // return or enter
              } else if ( key == ' ' ){
                     plinko.toggleStart();
              } else if (key==20){ //control t - toggle erasing
              } else if (key==3){ //control c - clear screen
              } else if (key==24){ //control x - kill all threads
              }
    }

Here is the call graph for this function:

void PlinkoBoard.keyReleased ( KeyEvent  ke) [inline]

Definition at line 595 of file PlinkoBoard.java.

{}
void PlinkoBoard.keyTyped ( KeyEvent  ke) [inline]

Definition at line 550 of file PlinkoBoard.java.

                                       {
    }
void PlinkoBoard.kill ( ) [inline]

Definition at line 261 of file PlinkoBoard.java.

                      {
              FIRST_BALL = null;
              if ( plinko.start.getText().equals(plinko.start_text) ){
                     active = false; 
                     plinko.active = false;
                     plinko.bins.setEnabled( true );
              }
    }
void PlinkoBoard.LimitReached ( ) [inline]

Definition at line 242 of file PlinkoBoard.java.

                              {
           plinko.active = true;
           FIRST_BALL=null;
           plinko.toggleStart();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void PlinkoBoard.mouseClicked ( MouseEvent  me) [inline]

Definition at line 621 of file PlinkoBoard.java.

                                             {
       requestFocus();
       Point p = me.getPoint();
       int bin;
       if ( p.x + DIST> PINS[BINS-1][0][0] && p.x-DIST < PINS[BINS-1][BINS-1][0] && p.y> H-100-BOTTOM_MARGIN && p.y<H-BOTTOM_MARGIN){
           bin = 0; 
           while ( bin<BINS-1 ){
              if ( p.x + DIST < PINS[BINS-1][bin+1][0] ) break;
               bin++;
           }
           CURRENT_BIN = bin;
           updatePercent();
           repaint();
       }                    
    }

Here is the call graph for this function:

void PlinkoBoard.mouseDragged ( MouseEvent  me) [inline]

Definition at line 640 of file PlinkoBoard.java.

{}
void PlinkoBoard.mouseEntered ( MouseEvent  me) [inline]

Definition at line 599 of file PlinkoBoard.java.

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

Definition at line 601 of file PlinkoBoard.java.

{}
void PlinkoBoard.mouseMoved ( MouseEvent  me) [inline]

Definition at line 642 of file PlinkoBoard.java.

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

Definition at line 638 of file PlinkoBoard.java.

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

Definition at line 597 of file PlinkoBoard.java.

{}
void PlinkoBoard.newHist ( ) [inline]

Definition at line 220 of file PlinkoBoard.java.

                         {
              COUNT = 0;
              TOTAL = 0;
              TOTAL_SQUARES = 0;
              MAX = 0;
              PERCENT = 0;

              HIST = new long[ BINS ];
              for (int i=0; i<BINS; i++){
                     HIST[i] = 0;
              }
    }

Here is the caller graph for this function:

void PlinkoBoard.paintComponent ( Graphics  g) [inline]

Definition at line 294 of file PlinkoBoard.java.

                                            {
              // have a copy of the background on which to draw
              W = getWidth();
              H = getHeight();

              if ( background == null || background.getWidth(this) != W || background.getHeight(this) != H || image == null || image.getWidth(this) != W || image.getHeight(this) != H ){
                     setup();
                     background = createImage( W, H );
                     drawBackground(W,H);
                     image = createImage( W, H );
                     graphics = (Graphics2D) image.getGraphics();
                     graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
                     graphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
              }

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

              // run through all active balls and draw them on the image
              PlinkoBall ball = FIRST_BALL;
              while ( ball != null ){
                     graphics.drawImage( IMAGES[ball.spaz], (int)(ball.X - BALL_RAD),  (int)(ball.Y - 2*BALL_RAD - PIN_RAD + 1), this );
                     //if ( ball.t == ball.C && ball.ROW < BINS-2 ) Plinko.click.play();
                     //try {
                            increment( ball );
                     //} catch ( NullPointerException npe ) {
                     //}
                     ball = ball.nextBall;
              }
              drawHist( graphics );
       //     if(showstats==1){
                  drawStats( graphics );
       //     }
              g.drawImage(image,0,0,this);
    }

Here is the call graph for this function:

String PlinkoBoard.ReadData ( ) [inline]

Definition at line 234 of file PlinkoBoard.java.

                            {
       String reply="";
       for(int i=0;i<HIST.length;i++){
           if(i != 0){reply=reply+","+HIST[i];}else{reply=""+HIST[0];}
       }
       return reply;
    }

Here is the caller graph for this function:

void PlinkoBoard.run ( ) [inline]

Definition at line 248 of file PlinkoBoard.java.

                     {
       while ( BALL_COUNT>0 ){
           repaint();
           try {Thread.sleep(50);} catch (InterruptedException e){}
       }
       repaint();
       active = false;
       plinko.active = false;
       plinko.bins.setEnabled( true );
    }
void PlinkoBoard.setup ( ) [inline]

Definition at line 87 of file PlinkoBoard.java.

                       {
              W = getWidth();
              H = getHeight();

              BINS = ((Integer)plinko.bins.getValue()).intValue();
              CURRENT_BIN = BINS/2;
              LEFT = BINS+1;
              RIGHT = BINS;
              PERCENT = 0;

              if ( H-100-BOTTOM_MARGIN<W/2 ){
                     DIST = (double)(H-100-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[ COLORS.length ];
              Graphics2D g;
              int red;
              int green;
              int blue;
              for ( int i=0; i<COLORS.length; i++ ){
                     IMAGES[i] = getBall( BALL_RAD, COLORS[i] );
                     /*
                     IMAGES[i] = new BufferedImage( (int)(2*BALL_RAD+2), (int)(2*BALL_RAD+2), BufferedImage.TYPE_INT_ARGB);
                     g = (Graphics2D)(IMAGES[i].getGraphics());
                     g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
                     g.setBackground( new Color(0,0,0,255) );

                     red = COLORS[i].getRed();
                     green = COLORS[i].getGreen();
                     blue = COLORS[i].getBlue();
                     
                     for ( float k=0; k<1; k=k+(float)(1/BALL_RAD) ){
                            g.setColor( new Color(red + (int)(k*k*(255-red)),green + (int)(k*k*(255-green)),blue + (int)(k*k*(255-blue))) );
                            g.fill( new Ellipse2D.Double( k*k*BALL_RAD/2, k*k*BALL_RAD/2, 2*(BALL_RAD-k*k*BALL_RAD), 2*(BALL_RAD-k*k*BALL_RAD) ) );
                     }
                     */
              }
              

              PINS = new double[BINS][][];
              for (int i=0; i<BINS; i++){
                     PINS[i] = new double[i+1][2];
                     for (int j=0; j<=i; j++){
                            //PINS[i][j] = new Point((int)(DIST*(2*j-i)+W/2),(int)(DIST*(i+1)));
                            PINS[i][j][0] = DIST*(2*j-i)+W/2;
                            PINS[i][j][1] = DIST*(i+1);
                     }
              }             
              
              // 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));
                     PINS[BINS-1][i][0] = DIST*(2*i-BINS+1)+W/2;
                     PINS[BINS-1][i][1] = H-30-BALL_RAD;
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void PlinkoBoard.updateHist ( int  i) [inline]

Definition at line 406 of file PlinkoBoard.java.

                                   {
              HIST[i]++;
              COUNT++;
              TOTAL += i;
              TOTAL_SQUARES += i*i;
              if ( HIST[i] > MAX) MAX = HIST[i];
              if ( i>= LEFT && i <= RIGHT ){
                     PERCENT++;
              }
    }

Here is the caller graph for this function:

void PlinkoBoard.updatePercent ( ) [inline]

Definition at line 603 of file PlinkoBoard.java.

                               {
       double mean = (BINS-1)*((Double)plinko.prob.getValue()).doubleValue();
       if ( CURRENT_BIN <= mean ){
           LEFT = CURRENT_BIN;
           RIGHT = (int)(2*mean) - LEFT;
       } else {
           RIGHT = CURRENT_BIN;
           LEFT = (int)(2*mean) - RIGHT;
       }
       LEFT = Math.max( LEFT, 0 );
       RIGHT = Math.min( RIGHT, BINS-1 );
       PERCENT = 0;
       for ( int i=LEFT; i<=RIGHT; i++ ){
           PERCENT += HIST[i];
       }
    }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 55 of file PlinkoBoard.java.

Image PlinkoBoard.background [package]

Definition at line 56 of file PlinkoBoard.java.

int PlinkoBoard.BALL_COUNT [package]

Definition at line 24 of file PlinkoBoard.java.

double PlinkoBoard.BALL_RAD [package]

Definition at line 18 of file PlinkoBoard.java.

int PlinkoBoard.BINS [package]

Definition at line 20 of file PlinkoBoard.java.

int PlinkoBoard.BOTTOM_MARGIN = 5 [package]

Definition at line 25 of file PlinkoBoard.java.

Color [] PlinkoBoard.COLORS = { Color.red, Color.magenta, Color.orange, Color.yellow, Color.green, Color.blue, Color.cyan } [static, package]

Definition at line 37 of file PlinkoBoard.java.

double PlinkoBoard.COUNT [package]

Definition at line 10 of file PlinkoBoard.java.

int PlinkoBoard.CURRENT_BIN = 0 [package]

Definition at line 31 of file PlinkoBoard.java.

double PlinkoBoard.DIST [package]

Definition at line 17 of file PlinkoBoard.java.

double [][] PlinkoBoard.DYS [static, package]

Definition at line 33 of file PlinkoBoard.java.

Definition at line 23 of file PlinkoBoard.java.

Graphics2D PlinkoBoard.graphics [package]

Definition at line 58 of file PlinkoBoard.java.

int PlinkoBoard.H [package]

Definition at line 22 of file PlinkoBoard.java.

long [] PlinkoBoard.HIST [package]

Definition at line 14 of file PlinkoBoard.java.

Image PlinkoBoard.image [package]

Definition at line 57 of file PlinkoBoard.java.

Image [] PlinkoBoard.IMAGES [package]

Definition at line 53 of file PlinkoBoard.java.

int PlinkoBoard.incr = 1 [package]

Definition at line 35 of file PlinkoBoard.java.

int PlinkoBoard.LEFT [package]

Definition at line 28 of file PlinkoBoard.java.

float PlinkoBoard.MAX [package]

Definition at line 15 of file PlinkoBoard.java.

Definition at line 35 of file PlinkoBoard.java.

double PlinkoBoard.PERCENT [package]

Definition at line 30 of file PlinkoBoard.java.

int PlinkoBoard.PIN_RAD [package]

Definition at line 19 of file PlinkoBoard.java.

double [][][] PlinkoBoard.PINS [package]

Definition at line 16 of file PlinkoBoard.java.

Definition at line 59 of file PlinkoBoard.java.

int PlinkoBoard.RIGHT [package]

Definition at line 29 of file PlinkoBoard.java.

int PlinkoBoard.showstats = 0 [package]

Definition at line 32 of file PlinkoBoard.java.

String PlinkoBoard.start_number = "0" [package]

Definition at line 35 of file PlinkoBoard.java.

Thread PlinkoBoard.thread [package]

Definition at line 54 of file PlinkoBoard.java.

double PlinkoBoard.TOTAL [package]

Definition at line 11 of file PlinkoBoard.java.

double PlinkoBoard.TOTAL_SQUARES [package]

Definition at line 12 of file PlinkoBoard.java.

int PlinkoBoard.W [package]

Definition at line 21 of file PlinkoBoard.java.


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