new hexbgon shot... still quite shitty code, but at least I know the hex formulas appear to be equal(I made this quick mockup of a hexaplex to test if all sides will match... it's pretty damn close if not exact)
Image and screenshot behind cut...
The next goal is to create a class for hexagon, and also make each side a different color, so I need a "side" class as well(so it's no longer just "line"s, but the sides will have different properties, such as if something is adjacent, and if the adjacent hex has the same color on the touching side, etc...)
I also think I need to thicken the lines a little, maybe 2 or 3 pixels wide. I think a nice gradient around the edge-lines, as the mouse hovers over it would be a nice flare...(like the "mouse-over" javascript type code would normally do, and maybe a "mouse-down" code so the image can darken or something when it's clicked)
I need to figure out how to get colors loaded in the palette. I think a nice algorithm to give me a blend of color would rock, or I should just figure out basic colors and load them in the first 16 or so slots of the palette... I think blend of shades, with each major color on the 32 or 48 or 64 would be best, so I can have a nice gradient each way towards the other colors. I dunno.
Any suggestions? (the biggest problem is figuring out what algorithm to write the palette... the palette can be a file with RGB values(0-255), comma-separated...)
Anyways, here ya go...

CODE:
#include "allegro.h"
#include "math.h"
#include "stdio.h"
#define H_LEN 32;
typedef struct point
{
int x, y;
};
typedef struct hexagon
{
int length, locx, locy;
point p1, p2, p3, p4, p5, p6;
int color;
} hex;
hex hex_create(int x, int y, int c);
void hex_draw(hex h);
PALETTE pal;
int main()
{
hex h1 = hex_create(320, 240, 4);
hex h2 = hex_create(270, 212, 3);
hex h3 = hex_create(270, 269, 2);
hex h4 = hex_create(320, h1.p5.y + 2, 5);
hex h5 = hex_create(h1.p1.x + 50, 268, 6);
hex h6 = hex_create(h5.p1.x, h1.p1.y - 29, 7);
hex h7 = hex_create(320, h1.p1.y - 57, 9);
//---------------
allegro_init();
install_keyboard();
if(set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) < 0)
{
printf("%s\n", allegro_error);
}
clear_keybuf();
get_palette(pal);
do
{
hex_draw(h1);
hex_draw(h2);
hex_draw(h3);
hex_draw(h4);
hex_draw(h5);
hex_draw(h6);
hex_draw(h7);
} while(!keypressed());
//save_bitmap("screen.pcx", screen, pal);
return 0;
}
END_OF_MAIN()
hex hex_create(int x, int y, int color)
{
hex h;
h.locx = x;
h.locy = y;
h.color = color;
h.length = H_LEN;
h.p1.x = h.locx;
h.p1.y = h.locy;
h.p2.x = h.p1.x + h.length;
h.p2.y = h.p1.y;
h.p3.x = h.p2.x + (int(h.length/2));
h.p3.y = h.p1.y + int(h.length * sqrt(3)/2);
h.p4.x = h.p2.x;
h.p4.y = h.p2.y + int(h.length * sqrt(3));
h.p5.x = h.p1.x;
h.p5.y = h.p4.y;
h.p6.x = h.p1.x - (int(h.length/2));
h.p6.y = h.p5.y - int(h.length * sqrt(3)/2);
return h;
}
void hex_draw(hex h)
{
line(screen, h.p1.x, h.p1.y, h.p2.x, h.p2.y, h.color);
line(screen, h.p2.x, h.p2.y, h.p3.x, h.p3.y, h.color);
line(screen, h.p3.x, h.p3.y, h.p4.x, h.p4.y, h.color);
line(screen, h.p4.x, h.p4.y, h.p5.x, h.p5.y, h.color);
line(screen, h.p5.x, h.p5.y, h.p6.x, h.p6.y, h.color);
line(screen, h.p6.x, h.p6.y, h.p1.x, h.p1.y, h.color);
}
Image and screenshot behind cut...
The next goal is to create a class for hexagon, and also make each side a different color, so I need a "side" class as well(so it's no longer just "line"s, but the sides will have different properties, such as if something is adjacent, and if the adjacent hex has the same color on the touching side, etc...)
I also think I need to thicken the lines a little, maybe 2 or 3 pixels wide. I think a nice gradient around the edge-lines, as the mouse hovers over it would be a nice flare...(like the "mouse-over" javascript type code would normally do, and maybe a "mouse-down" code so the image can darken or something when it's clicked)
I need to figure out how to get colors loaded in the palette. I think a nice algorithm to give me a blend of color would rock, or I should just figure out basic colors and load them in the first 16 or so slots of the palette... I think blend of shades, with each major color on the 32 or 48 or 64 would be best, so I can have a nice gradient each way towards the other colors. I dunno.
Any suggestions? (the biggest problem is figuring out what algorithm to write the palette... the palette can be a file with RGB values(0-255), comma-separated...)
Anyways, here ya go...

CODE:
#include "allegro.h"
#include "math.h"
#include "stdio.h"
#define H_LEN 32;
typedef struct point
{
int x, y;
};
typedef struct hexagon
{
int length, locx, locy;
point p1, p2, p3, p4, p5, p6;
int color;
} hex;
hex hex_create(int x, int y, int c);
void hex_draw(hex h);
PALETTE pal;
int main()
{
hex h1 = hex_create(320, 240, 4);
hex h2 = hex_create(270, 212, 3);
hex h3 = hex_create(270, 269, 2);
hex h4 = hex_create(320, h1.p5.y + 2, 5);
hex h5 = hex_create(h1.p1.x + 50, 268, 6);
hex h6 = hex_create(h5.p1.x, h1.p1.y - 29, 7);
hex h7 = hex_create(320, h1.p1.y - 57, 9);
//---------------
allegro_init();
install_keyboard();
if(set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) < 0)
{
printf("%s\n", allegro_error);
}
clear_keybuf();
get_palette(pal);
do
{
hex_draw(h1);
hex_draw(h2);
hex_draw(h3);
hex_draw(h4);
hex_draw(h5);
hex_draw(h6);
hex_draw(h7);
} while(!keypressed());
//save_bitmap("screen.pcx", screen, pal);
return 0;
}
END_OF_MAIN()
hex hex_create(int x, int y, int color)
{
hex h;
h.locx = x;
h.locy = y;
h.color = color;
h.length = H_LEN;
h.p1.x = h.locx;
h.p1.y = h.locy;
h.p2.x = h.p1.x + h.length;
h.p2.y = h.p1.y;
h.p3.x = h.p2.x + (int(h.length/2));
h.p3.y = h.p1.y + int(h.length * sqrt(3)/2);
h.p4.x = h.p2.x;
h.p4.y = h.p2.y + int(h.length * sqrt(3));
h.p5.x = h.p1.x;
h.p5.y = h.p4.y;
h.p6.x = h.p1.x - (int(h.length/2));
h.p6.y = h.p5.y - int(h.length * sqrt(3)/2);
return h;
}
void hex_draw(hex h)
{
line(screen, h.p1.x, h.p1.y, h.p2.x, h.p2.y, h.color);
line(screen, h.p2.x, h.p2.y, h.p3.x, h.p3.y, h.color);
line(screen, h.p3.x, h.p3.y, h.p4.x, h.p4.y, h.color);
line(screen, h.p4.x, h.p4.y, h.p5.x, h.p5.y, h.color);
line(screen, h.p5.x, h.p5.y, h.p6.x, h.p6.y, h.color);
line(screen, h.p6.x, h.p6.y, h.p1.x, h.p1.y, h.color);
}