• home
  • forum
  • my
  • kt
  • download
  • Minimap Tutorial

    Author: 2008-08-24 07:36:56 From:

     <?
    //set width, height and grid size of your map
    $width = 200;
    $height = 200;
    $grid_size = 7;
     
    //select how many object will be there on the map
    $n = 4;
     
    //set X and Y position for each object
    $array[0]['x']=1;
    $array[0]['y']=1;
     
    $array[1]['x']=3;
    $array[1]['y']=5;
     
    $array[2]['x']=6;
    $array[2]['y']=7;
     
    $array[3]['x']=0;
    $array[3]['y']=0;
     
    //Create a new image 
        $image = ImageCreate($width, $height); 
     
    //Make 3 new colors, background, grid and block
        $bground = ImageColorAllocate($image, 200, 200, 200);
        $grid = ImageColorAllocate($image, 100, 100, 100);
        $block = ImageColorAllocate($image, 0, 0, 0);
     
    //Fill background with background color.
        ImageFill($image, 0, 0, $bground); 
     
    //If grid size is not zero, draw grid 
        if($grid_size)
       {
       $step = $grid_size;
     
    //Draw horizontal lines
       while($step < $height)
      {
    imageline ($image,   0,  $step, $width, $step, $grid);
       $step += $grid_size;
       }
     
      $step = $grid_size;
     
    //Draw vertical lines
       while($step < $width)
       {
    imageline ($image,   $step,  0, $step, $height, $grid);
    $step += $grid_size;
       } 
       }
     
    //for each element in array
        for($i=0;$i<$n;$i++)
        {
     
    //get X and Y position
       $x1 = $array[$i]['x'];
    $y1 = $array[$i]['y'];
     
    //if grid is larger then 0 then snap to it
    if($grid_size)
    {
    $x1 = $x1 * $grid_size;
    $y1 = $y1 * $grid_size;
    }
     
    //make thing on mape same size as grid
    $x2 = $x1 + $grid_size;
       $y2 = $y1 + $grid_size;
     
    //draw it 
        imagefilledrectangle ($image,   $x1,$y1,$x2,$y2, $block);   
     
    }
     
    //tell the browser that this file act as an image
        header("Content-Type: image/jpeg");
     
    //output the image in jpeg format
        ImageJpeg($image);
     
    //free up resources
        ImageDestroy($image);
    ?>

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (19)
      Installing PHP (7)
      Introduction to PHP (24)
      Link Indexing (8)
      Mailing List Management (9)
      Miscellaneous (54)
      Networking (8)
      News Publishing (9)
      OOP (24)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (6)
      Postcards (1)
      Randomizing (14)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot