Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
fill.c File Reference

Functions

void fillDisplayArea (int16_t x1, int16_t y1, int16_t x2, int16_t y2, paletteColor_t c)
 Fill a rectangular area on a display with a single color.
 
void shadeDisplayArea (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t shadeLevel, paletteColor_t color)
 
void oddEvenFill (int x0, int y0, int x1, int y1, paletteColor_t boundaryColor, paletteColor_t fillColor)
 Attempt to fill a convex shape bounded by a border of a given color using the even-odd rule.
 
void floodFill (uint16_t x, uint16_t y, paletteColor_t col, uint16_t xMin, uint16_t yMin, uint16_t xMax, uint16_t yMax)
 
void fillCircleSector (uint16_t x, uint16_t y, uint16_t innerR, uint16_t outerR, uint16_t startAngle, uint16_t endAngle, paletteColor_t col)
 Helper function to draw a filled circle with translation and scaling.
 

Function Documentation

◆ fillDisplayArea()

void fillDisplayArea ( int16_t x1,
int16_t y1,
int16_t x2,
int16_t y2,
paletteColor_t c )

Fill a rectangular area on a display with a single color.

Parameters
x1The x coordinate to start the fill (top left)
y1The y coordinate to start the fill (top left)
x2The x coordinate to stop the fill (bottom right)
y2The y coordinate to stop the fill (bottom right)
cThe color to fill

◆ shadeDisplayArea()

void shadeDisplayArea ( int16_t x1,
int16_t y1,
int16_t x2,
int16_t y2,
uint8_t shadeLevel,
paletteColor_t color )

'Shade' an area by drawing pixels over it in a ordered-dithering way

Parameters
x1The X pixel to start at
y1The Y pixel to start at
x2The X pixel to end at
y2The Y pixel to end at
shadeLevelThe level of shading, Higher means more shaded. Must be 0 to 4
colorthe color to draw with

◆ oddEvenFill()

void oddEvenFill ( int x0,
int y0,
int x1,
int y1,
paletteColor_t boundaryColor,
paletteColor_t fillColor )

Attempt to fill a convex shape bounded by a border of a given color using the even-odd rule.

https://en.wikipedia.org/wiki/Even%E2%80%93odd_rule

WARNING!!! This is very finicky and is not guaranteed to work in all cases.

This iterates over each row in the bounding box, top to bottom, left to right

This assumes that each row starts outside or on the boundary of the shape to be filled.

Each time a pixel of the 'boundary color' is iterated over, the in/out boolean will flip. Thick boundaries will have hysteresis, but shapes with concave features will have undrawn rows because the function checks for an even number of transitions within a row before drawing.

Parameters
x0The left index of the bounding box
y0The top index of the bounding box
x1The right index of the bounding box
y1The bottom index of the bounding box
boundaryColorThe color of the boundary to fill in
fillColorThe color to fill

◆ floodFill()

void floodFill ( uint16_t x,
uint16_t y,
paletteColor_t col,
uint16_t xMin,
uint16_t yMin,
uint16_t xMax,
uint16_t yMax )

This is a recursive flood fill algorithm. It starts at the given coordinate, and will replace the color at that coordinate, and all adjacent pixels with the same color, with the fill color.

The flood is also bounded wthin the given rectangle.

Note that the recursive algorithm is relatively slow and uses a lot of stack memory, so try not to use it when possible.

This is adapted from http://www.adammil.net/blog/v126_A_More_Efficient_Flood_Fill.html

Parameters
xThe X coordinate to start the fill at
yThe Y coordinate to start the fill at
colThe color to fill in
xMinThe minimum X coordinate to bound the fill
yMinThe minimum Y coordinate to bound the fill
xMaxThe maximum X coordinate to bound the fill
yMaxThe maximum Y coordinate to bound the fill

◆ fillCircleSector()

void fillCircleSector ( uint16_t x,
uint16_t y,
uint16_t innerR,
uint16_t outerR,
uint16_t startAngle,
uint16_t endAngle,
paletteColor_t col )

Helper function to draw a filled circle with translation and scaling.

Parameters
xThe X coordinate of the center of the circle
yThe Y coordinate of the center of the circle
innerRThe radius of the inside of the sector, or 0 for the whole circle
outerRThe radius of the circle
startAngleThe starting angle of the sector, in degrees CCW
endAngleThe ending angle of the sector, in degrees CCW
colThe color to fill