doodle  0.2
Intended to support teaching C++, doodle is a simple library that helps make a window and makes it easy to do some drawing.
Functions
Transform

Functions

void doodle::apply_scale (double scale) noexcept
 Uniformly increases or decreases the size of a shape by expanding and contracting vertices. More...
 
void doodle::apply_scale (double scale_x, double scale_y) noexcept
 Increases or decreases the size of a shape by expanding and contracting vertices. More...
 
void doodle::apply_rotate (double angle_in_radians) noexcept
 Rotates a shape the amount specified by the angle in radians. More...
 
void doodle::apply_translate (double translate_x, double translate_y) noexcept
 Specifies an amount to displace objects within the display window. More...
 
void doodle::apply_matrix (double a, double b, double c, double d, double e, double f) noexcept
 Multiplies the current matrix by the one specified through the parameters. More...
 

Detailed Description

Function Documentation

◆ apply_matrix()

void doodle::apply_matrix ( double  a,
double  b,
double  c,
double  d,
double  e,
double  f 
)
noexcept

Multiplies the current matrix by the one specified through the parameters.

This is a powerful operation that can perform the equivalent of translate, scale, shear and rotate all at once. You can learn more about transformation matrices on Wikipedia.

The naming of the arguments here follows the naming of the WHATWG specification and corresponds to a transformation matrix of the form:

\( \begin{bmatrix} a & c & e \\ b & d & f \\ 0 & 0 & 1 \end{bmatrix} \)

Parameters
a1st Column 1 Row
b1st Column 2nd Row
c2nd Column 1st Row
d2nd Column 2nd Row
e3rd Column 1st Row
f3rd Column 2nd Row
#include <cmath>
using namespace doodle;
int main(void)
{
create_window(480, 320);
set_outline_color(228, 63, 86);
set_fill_color(245, 170, 101);
while (!is_window_closed())
{
update_window(); // resets transformations
clear_background(97, 127, 235, 128);
const double shapeWidth = Height / 3.0;
const double angle = std::sin(ElapsedTime) * QUARTER_PI;
const double shearFactor = 1.0 / std::tan(HALF_PI - angle);
apply_matrix(1, 0, shearFactor, 1, 0, 0);
draw_rectangle(0, 0, shapeWidth);
}
return 0;
}
constexpr double HALF_PI
Definition: angle.hpp:39
constexpr double QUARTER_PI
Definition: angle.hpp:50
void set_fill_color(HexColor color) noexcept
Sets the color used to fill shapes to the specified HexColor.
void set_outline_color(HexColor color) noexcept
Set the outline and lines of shapes to the specified HexColor.
void clear_background() noexcept
Clear the background to black.
double ElapsedTime
Returns the number of seconds since starting the program. This information is often used for timing e...
bool create_window() noexcept
Create a default window.
bool is_window_closed() noexcept
Is the window closed?
int Height
System variable that stores the height of the drawing canvas. This value is set by the desired_height...
void update_window() noexcept
Update the doodle application.
void set_outline_width(double line_width) noexcept
Sets the width of the outline used for lines and the border around shapes. All widths are set in unit...
void set_rectangle_mode(RectMode mode) noexcept
Modifies the location from which rectangles are drawn by changing the way in which parameters given t...
void draw_rectangle(double x, double y, double width, double height=0) noexcept
Draws a rectangle to the screen.
@ Center
RectMode::CENTER interprets the first two parameters of draw_rectangle() as the shape's center point.
void apply_matrix(double a, double b, double c, double d, double e, double f) noexcept
Multiplies the current matrix by the one specified through the parameters.
Definition: angle.hpp:11

◆ apply_rotate()

void doodle::apply_rotate ( double  angle_in_radians)
noexcept

Rotates a shape the amount specified by the angle in radians.

Objects are always rotated around their relative position to the origin. If the doodle::FrameOfReference is right-handed then positive angles rotate counter-clockwise and if it is left-handed then positive angles rotate clockwise. Transformations apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling apply_rotate(HALF_PI) and then apply_rotate(HALF_PI) is the same as apply_rotate(PI). All transformations are reset when update_window() is called.

Technically, apply_rotate() multiplies the current transformation matrix by a rotation matrix. This function can be further controlled by the push_settings() and pop_settings().

Parameters
angle_in_radiansthe angle of rotation
using namespace doodle;
int main(void)
{
create_window(480, 320);
while (!is_window_closed())
{
update_window(); // resets transformations
clear_background(97, 127, 235);
set_fill_color(164, 183, 177);
draw_ellipse(0, 0, 100, 40);
set_fill_color(228, 63, 86);
draw_rectangle(10, 10, 100, 75);
}
return 0;
}
void draw_ellipse(double x, double y, double width, double height=0) noexcept
Draws an ellipse (oval) to the screen.
void apply_rotate(double angle_in_radians) noexcept
Rotates a shape the amount specified by the angle in radians.

◆ apply_scale() [1/2]

void doodle::apply_scale ( double  scale)
noexcept

Uniformly increases or decreases the size of a shape by expanding and contracting vertices.

Objects always scale from their relative origin to the coordinate system. Scale values are specified as decimal percentages. For example, the function call apply_scale(2.0) increases the dimension of a shape by 200%.

Transformations apply to everything that happens after and subsequent calls to the function multiply the effect. For example, calling apply_scale(2.0) and then apply_scale(1.5) is the same as apply_scale(3.0). The transformation is reset when update_window() is called.

Parameters
scalepercent to scale the object
using namespace doodle;
int main(void)
{
create_window(480, 320);
while (!is_window_closed())
{
update_window(); // resets transformations
clear_background(97, 127, 235);
set_fill_color(245, 170, 101);
draw_rectangle(10, 10, 100, 75); // draw at normal size
set_fill_color(228, 187, 142, 192);
draw_rectangle(10, 10, 100, 75); // draw 3 times bigger
}
return 0;
}
void set_frame_of_reference(FrameOfReference frame_of_reference) noexcept
Change the coordinate system you would like to use when describing your primitives.
@ RightHanded_OriginBottomLeft
The Origin (0,0) is always in the bottom left of the screen. Positive x goes to the right and Positiv...
void apply_scale(double scale) noexcept
Uniformly increases or decreases the size of a shape by expanding and contracting vertices.

◆ apply_scale() [2/2]

void doodle::apply_scale ( double  scale_x,
double  scale_y 
)
noexcept

Increases or decreases the size of a shape by expanding and contracting vertices.

Objects always scale from their relative origin to the coordinate system. Scale values are specified as decimal percentages. For example, the function call apply_scale(2.0, 0.5) increases the dimension of a shape horizontally by 200% and vertically bu 50%.

Transformations apply to everything that happens after and subsequent calls to the function multiply the effect. For example, calling apply_scale(2.0, 1.0) and then apply_scale(1.5, 2.0) is the same as apply_scale(3.0, 2.0). The transformation is reset when update_window() is called.

Parameters
scale_xpercentage to scale the object in the x-axis
scale_ypercentage to scale the object in the y-axis
using namespace doodle;
int main(void)
{
create_window(480, 320);
while (!is_window_closed())
{
update_window(); // resets transformations
clear_background(97, 127, 235);
set_fill_color(245, 170, 101);
draw_rectangle(10, 10, 100, 75); // draw at normal size
// 4x bigger in the x and 3x bigger in the y
apply_scale(4.0, 3.0);
set_fill_color(228, 187, 142, 192);
draw_rectangle(10, 10, 100, 75);
}
return 0;
}

◆ apply_translate()

void doodle::apply_translate ( double  translate_x,
double  translate_y 
)
noexcept

Specifies an amount to displace objects within the display window.

The x parameter specifies left/right translation, the y parameter specifies up/down translation.

Transformations are cumulative and apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling apply_translate(50, 0) and then apply_translate(20, 0) is the same as apply_translate(70, 0). All transformations are reset when update_window() is called. This function can be further controlled by the push_settings() and pop_settings().

Parameters
translate_xleft/right translation
translate_yup/down translation
#include <cmath>
using namespace doodle;
int main(void)
{
create_window(480, 320);
set_fill_color(245, 170, 101);
constexpr double shapeWidth = 50;
while (!is_window_closed())
{
update_window(); // resets transformations
clear_background(97, 127, 235, 128);
const double radius = std::sqrt(Width * Width / 9.0 + Height * Height / 9.0) - shapeWidth;
const double x = std::cos(ElapsedTime) * radius;
const double y = std::sin(ElapsedTime) * radius;
draw_ellipse(0, 0, shapeWidth);
}
return 0;
}
void no_outline()
Disables drawing the outline.
int Width
System variable that stores the width of the drawing canvas. This value is set by the desired_width p...
void apply_translate(double translate_x, double translate_y) noexcept
Specifies an amount to displace objects within the display window.