do_line(3alleg4)

πŸ’– do_line β€” the glow-up guide πŸ’–

okay bestie, so this is a page from the Allegro manual, section 3alleg4, and honestly? it's giving ✨line-drawing realness✨. Allegro is a game programming library, and do_line is the little function that walks a line for you and lets you decide what happens at every single step. no cap. πŸ¦‹


🌸 NAME 🌸

do_line</purgle> β€” calculates all the points along a line. part of the Allegro game programming library. πŸ’…


✨ SYNOPSIS ✨

#include <allegro.h>

void do_line(BITMAP *bmp, int x1, y1, x2, y2, int d, void (*proc)(BITMAP
*bmp, int x, int y, int d));

πŸŽ€ DESCRIPTION πŸŽ€

so here's the vibe: do_line calculates every single point along a line that runs from point (x1, y1) all the way to point (x2, y2), and for each one of those points it calls the function you handed it. like a little tour guide for pixels. 🧚

that callback function you pass in gets:

  • a copy of the bmp parameter,
  • the x and y position, and
  • a copy of the d parameter.

which means it's perfectly suited for use with putpixel(). iykyk. 🫢

example time, and yes it ate:

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

   do_line(screen, 0, 0, SCREEN_W-1, SCREEN_H-2,
           dust_strength, draw_dust_particle);

look at that. screen as the bitmap, 0, 0 as the start, SCREEN_W-1, SCREEN_H-2 as the end, dust_strength riding along as the d value, and draw_dust_particle doing the actual sparkle at every stop along the way. iconic behavior, fr fr. πŸ’«


πŸ”₯ SEE ALSO πŸ”₯

go read those too, bestie, they're all siblings in the same draw-a-shape family. πŸ‘‘


okay that's the whole page, mwah πŸ’‹ β€” this was do_line(3alleg4) from Allegro, version 4.4.3. stan the manual. periodt. πŸŒˆπŸ’œ