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.
Enumerations | Functions
Shape

Enumerations

enum class  doodle::EllipseMode { doodle::Center , doodle::Corner }
 With set_ellipse_mode(), modifies the location from which ellipses are drawn by changing the way in which parameters given to draw_ellipse() are interpreted. More...
 
enum class  doodle::RectMode { doodle::Corner , doodle::Center }
 With set_rectangle_mode(), modifies the location from which rectangles are drawn by changing the way in which parameters given to draw_rectangle() are interpreted. More...
 
enum class  doodle::FrameOfReference { doodle::RightHanded_OriginCenter , doodle::RightHanded_OriginBottomLeft , doodle::LeftHanded_OriginTopLeft }
 Used to define the coordinate system you would like to reference. More...
 

Functions

void doodle::draw_ellipse (double x, double y, double width, double height=0) noexcept
 Draws an ellipse (oval) to the screen. More...
 
void doodle::draw_line (double x1, double y1, double x2, double y2) noexcept
 Draws a line (a direct path between two points) to the screen. More...
 
void doodle::draw_quad (double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) noexcept
 Draw a quad. More...
 
void doodle::draw_rectangle (double x, double y, double width, double height=0) noexcept
 Draws a rectangle to the screen. More...
 
void doodle::draw_triangle (double x1, double y1, double x2, double y2, double x3, double y3) noexcept
 Draw a triangle to the screen. More...
 
void doodle::set_ellipse_mode (EllipseMode mode) noexcept
 Modifies the location from which ellipses are drawn by changing the way in which parameters given to draw_ellipse() are interpreted. More...
 
void doodle::set_rectangle_mode (RectMode mode) noexcept
 Modifies the location from which rectangles are drawn by changing the way in which parameters given to draw_rectangle() are interpreted. More...
 
void doodle::set_frame_of_reference (FrameOfReference frame_of_reference) noexcept
 Change the coordinate system you would like to use when describing your primitives. More...
 
void doodle::smooth_drawing () noexcept
 Draws all geometry with smooth (anti-aliased) edges. More...
 
void doodle::no_smoothing () noexcept
 Draws all geometry with jagged (aliased) edges. More...
 
void doodle::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 units of pixels. More...
 
void doodle::push_settings () noexcept
 The push_settings() function saves the current drawing style settings and transformations, while pop_settings() restores these settings. More...
 
void doodle::pop_settings () noexcept
 The pop_settings() function restores to the previous style settings and transformations, while push_settings() saves a new set these settings. More...
 

Detailed Description

Enumeration Type Documentation

◆ EllipseMode

enum doodle::EllipseMode
strong

With set_ellipse_mode(), modifies the location from which ellipses are drawn by changing the way in which parameters given to draw_ellipse() are interpreted.

Enumerator
Center 

Interprets the first two parameters of draw_ellipse() as the shape's center point.

Corner 

Interprets the first two parameters of draw_ellipse() as the upper-left or bottom-left corner of the shape in a left handed doodle::FrameOfReference and right handed doodle::FrameOfReference respectively.

Definition at line 661 of file drawing.hpp.

662  {
666  Center,
671  Corner
672  };
@ Corner
Interprets the first two parameters of draw_ellipse() as the upper-left or bottom-left corner of the ...
@ Center
Interprets the first two parameters of draw_ellipse() as the shape's center point.

◆ FrameOfReference

Used to define the coordinate system you would like to reference.

Enumerator
RightHanded_OriginCenter 

The Origin (0,0) is always in the center of the screen. Positive x goes to the right and Positive y goes up. This is the default reference frame.

W = Width, H = Height
           (W/2,H/2)
     +--------o
     |        |
     |  0,0   |
     |        |
     o--------+
(-W/2,-H/2)
RightHanded_OriginBottomLeft 

The Origin (0,0) is always in the bottom left of the screen. Positive x goes to the right and Positive y goes up.

W = Width, H = Height
            (W,H)
     +--------o
     |        |
     |        |
     |        |
     o--------+
   (0,0)
LeftHanded_OriginTopLeft 

The Origin (0,0) is always in the top left of the screen. Positive x goes to the right and Positive y goes down.

W = Width, H = Height
   (0,0)
     o--------+
     |        |
     |        |
     |        |
     +--------o
            (W,H)

Definition at line 777 of file drawing.hpp.

778  {
827  };
@ LeftHanded_OriginTopLeft
The Origin (0,0) is always in the top left of the screen. Positive x goes to the right and Positive y...
@ RightHanded_OriginCenter
The Origin (0,0) is always in the center of the screen. Positive x goes to the right and Positive y g...
@ RightHanded_OriginBottomLeft
The Origin (0,0) is always in the bottom left of the screen. Positive x goes to the right and Positiv...

◆ RectMode

enum doodle::RectMode
strong

With set_rectangle_mode(), modifies the location from which rectangles are drawn by changing the way in which parameters given to draw_rectangle() are interpreted.

Enumerator
Corner 

The default mode is RectMode::CORNER, which interprets the first two parameters of draw_rectangle() as the upper-left or bottom-left corner of the shape in a left handed doodle::FrameOfReference and right handed doodle::FrameOfReference respectively.

Center 

RectMode::CENTER interprets the first two parameters of draw_rectangle() as the shape's center point.

Definition at line 718 of file drawing.hpp.

719  {
725  Corner,
729  Center
730  };

Function Documentation

◆ draw_ellipse()

void doodle::draw_ellipse ( double  x,
double  y,
double  width,
double  height = 0 
)
noexcept

Draws an ellipse (oval) to the screen.

An ellipse with equal width and height is a circle. By default, the first two parameters set the location, and the third and fourth parameters set the shape's width and height. If no height is specified, the value of width is used for both the width and height. The origin may be changed with the set_ellipse_mode() function. By default the (x,y) location is in the center of the ellipse.

Parameters
xx-coordinate of the ellipse.
yy-coordinate of the ellipse.
widthwidth of the ellipse.
heightheight of the ellipse.
using namespace doodle;
int main(void)
{
create_window(480, 320);
while (!is_window_closed())
{
clear_background(HexColor{0xBF8679FF});
set_fill_color(HexColor{0x8C2B2EFF});
// opaque and wide ellipse
draw_ellipse(0, 0, Width * 0.8, Height * 0.6);
set_fill_color(HexColor{0xDDD3D680});
// translucent circle
draw_ellipse(0, 0, Width * 0.6);
}
return 0;
}
void set_fill_color(HexColor color) noexcept
Sets the color used to fill shapes to the specified HexColor.
void clear_background() noexcept
Clear the background to black.
bool create_window() noexcept
Create a default window.
int Width
System variable that stores the width of the drawing canvas. This value is set by the desired_width p...
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 draw_ellipse(double x, double y, double width, double height=0) noexcept
Draws an ellipse (oval) to the screen.
Definition: angle.hpp:11

◆ draw_line()

void doodle::draw_line ( double  x1,
double  y1,
double  x2,
double  y2 
)
noexcept

Draws a line (a direct path between two points) to the screen.

To color a line, use the set_outline_color() function. A line cannot be filled, therefore the set_fill_color() function will not affect the color of a line. Lines are drawn with a width of one pixel by default, but this can be changed with the set_outline_width() function.

Parameters
x1the x-coordinate of the first point
y1the y-coordinate of the first point
x2the x-coordinate of the second point
y2the y-coordinate of the second point
using namespace doodle;
int main(void)
{
create_window(480, 320);
while (!is_window_closed())
{
const double top = Height - 30.0;
const double bottom = 30.0;
const double left = 30.0;
const double right = Width - 30.0;
draw_line(left, top, right, top);
draw_line(right, top, right, bottom);
draw_line(left, bottom, right, bottom);
}
return 0;
}
void set_outline_color(HexColor color) noexcept
Set the outline and lines of shapes to the specified HexColor.
void draw_line(double x1, double y1, double x2, double y2) noexcept
Draws a line (a direct path between two points) to the screen.
void set_frame_of_reference(FrameOfReference frame_of_reference) noexcept
Change the coordinate system you would like to use when describing your primitives.

◆ draw_quad()

void doodle::draw_quad ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3,
double  x4,
double  y4 
)
noexcept

Draw a quad.

A quad is a quadrilateral, a four sided polygon. It is similar to a rectangle, but the angles between its edges are not constrained to ninety degrees. The first pair of parameters (x1,y1) sets the first vertex and the subsequent pairs should proceed clockwise or counter-clockwise around the defined shape.

Parameters
x1the x-coordinate of the first point
y1the y-coordinate of the first point
x2the x-coordinate of the second point
y2the y-coordinate of the second point
x3the x-coordinate of the third point
y3the y-coordinate of the third point
x4the x-coordinate of the fourth point
y4the y-coordinate of the forth point
using namespace doodle;
int main(void)
{
create_window(480, 320);
set_outline_color(HexColor{0xAD4A3BFF});
set_fill_color(HexColor{0xEBE3C0FF});
while (!is_window_closed())
{
clear_background(HexColor{0x457648FF});
draw_quad(152, 124, 344, 80, 276, 252, 120, 304);
}
return 0;
}
void draw_quad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) noexcept
Draw a quad.
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...

◆ draw_rectangle()

void doodle::draw_rectangle ( double  x,
double  y,
double  width,
double  height = 0 
)
noexcept

Draws a rectangle to the screen.

A rectangle is a four-sided shape with every angle at ninety degrees. By default, the first two parameters set the location of a corner, the third sets the width, and the fourth sets the height. The way these parameters are interpreted, however, may be changed with the set_rectangle_mode() function. If the height is omitted then the height will be set to the width, thus creating a square.

Parameters
xx-coordinate of the rectangle.
yy-coordinate of the rectangle.
widthwidth of the rectangle.
heightheight of the rectangle.
using namespace doodle;
int main(void)
{
create_window(480, 320);
while (!is_window_closed())
{
clear_background(HexColor{0x9EA2B8FF});
set_fill_color(HexColor{0x7E5873FF});
// opaque and wide rectangle
double left = Width * -0.4, bottom = Height * -0.3;
draw_rectangle(left, bottom, Width * 0.8, Height * 0.6);
set_fill_color(HexColor{0x372F4A80});
// translucent square
left = Width * -0.3, bottom = Width * -0.3;
draw_rectangle(left, bottom, Width * 0.6);
}
return 0;
}
void draw_rectangle(double x, double y, double width, double height=0) noexcept
Draws a rectangle to the screen.

◆ draw_triangle()

void doodle::draw_triangle ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)
noexcept

Draw a triangle to the screen.

A triangle is a plane created by connecting three points. The first two arguments specify the first point, the middle two arguments specify the second point, and the last two arguments specify the third point.

Parameters
x1the x-coordinate of the first point
y1the y-coordinate of the first point
x2the x-coordinate of the second point
y2the y-coordinate of the second point
x3the x-coordinate of the third point
y3the y-coordinate of the third point
#include <cmath>
using namespace doodle;
int main(void)
{
create_window(480, 320);
set_fill_color(HexColor{0xE5C8B4FF});
set_outline_color(HexColor{0x483524FF});
double offset = 0.0;
while (!is_window_closed())
{
clear_background(HexColor{0xA47B56FF});
const double angle1 = offset + TWO_PI / 3.0 + to_radians(60.0) * noise(ElapsedTime, 2.0);
const double angle2 = offset + 2.0 * TWO_PI/3.0 + to_radians(30.0) * noise(ElapsedTime/2.0, 40.0);
const double angle3 = offset + TWO_PI + to_radians(80.0) * noise(ElapsedTime, 200.0);
offset += 0.25 * QUARTER_PI * DeltaTime;
draw_triangle(cos(angle1), sin(angle1), cos(angle2), sin(angle2), cos(angle3), sin(angle3));
}
return 0;
}
constexpr double to_radians(double angle_in_degrees) noexcept
Converts a degree measurement to its corresponding value in radians. Radians and degrees are two ways...
Definition: angle.hpp:78
constexpr double QUARTER_PI
Definition: angle.hpp:50
constexpr double TWO_PI
Definition: angle.hpp:62
double DeltaTime
The system variable DeltaTime contains the time difference between the beginning of the previous fram...
double ElapsedTime
Returns the number of seconds since starting the program. This information is often used for timing e...
void draw_triangle(double x1, double y1, double x2, double y2, double x3, double y3) noexcept
Draw a triangle to the screen.
void apply_scale(double scale) noexcept
Uniformly increases or decreases the size of a shape by expanding and contracting vertices.
double noise(double x, double y=0.0, double z=0.0) noexcept
Returns the Perlin noise value at specified coordinates.

◆ no_smoothing()

void doodle::no_smoothing ( )
noexcept

Draws all geometry with jagged (aliased) edges.

Note that smooth_drawing() is active by default in; no_smoothing() can be used to disable smoothing of geometry, images, and fonts.

using namespace doodle;
int main(void)
{
create_window(480, 320);
set_outline_color(HexColor{0xE7C0ABFF});
while (!is_window_closed())
{
const double shape_width = Width * 0.4;
const double shape_height = Height * 0.4;
clear_background(HexColor{0xAC7476FF});
draw_rectangle(-Width / 4.0, 0, shape_width, shape_height);
draw_rectangle(Width / 4.0, 0, shape_width, shape_height);
}
return 0;
}
void smooth_drawing() noexcept
Draws all geometry with smooth (anti-aliased) edges.
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 no_smoothing() noexcept
Draws all geometry with jagged (aliased) edges.
@ Center
RectMode::CENTER interprets the first two parameters of draw_rectangle() as the shape's center point.

◆ pop_settings()

void doodle::pop_settings ( )
noexcept

The pop_settings() function restores to the previous style settings and transformations, while push_settings() saves a new set these settings.

Note that these functions are always used together. They allow you to change the style and transformation settings and later return to what you had. When a new state is started with push_settings(), it builds on the current style and transform information. The push_settings() and pop_settings() functions can be embedded to provide more control.

push_settings() stores information related to the current transformation (apply_scale(), apply_rotate(), apply_translate(), apply_matrix()) state and style settings controlled by the following functions: set_fill_color(), no_fill(), set_outline_color(), no_outline(), set_ellipse_mode(), set_rectangle_mode(), smooth_drawing(), no_smoothing(), set_outline_width(), set_tint_color(), no_tint(), set_image_mode(), set_font(), set_frame_of_reference()

using namespace doodle;
int main(void)
{
create_window(480, 320);
while (!is_window_closed())
{
clear_background(HexColor{0xBB8F99FF});
const double center = 0;
const double left = -3.0 * Width / 8.0, left_middle = -Width / 8.0;
const double right_middle = -left_middle, right = -left;
const double shape_width = Width / 3.0;
draw_ellipse(left, center, shape_width); // Left circle
push_settings(); // Start a new drawing state
set_fill_color(204, 153, 0);
draw_ellipse(left_middle, center, shape_width); // Left-middle circle
push_settings(); // Start another new drawing state
set_outline_color(0, 102, 153);
draw_ellipse(right_middle, center, shape_width); // Right-middle circle
pop_settings(); // Restore previous state
pop_settings(); // Restore original state
draw_ellipse(right, center, shape_width); // Right circle
}
return 0;
}
void pop_settings() noexcept
The pop_settings() function restores to the previous style settings and transformations,...
void push_settings() noexcept
The push_settings() function saves the current drawing style settings and transformations,...

◆ push_settings()

void doodle::push_settings ( )
noexcept

The push_settings() function saves the current drawing style settings and transformations, while pop_settings() restores these settings.

Note that these functions are always used together. They allow you to change the style and transformation settings and later return to what you had. When a new state is started with push_settings(), it builds on the current style and transform information. The push_settings() and pop_settings() functions can be embedded to provide more control.

push_settings() stores information related to the current transformation (apply_scale(), apply_rotate(), apply_translate(), apply_matrix()) state and style settings controlled by the following functions: set_fill_color(), no_fill(), set_outline_color(), no_outline(), set_ellipse_mode(), set_rectangle_mode(), smooth_drawing(), no_smoothing(), set_outline_width(), set_tint_color(), no_tint(), set_image_mode(), set_font(), set_frame_of_reference()

using namespace doodle;
int main(void)
{
create_window(480, 320);
double thetaOffset = 0.0;
constexpr double radiansPerSecond = QUARTER_PI / 2.0;
constexpr int outerCircleSlices = 32;
constexpr int innerCircleSlices = 12;
constexpr double outerIncrement = TWO_PI / outerCircleSlices;
constexpr double innerIncrement = TWO_PI / innerCircleSlices;
while (!is_window_closed())
{
clear_background(255, 128);
// Loop from 0 to 360 degrees (2*PI radians)
for (int i = 0; i < outerCircleSlices; ++i)
{
// Push, rotate and draw a line
// The transformation state is saved at the beginning of each cycle through the for loop and
// restored at the end. Try commenting out these lines to see the difference!
apply_rotate(thetaOffset + i * outerIncrement);
draw_line(0, 0, 100, 0);
// draw a "flower" of lines at the end of the ith parent line
for (int j = 0; j < innerCircleSlices; ++j)
{
// Push, translate, rotate and draw a line!
apply_translate(100, 0);
apply_rotate(-thetaOffset - j * innerIncrement);
draw_line(0, 0, 50, 0);
// We're done with the inside loop, pop!
}
// We're done with the outside loop, pop!
}
thetaOffset += radiansPerSecond * DeltaTime;
}
return 0;
}
void apply_rotate(double angle_in_radians) noexcept
Rotates a shape the amount specified by the angle in radians.
void apply_translate(double translate_x, double translate_y) noexcept
Specifies an amount to displace objects within the display window.

◆ set_ellipse_mode()

void doodle::set_ellipse_mode ( EllipseMode  mode)
noexcept

Modifies the location from which ellipses are drawn by changing the way in which parameters given to draw_ellipse() are interpreted.

The default mode is EllipseMode::CENTER, which interprets the first two parameters of draw_ellipse() as the shape's center point, while the third and fourth parameters are its width and height.

EllipseMode::CORNER interprets the first two parameters of draw_ellipse() as the upper-left or bottom-left corner of the shape in a left handed doodle::FrameOfReference and right handed doodle::FrameOfReference respectively, while the third and fourth parameters are its width and height.

Parameters
modeeither CENTER or CORNER
using namespace doodle;
int main(void)
{
create_window(480, 320);
set_outline_color(HexColor{0x483524FF});
while (!is_window_closed())
{
const double circle_width = Width * 0.3;
clear_background(HexColor{0xA47B56FF});
draw_ellipse(0, 0, circle_width);
draw_ellipse(0, 0, circle_width);
}
return 0;
}
void set_ellipse_mode(EllipseMode mode) noexcept
Modifies the location from which ellipses are drawn by changing the way in which parameters given to ...

◆ set_frame_of_reference()

void doodle::set_frame_of_reference ( FrameOfReference  frame_of_reference)
noexcept

Change the coordinate system you would like to use when describing your primitives.

Parameters
frame_of_referenceThe coordinate system you would like to use.
using namespace doodle;
int main(void)
{
create_window(480, 320);
constexpr int gridSize = 50;
constexpr double x1 = 10, y1 = 10; // left
constexpr double x2 = 210, y2 = 10; // right
constexpr double x3 = 110, y3 = 140; // top
while (!is_window_closed())
{
clear_background(HexColor{0xD7A586ff});
// Red
set_fill_color(255, 0, 0);
draw_triangle(x1, y1, x2, y2, x3, y3);
// green
set_fill_color(0, 255, 0);
draw_triangle(x1, y1, x2, y2, x3, y3);
// blue
set_fill_color(0, 0, 255);
draw_triangle(x1, y1, x2, y2, x3, y3);
}
return 0;
}

◆ set_outline_width()

void doodle::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 units of pixels.

Parameters
line_widthhow thick to make lines
using namespace doodle;
int main(void)
{
create_window(250, 200);
set_outline_color(HexColor{0x471623FF});
while (!is_window_closed())
{
clear_background(HexColor{0xBB8F99FF});
const double top = Height / 3.0, bottom = -top, center = 0;
const double left = -Width / 2.0 + 20, right = Width / 2.0 - 20;
draw_line(left, top, right, top);
draw_line(left, center, right, center);
draw_line(left, bottom, right, bottom);
}
return 0;
}

◆ set_rectangle_mode()

void doodle::set_rectangle_mode ( RectMode  mode)
noexcept

Modifies the location from which rectangles are drawn by changing the way in which parameters given to draw_rectangle() are interpreted.

The default mode is RectMode::CORNER, which interprets the first two parameters of draw_rectangle() as upper-left or bottom-left corner of the shape in a left handed doodle::FrameOfReference and right handed doodle::FrameOfReference respectively, while the third and fourth parameters are its width and height.

RectMode::CENTER interprets the first two parameters of draw_rectangle() as the shape's center point, while the third and fourth parameters are its width and height.

Parameters
modeeither CORNER or CENTER
using namespace doodle;
int main(void)
{
create_window(480, 320);
set_outline_color(HexColor{0xE7C0ABFF});
while (!is_window_closed())
{
const double shape_width = Width * 0.4;
clear_background(HexColor{0xAC7476FF});
draw_rectangle(shape_width / 2, shape_width / 2, shape_width);
draw_rectangle(shape_width / 2, shape_width / 2, shape_width);
}
return 0;
}
@ Corner
The default mode is RectMode::CORNER, which interprets the first two parameters of draw_rectangle() a...

◆ smooth_drawing()

void doodle::smooth_drawing ( )
noexcept

Draws all geometry with smooth (anti-aliased) edges.

Note that smooth_drawing() is active by default in; no_smoothing() can be used to disable smoothing of geometry, images, and fonts.

using namespace doodle;
int main(void)
{
create_window(480, 320);
set_outline_color(HexColor{0xE7C0ABFF});
while (!is_window_closed())
{
const double shape_width = Width * 0.4;
const double shape_height = Height * 0.4;
clear_background(HexColor{0xAC7476FF});
draw_ellipse(-Width/4.0, 0, shape_width, shape_height);
draw_ellipse(Width/4.0, 0, shape_width, shape_height);
}
return 0;
}