rotagon/polygons.c
Frank Villaro-Dixon 76276c5275 rework file
2015-01-01 06:03:28 +01:00

48 lines
1 KiB
C

/*
** polygons.c - <+DESC+>
**
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "game.h"
#include "polygons.h"
#include "obs.h"
#include "SDL_prims.h"
#include "SDL/SDL.h"
SDL_Point
get_hexagon_vertice(int faceno, int dist) { //{{{
SDL_Point p1;
p1.x = dist * cos((M_PI/3)*faceno);
p1.y = dist * sin((M_PI/3)*faceno);
OFFSET_POINT(p1);
return p1;
} //}}}
void
draw_hexagon_side(struct s_game *g, int faceno, int dist, int thick, int col) { //{{{
SDL_Point p1, p2, p3, p4;
p1 = get_hexagon_vertice(faceno, dist);
p2 = get_hexagon_vertice(faceno+1, dist);
p3 = get_hexagon_vertice(faceno+1, dist+thick);
p4 = get_hexagon_vertice(faceno, dist+thick);
SDL_Point points[4] = {p1, p2, p3, p4} ;
SDL_FillPolygon(g->screen, points, 4, col);
}//}}}
void
draw_hexagon(struct s_game *g) { //{{{
int faces;
#define DFT_COLOR 128
for(faces = 0; faces < SHAPE_HEXAGON; faces++) {
draw_hexagon_side(g, faces, POLYGON_SIZE, SHAPE_THICK-5, g->color);
}
} //}}}