bressenham::figure

class figure

Manage pixel-by-pixel writes to the frame buffer.

It stores and manages the pixel buffer to be rendered to the screen. The RGB codes of individual pixels’ can be set to produce visual elements.

The class provides the following primitive drawing methods:

The color to be used by the add_*() primitives can be set by set_color(), prior to the function calls.

Finally, the block of pixels can be added to the frame buffer by calling draw().

Public Functions

figure(uint width, uint height)

Constructor.

Parameters
  • width: The width of the screen in pixels.
  • height: The height of the screen in pixels.

void flip_vertically(bool flip)

Sets the state so that all figures drawn are flipped vertically.

Parameters
  • flip: A boolean that tells whether to set the flip state.

void set_color(color rgb)

Sets the pixel drawing color m_rgb.

Any add_*() commands will use the currently set m_rgb value.

Parameters
  • rgb: The color to set.

void add_pixel(uint x, uint y)

Draws a single pixel.

Uses the currently set m_rgb value.

Parameters
  • x: The \(x\) coordinate of the pixel. \((0 \le x \lt width)\)
  • y: The \(y\) coordinate of the pixel. \((0 \le y \lt height)\)

void add_line(uint x1, uint y1, uint x2, uint y2)

Draws a straight line between two given pixels using the Bresenham midpoint algorithm.

Uses the currently set m_rgb value.

Parameters
  • x1: The \(x\) coordinate of the first pixel. \((0 \le x_1 \lt width)\)
  • y1: The \(y\) coordinate of the first pixel. \((0 \le y_1 \lt height)\)
  • x2: The \(x\) coordinate of the second pixel. \((0 \le x_2 \lt width)\)
  • y2: The \(y\) coordinate of the second pixel. \((0 \le y_2 \lt height)\)

void add_circle(uint cx, uint cy, uint radius)

Draws a circle using the midpoint algorithm.

Uses the currently set m_rgb value.

Parameters
  • cx: The \(x\) coordinate of the center of the circle. \((0 \le c_x \lt width)\)
  • cy: The \(y\) coordinate of the center of the circle. \((0 \le c_y \lt height)\)
  • radius: The radius of the circle in pixels.

void add_ellipse(uint cx, uint cy, uint a, uint b)

Draws an axes-aligned ellipse using the midpoint algorithm.

Uses the currently set m_rgb value.

Parameters
  • cx: The \(x\) coordinate of the center of the ellipse. \((0 \le c_x \lt width)\)
  • cy: The \(y\) coordinate of the center of the ellipse. \((0 \le c_y \lt height)\)
  • a: The length of the horizontal axis in pixels.
  • b: The length of the vertical axis in pixels

void fill(uint x, uint y, color boundary_color)

Fills a bounded region using the Boundary Fill algorithm.

Uses the currently set m_rgb value as the fill color.

Starts at the given pixel and recursively colors adjacent pixels until a pixel of color boundary_color is found or the end of the screen is reached.

Only a single boundary color is supported.

Parameters
  • x: The \(x\) coordinate of an interior point in the region. \((0 \le x \lt width)\)
  • y: The \(y\) coordinate of an interior point in the region. \((0 \le y \lt height)\)
  • boundary_color: The color of the boundary pixels.

void draw()

Writes the block of pixels to the frame buffer.

Is usually preceeded by one or more add_*() commands.