Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Smart6502 committed May 13, 2021
1 parent 4043f99 commit 8c90ba8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 58 deletions.
7 changes: 7 additions & 0 deletions src/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ void pluto_draw_frame(pluto_canvas_t *canvas)
printf("\e[%d;%dH%lc", i, j, (canvas->buffer[i][j]) ? PLUTO_PIX_CHAR_OFF + canvas->buffer[i][j] : ' ');
}

void pluto_draw_area(pluto_canvas_t *canvas, int start_x, int start_y, int height, int width)
{
for (int i = start_y; i < height; i++)
for (int j = start_x; j < width; j++)
printf("\e[%d;%dH%lc", i, j, (canvas->buffer[i][j]) ? PLUTO_PIX_CHAR_OFF + canvas->buffer[i][j] : ' ');
}

void pluto_clear(pluto_canvas_t *canvas)
{
for (int i = 0; i < canvas->cheight; i++)
Expand Down
41 changes: 0 additions & 41 deletions src/extra.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,47 +137,6 @@ void pluto_rast_tri(pluto_canvas_t *canvas, pt_t p0, pt_t p1, pt_t p2)
}
}

polygon_t *pluto_new_polygon(int sides, double radius, double ort)
{
polygon_t *polygon = malloc(sizeof(polygon_t));
polygon->sides = sides;
polygon->radius = radius;
polygon->ort = ort;
polygon->points = malloc(sizeof(pt_t) * sides);

pluto_calc_polygon_verts(polygon);

return polygon;
}

void pluto_calc_polygon_verts(polygon_t *polygon)
{
double vt;
for (int i = 0; i < polygon->sides; i++)
{
vt = 2 * M_PI * ((double)i / polygon->sides + polygon->ort);
polygon->points[i].x = round(cos(vt) * polygon->radius);
polygon->points[i].y = round(sin(vt) * polygon->radius);
}
}

void pluto_draw_polygon(pluto_canvas_t *canvas, polygon_t *polygon, pt_t centre)
{
for (int i = 0; i < polygon->sides - 1; i++)
{
pluto_draw_line(canvas, (pt_t){polygon->points[i].x + centre.x, polygon->points[i].y + centre.y},
(pt_t){polygon->points[i + 1].x + centre.x, polygon->points[i + 1].y + centre.y});
}
pluto_draw_line(canvas, (pt_t){polygon->points[0].x + centre.x, polygon->points[0].y + centre.y},
(pt_t){polygon->points[polygon->sides - 1].x + centre.x, polygon->points[polygon->sides - 1].y + centre.y});
}

void pluto_free_polygon(polygon_t *polygon)
{
free(polygon->points);
free(polygon);
}

void pluto_draw_ellipse(pluto_canvas_t *canvas, pt_t p0, int a, int b)
{
int wx, wy, t;
Expand Down
6 changes: 1 addition & 5 deletions src/inc/pluto.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,14 @@ extern void pluto_write_pix(pluto_canvas_t *canvas, int posx, int posy);
extern void pluto_del_pix(pluto_canvas_t *canvas, int posx, int posy);

extern void pluto_draw_frame(pluto_canvas_t *canvas);
extern void pluto_draw_area(pluto_canvas_t *canvas, int start_x, int start_y, int height, int width);
extern void pluto_clear(pluto_canvas_t *canvas);
extern void pluto_draw_line(pluto_canvas_t *canvas, pt_t p0, pt_t p1);

extern void pluto_rast_bftri(pluto_canvas_t *canvas, pt_t p0, pt_t p1, pt_t p2);
extern void pluto_rast_tftri(pluto_canvas_t *canvas, pt_t p0, pt_t p1, pt_t p2);
extern void pluto_rast_tri(pluto_canvas_t *canvas, pt_t p0, pt_t p1, pt_t p2);

extern polygon_t *pluto_new_polygon(int sides, double radius, double ort);
extern void pluto_calc_polygon_verts(polygon_t *polygon);
extern void pluto_draw_polygon(pluto_canvas_t *canvas, polygon_t *polygon, pt_t centre);
extern void pluto_free_polygon(polygon_t *polygon);

extern void pluto_draw_ellipse(pluto_canvas_t *canvas, pt_t p0, int a, int b);
typedef unsigned char uchar;
#endif
12 changes: 0 additions & 12 deletions tests/polygon.c

This file was deleted.

0 comments on commit 8c90ba8

Please sign in to comment.