Code Monkey home page Code Monkey logo

leland's Introduction

This PHP code uses the GD functions to create hex map images (eg. for wargames).

## Features:

* Shapes: rectangule, hexagonal ('circle'), freeform ('free')
* Variable hex sizes
* shape() to calculate distance in hexes
* highlight a hex
* set a border on a hex
* color a hex
* add text to a hex
* I swear it used to allow setting a background picture, but I don't see that functionality so maybe I dreamed it or lost it when I misplaced this code for four years.

## Known Issues

The code has ugly styling (tabs, odd spacing, no optional braces) - sorry, I was young(er) and stupid(er).

There's a fair amount of temporal coupling in there - functions that you can't call before other functions, etc. I hadn't heard of the command pattern or closures yet.

There's a bug in the 'circle' shape (that the following code exercices), see http://push.cx/2010/php-hex-map-graphics for the image generated by the following code:

    <?php

    require 'class_hex_image.php';

    $radius = 3;
    $map = new Hex_image;
    $map->set_color('bg', 255, 255, 255);
    $map->set_l(20);
    $map->set_shape('circle', $radius);
    $map->start();
    for($x = 1; $x <= $map->xsize; $x++) {
        for($y = 1; $y <= $map->ysize; $y++) {
            $map->text($x, $y, 'black', $map->steps($x, $y, $radius, $radius));
            // nice for getting a feel for coordinates
            //$map->text($x, $y, 'black', "$x,$y");
        }
    }

    header('Content-Type: image.png');
    $map->finish();       // calls imagepng()

    ?>

## Future

One of the guys in #bbg on irc,freenode.net is building a browser-based game with a hex map and I remembered this code was squirreled away somewhere on my hard drive. I have no plans to fix, improve, or in any way maintain this code. I figure I may as well release it so someone can do something with it.

## License

I release this code to the public domain. You may use it for any purpose with or without attribution. It would be polite to mention my name and let me know you come up with, but it's not at all required.

leland's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

cybercog

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.