----------------------------------------------------------------------
--- Knud van Eeden --- 26 February 2008 - 01:20 am -------------------

Java: Graphics: Draw: Mathematics: Hexstat: Graph: Create: How to

===

Steps: Overview:

 1. -E.g. create the following program (applet):

--- cut here: begin --------------------------------------------------

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.Random;
//
public class GraphicsMathematicsHexstat extends Applet {
 public void paint( Graphics g ) {
  int trialMinI = 1;
  int trialMaxI = 100000;
  int stepMinI = 1;
  int stepMaxI = 640;
  int yMaxI = -99999;
  int yScreenMaxI = 800;
  int x[] = new int[ ( stepMaxI + 1 + stepMaxI ) + 1 ]; // obliged to declare one more than the maximum. Otherwise for next loops appear to hang
  int x0 = 0;
  int trialI = 0;
  int stepI = 0;
  int yI = 0;
  //
  // g.drawString( Integer.toString( FNMathGetNumberRandomI( 2 ) ), 100, 100 );
  //
  for ( stepI = stepMinI; stepI <= ( stepMaxI + 1 + stepMaxI ); stepI++ ) {
   x[ stepI ] = 0;
  }
  //
  for ( trialI = trialMinI; trialI <= trialMaxI; trialI++ ) {
   x0 = stepMaxI + 1;
   for ( stepI = stepMinI; stepI <= stepMaxI; stepI++ ) {
     // output is 0 or 2-1, or thus 0 or 1
     if ( FNMathGetNumberRandomI( 2 ) == 1 ) {
      x0 = x0 + 1;
     }
     else {
      x0 = x0 - 1;
     }
   }
   x[ x0 ] = x[ x0 ] + 1;
  }
  //
  for ( stepI = stepMinI; stepI <= ( stepMaxI + 1 + stepMaxI ); stepI++ ) {
   if ( yMaxI < x[ stepI ] ) {
    yMaxI = x[ stepI ];
   }
  }
  //
  g.setColor( Color.black );
  //
  for ( stepI = stepMinI; stepI <= ( stepMaxI + 1 + stepMaxI ); stepI++ ) {
   // g.drawLine( stepI, 0, stepI, ( x[ stepI ] / yMaxI ) * yScreenMaxI ); // this is handled as integer division
   //
   // so convert each integer first to a double, do the calculations (e.g. division), then convert it back to an integer (obligatory for drawLine())
   g.drawLine( stepI, 0, stepI, (int ) ( ( double ) ( x[ stepI ] / ( double ) yMaxI ) * ( double ) yScreenMaxI ) );
  }
  //
  g.setColor( Color.red );
  //
  g.drawLine( stepMaxI + 1, 0, stepMaxI + 1, yScreenMaxI );
 }
 //
 public int FNMathGetNumberRandomI( int I ) {
  return( ( int ) ( I * FNMathGetNumberRandomD() ) );
 }
 //
 public double FNMathGetNumberRandomD() {
  Random randomO = new Random();
  return( randomO.nextDouble() );
 }
 //
}

--- cut here: end ----------------------------------------------------

 2. -Save this program as

      GraphicsMathematicsHexstat.java

 3. -Compile the program (e.g. using javac.exe)

 4. -This will create a .class file

      GraphicsMathematicsHexstat.class

 5. -Create the following file

--- cut here: begin --------------------------------------------------

 <HTML>
  <TITLE>
   Graphics Mathematics Hexstat applet
  </TITLE>
  <APPLET
    CODE="GraphicsMathematicsHexstat.class"
    WIDTH="1000"
    HEIGHT="1000"
  >
  </APPLET>
 </HTML>

--- cut here: end ----------------------------------------------------

 6. -Save this program as (in the same directory as your .class file)

      GraphicsMathematicsHexstat.htm

 7. -Run this program

      GraphicsMathematicsHexstat.htm

     in your browser

 8. -That will show a screen output similar to the graph

===

Screencast: see also:



===

Image: see also:



=== Program: see also: 01.java
01.class
01.htm === Video: see also: === Internet: see also: Mathematics: Probability: Distribution: Binomial: Hexstat: Links: Can you give an overview of links? http://www.knudvaneeden.com/tinyurl.php?urlKey=url000123 ----------------------------------------------------------------------