diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-09-25 17:16:54 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-09-25 17:16:54 -0400 |
| commit | 44dd6ad61dfed5d89f8abf7e8f41797501f071cc (patch) | |
| tree | 299f0b12e0f19c9b9f117232a1b0f1266b879632 /graphics.c | |
| parent | 50f5164c529d57aeaf5c435b33683afabfc25c40 (diff) | |
| download | balls-44dd6ad61dfed5d89f8abf7e8f41797501f071cc.zip | |
refactor graphics functions
Diffstat (limited to 'graphics.c')
| -rw-r--r-- | graphics.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/graphics.c b/graphics.c new file mode 100644 index 0000000..c03dc8e --- /dev/null +++ b/graphics.c @@ -0,0 +1,35 @@ +#include "balls.h" + +void +drawbg(Image *walls, Image *bg) { + draw(screen, screen->r, walls, nil, ZP); + draw(screen, screen->r, bg, nil, ZP); + flushimage(display, Refnone); +} + +Image * +alloccircle(int fg, int bg) { + Image *m, *fill; + + m = allocimage(display, Rect(0, 0, 2*RADIUS, 2*RADIUS), RGBA32, 0, bg); + if (m == nil) + return nil; + + fill = allocimage(display, Rect(0, 0, 1, 1), RGBA32, 1, fg); + if (fill == nil) { + free(m); + return nil; + } + + fillellipse(m, Pt(RADIUS, RADIUS), RADIUS, RADIUS, fill, ZP); + freeimage(fill); + return m; +} + +void +drawcircle(Image *m, Point pos) { + Rectangle r; + + r = Rpt(subpt(pos, Pt(RADIUS, RADIUS)), addpt(pos, Pt(RADIUS, RADIUS))); + draw(screen, r, m, nil, ZP); +} |