----------------------------------------------------------------------
--- Knud van Eeden --- 25 February 2008 - 00:24 am -------------------

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

===

Steps: Overview:

 1. -E.g. create the following program:

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

<?php
 //
 $trialMinI = 1;
 // $trialMaxI = 100000;
 $trialMaxI = 2000; // low value, otherwise execution time exceeded error (Apache related)
 $stepMinI = 1;
 $stepMaxI = 640;
 $yMaxI = -999999;
 $yScreenMaxI = 800;
 $x = array();
 //
 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++ ) {
   //
   // use the Mersenne Twister random generator
   //
   if ( mt_rand( 1, 2 ) == 1 ) {
    $x0 = $x0 + 1;
   }
   else {
    $x0 = $x0 - 1;
   };
  }
  $x[ $x0 ] = $x[ $x0 ] + 1;
 }
//
// Calculate the maximum value we are going to plot for graph
$columns1 = count( $x );
for( $stepI = 1; $stepI < $columns1; $stepI++ ) {
 $yMaxI = max( $x[ $stepI ], $yMaxI );
}
//
$imgWidth = $stepMaxI + 1 + $stepMaxI;
//
$image = imagecreate( $imgWidth, $yScreenMaxI );
//
$colorWhite = imagecolorallocate( $image, 255, 255, 255 );
$colorGrey = imagecolorallocate( $image, 192, 192, 192 );
$colorRed = imagecolorallocate( $image, 255, 0, 0 ) ;
$colorBlack = imagecolorallocate( $image, 0, 0, 0 );
$color1 = $colorBlack;
$color2 = $colorRed;
//
// Create line graph
//
for ( $stepI = $stepMinI; $stepI <= $stepMaxI + 1 + $stepMaxI; $stepI++ ) {
 imageline( $image, $stepI, 0, $stepI, $x[ $stepI ] / $yMaxI * $yScreenMaxI, $color1 );
}
//
 imageline( $image, $stepMaxI + 1, 0, $stepMaxI + 1, $yScreenMaxI, $color2 );
//
// Define .PNG image
//
header( "Content-type: image/png" );
//
// Output graph and clear image from memory
//
imagepng( $image );
//
imagedestroy( $image );
?>

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

 2. -Save this program as

      yourfilename.php

 3. -Run the program (open the filename URL on a computer where PHP is installed and enabled in your webbrowser (web server))

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

===

Screencast: see also:



===

Image: see also:



===

Program: see also:


01.php


===


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

----------------------------------------------------------------------