Graphics - Polkm105/DesignPatternPractice GitHub Wiki
PARTIAL
This section contains all functions relating to CP_Graphics
Table Of Contents
- CP_Graphics_ClearBackground
- CP_Graphics_DrawPoint
- CP_Graphics_DrawLine
- CP_Graphics_DrawLineAdvanced
- CP_Graphics_DrawRect
- CP_Graphics_DrawRectAdvanced
- CP_Graphics_DrawCircle
- CP_Graphics_DrawEllipse
- CP_Graphics_DrawEllipseAdvanced
- CP_Graphics_DrawTriangle
- CP_Graphics_DrawTriangleAdvanced
- CP_Graphics_DrawQuad
- CP_Graphics_DrawQuadAdvanced
- CP_Graphics_BeginShape
- CP_Graphics_AddVertex
- CP_Graphics_EndShape
CP_Graphics_ClearBackground
CP_Graphics_DrawPoint
This function draws a point at a given position. The color of the point is specified with the function CP_Settings_Fill. There is no stroke option for a point.
Function
void CP_Graphics_DrawPoint(float x, float y);
Parameters
- x - (float) The horizontal position of the point
- y - (float) The vertical position of the point
Return
This function does not return anything.
Example
void init()
{
// fill the background black to see the white points
CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
}
void update()
{
// Hide the cursor on this window
CP_System_ShowCursor(false);
// fill the pixel white
CP_Settings_Fill(CP_Color_Create(0, 0, 0, 255));
// draw a single pixel at the mouse position
CP_Graphics_DrawPoint(CP_Input_GetMouseX(), CP_Input_GetMouseY());
}
Related
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_ShowCursor
- CP_Settings_Fill
- CP_Input_GetMouseX
- CP_Input_GetMouseY
CP_Graphics_DrawLine
This function draws a line using two points. For most shapes you can set the color using CP_Settings_Fill, but a line is only a stroke, so you must use CP_Settings_Stroke to set the color.
Function
void CP_Graphics_DrawLine(float x1, float y1, float x2, float y2);
Parameters
- x1 - (float) the first point's x position
- y1 - (float) the first point's y position
- x2 - (float) the second point's x position
- y2 - (float) the second point's y position
Return
This function does not return anything.
Example
void update()
{
// set the stroke color to orange
CP_Settings_Stroke(CP_Color_Create(255, 160, 20, 255));
// draw a line from (100, 100) to (100, 200)
// x1 y1 x2 y2
CP_Graphics_DrawLine(100.0f, 100.0f, 500.0f, 100.0f);
// set the stroke color to light blue
CP_Settings_Stroke(CP_Color_Create(0, 160, 255, 255));
// draw a line from the origin to the mouse position
CP_Graphics_DrawLine(0.0f, 0.0f, CP_Input_GetMouseX(), CP_Input_GetMouseY());
}
Related
CP_Graphics_DrawLineAdvanced
A specialized version of the CP_Graphics_DrawLine function which allows the user to specify a rotation (in degrees). The line is always rotated around the center.
Function
void CP_Graphics_DrawLineAdvanced(float x1, float y1, float x2, float y2, float degrees);
Parameters
- x1 - (float) the horizontal position of the start of the line
- y1 - (float) the vertical position of the start of the line
- x2 - (float) the horizontal position of the end of the line
- y1 - (float) the vertical position of the end of the line
- degrees - (float) the rotation in degrees
Return
This function does not return anything.
Example
void update()
{
// a line from (100, 100) to (200, 100) rotated 45 degrees about the center
CP_Graphics_DrawLineAdvanced(100.0f, 100.0f, 200.0f, 100.0f, 45.0f);
}
Related
CP_Graphics_DrawRect
This is a function that draws a rectangle on the screen at a specified point with a specified width and height.
Function
void CP_Graphics_DrawRect(float x, float y, float w, float h);
Parameters
- x - (float) the horizontal position of the rectangle
- y - (float) the vertical position of the rectangle
- w - (float) the width of the rectangle
- h - (float) the height of the rectangle
Return
This function does not return anything.
Example
void update()
{
// Clear the background to a blue color
CP_Graphics_ClearBackground(CP_Color_Create(20, 200, 255, 255));
// Draw a rectangle at the point (100, 100)
CP_Graphics_DrawRect(100.0f, 100.0f, 50.0f, 50.0f);
// Draw a rectangle at the mouse position
CP_Graphics_DrawRect(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 25.0f, 25.0f);
}
Related
CP_Graphics_DrawRectAdvanced
This is a specialized version of the CP_Graphics_DrawRect function which additionally allows you to specify a rotation (in degrees). This rotates the rectangle around the reference point at which you draw the rectangle, so the CP_POSITION_CENTER CP_Settings_RectMode will rotate around the center of the rectangle, while the CP_POSITION_CORNER CP_Settings_RectMode will rotate around the top-left corner.
Function
void CP_Graphics_DrawRectAdvanced(float x, float y, float w, float h, float degrees, float cornerRadius);
Parameters
- x - (float) the horizontal position of the rectangle
- y - (float) the vertical position of the rectangle
- w - (float) the width of the rectangle
- h - (float) the height of the rectangle
- degrees - (float) the rotation in degrees
- cornerRadius - (float) the radius of the rounded corners of the rectangle (0 for no rounded corners)
Return
This function does not return anything.
Example
void update()
{
// draw a 100x50 rectangle rotated by 45 degrees
CP_Graphics_DrawRectAdvanced(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 100.0f, 50.0f, 45.0f);
}
Related
CP_Graphics_DrawCircle
This is a simplified version of CP_Graphics_DrawEllipse. A circle can be drawn on the screen using this function. The mode for drawing a circle and ellipse can be changed with CP_Settings_EllipseMode.
Function
void CP_Graphics_DrawCircle(float x, float y, float d);
Parameters
- x - (float) the horizontal position of the circle
- y - (float) the vertical position of the circle
- r - (float) the uniform radius of the circle by default
Return
This function does not return anything.
Example
void update()
{
// set the background color
CP_Graphics_ClearBackground(CP_Color_Create(255, 40, 200, 255));
//draw a circle at (100, 100)
CP_Graphics_DrawCircle(100, 100, 50.0f);
// draw a circle at the mouse position
CP_Graphics_DrawCircle(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 20.0f);
}
Related
CP_Graphics_DrawEllipse
This function allows you to draw an ellipse with differing width and height. To draw an ellipse, provide the x and y values of a point and the width and height (diameters) of your ellipse. You can set the fill color of the drawn shape with CP_Settings_Fill and the stroke color with CP_Settings_Stroke. The method for drawing ellipses can be changed to different modes using CP_Settings_EllipseMode.
Function
void CP_Graphics_DrawEllipse(float x, float y, float w, float h);
Parameters
- x - (float) the horizontal coordinate of the ellipse
- y - (float) the vertical coordinate of the ellipse
- w - (float) the width of the ellipse as a diameter
- h - (float) the height of the ellipse as a diameter
Return
This function does not return anything.
Example
void update()
{
// Set the background color to red
CP_Graphics_ClearBackground(CP_Color_Create(255, 100, 100, 255));
// Draw an ellipse at the point (100, 100)
CP_Graphics_DrawEllipse(100.0f, 100.0f, 50.0f, 80.0f);
// Draw an ellipse at the mouse position
CP_Graphics_DrawEllipse(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 20.0f, 60.0f);
}
Related
CP_Graphics_DrawEllipseAdvanced
A specialized version of the CP_Graphics_DrawEllipse function which allows you to specify a rotation (in degrees). The shape will rotate about the reference point specified by the CP_Settings_EllipseMode.
Function
void CP_Graphics_DrawEllipseAdvanced(float x, float y, float w, float h, float degrees);
Parameters
- x - (float) the horizontal position of the ellipse
- y - (float) the vertical position of the ellipse
- w - (float) the width (horizontal diameter) of the ellipse
- h - (float) the height (vertical diameter) of the ellipse
- degrees - (float) the rotation in degrees
Return
This function does not return anything.
Example
void update()
{
// draw a 100x50 ellipse rotated by 45 degrees at the mouse position
CP_Graphics_DrawEllipseAdvanced(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 100.0f, 50.0f, 45.0f);
}
Related
CP_Graphics_DrawTriangle
This function draws a triangle to the screen given three points. The filled color of the triangle can be set with CP_Settings_Fill and the stroke outline can be changed with CP_Settings_Stroke.
Function
void CP_Graphics_DrawTriangle(float x1, float y1, float x2, float y2, float x3, float y3);
Parameters
-
x1 - (float) the first point's horizontal position
-
y1 - (float) the first point's vertical position
-
x2 - (float) the second point's horizontal position
-
y2 - (float) the second point's vertical position
-
x3 - (float) the third point's horizontal position
-
y3 - (float) the third point's vertical position
Return
This function does not return anything.
Example
void update()
{
// set the fill color to red
CP_Settings_Fill(CP_Color_Create(255, 0, 0, 255));
// draw a triangle with three points
CP_Graphics_DrawTriangle(100.0f, 100.0f, // point 1
200.0f, 100.0f, // point 2
200.0f, 200.0f); // point 3
// set the fill color to dark blue
CP_Settings_Fill(CP_Color_Create(0, 0, 160, 255));
// draw a triangle with three points
CP_Graphics_DrawTriangle(0.0f, 0.0f, // point 1
CP_Input_GetMouseX(), CP_Input_GetMouseY(), // point 2
CP_Input_GetMousePreviousX(), CP_Input_GetMousePreviousY()); // point 3
}
Related
- CP_Settings_Fill
- CP_Color_Create
- CP_Input_GetMouseX
- CP_Input_GetMouseY
- CP_Input_GetMousePreviousX
- CP_Input_GetMousePreviousY
CP_Graphics_DrawTriangleAdvanced
A specialized version of the CP_Graphics_DrawTriangle function which allows the user to specify a rotation (in degrees). The rotation is always about the center of the triangle.
Function
void CP_Graphics_DrawTriangleAdvanced(float x1, float y1, float x2, float y2, float x3, float y3, float degrees);
Parameters
-
x1 - (float) the first point's horizontal position
-
y1 - (float) the first point's vertical position
-
x2 - (float) the second point's horizontal position
-
y2 - (float) the second point's vertical position
-
x3 - (float) the third point's horizontal position
-
y3 - (float) the third point's vertical position
-
degrees - (float) the rotation in degrees
Return
This function does not return anything.
Example
void update()
{
// A triangle drawn based on the points (100, 100), (125, 150), (75, 150)
// with a rotation of 15 degrees
CP_Graphics_DrawTriangleAdvanced(100.0f, 100.0f, 125.0f, 150.0f, 75.0f, 150.0f, 15.0f);
}
Related
CP_Graphics_DrawQuad
Quad will draw a quadrangle given four points. They need will need to be in clockwise or counter-clockwise order, but it doesn't matter which.
Function
void CP_Graphics_DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
Parameters
-
x1 - (float) the first point's horizontal position
-
y1 - (float) the first point's vertical position
-
x2 - (float) the second point's horizontal position
-
y2 - (float) the second point's vertical position
-
x3 - (float) the third point's horizontal position
-
y3 - (float) the third point's vertical position
-
x4 - (float) the fourth point's horizontal position
-
y4 - (float) the fourth point's vertical position
Return
This function does not return anything.
Example
void update()
{
// draw a quadrangle given four points
// x y
CP_Graphics_DrawQuad(0.0f, 0.0f,
100.0f, 0.0f,
100.0f, 50.0f,
0.0f, 50.0f);
}
Related
CP_Graphics_DrawQuadAdvanced
A specialized version of the CP_Graphics_DrawQuad function which allows the user to specify a rotation in degrees. The quadrangle is always rotated about the center.
Function
void CP_Graphics_DrawQuadAdvanced(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float degrees);
Parameters
-
x1 - (float) the first point's horizontal position
-
y1 - (float) the first point's vertical position
-
x2 - (float) the second point's horizontal position
-
y2 - (float) the second point's vertical position
-
x3 - (float) the third point's horizontal position
-
y3 - (float) the third point's vertical position
-
x4 - (float) the fourth point's horizontal position
-
y4 - (float) the fourth point's vertical position
-
degrees - (float) the rotation in degrees
Return
This function does not return anything.
Example
void update()
{
// draw a quad rotated by 45 degrees
CP_Graphics_DrawQuadAdvanced(100.0f, 100.0f, // corner 1
200.0f, 100.0f, // corner 2
200.0f, 150.0f, // corner 3
100.0f, 150.0f, // corner 4
45.0f); // degrees rotation
}
Related
CP_Graphics_BeginShape
Using CP_Graphics_BeginShape(), CP_Graphics_AddVertex, and CP_Graphics_EndShape, a shape can be defined with any number of vertices. After begin shape is called, use CP_Graphics_AddVertex to specify the specific vertices of the shape. A shape will not be drawn until CP_Graphics_EndShape is called.
Function
void CP_Graphics_BeginShape(void);
Parameters
This function has no parameters.
Return
This function does not return anything.
Example
void update()
{
// Start drawing a shape
CP_Graphics_BeginShape();
// Specify three vertices
CP_Graphics_AddVertex(100.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 200.0f);
// signal the end of the shape and draw the shape
CP_Graphics_EndShape();
}
Related
CP_Graphics_AddVertex
Using CP_Graphics_BeginShape, CP_Graphics_AddVertex, and CP_Graphics_EndShape, a shape can be defined with any number of vertices. After begin shape is called, use CP_Graphics_AddVertex to specify the specific vertices of the shape. A shape will not be drawn until CP_Graphics_EndShape is called.
Function
void CP_Graphics_AddVertex(float x, float y);
Parameters
- x - (float) the horizontal position of the vertex
- y - (float) the vertical position of the vertex
Return
This function does not return anything.
Example
void update()
{
// Start drawing a shape
CP_Graphics_BeginShape();
// Specify three vertices
CP_Graphics_AddVertex(100.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 200.0f);
// signal the end of the shape and draw the shape
CP_Graphics_EndShape();
}
Related
CP_Graphics_EndShape
Using CP_Graphics_BeginShape, CP_Graphics_AddVertex, and CP_Graphics_EndShape, a shape can be defined with any number of vertices. After begin shape is called, use CP_Graphics_AddVertex to specify the specific vertices of the shape. A shape will not be drawn until CP_Graphics_EndShape is called.
Function
void CP_Graphics_EndShape(void);
Parameters
This function has no parameters.
Return
This function does not return anything.
Example
void update()
{
// Start drawing a shape
CP_Graphics_BeginShape();
// Specify three vertices
CP_Graphics_AddVertex(100.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 200.0f);
// signal the end of the shape and draw the shape
CP_Graphics_EndShape();
}