sdl2 Gfxutils
sdl2 Gfxutils
𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛
Release latest
1 SDL2_gfxutils presentation 3
1.1 SDL2_gfxutils brief history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 SDL2_gfxutils presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 Animations advice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.5 SDL2_gfxutils Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 SDL2_gfxutils License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.7 Credits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 Base functions 15
3.1 Angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3 Pixel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5 Arc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5 Displaying forms 29
5.1 display functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.2 Anti-aliasing display functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
i
5.3 Thickness settable display functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.4 Define your own displaying functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6 Operations 39
6.1 Pixel operations functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.2 Forms operations functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7 Setters functions 45
7.1 Center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.2 Radius (size) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.3 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
8 Getters functions 47
8.1 Center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
8.2 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
8.3 Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
8.4 Real length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
8.5 Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
9 Miscellaneous 51
9.1 trajectories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
10 Utils 53
10.1 Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
10.2 Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
ii
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Contents:
Contents 1
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
2 Contents
CHAPTER 1
SDL2_gfxutils presentation
library SDL2_gfxutils
version 2.0.0
platform Linux, Windows, (Posix Compliant not tested).
compiler gcc, g++, clang, mingw32, mingw-w64-686, mingw-w64-x86_64.
synopsis SDL2_gfxutils a SDL2_gfx forms generating and manipulating helper functions set
Licence GPLv3
author Eddie Brüggemann <[email protected]>
SDL2_gfxutils is issue from an collection of functions that i have implemented over the years, everytime i had a
idea of a form to generate i try to implemented it as a function generating the sequence of coordinates or performing
operations on a form. At start i implemented my ideas with the python pygame module, which is based on the SDL
library, by start i get only the functions to set a pixel according the a radius and an angle offset, so SDL2_gfxutils is a
translation of python functions into the C language and the SDL2_gfx standart.
SDL2_gfxutils has been entirely rewritten after the first version release which suffers under severals bugs and was not
handy to use, mostly for animations.
note After the disaster everything are right.
All forms generating functions now return a pointer on a specific SDL2_gfxutils type compatible with the generic
SDL2_gfxutils Form type.
The pointers permit to manipulate the forms for transforming or animating (rotating, scaling, translating, mirror-
ing) functions easily.
3
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
The pointers can be destroyed at your convienence of course. And this mechanic is massively used in form generating
functions. So that no memory space is lost.
The generic Form type has been change to contains coordinates from type float, instead of type int16_t, so that
the computation like rotating, scaling, translating, mirroring are now exactly executed.
The subtype Pixel members are now from type float.
• Some functions have been removed because they become useless, because of the new pointers system.
• Some functions have been added for replacing the missing features, with many advantages, mostly for trans-
forming or animating forms in the SDL2 mainloop.
• All functions have been improved, favor of the pointers mechanic.
SDL2_gfxutils presentation
SDL2_gfxutils is en extension for the SDL2_gfx library helping you for the creation of the fantastics drawing your
brain can imagined.
SDL2_gfxutils provide severals functions for severals usages:
• A lot of forms generating functions, from the simple polygons, through stars, to the fantastic fractals.
• High-level Transforming or animating functions (rotating, scaling, translating and mirroring) acting on an entire
Form.
• Low-level Transforming or animating functions (rotating, scaling, translating and mirroring) acting on a single
Pixel.
• Memory management and check functions.
note I think it’s easy to adapt the SDL2_gfxutils library to be compatible with others libraries than the
SDL2 library.
Note: You can use this member to build bounding boxes for collision detection per example.
Note: For every displaying function it exist a thickness setttable displaying function and an anti-aliasing displaying
function except for the filled forms functions.
Angles
In the 2D display from SDL2: the X axes goes from left to right and the Y axes from up to down.
For the multiple used orientation parameter from type float. Sea the following image to become acquainted
with the values and with the conventional angle values.
1.3. Angles 5
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Animations advice
Polygon and forms are not only displayable object but can also be an guideline for the execution of an animation which
moving a form trough the way of the lines from the polygon or the form.
SDL2_gfxutils provide an function compute_trajectory() with which you can construct an moving line by moving a
form through the pixels of the positions array by translating it with the translate_form() function.
This ‘SDL2_gfxutils Documentation’ is licensed under the Creative Commons Attribution-NonCommercial 4.0 Inter-
national License.
To view a copy of this license, visit <http://creativecommons.org/licenses/by-nc/4.0/>.
SDL2_gfxutils License
Note: SDL2_gfxutils is under copyright from the GNU General Public License.
Credits
Thank’s
1.7. Credits 7
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
9
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
The Pixel type is used for holding the datas about an pixel:
the x and y coordinate values.
The Pixel type is used by functions which return a single pixel.
The Line type is used for holding the datas about a line:
• The line start Pixel.
• The line end Pixel.
• The color of the line as red, green, blue and alpha values.
The Line type is used by functions which return a segment.
The Coords type in only used internally to be a member of the Polygon type.
Note: By displaying operations the float array members are converted to int16_t (the SDL2_gfx coordinates
arrays standart type for displaying) in this way:
int c ;
ret=lineRGBA(pRenderer,
(int16_t) roundf(form->coords.x[c]),
(int16_t) roundf(form->coords.y[c]),
(int16_t) roundf(form->coords.x[c+1]),
(int16_t) roundf(form->coords.y[c+1]),
form->color.r,
form->color.g,
form->color.b,
form->color.a) ;
}
note After using a Form, Wenn you do not need it in the future, you can free the form.
• The length between the center and the most distant coordinate from the center: the real_length
member.
• The offset defining the incline of a form: the orientation.
note All derived types are define as an Form type so that you don’t need to cast it if you use a Form
generic function.
There are many forms representing derivated types from the Polygon type.
Notice
it’s easy to round and cast the float in the target type, like this:
2.7. Notice 13
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Base functions
Here are describe the geometric, base functions functions, from SDL2_gfxutils used from the differents
forms generating functions.
Angles
Distance
15
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Pixel
Pixel get_pixel_coords(uint32_t position, uint32_t scale, float length, Pixel center, float orientation)
Parameters
• position (uint32_t) – An unsigned integer needed for positional purpose.
• scale (uint32_t) – Scaling of the angle.
• length (float) – radius.
• center (Pixel) – center.
• orientation (float) – An additionnal offset to add.
Return type Pixel
Returns The pixel initialized in relationship to the given settings.
This function return an pixel initialized in relationship to the given settings,
by first getting the angle:
Line
Arc
3.5. Arc 17
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Polygons
19
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
• orientation (float) – An offset in degrees to add to influence the incline of the poly-
gon.
Return type Polygon *
Returns
A polygon which corners are arcs which size is in relationship to the number of sides of the
polygon.
see A blue 12 sides rounded corners polygon.
Note The radius goes from the center to the center of the circle arcs: the rounded corners.
Polygon *generate_sides_rounded_polygon(uint32_t sides, float radius, Pixel center, float orienta-
tion)
Parameters
• sides (uint32_t) – The number of sides of the polygon to generate.
• radius (float) – The radius of the polygon to generate.
• center (Pixel) – The wanted center of the polygon.
• orientation (float) – An offset in degrees to add to influence the incline of the poly-
gon.
Return type Polygon *
Returns
A polygon which sides are rounded according the number of sides of the polygon.
see A blue 12 sides rounded corners polygon.
Note The radius goes from the center to the center of the circle arcs.
Note The radius goes from the center to the center of the circle arcs.
Warning: The sides number is multiply per 2 to obtains an even numbered polygon.
Warning: The result is an even polygon of the double of the sides values.
Warning: The result is an even polygon of the double of the sides values.
4.1. Polygons 21
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Stars
pentagram
hexagram
Fractal
Polygon *generate_fractal(uint32_t polygon, float radius, Pixel center, float orientation, bool open)
Parameters
• polygon (uint32_t) – Base polygon from the fractal.
4.3. pentagram 23
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Spiral
Note: The base and the offset_exponent parameters values will influente of the size of
the spiral.
You cannot set an radius but the generating function does it.
note The value from the base parameter will be divided per two in the resulting spiral.
Warning: The turns parameter value will be multiply per 2 to obtains the number of
revolutions of the spiral.
The base parameter will be divided per two in the resulting spiral.
I can only generate even spirals.
Wheels
Polygon *generate_wheel(uint32_t polygon, float radius, Pixel center, float offset, float orientation)
Parameters
• polygon (uint32_t) – Number of sides of the wheel (base polygon).
• radius (float) – The radius of the wheel.
• center (Pixel) – The center from the wheel.
• offset (float) – Size of the peaks of the wheel.
Return type Polygon *
Returns
A pointed wheel according to the given settings.
note The peaks of the wheel are trigons like a star.
see A blue 24 peaks wheel.
Note The radius value is the radius of the base polygon.
Note: You must set an offset value other than 0 because it represent the size of the peaks of the
wheel.
The difference betwenn this wheel and a normal star is that is regular.
note the radius Polygon member from this wheel is the radius of the base polygon from
this wheel (interior).
4.7. Wheels 25
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
note This function generate an pointed wheel (rounded polygon) with peaks looking
like a tube but they are only right-angled line to the sides and connected trough an
arc.
see A blue 24 rounded square peaks wheel.
Note The radius value is the radius of the base polygon.
4.7. Wheels 27
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Displaying forms
display functions
Line
Arc
29
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Returns
0 on success, -1 on failure.
see display arc.
This function display the arc in the current color and at the current position.
Polygon
Star
Returns
0 on success, -1 on failure.
see display flower star.
This function display the flower star in the current color and at the current position.
int display_strikethrough_star(SDL_Renderer *pRenderer, Star *star)
Parameters
• pRenderer – A SDL_Renderer pointer.
• star (Star *) – The star to display.
Return type int
Returns
0 on success, -1 on failure.
see display strikethrough star.
This function display the strikethrough star in the current color and at the current position.
int display_polygon_star(SDL_Renderer *pRenderer, Star *star)
Parameters
• pRenderer – A SDL_Renderer pointer.
• star (Star *) – The star to display.
Return type int
Returns
0 on success, -1 on failure.
see display polygon star.
This function display the polygon star in the current color and at the current position.
int display_filled_star(SDL_Renderer *pRenderer, Star *star)
Parameters
• pRenderer – A SDL_Renderer pointer.
• star (Star *) – The star to display.
Return type int
Returns
0 on success, -1 on failure.
see display filled star.
This function display the strikethrough star in the current color and at the current position.
Spiral
Line
Arc
Polygon
Star
Spiral
Line
Arc
Polygon
Star
Spiral
Operations
Here are presented the functions which apply an transformation operation on a Pixel or on a Form.
This function are the base for the forms operations functions.
You can use it to implement your own operations.
Note: Rotating a pixel around the origin is easy doing according following formel in matrix form:
+- -+ +-- --+ +- -+
| x1 | | cos(angle) -sin(angle) 0 | | x |
| y2 | = | sin(angle) cos(angle) 0 | * | y |
| 0 | | 0 0 1 | | 0 |
+- -+ +-- --+ +- -+
39
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
So you can simply translate the pixel in accord to the origin rotate it and translate it back.
But SDL2_gfxutils use a function based on matrix to rotate the pixel around an arbitrary point.
See the source at file base_functions.c.
Note: For translating a pixel simply add (even negativ) the wanted values to the x and y from the pixel Pixel
members.
40 Chapter 6. Operations
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
They all apply a transformation on a form by calling the pixels operations functions.
By using a pointer on the generic Form type form to transform given as argument.
Parameters
• form (Form) – A pointer on the form to scale.
• factor (float) – The scaling factor.
Return type void.
This function scale the adressed form from value factor.
Note: You can set a new radius (which will update the length Form type member) directly,
With the function set_form_radius()
What permit to change the size of the form without using a factor but a radius instead.
warning Use only integers values or not more than 3 precision (%.3f) otherwise your request will
not be exactly satisfy.
42 Chapter 6. Operations
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Argument axes:
‘X’) If mirroring over axes X all pixels must must be above or below from the center argument x Pixel
type member.
‘Y’) If mirroring over axes Y all pixels must must be at the right or at the left from the center argument
y Pixel type member.
44 Chapter 6. Operations
CHAPTER 7
Setters functions
This functions will permit you to change and so transform and or animating your forms.
Or to change their colors.
Center
Radius (size)
45
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Returns void
This function set a new radius to the given form.
What permit to change the Form size directly by setting a new radius by given a value and not a scaling
factor as in the scale_form() function.
Warning Use only integers values or not more than 3 precision (%.3f) in the radius, Form gen-
erating functions, argument.
Color
void set_form_color(Form *form, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
Parameters
• form (Form) – The Form to change the color from.
• red (uint8_t) – a value between 0 and 255.
• green (uint8_t) – a value between 0 and 255.
• blue (uint8_t) – a value between 0 and 255.
• alpha (uint8_t) – a value between 0 and 255.
Return type void
Returns void
This function set a new color by updating the Color type members from the given form.
void set_line_color(Line *line, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
Parameters
• form (Form) – The Line to change the color from.
• red (uint8_t) – a value between 0 and 255.
• green (uint8_t) – a value between 0 and 255.
• blue (uint8_t) – a value between 0 and 255.
• alpha (uint8_t) – a value between 0 and 255.
Return type void
Returns void
This function set a new color by updating the Color type members from the given line.
Getters functions
This functions are convienence functions to get the current value of the generic Form type members.
note But you can easily access the members directly with the -> pointer notation.
Center
Color
47
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Length
Note: The member named length is very often the radius from the form.
See the Forms generating functions page for the what the length member represent.
Or in other words how it is compute from the often, radius argument value.
Real length
Note: The member named real_length is the distance between the center and the farest coordinates from
the center.
note It can be used per example to build a bounding box from a polygon for collision detection or
the purpose you want.
Warning The member name real_length is not always exactly after executing
set_form_radius() but nearly approximate.
Orientation
Note: The member and argument named orientation is always given as argument.
It represent the incline of the forms according the angle measurement convention.
You can use the orientation argument value to rotate a form if you generate and destroy the Form.
8.5. Orientation 49
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
Miscellaneous
trajectories
Pixel positions[steps] ;
/** Or **/
51
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
After executing this function you get an array of pixels with which you can implement an animation with the
array of pixels as guideline.
52 Chapter 9. Miscellaneous
CHAPTER 10
Utils
Check
if (pRenderer == NULL) {
fprintf(stderr,"SDL Renderer error (%s)\n",SDL_GetError());
exit(EXIT_FAILURE) ;
}
if (form == NULL) {
fprintf(stderr,"Invalid form argument !\n");
53
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
exit(EXIT_FAILURE) ;
}
Note: Function used in all forms setters functions and all forms operations functions.
Memory
generate segment
• display line
55
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
• display arc
• display polygon
• display polygon
• display polygon
• display polygon
• display polygon
• display polygon
generate fractal
• display polygon
generate star
• display star
• display star
• display star
generate pentagram
generate hexagram
generate spiral
• display spiral
generate wheel
• display wheel
• display wheel
• display wheel
• display wheel
/************************************************************************************
* SDL2_gfxutils a SDL2_gfx forms generating and manipulating helper functions set. *
* Copyright (©) 2016 Brüggemann Eddie <[email protected]>. *
* *
* This file is part of SDL2_gfxutils. *
* SDL2_gfxutils is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* SDL2_gfxutils is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with SDL2_gfxutils. If not, see <http://www.gnu.org/licenses/> *
************************************************************************************/
#include <SDL2/SDL.h>
#include <SDL2/SDL2_gfxPrimitives.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
109
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
#define EXTERN_C
#endif
#endif
/** This function return an pixel initialized in relationship to the given settings.
˓→**/
/** This function compute the pixel middle point from the given line. **/
EXTERN_C Pixel get_middle_from_line(Line line);
/** Return a pointer on a Line starting at start_point, from length length, incline
˓→from angle.
˓→ *********************************************************************************************/
˓→
/**
˓→**************************************************************************************************
˓→**/
/** Polygons:
***********/
˓→ ***************************************************************************************************
˓→
˓→ ***************************************************************************************************
˓→
˓→ ***************************************************************************************************
˓→
111
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
/** Generated an rounded polygon alternating arcs rounded to the outside and to the
˓→inside of the polygon.
* with sides sides, with radius length radius, having for center center, incline
˓→according orientation.
˓→ ***************************************************************************************************
˓→
/** Generated an polygon with half-circle rounded to the inside from the half sum
˓→from the sides of the polygon
* and the other half is even an arc or an straight line according to the side_arcs
˓→boolean value.
* with sides sides, with radius length radius, having for center center, incline
˓→according orientation.
˓→ ***************************************************************************************************
˓→
/** Generated an polygon with half-circle rounded to the outside from the half sum
˓→from the sides of the polygon
* and the other half is even an arc or an straight line according to the side_arcs
˓→boolean value.
* with sides sides, with radius length radius, having for center center, incline
˓→according orientation.
˓→ ***************************************************************************************************
˓→
/**
˓→***************************************************************************************************
˓→**/
/** Pentagram:
************/
/** Generate an 5 extremity star with an centered pentagon from which every vertex go
˓→to the center.
* From radius radius, having for center center, incline according orientation.
˓→ **************************************************************************************************/
˓→
* From radius radius, having for center center, incline according orientation.
˓→ **********************************************************************************************/
˓→
/** Hexagram:
***********/
/** Generate an 5 extremity star with an centered hexagon from which every vertex go
˓→to the center.
* From radius radius, having for center center, incline according orientation.
˓→ *************************************************************************************************/
˓→
* From radius radius, having for center center, incline according orientation.
˓→ *********************************************************************************************/
˓→
/** Stars:
********/
/** Wheels:
*********/
˓→ ***************************************************************************************************
˓→
113
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
˓→ **********************************************************************************************/
˓→
/** Generate an wheel (rounded polygon) with peaking as triangles which peaks ate
˓→very little arcs.
* With polygon as base polygon, having for center center, from peak size peak_
˓→offset, incline according orientation.
˓→ ***************************************************************************************************
˓→
/** Generate an wheel (rounded polygon) with peaks looking like a tube but they are
˓→only right-angled line to the sides connected trough an arc.
* With polygon as base polygon, having for center center, from peak size peak_
˓→length, incline according orientation.
˓→ ***************************************************************************************************
˓→
/**
˓→***************************************************************************************************
˓→**/
/** Spiral:
********/
˓→ ***************************************************************************************************
˓→
/**
˓→***************************************************************************************************
˓→**/
/** fractal:
*********/
˓→ ***************************************************************************************************
˓→
/**
˓→************************************************************************************************
˓→**/
/** Return a rotate a pixel around a center from the value angle in clock sens.
*****************************************************************************/
EXTERN_C Pixel rotate(Pixel center, float angle, Pixel pixel);
115
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
***************************************/
EXTERN_C void translate_form(Form * form, float x, float y);
/** Setters:
**********/
/**
˓→***********************************************************************************
˓→**/
/** Getters:
*********/
/** Return the current real length from the Form form.
* The real length member is the distance between the center and the farest point
˓→from it.
˓→ *****************************************************************************************/
˓→
117
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
************************************************/
EXTERN_C int display_arc_thick(SDL_Renderer * pRenderer, Arc * arc, uint8_t
˓→thickness);
119
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
/**
˓→***************************************************************************************************
˓→**/
/** Memory:
********/
/** Utils:
*******/
/** Miscealeanous:
***************/
121
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
• genindex
• modindex
• search
123
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
A display_strikethrough_polygon (C function), 30
aa_display_arc (C function), 33 display_strikethrough_polygon_thick (C function), 36
aa_display_flower_star (C function), 34 display_strikethrough_star (C function), 32
aa_display_hexagram (C function), 34 display_strikethrough_star_thick (C function), 37
aa_display_line (C function), 33
aa_display_pentagram (C function), 34 F
aa_display_polygon (C function), 33 free_form (C function), 54
aa_display_polygon_star (C function), 35
aa_display_spiral (C function), 35 G
aa_display_star (C function), 34 generate_alternate_inside_half_circle_polygon (C func-
aa_display_strikethrough_polygon (C function), 33 tion), 21
aa_display_strikethrough_star (C function), 35 generate_alternate_outside_half_circle_polygon (C func-
tion), 21
C generate_circle_arc (C function), 17
check_form (C function), 53 generate_circular_saw_wheel (C function), 25
check_renderer (C function), 53 generate_corners_rounded_polygon (C function), 19
compute_trajectory (C function), 51 generate_fractal (C function), 23
generate_hexagram (C function), 23
D generate_hexagram_star (C function), 22
display_arc (C function), 29 generate_pentagram (C function), 23
display_arc_thick (C function), 36 generate_pentagram_star (C function), 22
display_filled_polygon (C function), 30 generate_polygon_radius (C function), 19
display_filled_star (C function), 32 generate_rounded_inside_out_polygon (C function), 20
display_flower_star (C function), 31 generate_segment (C function), 16
display_flower_star_thick (C function), 37 generate_sides_rounded_polygon (C function), 20
display_hexagram (C function), 31 generate_simple_spiral (C function), 24
display_hexagram_thick (C function), 37 generate_star (C function), 22
display_line (C function), 29 generate_wheel (C function), 25
display_line_thick (C function), 35 generate_wheel_peaks_rounded_square (C function), 26
display_pentagram (C function), 31 generate_wheel_peaks_trigon (C function), 26
display_pentagram_thick (C function), 36 get_angle (C function), 15
display_polygon (C function), 30 get_distance_pixels (C function), 15
display_polygon_star (C function), 32 get_form_center (C function), 47
display_polygon_star_thick (C function), 38 get_form_color (C function), 47
display_polygon_thick (C function), 36 get_form_length (C function), 48
display_spiral (C function), 32 get_form_orientation (C function), 48
display_spiral_thick (C function), 38 get_form_real_length (C function), 48
display_star (C function), 31 get_middle_from_line (C function), 16
display_star_thick (C function), 37 get_pixel_coords (C function), 16
125
SDL2𝑔 𝑓 𝑥𝑢𝑡𝑖𝑙𝑠 − 𝑑𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛𝐷𝑜𝑐𝑢𝑚𝑒𝑛𝑡𝑎𝑡𝑖𝑜𝑛, 𝑅𝑒𝑙𝑒𝑎𝑠𝑒𝑙𝑎𝑡𝑒𝑠𝑡
M
mirror (C function), 40
mirror_form (C function), 42
N
new_form (C function), 54
R
rotate (C function), 39
rotate_form (C function), 41
S
scale (C function), 40
scale_form (C function), 41
set_form_center (C function), 45
set_form_color (C function), 46
set_form_radius (C function), 45
set_line_color (C function), 46
T
translate (C function), 40
translate_form (C function), 42
126 Index