Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
Fill algorithms are used to fill bounded spaces on the display with a given color. Fill algorithms can be computationally expensive, so a variety are provided to best suit your need.
fillDisplayArea() is used to fill a rectangular area. It does not care about what is on the display prior.
shadeDisplayArea() is used to shade a rectangular area using
oddEvenFill() is an efficient way to fill areas using the Even–odd rule. It may not work in all cases, but if it does work, it is preferrable to use.
floodFill() is a less efficient way to fill areas using the Flood fill recursive algorithm. It produces better results than oddEvenFill(), but is considerably slower and uses far more stack memory.
Go to the source code of this file.
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. | |
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.
x1 | The x coordinate to start the fill (top left) |
y1 | The y coordinate to start the fill (top left) |
x2 | The x coordinate to stop the fill (bottom right) |
y2 | The y coordinate to stop the fill (bottom right) |
c | The color to fill |
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
x1 | The X pixel to start at |
y1 | The Y pixel to start at |
x2 | The X pixel to end at |
y2 | The Y pixel to end at |
shadeLevel | The level of shading, Higher means more shaded. Must be 0 to 4 |
color | the color to draw with |
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.
x0 | The left index of the bounding box |
y0 | The top index of the bounding box |
x1 | The right index of the bounding box |
y1 | The bottom index of the bounding box |
boundaryColor | The color of the boundary to fill in |
fillColor | The color to fill |
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
x | The X coordinate to start the fill at |
y | The Y coordinate to start the fill at |
col | The color to fill in |
xMin | The minimum X coordinate to bound the fill |
yMin | The minimum Y coordinate to bound the fill |
xMax | The maximum X coordinate to bound the fill |
yMax | The maximum Y coordinate to bound the fill |
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.
x | The X coordinate of the center of the circle |
y | The Y coordinate of the center of the circle |
innerR | The radius of the inside of the sector, or 0 for the whole circle |
outerR | The radius of the circle |
startAngle | The starting angle of the sector, in degrees CCW |
endAngle | The ending angle of the sector, in degrees CCW |
col | The color to fill |