Simple Canvas
Public Member Functions | Public Attributes | List of all members
SimpleCanvas Class Reference

A simple library for 2D drawing in C++, by Chris Tralie. More...

#include <simplecanvas.h>

Public Member Functions

 SimpleCanvas (std::string fname)
 Construct a new image object from a file.
More...
 
 SimpleCanvas (int32_t width, int32_t height)
 Instantiate an image object of a particular dimension. More...
 
 ~SimpleCanvas ()
 Destroy the Simple Image object by de-allocating the pixel data.
 
void read (std::string fname)
 Read in a ppm file. Use ffmpeg to convert the file to a temporary .ppm file if it has a non ppm extension. More...
 
void write (std::string fname)
 
void setPixel (int x, int y, uint8_t R, uint8_t G, uint8_t B)
 Set the color of a particular pixel. More...
 
void fillRect (int x0, int y0, int w, int h, uint8_t R, uint8_t G, uint8_t B)
 Fill a solid rectangle with a color. More...
 
void clearRect (uint8_t R, uint8_t G, uint8_t B)
 Clear the entire canvas to be one color. More...
 
void drawRect (int x0, int y0, int w, int h, uint8_t R, uint8_t G, uint8_t B, uint8_t line_w)
 Draw the outline of a rectangle with a particular color. More...
 
void drawLine (int x0, int y0, int x1, int y1, uint8_t R, uint8_t G, uint8_t B)
 Draw a thin line from one point to another. More...
 
void drawLine (int x0, int y0, int x1, int y1, int thickness, uint8_t R, uint8_t G, uint8_t B)
 Draw a thick line from one point to another. More...
 
void fillCircle (int cx, int cy, double r, uint8_t R, uint8_t G, uint8_t B)
 Fill in a solid disc of a particular color. More...
 
void drawString (std::string s, int x0, int y0, std::string relpath)
 Draw a character at a string at a position. More...
 

Public Attributes

int width
 
int height
 
uint8_t *** data
 

Detailed Description

A simple library for 2D drawing in C++, by Chris Tralie.

Constructor & Destructor Documentation

◆ SimpleCanvas() [1/2]

SimpleCanvas::SimpleCanvas ( std::string  fname)

Construct a new image object from a file.

Parameters
fnamePath to file

◆ SimpleCanvas() [2/2]

SimpleCanvas::SimpleCanvas ( int32_t  width,
int32_t  height 
)

Instantiate an image object of a particular dimension.

Parameters
widthWidth of image
heightHeight of image

Member Function Documentation

◆ clearRect()

void SimpleCanvas::clearRect ( uint8_t  R,
uint8_t  G,
uint8_t  B 
)

Clear the entire canvas to be one color.

Parameters
RRed channel
GGreen channel
BBlue channel

◆ drawLine() [1/2]

void SimpleCanvas::drawLine ( int  x0,
int  y0,
int  x1,
int  y1,
int  thickness,
uint8_t  R,
uint8_t  G,
uint8_t  B 
)

Draw a thick line from one point to another.

Parameters
x0X coordinate of first point
y0Y coordinate of first point
x1X coordinate of second point
y1Y coordinate of second point
thicknessThickness of line
RRed channel
GGreen channel
BBlue channel

◆ drawLine() [2/2]

void SimpleCanvas::drawLine ( int  x0,
int  y0,
int  x1,
int  y1,
uint8_t  R,
uint8_t  G,
uint8_t  B 
)

Draw a thin line from one point to another.

Parameters
x0X coordinate of first point
y0Y coordinate of first point
x1X coordinate of second point
y1Y coordinate of second point
RRed channel
GGreen channel
BBlue channel

◆ drawRect()

void SimpleCanvas::drawRect ( int  x0,
int  y0,
int  w,
int  h,
uint8_t  R,
uint8_t  G,
uint8_t  B,
uint8_t  line_w 
)

Draw the outline of a rectangle with a particular color.

Parameters
x0Left of rectangle
y0Top of rectangle
wWidth of rectangle
hHeight of rectangle
RRed channel
GGreen channel
BBlue channel
line_wWidth of rectangle

◆ drawString()

void SimpleCanvas::drawString ( std::string  s,
int  x0,
int  y0,
std::string  relpath 
)

Draw a character at a string at a position.

Parameters
sThe string to draw
xx location of lower left corner of the string
yy location of lower left corner of the string
relpathRelative path to directory containing the fonts

◆ fillCircle()

void SimpleCanvas::fillCircle ( int  cx,
int  cy,
double  r,
uint8_t  R,
uint8_t  G,
uint8_t  B 
)

Fill in a solid disc of a particular color.

Parameters
cxX coordinate of center of disc
cyY coordinate of center of disc
rRadius of disc
RRed channel
GGreen channel
BBlue channel

◆ fillRect()

void SimpleCanvas::fillRect ( int  x0,
int  y0,
int  w,
int  h,
uint8_t  R,
uint8_t  G,
uint8_t  B 
)

Fill a solid rectangle with a color.

Parameters
x0Left of rectangle
y0Top of rectangle
wWidth of rectangle
hHeight of rectangle
RRed channel
GGreen channel
BBlue channel

◆ read()

void SimpleCanvas::read ( std::string  fname)

Read in a ppm file. Use ffmpeg to convert the file to a temporary .ppm file if it has a non ppm extension.

Parameters
fnamePath to file

◆ setPixel()

void SimpleCanvas::setPixel ( int  x,
int  y,
uint8_t  R,
uint8_t  G,
uint8_t  B 
)

Set the color of a particular pixel.

Parameters
xX coordinate of pixel
yY coordinate of pixel
RRed channel
GGreen channel
BBlue channel

◆ write()

void SimpleCanvas::write ( std::string  fname)

Write the image to a file If the filename ends with an extension other than ppm, write it to a temporary ppm file, and use ffmpeg to convert it to the desired name

Parameters
fnameName of the file

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