Rev 3653 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3653 | Rev 4033 | ||
---|---|---|---|
Line 42... | Line 42... | ||
42 | int CURRENT_BIN = 0; |
42 | int CURRENT_BIN = 0; |
43 | int showstats=0; |
43 | int showstats=0; |
44 | static double[][] DYS; |
44 | static double[][] DYS; |
45 | // jm.evers: defining a few things |
45 | // jm.evers: defining a few things |
46 | int maximum_balls;String start_number="0";int incr=1; |
46 | int maximum_balls;String start_number="0";int incr=1; |
- | 47 | int BIN_HEIGHT; // height of bins **** |
|
47 | 48 | ||
48 | static Color[] COLORS = { Color.red, Color.magenta, Color.orange, Color.yellow, Color.green, Color.blue, Color.cyan }; |
49 | static Color[] COLORS = { Color.red, Color.magenta, Color.orange, Color.yellow, Color.green, Color.blue, Color.cyan }; |
49 | /* new Color(.45f,.40f,.86f), new Color(.36f,.53f,.95f), |
50 | /* new Color(.45f,.40f,.86f), new Color(.36f,.53f,.95f), |
50 | new Color(.38f,.84f,.67f), new Color(.37f,.74f,.44f), new Color(.49f,.51f,.36f), new Color(.90f,.90f,.35f), |
51 | new Color(.38f,.84f,.67f), new Color(.37f,.74f,.44f), new Color(.49f,.51f,.36f), new Color(.90f,.90f,.35f), |
51 | new Color(.99f,.75f,.34f), new Color(.85f,.27f,.42f), new Color(.73f,.34f,.76f), new Color(.51f,.33f,.82f), |
52 | new Color(.99f,.75f,.34f), new Color(.85f,.27f,.42f), new Color(.73f,.34f,.76f), new Color(.51f,.33f,.82f), |
Line 90... | Line 91... | ||
90 | 91 | ||
91 | addKeyListener( this ); |
92 | addKeyListener( this ); |
92 | addMouseListener( this ); |
93 | addMouseListener( this ); |
93 | // jm.evers: if the applet is in an wims exercise...read appletparam and start buckets_number with 1 instead of 0 |
94 | // jm.evers: if the applet is in an wims exercise...read appletparam and start buckets_number with 1 instead of 0 |
94 | maximum_balls=(int)plinko.total_balls - 1; |
95 | maximum_balls=(int)plinko.total_balls - 1; |
- | 96 | BIN_HEIGHT=(int)plinko.bin_height ; |
|
95 | if(plinko.wims_exercise == false){ showstats = 1;}else{ start_number="1"; incr=2; } |
97 | if(plinko.wims_exercise == false){ showstats = 1;}else{ start_number="1"; incr=2; } |
96 | } |
98 | } |
97 | 99 | ||
98 | public void setup(){ |
100 | public void setup(){ |
99 | W = getWidth(); |
101 | W = getWidth(); |
Line 103... | Line 105... | ||
103 | CURRENT_BIN = BINS/2; |
105 | CURRENT_BIN = BINS/2; |
104 | LEFT = BINS+1; |
106 | LEFT = BINS+1; |
105 | RIGHT = BINS; |
107 | RIGHT = BINS; |
106 | PERCENT = 0; |
108 | PERCENT = 0; |
107 | 109 | ||
108 | if ( H- |
110 | if ( H-BIN_HEIGHT-BOTTOM_MARGIN<W/2 ){ |
109 | DIST = (double)(H- |
111 | DIST = (double)(H-BIN_HEIGHT-BOTTOM_MARGIN)/BINS; |
110 | } else { |
112 | } else { |
111 | DIST = (double)(W-10)/(2*BINS); |
113 | DIST = (double)(W-10)/(2*BINS); |
112 | } |
114 | } |
113 | 115 | ||
114 | PIN_RAD = (int)DIST/9 + 1; |
116 | PIN_RAD = (int)DIST/9 + 1; |
Line 280... | Line 282... | ||
280 | 282 | ||
281 | 283 | ||
282 | public void dropBall( boolean sound ){ |
284 | public void dropBall( boolean sound ){ |
283 | BALL_COUNT++; |
285 | BALL_COUNT++; |
284 | // jm.evers : I don't know of another/better way to get the system to stop at a given [param] number of balls... |
286 | // jm.evers : I don't know of another/better way to get the system to stop at a given [param] number of balls... |
285 | if(COUNT |
287 | if(COUNT >= maximum_balls ){LimitReached();} |
286 | if ( FIRST_BALL == null ){ |
288 | if ( FIRST_BALL == null ){ |
287 | FIRST_BALL = new PlinkoBall(); |
289 | FIRST_BALL = new PlinkoBall(); |
288 | FIRST_BALL.sound = sound; |
290 | FIRST_BALL.sound = sound; |
289 | } else { |
291 | } else { |
290 | FIRST_BALL.previousBall = new PlinkoBall(); |
292 | FIRST_BALL.previousBall = new PlinkoBall(); |
Line 441... | Line 443... | ||
441 | if(LEFT == RIGHT){ |
443 | if(LEFT == RIGHT){ |
442 | plinko.confidence.setText(plinko.label_confidence + (float)((double)(int)((100000D * PERCENT) / COUNT) / 1000D) + plinko.some_text + LEFT + "."); |
444 | plinko.confidence.setText(plinko.label_confidence + (float)((double)(int)((100000D * PERCENT) / COUNT) / 1000D) + plinko.some_text + LEFT + "."); |
443 | } |
445 | } |
444 | else |
446 | else |
445 | { |
447 | { |
446 | plinko.confidence.setText(plinko.label_confidence + (float)((double)(int)((100000D * PERCENT) / COUNT) / 1000D) + plinko. |
448 | plinko.confidence.setText(plinko.label_confidence + (float)((double)(int)((100000D * PERCENT) / COUNT) / 1000D) + plinko.some_text2 + LEFT + plinko.through + RIGHT + "."); |
447 | } |
449 | } |
448 | } |
450 | } |
449 | else |
451 | else |
450 | { |
452 | { |
451 | plinko.confidence.setText(plinko.label_confidence ); |
453 | plinko.confidence.setText(plinko.label_confidence ); |
Line 490... | Line 492... | ||
490 | x1 = PINS[BINS-2][i][0]; |
492 | x1 = PINS[BINS-2][i][0]; |
491 | } |
493 | } |
492 | 494 | ||
493 | //Draw bar |
495 | //Draw bar |
494 | h = HIST[i]; |
496 | h = HIST[i]; |
495 | if (MAX> |
497 | if (MAX>BIN_HEIGHT) h=(int)(BIN_HEIGHT*1.0*h/MAX); |
496 | g.setColor( new Color(255,0,0,175) ); |
498 | g.setColor( new Color(255,0,0,175) ); |
497 | if ( i >= LEFT && i <= RIGHT ) g.setColor( new Color(0,255,0,175) ); |
499 | if ( i >= LEFT && i <= RIGHT ) g.setColor( new Color(0,255,0,175) ); |
498 | rect = new Rectangle2D.Double(x0,H-h-BOTTOM_MARGIN,x1-x0,h); |
500 | rect = new Rectangle2D.Double(x0,H-h-BOTTOM_MARGIN,x1-x0,h); |
499 | g.fill( rect ); |
501 | g.fill( rect ); |
500 | g.setColor(Color.black); |
502 | g.setColor(Color.black); |
Line 534... | Line 536... | ||
534 | backgroundgraphics.drawImage(img, (int)(p[0]-PIN_RAD),(int)(p[1]-PIN_RAD),this ); |
536 | backgroundgraphics.drawImage(img, (int)(p[0]-PIN_RAD),(int)(p[1]-PIN_RAD),this ); |
535 | } |
537 | } |
536 | } |
538 | } |
537 | 539 | ||
538 | String s; |
540 | String s; |
539 | backgroundgraphics.setFont( new Font("Helvetica",Font.BOLD,Math.min((int)(4*DIST)/3 |
541 | backgroundgraphics.setFont( new Font("Helvetica",Font.BOLD,Math.min((int)(4*DIST)/3,BIN_HEIGHT/2)) ); |
540 | FontMetrics fm = backgroundgraphics.getFontMetrics(); |
542 | FontMetrics fm = backgroundgraphics.getFontMetrics(); |
541 | // draw lines and numbers |
543 | // draw lines and numbers |
542 | p = PINS[BINS-1][0]; |
544 | p = PINS[BINS-1][0]; |
543 | backgroundgraphics.draw( new Line2D.Double( p[0]-DIST,H- |
545 | backgroundgraphics.draw( new Line2D.Double( p[0]-DIST,H-BIN_HEIGHT-BOTTOM_MARGIN,p[0]-DIST,H-BOTTOM_MARGIN) ); |
544 | backgroundgraphics.setColor( Color.darkGray ); |
546 | backgroundgraphics.setColor( Color.darkGray ); |
545 | backgroundgraphics.drawString(start_number,(int)(p[0] - fm.stringWidth("0")/2), H- |
547 | backgroundgraphics.drawString(start_number,(int)(p[0] - fm.stringWidth("0")/2), H-BIN_HEIGHT-BOTTOM_MARGIN+Math.min((int)(4*DIST)/3, BIN_HEIGHT/2) ); |
546 | for (int i=0; i<BINS-1; i++){ |
548 | for (int i=0; i<BINS-1; i++){ |
547 | p = PINS[BINS-2][i]; |
549 | p = PINS[BINS-2][i]; |
548 | s = ""+(i+incr); |
550 | s = ""+(i+incr); |
549 | backgroundgraphics.setColor( Color.darkGray ); |
551 | backgroundgraphics.setColor( Color.darkGray ); |
550 | backgroundgraphics.drawString(s,(int)(p[0] + DIST - fm.stringWidth(s)/2),H- |
552 | backgroundgraphics.drawString(s,(int)(p[0] + DIST - fm.stringWidth(s)/2),H-BIN_HEIGHT-BOTTOM_MARGIN+Math.min((int)(4*DIST)/3,BIN_HEIGHT/2)); |
551 | backgroundgraphics.setColor( Color.black ); |
553 | backgroundgraphics.setColor( Color.black ); |
552 | backgroundgraphics.draw( new Line2D.Double( p[0],H- |
554 | backgroundgraphics.draw( new Line2D.Double( p[0],H-BIN_HEIGHT-BOTTOM_MARGIN,p[0],H-BOTTOM_MARGIN) ); |
553 | } |
555 | } |
554 | p = PINS[BINS-1][BINS-1]; |
556 | p = PINS[BINS-1][BINS-1]; |
555 | backgroundgraphics.draw( new Line2D.Double(p[0]+DIST,H- |
557 | backgroundgraphics.draw( new Line2D.Double(p[0]+DIST,H-BIN_HEIGHT-BOTTOM_MARGIN,p[0]+DIST,H-BOTTOM_MARGIN) ); |
556 | backgroundgraphics.draw( new Line2D.Double(0,H-BOTTOM_MARGIN,W,H-BOTTOM_MARGIN) ); |
558 | backgroundgraphics.draw( new Line2D.Double(0,H-BOTTOM_MARGIN,W,H-BOTTOM_MARGIN) ); |
557 | repaint(); |
559 | repaint(); |
558 | } |
560 | } |
559 | 561 | ||
560 | 562 | ||
Line 631... | Line 633... | ||
631 | 633 | ||
632 | public void mouseClicked( MouseEvent me ){ |
634 | public void mouseClicked( MouseEvent me ){ |
633 | requestFocus(); |
635 | requestFocus(); |
634 | Point p = me.getPoint(); |
636 | Point p = me.getPoint(); |
635 | int bin; |
637 | int bin; |
636 | if ( p.x + DIST> PINS[BINS-1][0][0] && p.x-DIST < PINS[BINS-1][BINS-1][0] && p.y> H- |
638 | if ( p.x + DIST> PINS[BINS-1][0][0] && p.x-DIST < PINS[BINS-1][BINS-1][0] && p.y> H-BIN_HEIGHT-BOTTOM_MARGIN && p.y<H-BOTTOM_MARGIN){ |
637 | bin = 0; |
639 | bin = 0; |
638 | while ( bin<BINS-1 ){ |
640 | while ( bin<BINS-1 ){ |
639 | if ( p.x + DIST < PINS[BINS-1][bin+1][0] ) break; |
641 | if ( p.x + DIST < PINS[BINS-1][bin+1][0] ) break; |
640 | bin++; |
642 | bin++; |
641 | } |
643 | } |