do_circle(3alleg4)

✨ do_circle ✨

okay bestie, gather round, because we're about to talk about the Allegro game programming library and one very specific little function that is lowkey iconic πŸ’–


πŸŽ€ NAME πŸŽ€

do_circle β€” calculates all the points in a circle. Allegro game programming library.


🌸 SYNOPSIS 🌸

#include <allegro.h>

void do_circle(BITMAP *bmp, int x, int y, int radius, int d, void
(*proc)(BITMAP *bmp, int x, int y, int d));

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the vibe: do_circle walks all the points in a circle around the point (x, y) with radius r, and for every single one of those points it calls the function you handed it. No cap. Every point, one by one, and it's calling your callback each time. πŸ’…

What does your callback get, you ask? It gets passed:

  • a copy of the bmp parameter πŸ–ΌοΈ
  • the x and y position πŸ“
  • a copy of the d parameter 🎨

which means it's suitable for use with putpixel(). That's the whole point, honestly β€” you're basically doing a custom pixel-by-pixel ring draw and Allegro is doing the annoying circle math for you. Obsessed.

Example, because we love a demonstration:

void draw_explosion_ring(BITMAP *bmp, int x, int y, int d)
{
   ...
}

   do_circle(screen, SCREEN_W/2, SCREEN_H/2,
             SCREEN_H/16, flame_color,
             draw_explosion_ring);

like… look at that. draw_explosion_ring as the callback, screen as the bmp, dead center of the screen as the coordinates, SCREEN_H/16 as the radius, and flame_color riding along as d. It's giving explosion ring main character energy fr fr πŸ”₯


πŸ’œ SEE ALSO πŸ’œ

go read those too, bestie, they're all in the same family 🫢


and that's the whole page!! 🌈 this was Allegro, version 4.4.3, dated back in the day, and do_circle(3alleg4) is the header it lives under. tysm for reading, go draw some circles, mwah πŸ’–βœ¨πŸŽ€