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

Macros

#define FIXEDPOINT   16
 
#define FIXEDPOINTD2   15
 
#define M_MAX   6
 
#define M_MAX   6
 

Functions

void initShapes (void)
 Initialize shape drawing by making a static local pointer to the framebuffer This is done for speed reasons.
 
void drawLine (int x0, int y0, int x1, int y1, paletteColor_t col, int dashWidth)
 Draw a one pixel wide straight line between two points. The line may be solid or dashed.
 
void drawLineScaled (int x0, int y0, int x1, int y1, paletteColor_t col, int dashWidth, int xOrigin, int yOrigin, int xScale, int yScale)
 Draw a line that that is translated and scaled. Scaling may make it wider than one pixel. The line may be solid or dashed. The line coordinates are given in terms scaled pixels, not display pixels. The origin of the scaled pixel coordinates can be translated using xOrigin and yOrigin, essentially creating a "canvas" of scaled pixels in a section of the screen.
 
void drawLineFast (int16_t x0, int16_t y0, int16_t x1, int16_t y1, paletteColor_t color)
 Optimized method to quickly draw a one pixel wide solid line.
 
void drawRect (int x0, int y0, int x1, int y1, paletteColor_t col)
 Draw the a one pixel wide outline of a rectangle.
 
void drawRectFilled (int x0, int y0, int x1, int y1, paletteColor_t col)
 Draw a filled rectangle, with bounds checking and arbitrary orders.
 
void drawRectScaled (int x0, int y0, int x1, int y1, paletteColor_t col, int xOrigin, int yOrigin, int xScale, int yScale)
 Draw the outline of a rectangle that is translated and scaled. Scaling may make it wider than one pixel.
 
void drawRoundedRect (int x0, int y0, int x1, int y1, int r, paletteColor_t fillColor, paletteColor_t outlineColor)
 Draw an outlined and filled rectangle with rounded corners.
 
void drawTriangleOutlined (int16_t v0x, int16_t v0y, int16_t v1x, int16_t v1y, int16_t v2x, int16_t v2y, paletteColor_t fillColor, paletteColor_t outlineColor)
 Optimized method to draw a triangle with outline. The interior color may be cTransparent to draw just an outline.
 
void drawEllipseScaled (int xm, int ym, int a, int b, paletteColor_t col, int xOrigin, int yOrigin, int xScale, int yScale)
 Draw the outline of an ellipse with translation and scaling. Scaling may make it wider than one pixel.
 
void drawEllipse (int xm, int ym, int a, int b, paletteColor_t col)
 Draw a one pixel wide outline of an ellipse.
 
void drawCircle (int xm, int ym, int r, paletteColor_t col)
 Draw the one pixel wide outline of a circle.
 
void drawCircleScaled (int xm, int ym, int r, paletteColor_t col, int xOrigin, int yOrigin, int xScale, int yScale)
 Draw the outline of a circle with translation and scaling. Scaling may make it wider than one pixel.
 
void drawCircleQuadrants (int xm, int ym, int r, bool q1, bool q2, bool q3, bool q4, paletteColor_t col)
 Draw the one pixel wide outline of the quadrants of a circle.
 
void drawCircleFilledQuadrants (int xm, int ym, int r, bool q1, bool q2, bool q3, bool q4, paletteColor_t col)
 Draw filled-in quadrants of a circle.
 
void drawCircleOutline (int xm, int ym, int r, int stroke, paletteColor_t col)
 Draw the outline of a circle with the given stroke width.
 
void drawCircleFilled (int xm, int ym, int r, paletteColor_t col)
 Draw a filled circle.
 
void drawCircleFilledScaled (int xm, int ym, int r, paletteColor_t col, int xOrigin, int yOrigin, int xScale, int yScale)
 Draw a filed circle with translation and scaling.
 
void drawEllipseRect (int x0, int y0, int x1, int y1, paletteColor_t col)
 Draw a one pixel wide outline of an ellipse within a rectangle.
 
void drawEllipseRectScaled (int x0, int y0, int x1, int y1, paletteColor_t col, int xOrigin, int yOrigin, int xScale, int yScale)
 Draw the outline of an ellipse with translation and scaling within a rectangle. Scaling may make it wider than one pixel.
 
void drawQuadBezierSeg (int x0, int y0, int x1, int y1, int x2, int y2, paletteColor_t col)
 Draw a one pixel wide quadratic Bezier curve. This is limited to gradients without sign change.
 
void drawQuadBezierSegScaled (int x0, int y0, int x1, int y1, int x2, int y2, paletteColor_t col, int xOrigin, int yOrigin, int xScale, int yScale)
 Draw a one pixel wide quadratic Bezier curve with translation and scaling. This is limited to gradients without sign change.
 
void drawQuadBezier (int x0, int y0, int x1, int y1, int x2, int y2, paletteColor_t col)
 Draw a one pixel wide quadratic Bezier curve.
 
void drawQuadBezierScaled (int x0, int y0, int x1, int y1, int x2, int y2, paletteColor_t col, int xOrigin, int yOrigin, int xScale, int yScale)
 Draw a one pixel wide quadratic Bezier curve with translation and scaling.
 
void drawQuadRationalBezierSeg (int x0, int y0, int x1, int y1, int x2, int y2, float w, paletteColor_t col)
 Draw a limited one pixel wide rational Bezier curve with squared weight.
 
void drawQuadRationalBezier (int x0, int y0, int x1, int y1, int x2, int y2, float w, paletteColor_t col)
 Draw any one pixel wide quadratic rational Bezier curve with squared weight.
 
void drawRotatedEllipse (int x, int y, int a, int b, float angle, paletteColor_t col)
 Draw an ellipse rotated by angle (radian)
 
void drawRotatedEllipseRect (int x0, int y0, int x1, int y1, long zd, paletteColor_t col)
 Draw an ellipse, bounded by a rectangle, rotated (integer)
 
void drawCubicBezierSeg (int x0, int y0, float x1, float y1, float x2, float y2, int x3, int y3, paletteColor_t col)
 Draw limited cubic Bezier segment.
 
void drawCubicBezier (int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, paletteColor_t col)
 Draw any cubic Bezier curve.
 
void drawCubicBezierScaled (int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, paletteColor_t col, int xOrigin, int yOrigin, int xScale, int yScale)
 Draw any cubic Bezier curve with translation and scaling.
 
void drawQuadSpline (int n, int x[], int y[], paletteColor_t col)
 Draw a quadratic spline. This overwrites the input arrays x and y.
 
void drawCubicSpline (int n, int x[], int y[], paletteColor_t col)
 Draw a cubic spline. This overwrites the input arrays x and y.
 

Macro Definition Documentation

◆ FIXEDPOINT

#define FIXEDPOINT   16

◆ FIXEDPOINTD2

#define FIXEDPOINTD2   15

◆ M_MAX [1/2]

#define M_MAX   6

◆ M_MAX [2/2]

#define M_MAX   6

Function Documentation

◆ initShapes()

void initShapes ( void )

Initialize shape drawing by making a static local pointer to the framebuffer This is done for speed reasons.

◆ drawLine()

void drawLine ( int x0,
int y0,
int x1,
int y1,
paletteColor_t col,
int dashWidth )

Draw a one pixel wide straight line between two points. The line may be solid or dashed.

Parameters
x0The X coordinate to start the line at
y0The Y coordinate to start the line at
x1The X coordinate to end the line at
y1The Y coordinate to end the line at
colThe color to draw
dashWidthThe width of each dash, or 0 for a solid line

◆ drawLineScaled()

void drawLineScaled ( int x0,
int y0,
int x1,
int y1,
paletteColor_t col,
int dashWidth,
int xOrigin,
int yOrigin,
int xScale,
int yScale )

Draw a line that that is translated and scaled. Scaling may make it wider than one pixel. The line may be solid or dashed. The line coordinates are given in terms scaled pixels, not display pixels. The origin of the scaled pixel coordinates can be translated using xOrigin and yOrigin, essentially creating a "canvas" of scaled pixels in a section of the screen.

Parameters
x0The X coordinate to start the line at, in scaled pixels
y0The Y coordinate to start the line at, in scaled pixels
x1The X coordinate to end the line at, in scaled pixels
y1The Y coordinate to end the line at, in scaled pixels
colThe color to draw
dashWidthThe width of each dash, in scaled pixels, or 0 for a solid line
xOriginThe X-origin, in display pixels, of the scaled pixel area
yOriginThe Y-origin, in display pixels, of the scaled pixel area
xScaleThe width of each scaled pixel
yScaleThe height of each scaled pixel

◆ drawLineFast()

void drawLineFast ( int16_t x0,
int16_t y0,
int16_t x1,
int16_t y1,
paletteColor_t color )

Optimized method to quickly draw a one pixel wide solid line.

Parameters
x0The X coordinate to start the line at
y0The Y coordinate to start the line at
x1The X coordinate to end the line at
y1The Y coordinate to end the line at
colorThe color to draw the line

◆ drawRect()

void drawRect ( int x0,
int y0,
int x1,
int y1,
paletteColor_t col )

Draw the a one pixel wide outline of a rectangle.

Parameters
x0The X coordinate of the top left corner
y0The Y coordinate of the top left corner
x1The X coordinate of the bottom right corner
y1The Y coordinate of the bottom right corner
colThe color to draw

◆ drawRectFilled()

void drawRectFilled ( int x0,
int y0,
int x1,
int y1,
paletteColor_t col )

Draw a filled rectangle, with bounds checking and arbitrary orders.

Parameters
x0
y0
x1
y1
col

◆ drawRectScaled()

void drawRectScaled ( int x0,
int y0,
int x1,
int y1,
paletteColor_t col,
int xOrigin,
int yOrigin,
int xScale,
int yScale )

Draw the outline of a rectangle that is translated and scaled. Scaling may make it wider than one pixel.

Parameters
x0The X coordinate of the top left corner
y0The Y coordinate of the top left corner
x1The X coordinate of the bottom right corner
y1The Y coordinate of the bottom right corner
colThe color to draw
xOriginThe X-origin, in display pixels, of the scaled pixel area
yOriginThe Y-origin, in display pixels, of the scaled pixel area
xScaleThe width of each scaled pixel
yScaleThe height of each scaled pixel

◆ drawRoundedRect()

void drawRoundedRect ( int x0,
int y0,
int x1,
int y1,
int r,
paletteColor_t fillColor,
paletteColor_t outlineColor )

Draw an outlined and filled rectangle with rounded corners.

Parameters
x0The left edge of the rectangle
y0The top edge of the rectangle
x1The right edge of the rectangle
y1The bottom edge of the rectangle
rThe radius of the rectangle corners
fillColorThe color to fill the body, or cTransparent to skip
outlineColorThe color to outline the rectangle, or cTransparent to skip

◆ drawTriangleOutlined()

void drawTriangleOutlined ( int16_t v0x,
int16_t v0y,
int16_t v1x,
int16_t v1y,
int16_t v2x,
int16_t v2y,
paletteColor_t fillColor,
paletteColor_t outlineColor )

Optimized method to draw a triangle with outline. The interior color may be cTransparent to draw just an outline.

Parameters
v0xVertex 0's X coordinate
v0yVertex 0's Y coordinate
v1xVertex 1's X coordinate
v1yVertex 1's Y coordinate
v2xVertex 2's X coordinate
v2yVertex 2's Y coordinate
fillColorfilled area color
outlineColoroutline color

◆ drawEllipseScaled()

void drawEllipseScaled ( int xm,
int ym,
int a,
int b,
paletteColor_t col,
int xOrigin,
int yOrigin,
int xScale,
int yScale )

Draw the outline of an ellipse with translation and scaling. Scaling may make it wider than one pixel.

Parameters
xmThe X coordinate of the center of the ellipse
ymThe Y coordinate of the center of the ellipse
aThe X radius of the ellipse
bThe Y radius of the ellipse
colThe color to draw
xOriginThe X-origin, in display pixels, of the scaled pixel area
yOriginThe Y-origin, in display pixels, of the scaled pixel area
xScaleThe width of each scaled pixel
yScaleThe height of each scaled pixel

◆ drawEllipse()

void drawEllipse ( int xm,
int ym,
int a,
int b,
paletteColor_t col )

Draw a one pixel wide outline of an ellipse.

Parameters
xmThe X coordinate of the center of the ellipse
ymThe Y coordinate of the center of the ellipse
aThe X radius of the ellipse
bThe Y radius of the ellipse
colThe color to draw

◆ drawCircle()

void drawCircle ( int xm,
int ym,
int r,
paletteColor_t col )

Draw the one pixel wide outline of a circle.

Parameters
xmThe X coordinate of the center of the circle
ymThe Y coordinate of the center of the circle
rThe radius of the circle
colThe color to draw

◆ drawCircleScaled()

void drawCircleScaled ( int xm,
int ym,
int r,
paletteColor_t col,
int xOrigin,
int yOrigin,
int xScale,
int yScale )

Draw the outline of a circle with translation and scaling. Scaling may make it wider than one pixel.

Parameters
xmThe X coordinate of the center of the circle
ymThe Y coordinate of the center of the circle
rThe radius of the circle
colThe color to draw
xOriginThe X-origin, in display pixels, of the scaled pixel area
yOriginThe Y-origin, in display pixels, of the scaled pixel area
xScaleThe width of each scaled pixel
yScaleThe height of each scaled pixel

◆ drawCircleQuadrants()

void drawCircleQuadrants ( int xm,
int ym,
int r,
bool q1,
bool q2,
bool q3,
bool q4,
paletteColor_t col )

Draw the one pixel wide outline of the quadrants of a circle.

Parameters
xmThe X coordinate of the center of the circle
ymThe Y coordinate of the center of the circle
rThe radius of the circle
q1True to draw the top right quadrant
q2True to draw the top left quadrant
q3True to draw the bottom left quadrant
q4True to draw the bottom right quadrant
colThe color to draw

◆ drawCircleFilledQuadrants()

void drawCircleFilledQuadrants ( int xm,
int ym,
int r,
bool q1,
bool q2,
bool q3,
bool q4,
paletteColor_t col )

Draw filled-in quadrants of a circle.

Parameters
xmThe X coordinate of the center of the circle
ymThe Y coordinate of the center of the circle
rThe radius of the circle
q1True to draw the top right quadrant
q2True to draw the top left quadrant
q3True to draw the bottom left quadrant
q4True to draw the bottom right quadrant
colThe color to fill the shape in

Left half

◆ drawCircleOutline()

void drawCircleOutline ( int xm,
int ym,
int r,
int stroke,
paletteColor_t col )

Draw the outline of a circle with the given stroke width.

Parameters
xmThe X coordinate of the center of the circle
ymThe Y coordinate of the center of the circle
rThe radius of the circle
strokeThe stroke width (pixels inside the radius)
colThe color to draw

◆ drawCircleFilled()

void drawCircleFilled ( int xm,
int ym,
int r,
paletteColor_t col )

Draw a filled circle.

Parameters
xmThe X coordinate of the center of the circle
ymThe Y coordinate of the center of the circle
rThe radius of the circle
colThe color to draw

◆ drawCircleFilledScaled()

void drawCircleFilledScaled ( int xm,
int ym,
int r,
paletteColor_t col,
int xOrigin,
int yOrigin,
int xScale,
int yScale )

Draw a filed circle with translation and scaling.

Parameters
xmThe X coordinate of the center of the circle
ymThe Y coordinate of the center of the circle
rThe radius of the circle
colThe color to draw
xOriginThe X-origin, in display pixels, of the scaled pixel area
yOriginThe Y-origin, in display pixels, of the scaled pixel area
xScaleThe width of each scaled pixel
yScaleThe height of each scaled pixel

◆ drawEllipseRect()

void drawEllipseRect ( int x0,
int y0,
int x1,
int y1,
paletteColor_t col )

Draw a one pixel wide outline of an ellipse within a rectangle.

Parameters
x0The X coordinate of the top left corner
y0The Y coordinate of the top left corner
x1The X coordinate of the bottom right corner
y1The Y coordinate of the bottom right corner
colThe color to draw

◆ drawEllipseRectScaled()

void drawEllipseRectScaled ( int x0,
int y0,
int x1,
int y1,
paletteColor_t col,
int xOrigin,
int yOrigin,
int xScale,
int yScale )

Draw the outline of an ellipse with translation and scaling within a rectangle. Scaling may make it wider than one pixel.

Parameters
x0The X coordinate of the top left corner
y0The Y coordinate of the top left corner
x1The X coordinate of the bottom right corner
y1The Y coordinate of the bottom right corner
colThe color to draw
xOriginThe X-origin, in display pixels, of the scaled pixel area
yOriginThe Y-origin, in display pixels, of the scaled pixel area
xScaleThe width of each scaled pixel
yScaleThe height of each scaled pixel

◆ drawQuadBezierSeg()

void drawQuadBezierSeg ( int x0,
int y0,
int x1,
int y1,
int x2,
int y2,
paletteColor_t col )

Draw a one pixel wide quadratic Bezier curve. This is limited to gradients without sign change.

Parameters
x0The X coordinate of the first point
y0The Y coordinate of the first point
x1The X coordinate of the second point
y1The Y coordinate of the second point
x2The X coordinate of the third point
y2The Y coordinate of the third point
colThe color to draw

◆ drawQuadBezierSegScaled()

void drawQuadBezierSegScaled ( int x0,
int y0,
int x1,
int y1,
int x2,
int y2,
paletteColor_t col,
int xOrigin,
int yOrigin,
int xScale,
int yScale )

Draw a one pixel wide quadratic Bezier curve with translation and scaling. This is limited to gradients without sign change.

Parameters
x0The X coordinate of the first point
y0The Y coordinate of the first point
x1The X coordinate of the second point
y1The Y coordinate of the second point
x2The X coordinate of the third point
y2The Y coordinate of the third point
colThe color to draw
xOriginThe X-origin, in display pixels, of the scaled pixel area
yOriginThe Y-origin, in display pixels, of the scaled pixel area
xScaleThe width of each scaled pixel
yScaleThe height of each scaled pixel

◆ drawQuadBezier()

void drawQuadBezier ( int x0,
int y0,
int x1,
int y1,
int x2,
int y2,
paletteColor_t col )

Draw a one pixel wide quadratic Bezier curve.

Parameters
x0The X coordinate of the first point
y0The Y coordinate of the first point
x1The X coordinate of the second point
y1The Y coordinate of the second point
x2The X coordinate of the third point
y2The Y coordinate of the third point
colThe color to draw

◆ drawQuadBezierScaled()

void drawQuadBezierScaled ( int x0,
int y0,
int x1,
int y1,
int x2,
int y2,
paletteColor_t col,
int xOrigin,
int yOrigin,
int xScale,
int yScale )

Draw a one pixel wide quadratic Bezier curve with translation and scaling.

Parameters
x0The X coordinate of the first point
y0The Y coordinate of the first point
x1The X coordinate of the second point
y1The Y coordinate of the second point
x2The X coordinate of the third point
y2The Y coordinate of the third point
colThe color to draw
xOriginThe X-origin, in display pixels, of the scaled pixel area
yOriginThe Y-origin, in display pixels, of the scaled pixel area
xScaleThe width of each scaled pixel
yScaleThe height of each scaled pixel

◆ drawQuadRationalBezierSeg()

void drawQuadRationalBezierSeg ( int x0,
int y0,
int x1,
int y1,
int x2,
int y2,
float w,
paletteColor_t col )

Draw a limited one pixel wide rational Bezier curve with squared weight.

Parameters
x0The X coordinate of the first point
y0The Y coordinate of the first point
x1The X coordinate of the second point
y1The Y coordinate of the second point
x2The X coordinate of the third point
y2The Y coordinate of the third point
wSquared Weight
colThe color to draw

◆ drawQuadRationalBezier()

void drawQuadRationalBezier ( int x0,
int y0,
int x1,
int y1,
int x2,
int y2,
float w,
paletteColor_t col )

Draw any one pixel wide quadratic rational Bezier curve with squared weight.

Parameters
x0The X coordinate of the first point
y0The Y coordinate of the first point
x1The X coordinate of the second point
y1The Y coordinate of the second point
x2The X coordinate of the third point
y2The Y coordinate of the third point
wSquared Weight
colThe color to draw

◆ drawRotatedEllipse()

void drawRotatedEllipse ( int x,
int y,
int a,
int b,
float angle,
paletteColor_t col )

Draw an ellipse rotated by angle (radian)

Parameters
xThe X coordinate of the center of the ellipse
yThe Y coordinate of the center of the ellipse
aThe X radius of the ellipse
bThe Y radius of the ellipse
angleThe angle, in radians, to rotate the ellipse by
colThe color to draw

◆ drawRotatedEllipseRect()

void drawRotatedEllipseRect ( int x0,
int y0,
int x1,
int y1,
long zd,
paletteColor_t col )

Draw an ellipse, bounded by a rectangle, rotated (integer)

Parameters
x0The X coordinate of the top left corner
y0The Y coordinate of the top left corner
x1The X coordinate of the bottom right corner
y1The Y coordinate of the bottom right corner
zdThe integer angle to rotate the ellipse
colThe color to draw

◆ drawCubicBezierSeg()

void drawCubicBezierSeg ( int x0,
int y0,
float x1,
float y1,
float x2,
float y2,
int x3,
int y3,
paletteColor_t col )

Draw limited cubic Bezier segment.

Parameters
x0The X coordinate of the first point
y0The Y coordinate of the first point
x1The X coordinate of the second point
y1The Y coordinate of the second point
x2The X coordinate of the third point
y2The Y coordinate of the third point
x3The X coordinate of the fourth point
y3The Y coordinate of the fourth point
colThe color to draw

◆ drawCubicBezier()

void drawCubicBezier ( int x0,
int y0,
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
paletteColor_t col )

Draw any cubic Bezier curve.

Parameters
x0The X coordinate of the first point
y0The Y coordinate of the first point
x1The X coordinate of the second point
y1The Y coordinate of the second point
x2The X coordinate of the third point
y2The Y coordinate of the third point
x3The X coordinate of the fourth point
y3The Y coordinate of the fourth point
colThe color to draw

◆ drawCubicBezierScaled()

void drawCubicBezierScaled ( int x0,
int y0,
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
paletteColor_t col,
int xOrigin,
int yOrigin,
int xScale,
int yScale )

Draw any cubic Bezier curve with translation and scaling.

Parameters
x0The X coordinate of the first point
y0The Y coordinate of the first point
x1The X coordinate of the second point
y1The Y coordinate of the second point
x2The X coordinate of the third point
y2The Y coordinate of the third point
x3The X coordinate of the fourth point
y3The Y coordinate of the fourth point
colThe color to draw
xOriginThe X-origin, in display pixels, of the scaled pixel area
yOriginThe Y-origin, in display pixels, of the scaled pixel area
xScaleThe width of each scaled pixel
yScaleThe height of each scaled pixel

◆ drawQuadSpline()

void drawQuadSpline ( int n,
int x[],
int y[],
paletteColor_t col )

Draw a quadratic spline. This overwrites the input arrays x and y.

Parameters
nThe number of points in the spline
xThe X coordinates of the points in the spline
yThe Y coordinates of the points in the spline
colThe color to draw

◆ drawCubicSpline()

void drawCubicSpline ( int n,
int x[],
int y[],
paletteColor_t col )

Draw a cubic spline. This overwrites the input arrays x and y.

Parameters
nThe number of points in the spline
xThe X coordinates of the points in the spline
yThe Y coordinates of the points in the spline
colThe color to draw