Polymorphism and Self-Modifying Code 81 Indeed, the regular
82 Chapter 2 Advanced Syntax Listing 2.6 Continued // the diagram height is fixed as we do not check for the // function s extreme points $width = PLOT_MAX / PLOT_STEP; $height = DIAGRAM_HEIGHT; $image = imagecreate($width, $height); // allocate colors $color_backgr = imagecolorallocate($image, 255, 255, 255); $color_grid = imagecolorallocate($image, 0, 0, 0); $color_plot = imagecolorallocate($image, 255, 0, 0); // clear image imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $color_backgr); // draw axes imageline($image, 0, 0, 0, $height - 1, $color_grid); imageline($image, 0, DIAGRAM_HORIZON, $width - 1, DIAGRAM_HORIZON, .$color_grid); // print some text imagestring($image, 3, 10, DIAGRAM_HORIZON + 10, PLOT_MIN, $color_grid); imagestring($image, 3, $width - 30, DIAGRAM_HORIZON + 10, PLOT_MAX, .$color_grid); // return image return($image); } function plot($image, $x, $y) { // import the color handle global $color_plot; // set these as static to remember the last coordinates static $old_x = PLOT_MIN; static $old_y = 0; // only plot from the second time on if($old_x != PLOT_MIN) imageline($image, $old_x / PLOT_STEP, DIAGRAM_HEIGHT .($old_y + DIAGRAM_HORIZON), $x / PLOT_STEP, DIAGRAM_HEIGHT .($y + DIAGRAM_HORIZON), $color_plot); $old_x = $x; $old_y = $y; }
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services