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.
Public Member Functions | Public Attributes | List of all members
doodle::Color Class Reference

Color is a color represented with four unsigned bytes. More...

#include <doodle/color.hpp>

Public Member Functions

constexpr Color () noexcept=default
 The default color is black with full opacity. More...
 
constexpr Color (double grey, double alpha=255) noexcept
 Note that if only one value is provided to Color, it will be interpreted as a grayscale value. Add a second value, and it will be used for alpha transparency. More...
 
constexpr Color (double red, double green, double blue, double alpha=255) noexcept
 When three values are specified, they are interpreted as RGB. Adding a fourth value applies alpha transparency. More...
 

Public Attributes

double red = 0
 
double green = 0
 
double blue = 0
 
double alpha = 255
 

Detailed Description

Color is a color represented with four unsigned bytes.

It has the red, green, blue, and alpha color channels in the range of 0 to 255, where 255 is full intensity of the color channel, 128 is roughly half intensity and 0 is no intensity of the color channel. The alpha channel doesn't contribute light intensity but is used to define transparency. The alpha value also uses the range 0 to 255 to set the amount of transparency. The value 0 defines the color as entirely transparent (it won't display), the value 255 is entirely opaque, and the values between these extremes cause the colors to mix on the screen.

using namespace doodle;
int main(void)
{
create_window(100, 100);
Color squareColor{100, 50, 150};
while (!is_window_closed())
{
draw_ellipse(0, 0, 80.f);
squareColor.alpha = 128 + 128.0 * std::sin(ElapsedTime);
set_fill_color(squareColor);
draw_rectangle(-Width / 2.0 + 13, -Height / 2.0 + 13, Width - 26.0, Height - 26.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.
void set_outline_color(HexColor color) noexcept
Set the outline and lines of shapes to the specified HexColor.
void no_fill() noexcept
Disables filling geometry.
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.
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 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 draw_rectangle(double x, double y, double width, double height=0) noexcept
Draws a rectangle to the screen.
void draw_ellipse(double x, double y, double width, double height=0) noexcept
Draws an ellipse (oval) to the screen.
Definition: angle.hpp:11
constexpr Color() noexcept=default
The default color is black with full opacity.

Definition at line 52 of file color.hpp.

Constructor & Destructor Documentation

◆ Color() [1/3]

constexpr doodle::Color::Color ( )
constexprdefaultnoexcept

The default color is black with full opacity.

using namespace doodle;
int main(void)
{
create_window(100, 100);
while (!is_window_closed())
{
set_fill_color(Color{}); // default is black color
draw_ellipse(0, 0, 35);
}
return 0;
}

◆ Color() [2/3]

constexpr doodle::Color::Color ( double  grey,
double  alpha = 255 
)
inlineexplicitconstexprnoexcept

Note that if only one value is provided to Color, it will be interpreted as a grayscale value. Add a second value, and it will be used for alpha transparency.

Parameters
greynumber specifying value between white and black
alphaalpha value relative to color range 0-255
using namespace doodle;
int main(void)
{
create_window(100, 100);
while (!is_window_closed())
{
draw_rectangle(-20, -20, 35, 35);
set_fill_color(Color{100, 128});
draw_rectangle(0, 0, 35, 35);
}
return 0;
}

Definition at line 111 of file color.hpp.

112  : red(grey), green(grey), blue(grey), alpha(alpha)
113  {
114  }
double alpha
Definition: color.hpp:58
double green
Definition: color.hpp:56
double blue
Definition: color.hpp:57
double red
Definition: color.hpp:55

◆ Color() [3/3]

constexpr doodle::Color::Color ( double  red,
double  green,
double  blue,
double  alpha = 255 
)
inlineconstexprnoexcept

When three values are specified, they are interpreted as RGB. Adding a fourth value applies alpha transparency.

Parameters
redred value relative to the color range 0-255
greenvalue relative to the color range 0-255
bluevalue relative to the color range 0-255
alphaalpha value relative to color range 0-255
using namespace doodle;
int main(void)
{
create_window(100, 100);
constexpr Color yellow{255, 204, 0};
constexpr Color transparent_green{220, 236, 165, 120};
while (!is_window_closed())
{
set_fill_color(yellow);
draw_ellipse(-20, 20, 80);
set_fill_color(transparent_green);
draw_ellipse(15, -15, 80);
}
return 0;
}

Definition at line 147 of file color.hpp.

148  : red(red), green(green), blue(blue), alpha(alpha)
149  {
150  }

Member Data Documentation

◆ alpha

double doodle::Color::alpha = 255

Definition at line 58 of file color.hpp.

◆ blue

double doodle::Color::blue = 0

Definition at line 57 of file color.hpp.

◆ green

double doodle::Color::green = 0

Definition at line 56 of file color.hpp.

◆ red

double doodle::Color::red = 0

Definition at line 55 of file color.hpp.


The documentation for this class was generated from the following file: