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.
Classes | Functions
Color

Classes

class  doodle::Color
 Color is a color represented with four unsigned bytes. More...
 
class  doodle::HexColor
 This is a helper class to easily represent an RGBA color as an int with hexadecimal notation. More...
 

Functions

void doodle::clear_background () noexcept
 Clear the background to black. More...
 
void doodle::clear_background (HexColor color) noexcept
 Clear the background to the specified HexColor. More...
 
void doodle::clear_background (Color color) noexcept
 Clear the background to the specified Color. More...
 
void doodle::clear_background (double grey, double alpha=255) noexcept
 Clear the background to a grey color. More...
 
void doodle::clear_background (double red, double green, double blue, double alpha=255) noexcept
 Clear the background to a specified RGBA color. More...
 
void doodle::set_fill_color (HexColor color) noexcept
 Sets the color used to fill shapes to the specified HexColor. More...
 
void doodle::set_fill_color (Color color) noexcept
 Sets the color used to fill shapes to the specified Color. More...
 
void doodle::set_fill_color (double grey, double alpha=255) noexcept
 Sets the color used to fill shapes to a grey. More...
 
void doodle::set_fill_color (double red, double green, double blue, double alpha=255) noexcept
 Sets the color used to fill shapes to the specified RGBA values. More...
 
void doodle::no_fill () noexcept
 Disables filling geometry. More...
 
void doodle::set_outline_color (HexColor color) noexcept
 Set the outline and lines of shapes to the specified HexColor. More...
 
void doodle::set_outline_color (Color color) noexcept
 Set the outline and lines of shapes to the specified Color. More...
 
void doodle::set_outline_color (double grey, double alpha=255) noexcept
 Set the outline and lines of shapes to a grey color. More...
 
void doodle::set_outline_color (double red, double green, double blue, double alpha=255) noexcept
 Set the outline and lines of shapes to an RGBA color. More...
 
void doodle::no_outline ()
 Disables drawing the outline. More...
 

Detailed Description

Function Documentation

◆ clear_background() [1/5]

void doodle::clear_background ( )
noexcept

Clear the background to black.

The clear_background() function sets the color used for the background of the canvas. The default background is black. This function is typically used within draw loop to clear the display window at the beginning of each frame, but it can be used outside the loop to set the background on the first frame of animation or if the background need only be set once.

using namespace doodle;
int main(void)
{
create_window(480, 360);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(clear_background_1.png)");
return 0;
}
void clear_background() noexcept
Clear the background to black.
bool create_window() noexcept
Create a default window.
Image capture_screenshot_to_image()
Captures a screenshot of the whole screen.
Definition: angle.hpp:11

◆ clear_background() [2/5]

void doodle::clear_background ( Color  color)
noexcept

Clear the background to the specified Color.

The clear_background() function sets the color used for the background of the canvas. The default background is black. This function is typically used within draw loop to clear the display window at the beginning of each frame, but it can be used outside the loop to set the background on the first frame of animation or if the background need only be set once.

Parameters
colorColor to clear the screen to
using namespace doodle;
Color GenerateColor()
{
const double control = ElapsedTime / 3.0;
const double r = 0.25 + noise(control) * 0.75;
const double g = 0.25 + noise(control * 2.0, control) * 0.75;
const double b = 0.25 + noise(control / 2.0, control / 4.0, control) * 0.75;
return Color{r * 255, g * 255, b * 255 };
}
int main(void)
{
create_window(480, 360);
while (!is_window_closed())
{
clear_background(GenerateColor());
}
return 0;
}
double ElapsedTime
Returns the number of seconds since starting the program. This information is often used for timing e...
bool is_window_closed() noexcept
Is the window closed?
void update_window() noexcept
Update the doodle application.
double noise(double x, double y=0.0, double z=0.0) noexcept
Returns the Perlin noise value at specified coordinates.

◆ clear_background() [3/5]

void doodle::clear_background ( double  grey,
double  alpha = 255 
)
noexcept

Clear the background to a grey color.

The clear_background() function sets the color used for the background of the canvas. The default background is black. This function is typically used within draw loop to clear the display window at the beginning of each frame, but it can be used outside the loop to set the background on the first frame of animation or if the background need only be set once.

Parameters
greyspecifies a value between white and black
alphaoptional opacity value of the background between 0-255. The default value is 255.
using namespace doodle;
int main(void)
{
create_window(480, 360);
set_fill_color(255, 64);
while (!is_window_closed())
{
const double alpha = 255.0 * (std::sin(ElapsedTime) * 0.5 + 0.5);
clear_background(220, alpha);
draw_ellipse(0, 0, Width / 2.0);
}
return 0;
}
void set_fill_color(HexColor color) noexcept
Sets the color used to fill shapes to the specified HexColor.
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 draw_ellipse(double x, double y, double width, double height=0) noexcept
Draws an ellipse (oval) to the screen.

◆ clear_background() [4/5]

void doodle::clear_background ( double  red,
double  green,
double  blue,
double  alpha = 255 
)
noexcept

Clear the background to a specified RGBA color.

The clear_background() function sets the color used for the background of the canvas. The default background is black. This function is typically used within draw loop to clear the display window at the beginning of each frame, but it can be used outside the loop to set the background on the first frame of animation or if the background need only be set once.

Parameters
redvalue between 0-255
greenvalue between 0-255
bluevalue between 0-255
alphaoptional opacity value of the background between 0-255. The default value is 255.
using namespace doodle;
int main(void)
{
create_window(480, 360);
while (!is_window_closed())
{
clear_background(255, 204, 0);
draw_ellipse(0, 0, Width / 2.0);
const double alpha = 255.0 * (std::cos(ElapsedTime * 2.0) * 0.5 + 0.5);
clear_background(0, 0, 255, alpha);
}
return 0;
}

◆ clear_background() [5/5]

void doodle::clear_background ( HexColor  color)
noexcept

Clear the background to the specified HexColor.

The clear_background() function sets the color used for the background of the canvas. The default background is black. This function is typically used within draw loop to clear the display window at the beginning of each frame, but it can be used outside the loop to set the background on the first frame of animation or if the background need only be set once.

Parameters
colorHexColor to clear the screen to.
using namespace doodle;
int main(void)
{
create_window(480, 360);
clear_background(HexColor{0x2B61D5FF});
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(clear_background_2.png)");
return 0;
}

◆ no_fill()

void doodle::no_fill ( )
noexcept

Disables filling geometry.

If both no_outline() and no_fill() are called, nothing will be drawn to the screen.

using namespace doodle;
int main(void)
{
create_window(480, 360);
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
draw_rectangle(10, 20, Width * 0.6, Height * 0.6);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(no_fill.png)");
return 0;
}
void no_fill() noexcept
Disables filling geometry.
int Height
System variable that stores the height of the drawing canvas. This value is set by the desired_height...
void close_window() noexcept
Programmatically close the window.
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.

◆ no_outline()

void doodle::no_outline ( )

Disables drawing the outline.

If both no_outline() and no_fill() are called, nothing will be drawn to the screen.

using namespace doodle;
int main(void)
{
create_window(200, 200);
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(no_outline.png)");
return 0;
}

◆ set_fill_color() [1/4]

void doodle::set_fill_color ( Color  color)
noexcept

Sets the color used to fill shapes to the specified Color.

For example, if you run set_fill_color(Color{0,255,0,64}), all shapes drawn after the fill command will be filled with a translucent green color. The color space is RGBA, with each value in the range from 0 to 255.

Parameters
colorColor to apply
using namespace doodle;
int main(void)
{
create_window(480, 360);
set_fill_color(Color{0, 255, 0, 64}); // see-through green
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
draw_rectangle(0, -Width / 4.0, Width * 0.2, Height * 0.2);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(set_fill_color_2_Color.png)");
return 0;
}

◆ set_fill_color() [2/4]

void doodle::set_fill_color ( double  grey,
double  alpha = 255 
)
noexcept

Sets the color used to fill shapes to a grey.

For example, if you run set_fill_color(51), all shapes drawn after the fill command will be filled with the color dark dark grey. The color space is RGBA, with each value in the range from 0 to 255.

Parameters
greyspecifies a value between white and black
alphaoptional opacity value of the background between 0-255. The default value is 255.
using namespace doodle;
int main(void)
{
create_window(480, 360);
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(set_fill_color_3_grey.png)");
return 0;
}

◆ set_fill_color() [3/4]

void doodle::set_fill_color ( double  red,
double  green,
double  blue,
double  alpha = 255 
)
noexcept

Sets the color used to fill shapes to the specified RGBA values.

For example, if you run set_fill_color(138,43,226), all shapes drawn after the fill command will be filled with the color purple. The color space is RGBA, with each value in the range from 0 to 255.

Parameters
redvalue between 0-255
greenvalue between 0-255
bluevalue between 0-255
alphaoptional opacity value of the background between 0-255. The default value is 255.
using namespace doodle;
int main(void)
{
create_window(200, 200);
set_outline_color(138, 43, 226);
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
draw_rectangle(0, -Width / 4.0, Width * 0.2, Height * 0.2);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(set_outline_color_4_rgba.png)");
return 0;
}
void set_outline_color(HexColor color) noexcept
Set the outline and lines of shapes to the specified HexColor.

◆ set_fill_color() [4/4]

void doodle::set_fill_color ( HexColor  color)
noexcept

Sets the color used to fill shapes to the specified HexColor.

For example, if you run set_fill_color(HexColor{0xffaaeeff}), all shapes drawn after the fill command will be filled with the color pink. The color space is RGBA, with each value in the range from 0 to 255.

Parameters
colorHexColor to apply
using namespace doodle;
int main(void)
{
create_window(480, 360);
set_fill_color(HexColor{0xffaaeeff}); // pink
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(set_fill_color_1_hexcolor.png)");
return 0;
}

◆ set_outline_color() [1/4]

void doodle::set_outline_color ( Color  color)
noexcept

Set the outline and lines of shapes to the specified Color.

Sets the color used to draw lines and borders around shapes. The color space is RGBA, with each value in the range from 0 to 255.

Parameters
colorColor to apply
using namespace doodle;
int main(void)
{
create_window(200, 200);
set_outline_color(Color{0, 255, 0, 64}); // see-through green
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
draw_rectangle(0, -Width / 4.0, Width * 0.2, Height * 0.2);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(set_outline_color_2_Color.png)");
return 0;
}
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...

◆ set_outline_color() [2/4]

void doodle::set_outline_color ( double  grey,
double  alpha = 255 
)
noexcept

Set the outline and lines of shapes to a grey color.

Sets the color used to draw lines and borders around shapes. The color space is RGBA, with each value in the range from 0 to 255.

Parameters
greyspecifies a value between white and black
alphaoptional opacity value of the background between 0-255. The default value is 255.
using namespace doodle;
int main(void)
{
create_window(200, 200);
clear_background(51, 65, 80);
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(set_outline_color_3_grey.png)");
return 0;
}

◆ set_outline_color() [3/4]

void doodle::set_outline_color ( double  red,
double  green,
double  blue,
double  alpha = 255 
)
noexcept

Set the outline and lines of shapes to an RGBA color.

Sets the color used to draw lines and borders around shapes. The color space is RGBA, with each value in the range from 0 to 255.

Parameters
redvalue between 0-255
greenvalue between 0-255
bluevalue between 0-255
alphaoptional opacity value of the background between 0-255. The default value is 255.
using namespace doodle;
int main(void)
{
create_window(200, 200);
set_outline_color(138, 43, 226);
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
draw_rectangle(0, -Width / 4.0, Width * 0.2, Height * 0.2);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(set_outline_color_4_rgba.png)");
return 0;
}

◆ set_outline_color() [4/4]

void doodle::set_outline_color ( HexColor  color)
noexcept

Set the outline and lines of shapes to the specified HexColor.

Sets the color used to draw lines and borders around shapes. The color space is RGBA, with each value in the range from 0 to 255.

Parameters
colorHexColor to apply
using namespace doodle;
int main(void)
{
create_window(100, 100);
set_outline_color(HexColor{0x2B61D5FF});
draw_rectangle(0, 0, Width * 0.6, Height * 0.6);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(set_outline_color_1_hexcolor.png)");
return 0;
}