2d Computer Graphics in Modern C and Standard Library Compress
2d Computer Graphics in Modern C and Standard Library Compress
standard library
Håkan Blomqvist
This book is for sale at http://leanpub.com/2dcomputergraphicsinmoderncandstandardlibrary
This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing
process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and
many iterations to get reader feedback, pivot until you have the right book and build traction once
you do.
1 2D Drawing Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Standard Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Compile Code Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Prerequisite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1 History
2D Drawings with computers started out in, as most things computer related, in academia. It was
first created as a visualization tool for scientists and engineers in US government and US corporate
research centers such as Bell Labs and Boeing in the 1950s. Later the tools would be developed at
Universities in the 60s and 70s at places such as Ohio State University, MIT, University of Utah,
Cornell, North Carolina and the New York Institute of Technology. The early breakthroughs that
took place in academic centers continued at research centers such as the famous Xerox PARC in the
1970s. These efforts broke first into broadcast video graphics and then major motion pictures in the
late 70¹s and early 1980s. Computer graphic research continues today around the world, now joined
by the research and development departments of entertainment and production companies.
Since 1974 ACM SIGGRAPH has evolved to become an international community of researchers,
artists, developers, filmmakers, scientists, and business professionals who share an interest in
computer graphics and interactive techniques. Each year the latest and greatest with this research
gets presented.
1.4 Prerequisite
You’ll need to already know how to program in C++. This book is about how to draw and and not
about how to program.
2 Draw Pixels with Standard Library
We’re using RGB elements to draw a pixel in C++. To handle RGB elements as one unit for
convenience there is something called std::tuple.
Reference: https://en.cppreference.com/w/cpp/utility/tuple e.g. a function that takes three integers
as input and returns it as a tuple
01_tuples.cpp demonstrates the usage of ‘std::tuple’ in C++17. It uses a tuple to store and
manipulate RGB color elements as a single entity. The code includes the ‘’ headers and defines
a function ‘get_rgb_elements_as_a_tuple’ that takes three integers (r, g, and b) and returns a tuple
containing these integers.
The ‘main’ function initializes three sets of RGB values (r1, g1, b1, r2, g2, b2, and r3, g3, b3). Initially,
only the first set (r1, g1, b1) is given values, while the other two sets are initialized to 0.
The code then prints the initial RGB values of all three sets. Next, it calls ‘get_rgb_elements_as_-
a_tuple’ with the first set of RGB values (r1, g1, b1) and assigns the returned tuple to ‘rgb’.
Two different methods are then used to “unroll” the ’ ’ tuple into the other two sets of RGB values:
1. “unroll #1”: Using ‘std::get’ to access individual elements of the tuple by index and assigning
them to r2, g2, and b2.
2. “unroll #2”: Using ‘std::tie’ to unpack the tuple into r3, g3, and b3.
After each unroll, the RGB values of all three sets are printed to verify that the tuple has been
correctly unpacked into the second and third sets of RGB values.
take a look in Appendix A: 01_tuples.cpp
Now that we know how to store and unroll a tuple of rgb elements. Let’s talk about adding rgb
tuples to an image — to set a pixel where we want it to be in the image.
But, before that we need to talk about the way computers memory (1D) is physically represented
and the representation of an image (2D). To know where to store the tuple we need to translate (2D)
into (1D). To store the pixel at a certain x and y in the image, but in memory.
index = x + width ∗ y
2 Draw Pixels with Standard Library 5
X + width * Y = 2 + 10 * 3 = 32 Index = 32
Let’s create a function that handles the index-calculations for us. A function that takes X and Y as
input and returns the index.
Or, take a look in Appendix A: 02_index.cpp
Besides calculating index we need to know how many tuples with we need to store in a std::vector
for a beforehand defined width and height of an image. For instance, an image that has a width of
640 and a height of 360 is 640 * 360 (230400) in size for a std::vector with those dimensions.
Reference: https://en.cppreference.com/w/cpp/container/vector As always we need to include the
header: #include
To set the vector container size we calculate it by multiplying the image width times the height.
We use the Resize function in std::vector to set the size of the vector. Then we can use the vectors
operator[] and operator= for index and assigns.
Also, why not assign the color black to all the pixels while we are at it, as a clear image function.
For the source code, take a look in Appendix A: 03_calcsize.cpp
Note that this code example uses float for the rgb elements. We do that as it’s preferred later when
we work with colors and that red, green and blue are a float number between 0.0 - 1.0 and not an
integer.Enough with the calculations of metadata about the image. It’s time to draw some pixels
and save it into a textile. Yes, there are a few image formats that are text based. In this book we’re
going to use PPM file format. This graphics format comes from the open source Netpbm project that
is several graphics programs and a programming library — used mainly in the Unix world. PPM
stands for Portable PixMap format and is portable due to its written as ASCII (Type: P3). A PPM
2 Draw Pixels with Standard Library 6
file consists of two parts: a header and the image data. Don’t worry about the it being ASCII, PPM
can be converted to PNG, JPG or any other format. Here’s how the PPM format looks like as ASCII:
The header starts with the ”P3” indicator. Second line contains the width and height of the image
separated with a whitespace. Third line has the number 255 stated, this is going to be used for all
examples in this book. The 255 is about the max value for each rgb element. And as we see below
the header, each pixel is represented as three integer values between 0 - 255 for rgb.
Include header: #include Reference: https://en.cppreference.com/w/cpp/io/basic_fstream
For the source code, take a look in Appendix A: 04_helloworld.cpp
04_helloworld_square.ppm
04_helloworld.ppm
That’s great, but even more awesome if we also could read a PPM image too.
For the source code, take a look in Appendix A: 05_randomwalker.cpp
2 Draw Pixels with Standard Library 7
05_randomwalker.ppm
Now, we have a lot of code to go through in the 05 example. There are one new header and few new
functions that needs some explanation.
Example 05 was not only about reading a PPM file. We implemented a random walker. Let go
through the code function by function.
Reference: https://en.cppreference.com/w/cpp/header/random
Add random header to the file: #include
Following functions are new:
• walker
• update_x_and_y
• read_image
• get_color
• get_width_and_height
• startsWithCaseInsensitive
We start by reading 04_helloworld.ppm into image1 and at the same time set width and height from
the PPM file using get_width_and_height. read_image uses the helper function startsWithCaseIn-
sensitive to sort through the PPM data. get_color is used to read the rgb color.
We use the walker function to implement a random walker algorithm. Walker uses random function
to randomize the walker. For each walker generation we use the update_x_and_y function to move
the walker in a random direction.
3 Texture Generation with Standard
Library
Neat, now we can draw pixels. Let’s play around with that a bit and generate different types of
textures that can be useful to have.
Let’s generate textures by using boolean XOR (Exclusive-OR) AND and OR.
The code generates and saves three different textures based on bitwise operations: XOR, AND, and
OR. To achieve this, it defines several functions to create, manipulate, and save the images. The
‘get_index’ function is responsible for converting 2D grid coordinates (x, y) into a 1D array index,
while the ‘calc_size’ function calculates the total number of elements in a 2D grid. The ‘clear_-
image’ function sets all the pixels of an image to a given color, effectively clearing the image.
The code also provides three functions to create different textures: ‘draw_xor’, ‘draw_and’, and
‘draw_or’. Each function iterates through the image’s pixels and calculates the corresponding
bitwise operation (XOR, AND, or OR) on the x and y coordinates of each pixel. The resulting value
is then used as the color intensity for that pixel.
In the ‘main’ function, the program starts by initializing the image vector and color tuple, followed
by resizing the image vector based on the calculated size. The image is then cleared using a dark
blue color. After that, the XOR texture is generated and saved to the “06_xor_texture.ppm” file.
Subsequently, the AND texture is generated and saved to the “06_and_texture.ppm” file. Finally,
the OR texture is generated and saved to the “06_or_texture.ppm” file.
For the source code, take a look in Appendix A: 06_xor_and_or_texture.cpp
06_xor_texture.ppm
3 Texture Generation with Standard Library 9
06_and_texture.ppm
06_or_texture.ppm
XOR, AND and OR type of textures are the simplest ones. It’s just x XOR y, x AND y, or x OR y.
These textures are nice to have if you just want to do an example. Excellent for prototyping use.
Procedural texture generation is another way to create textures. With random noise we can generate
textures like clouds, marble, and wood.
Reference: https://en.cppreference.com/w/cpp/numeric/math/fabs
This code generates and saves three different textures: Clouds, Marble, and Wood. It includes several
functions to create, manipulate, and save images. The ‘get_index’, ‘calc_size’, ‘clear_image’, and
‘save_image’ functions were explained in the previous response, and they serve the same purpose
here. Additionally, a new function ‘generate_noise’ is introduced, which fills a noise vector with
random values in the range of 0.0 to 1.0.
The ‘smooth_noise’, ‘turbulence’, and texture generation functions (‘generate_cloud’, ‘generate_-
marble’, and ‘generate_wood’) are the core of this code. The ‘smooth_noise’ function calculates a
bilinear interpolation of the noise values at a given position, while the ‘turbulence’ function sums
up the smooth noise values at different scales to generate more complex patterns.
The ‘generate_cloud’ function uses the ‘turbulence’ function to create a cloud-like texture. In
contrast, the ‘generate_marble’ function calculates a sine pattern that is distorted by turbulence to
mimic the appearance of marble. Finally, the ‘generate_wood’ function creates a wood-like texture
by calculating the distance from the center of the image and applying a sine pattern combined with
turbulence.
In the ‘main’ function, the program initializes the noise and image vectors and resizes them based on
3 Texture Generation with Standard Library 10
the calculated size. The image is then cleared using a dark blue color. The noise vector is generated,
and the Cloud texture is created and saved to the “07_cloud_texture.ppm” file. Subsequently, the
Marble texture is generated and saved to the “07_marble_texture.ppm” file. Finally, the Wood texture
is generated and saved to the “07_wood_texture.ppm” file.
For the source code, take a look in Appendix A: 07_clouds_marble_wood_texture.cpp
07_cloud_texture.ppm
07_marble_texture.ppm
07_wood_texture.ppm
Uses bilinear interpolation to smooth the noise. Turbulence is added for marble and wood.
Procedural generation in itself is an interesting topic.
4 Time to draw some lines with
Standard Library
Well, not yet, first we go through some theory about light and color that is good to know.
A C++ program designed to manipulate images in the PPM format, specifically the P3 (ASCII) format.
It includes various functions to perform image manipulation tasks such as creating a negative image,
adjusting brightness and darkness, converting to grayscale, swapping color channels, and blending
two images. The program uses the Standard Library and has a main function to perform user-
specified manipulations on an input image file and save the result to an output file.
The code begins by importing necessary headers and declaring several utility functions like
‘startsWithCaseInsensitive’, ‘get_index’, ‘calc_size’, ‘get_width_and_height’, and ‘get_color’.
These functions help with string manipulation, getting an index in a 1D array representing a 2D
image, calculating the size of an image, and extracting image dimensions and color values from
strings.
The ‘read_image’ function reads an image from a file and stores it as a vector of tuples with float
values representing the red, green, and blue (RGB) components of each pixel. The function reads
the file line by line, determining the file format, dimensions, and maximum color value, and then
populates the image vector with the pixel data.
Several functions perform image manipulations like ‘negative_image’, ‘double_as_dark’,
‘onefive_as_dark’, ‘twice_as_bright’, ‘add_for_brighter’, ‘sub_for_darker’, ‘greyscale_image’,
‘zero_gb_image’, ‘r_zero_b_image’, ‘rg_zero_image’, ‘grb_image’, ‘bgr_image’, ‘rrb_image’,
and ‘blended_two_images’. These functions take an image (vector of tuples) and its dimensions
as input and modify the image in place. Some functions also take additional parameters like the
blending factor ‘alpha’ for ‘blended_two_images’.
The main function of the program reads an input image file, performs the user-specified image
manipulations using the functions mentioned above, and writes the modified image to an output
file. The main function also takes care of validating the user input and making sure the provided
parameters are valid.
For the source code, take a look in Appendix A: 08_light_and_color.cpp
For every image generated, 04_helloworld.ppm get’s reread.
4 Time to draw some lines with Standard Library 12
08_negative_image.ppm
Subtraction Eg. original color rgb(203, 37, 101) as negative: rgb(255-203, 255-37, 255-101) which is
the same as: rgb(52, 218, 154).
08_double_as_dark.ppm
Division Eg. rgb(203, 37, 101) as double as dark: rgb(203/2, 37/2, 101/2) which is the same as: rgb(101,
18, 50).
08_onefive_as_dark.ppm
Division Eg. rgb(203, 37, 101) as 1.5 as dark: rgb(203/1.5, 37/1.5, 101/1.5) which is the same as:
rgb(135, 25, 67).
08_twice_as_bright.ppm
Multiplication Eg. rgb(203, 37, 101) as twice as bright: rgb(203x2, 37x2, 101x2) which is the same
as: rgb(255, 74, 202).
4 Time to draw some lines with Standard Library 13
08_add_for_brighter.ppm
Addition Eg. rgb(203, 37, 101) add for brighter: rgb(203+30, 37+30, 101+30) which is nthe same as:
Eg. rgb(233, 67, 131)
08_sub_for_darker.ppm
Subtraction Eg. rgb(203, 37, 101) sub for darker: rgb(203-30, 37-30, 101-30) which is nthe same as:
Eg. rgb(173, 7, 71)
08_greyscale_image.ppm
08_zero_gb_image.ppm
R = 0;
08_r_zero_b_image.ppm
G = 0;
4 Time to draw some lines with Standard Library 14
08_rg_zero_image.ppm
B = 0;
08_grb_image.ppm
08_bgr_image.ppm
08_rrb_image.ppm
08_blended_two_images.ppm
4 Time to draw some lines with Standard Library 15
Or blend two images together as above (based on bg: 06_xor_texture.ppm and fg: 04_helloworld_-
square.ppm). Or as below, with bg: 05_randomwalker.ppm and fg: 04_helloworld.ppm.
08_blended_two_images(2).ppm
use of floating-point arithmetic and division, which can be computationally expensive. Instead, it
relies on integer operations, which are generally faster and more efficient. This makes the algorithm
ideal for use in low-level graphics systems, such as early computer displays and video game consoles,
where computational resources are limited.
The ‘find_region’ and ‘clip_line’ functions uses the Cohen-Sutherland line clipping algorithm. This
algorithm is used to determine the parts of a line segment that lie within a rectangular viewport or
window. The main goal of the algorithm is to reduce the amount of line drawing computation
required for lines that are partially or entirely outside the viewport.
The Cohen-Sutherland algorithm assigns a 4-bit region code to each endpoint of a line segment
based on its position relative to the viewport. The bits correspond to the top, bottom, right, and
left regions outside the viewport. The ‘find_region’ function computes this region code for a given
point. If both endpoints have a region code of 0, the line segment is entirely inside the viewport, and
no clipping is required. If the bitwise AND of the two region codes is non-zero, the line segment is
entirely outside the viewport and can be discarded.
When a line segment straddles the viewport boundary, the ‘clip_line’ function comes into play.
This function iteratively clips the line segment against each edge of the viewport by calculating the
intersection point between the line and the edge. It then replaces the endpoint that lies outside the
viewport with the intersection point and updates its region code. This process is repeated until the
line segment is either fully inside the viewport or determined to be outside the viewport.
For the source code, take a look in Appendix A: 09_lines.cpp
09_random_lines.ppm
In this example we use HSV (Hue, Saturation, and Value) as a color model and converts it back to
RGB afterwords. A random Hue gets produced and with the h_to_rgb(float h) function we get a
RGB value back.
We also use clip_line function together with find_region function for clipping every line that is
clipped between the visible and non-visible screen.
‘std::mt19937’ is a C++ standard library implementation of the Mersenne Twister pseudorandom
number generator (PRNG) algorithm. The name “mt19937” is derived from the fact that the
Mersenne Twister uses a Mersenne prime number, 2^19937 - 1, as the basis for its internal state.
This PRNG is widely used for its high-quality random number generation, large period, and efficient
performance. Mersenne Twister is a popular choice for various applications, including simulations,
statistical modeling, and computer games, where high-quality random numbers are needed.
The ‘std::mt19937’ generator is part of the C++11 ‘’’ library is designed to offer a more versatile and
flexible approach to random number generation compared to older C++ functions like ‘rand()’ and
4 Time to draw some lines with Standard Library 17
‘srand()’.
To use ‘std::mt19937’, you first need to create an instance of the generator and seed it with an initial
value. The quality of the random numbers generated depends on the seed value, which is typically
derived from a high-resolution clock or other sources of entropy. Once the generator is seeded, you
can use it to generate random numbers within a specified range or to generate random numbers
according to a probability distribution using distribution classes provided by the ‘’’ header.
09_damped_sine.ppm
Here we use the previous X and Y to draw a continous line that gets shaped into the demped sine
as calculated.
A damped sine wave is a sinusoidal function that gradually decreases in amplitude over time due to
the presence of a damping factor. In mathematical terms, a damped sine wave can be represented
as A(t) = A₀ * sin(ωt + φ) * e^(-αt), where A₀ is the initial amplitude, ω is the angular frequency, φ
is the phase, α is the damping factor, and t represents time. The damping factor, α, determines the
rate at which the amplitude decreases; a larger damping factor results in a more rapid decrease in
amplitude, while a smaller damping factor causes the amplitude to decay more slowly.
Damped sine waves can be effectively used in animations to create natural-looking motion or to
simulate physical processes that involve oscillatory behavior. For example, they can be employed to
animate the movement of a pendulum, the bouncing of a ball, or the oscillation of a spring. In these
cases, the damped sine wave helps to model the gradual loss of energy due to friction, air resistance,
or other dissipative forces that are present in real-world systems. By incorporating damped sine
waves into animations, designers can create more realistic and visually appealing motion that closely
mimics the behavior observed in nature, making the animation more immersive and engaging for
the audience.
Also, we can draw a line with starting x and y point, length and degrees.
09_angle_lines.ppm
The code is designed to create an image with lines drawn at different angles. The code begins
with several include statements, bringing in necessary libraries, followed by a series of function
definitions.
The ‘get_index’, ‘calc_size’, and ‘clear_image’ functions are utility functions for image manipula-
tion. ‘get_index’ calculates a one-dimensional index from two-dimensional coordinates, ‘calc_size’
4 Time to draw some lines with Standard Library 18
calculates the total size of the image given its width and height, and ‘clear_image’ sets all pixels in
the image to white.
‘draw_line’ is a function that draws a line between two points in the image with a specified color.
The ‘find_region’, ‘clip_line’, and ‘get_angle_line’ functions are used for line clipping and angle
calculations. ‘find_region’ determines which region of the image a point lies in, ‘clip_line’ clips a
line to the image boundaries, and ‘get_angle_line’ calculates the endpoint of a line given a starting
point, angle, and length.
Finally, ‘save_image’ is a function that writes the image data to a file in PPM format.
The ‘main’ function initializes the image and sets its dimensions. It then draws lines at various
angles (0, 45, 90, 135, 180, 225, 270, and 315 degrees) around the center of the image with a fixed
length. The clip_line function is used to ensure that lines are only drawn within the boundaries of
the image. After drawing all the lines, the image is saved to a file named “09_angle_lines.ppm”.
5 There are no straight curves, only
curved lines
Bézier curve is a parametric curve. There are three types of Bézier curves:
Linear Interpolation, is a mathematical function that returns a value between two others at a point
on a linear scale. Most commonly it’s used for moving or changing values over a period of time.
With std::lerp (Linear Interpolation) function in C++20 we can draw curves using Linear, Quadratic
and Cubic Bézier curves (using a std::lerp inception; As they build on each other).
Reference: https://en.cppreference.com/w/cpp/numeric/lerp
C++17 version: https://github.com/emsr/cxx_linear
Use the lerp and midpoint code above if you’re only allowed to use C++17.
The C++ code demonstrates how to draw linear, quadratic, and cubic Bezier curves using dots on
an image. It creates an image with various types of Bezier curves and saves the result as a PPM
file. The code starts by including the necessary header files and then defines several functions to
compute the points on the Bezier curves, manipulate the image, and render the curves on the image.
The linear, quadratic, and cubic Bezier curve functions take the coordinates of the start, control, and
end points, along with the number of splits as input, and compute the points on the curves. Utility
functions are defined to help with image manipulation and rendering, such as getting an index in
the image vector, calculating the size of the image, clearing the image, and drawing lines.
In addition to the Bezier curve functions, the code also has functions to draw the Bezier curve points
and markers on the image, which are used for better visualization. Another function, save_image,
is defined to save the image as a PPM file.
In the main function, the program initializes the width and height of the image, creates a vector
for storing the image data, and then clears the image. Next, it draws linear, quadratic, and cubic
Bezier curves by using the previously defined functions. The program also draws the control lines
and markers for better visualization. Finally, it saves the resulting image as a PPM file named
“10_curved_dots.ppm”.
For the source code, take a look in Appendix A: 10_curved_dots.cpp
5 There are no straight curves, only curved lines 20
10_curved_dots.ppm
This is what std::lerp does… it’s these points that then can use a line function and dra the curve. The
curve is controlled with the two control points.
This C++ code is designed to create an image of curved lines using linear, quadratic, and cubic Bezier
curves. It first includes the necessary libraries and then defines several functions to calculate Bezier
curves, draw lines and dots, and save the image.
The ‘linear_bezier_curves’, ‘quadratic_bezier_curves’, and ‘cubic_bezier_curves’ functions are
used to generate the points for linear, quadratic, and cubic Bezier curves, respectively. The ‘draw_-
line’ function draws a straight line between two points. The ‘draw_xy_line’ function draws a line
using the points generated from Bezier curves, while the ‘draw_xy_dots’ function draws dots at
the points generated by the Bezier curves.
The ‘draw_marker’ function creates a small marker at a specified point, and the ‘save_image’
function saves the image to a file in PPM format.
In the ‘main’ function, the code sets up an image of specified width and height and fills it with a
white background. Then, it proceeds to draw lines using the Bezier curves functions, along with
markers and dots at various points. Finally, it saves the created image to a file.
The code demonstrates the use of linear, quadratic, and cubic Bezier curves to create smooth curves
between points in an image, as well as drawing markers and dots at specific points along the curve.
For the source code, take a look in Appendix A: 10_curved_lines.cpp
10_curved_lines.ppm
Here we have the curves drawn with the line function and the points is marked as well as also the
control points.
6 Rectangles with Standard Library
A rectangle is a closed 2D shape, having 4 sides, 4 corners, and 4 right angles (90°).The opposite
sides of a rectangle are equal and parallel. Since, a rectangle is a 2D shape, it is characterized by
two dimensions, width, and height. To draw a rectangle you’ll need X and Y together with the
rectangles width and height.
The C++ code generates an image containing two rectangles, one outlined and one filled, saved as a
PPM file. The code consists of several functions, each serving a specific purpose in order to create
and manipulate the image.
The first few functions in the code are used for basic image handling. The ‘get_index’ function
calculates the index of a pixel in a 1D vector representation of a 2D image given its (x, y) coordinates
and the image width. The ‘calc_size’ function calculates the size of the image given its width and
height, while the ‘clear_image’ function fills the image vector with white pixels (R=1.0, G=1.0,
B=1.0).
Next, there are functions for drawing shapes on the image. The ‘draw_line’ function draws a line
between two points in the image using Bresenham’s line algorithm, an efficient method for drawing
lines on a raster grid. The ‘draw_rect’ function draws an outlined rectangle by connecting its four
corners using the ‘draw_line’ function. The ‘draw_filled_rect’ function, on the other hand, draws
a filled rectangle by iterating over its area and setting the color of each pixel inside the rectangle.
Finally, the ‘save_image’ function saves the image to a PPM file, which is a simple, uncompressed
image file format.
In the ‘main’ function, the image parameters, such as width, height, and the position and size of the
two rectangles are initialized. Then, a vector representing the image is created and initialized with
white pixels. After that, the two rectangles are drawn on the image. The resulting image is then
saved to a PPM file named “11_rectangles.ppm”.
For the source code, take a look in Appendix A: 11_rectangles.cpp
11_rectangles.ppm
of the code is to create an image where the filled rectangles are blended with the background color
using an alpha channel for transparency.
The code starts by including necessary headers and defining helper functions such as ‘startsWith-
CaseInsensitive’, ‘get_index’, ‘calc_size’, ‘clear_image’, ‘parse_bginfo_line’, ‘parse_rect_line’,
‘blend_colors’, ‘draw_filled_rect’, and ‘save_image’. These functions perform various operations,
such as string manipulation, parsing input lines, calculating indices for a 2D image stored as a 1D
vector, blending colors, drawing rectangles, and saving the final image as a PPM file.
In the ‘main’ function, the program reads lines from the input file “11_squint_with_your_eyes.txt”.
If a line starts with “r”, it is considered a rectangle specification and parsed using the parse_rect_line
function. The rectangle’s coordinates, color, and alpha values are then used to draw the rectangle
on the image using the ‘draw_filled_rect’ function. If a line starts with “b”, it is considered a
background specification and parsed using the ‘parse_bginfo_line’ function. The background color
and image dimensions are extracted from the line, and the image vector is resized accordingly. The
‘clear_image’ function is called to fill the entire image with the background color.
After processing all the lines from the input file, the program saves the resulting image to a PPM
file called “11_squint_with_your_eyes.ppm” using the ‘save_image’ function. The PPM file format
is a simple, text-based format that stores pixel color information as plain text. The code writes the
PPM header, followed by the pixel color values, one pixel per line, in the output file.
For the source code, take a look in Appendix A: 11_rectangles_from_file.cpp
For the source code, take a look in Appendix A: 11_squint_with_your_eyes.txt
11_squint_with_your_eyes.ppm
This is an example how you can read data and present it into a image.
7 Circles with Standard Library
A circle is a round-shaped figure that has no corners or edges.
The midpoint circle algorithm is a widely-used technique for efficiently drawing circles on raster
displays, such as computer screens or images. The algorithm was developed as an extension of
Bresenham’s line algorithm, which is used for drawing lines. The midpoint circle algorithm employs
integer arithmetic and incremental calculations to minimize computational overhead and avoid
the use of computationally expensive floating-point arithmetic, such as square root operations. It
generates a set of points on the circle’s circumference, taking advantage of the circle’s inherent
symmetry to reduce the number of calculations required.
The algorithm works by starting at the topmost point of the circle and incrementally moving towards
the x-axis while calculating the appropriate y-coordinate for each x-coordinate. It does this by
evaluating a decision parameter at each step to determine whether to increment the x-coordinate,
the y-coordinate, or both. The decision parameter is based on the circle equation, and it helps to
determine whether the midpoint between two candidate pixels is inside or outside the circle. If the
midpoint is inside the circle, the algorithm chooses the pixel closer to the x-axis; if it is outside, the
algorithm chooses the pixel closer to the y-axis.
One of the key features of the midpoint circle algorithm is its ability to exploit the eightfold
symmetry of a circle. Since a circle is symmetrical about both the x and y axes, as well as the
lines y = x and y = -x, the algorithm only needs to compute the points in one-eighth of the
circle and then derive the remaining points by reflection. This significantly reduces the number
of calculations required to draw the entire circle. The result is an efficient method for drawing
circles in computer graphics, particularly when working with low-level raster graphics operations
or limited computational resources.
This C++ code generates an image containing two circles, one filled and one unfilled, with a white
background. The primary purpose of the code is to demonstrate the process of drawing circles using
a simple implementation of the midpoint circle algorithm and saving the resulting image as a PPM
file.
The code starts by including necessary headers and defining helper functions, such as ‘get_index’,
‘calc_size’, ‘clear_image’,‘draw_circle’, ‘draw_filled_circle’, and ‘save_image’. These functions
perform various operations, such as calculating indices for a 2D image stored as a 1D vector, clearing
the image by setting all pixel colors to white, drawing unfilled and filled circles using the midpoint
circle algorithm, and saving the final image as a PPM file.
In the ‘main’ function, the program sets the width and height of the image, as well as the positions
and radii of the two circles. The x and y coordinates, as well as the radius of the circles, are calculated
based on the dimensions of the image. The image vector is resized accordingly, and the ‘clear_image’
function is called to fill the entire image with the white background color.
7 Circles with Standard Library 24
Next, the ‘draw_circle’ function is called to draw the first circle (unfilled) on the image, and the
‘draw_filled_circle’ function is called to draw the second circle (filled) on the image. Both functions
use the midpoint circle algorithm to determine which pixels to set to the desired color (black in
this case). The ‘draw_filled_circle’ function additionally fills the interior of the circle by drawing
horizontal lines between the boundary points.
Finally, the ‘save_image’ function is called to save the resulting image as a PPM file called “12_-
circle.ppm”. The PPM file format is a simple, text-based format that stores pixel color information
as plain text. The code writes the PPM header, followed by the pixel color values, one pixel per line,
in the output file.
For the source code, take a look in Appendix A: 12_circle.cpp
12_circle.ppm
12_squint_with_your_eyes.ppm
12_wedge.ppm
This C++ program generates an image with a radial pattern resembling a wedge or a pie slice. The
image is saved in the PPM format.
The program begins by including necessary headers and defining functions for handling image data,
such as calculating the size of the image, clearing it, and saving it to a file. It also contains functions
to draw lines and wedges, both filled and unfilled, on the image. The main part of the program
initializes the image dimensions and creates an empty white image of the specified size.
7 Circles with Standard Library 26
The program then sets the center, radius, and angles for the wedge to be drawn. The center of the
wedge is set to be the midpoint of the image, and the radius is set to 80% of half of the image height.
The starting and ending angles of the wedge are defined in degrees, with 0 and 348 degrees being
used in this example.
Next, the program draws a filled black wedge with the specified dimensions, followed by a filled gray
wedge with half the radius, creating a “doughnut” shape. Then, it draws an unfilled purple wedge
outline around the larger black wedge. Finally, the image is saved to a file named “12_wedge.ppm”.
For the source code, take a look in Appendix A: 12_wedge.cpp
8 Triangles with Standard Library
A triangle is a closed, 2 dimensional shape with 3 sides, 3 angles, and 3 vertices. A triangle is also a
polygon.
Create an image containing two triangles, one outlined and the other filled, and save it as a PPM
file. The code is divided into several sections, such as defining functions for operations on images,
drawing lines and triangles, and the main program logic.
The program begins by including necessary headers and then defining several utility functions.
The ‘get_index’ function calculates the index of a given pixel in a 1D vector based on its x and
y coordinates and the image width. The ‘calc_size’ function calculates the total number of pixels
in an image given its width and height. The ‘clear_image’ function sets all pixels in an image to a
specified color.
The ‘draw_line’ function uses a modified Bresenham’s line algorithm to draw a line between two
points on an image. The ‘draw_triangle’ and ‘draw_filled_triangle’ functions utilize the ‘draw_-
line’ function to draw the edges of triangles, either outlined or filled, using an incremental scanline
rendering approach.
The ‘save_image’ function takes an image represented as a vector of RGB color tuples, its width
and height, and a filename as arguments, and saves the image as a PPM file.
In the main function, the program first initializes the width and height of the image, as well as the
coordinates of the vertices of the two triangles. It then creates a vector to store the image and sets
its initial color to white using the ‘clear_image’ function. Next, it sets the color to black and calls
the ‘draw_triangle’ function to draw the first triangle and the ‘draw_filled_triangle’ function to
draw the second triangle.
Finally, the program saves the image using the ‘save_image’ function, resulting in a PPM file
containing the two triangles.
For the source code, take a look in Appendix A: 13_triangles.cpp
13_triangles.ppm
fstream, tuple, vector, random, cmath, and algorithm. It defines several utility functions to handle
string processing, coordinate calculations, and image manipulation. The main part of the code
consists of functions to parse input strings, blend colors, find the region of a point, clip lines, draw
filled triangles, and save the generated image to a file.
The ‘parse_bginfo_line()’ and ‘parse_triangle_line()’ functions read lines from the input file
and convert the data into the appropriate data types for further processing. The ‘blend_colors()’
function is used to blend colors using the alpha value, which determines how transparent the color
should be when applied to the image. The ‘find_region()’ and ‘clip_line()’ functions are used to
determine if a point is within the image bounds and to clip any lines that are outside of the image
bounds, respectively.
The ‘draw_filled_triangle()’ function is responsible for rendering triangles onto the image. It uses
a scanline algorithm to fill the triangles with the specified color. This function takes care of edge
cases and ensures that the triangles are drawn correctly within the image boundaries. Finally, the
‘save_image()’ function writes the generated image data to a file in PPM (Portable Pixmap) format.
For the source code, take a look in Appendix A: 13_triangles_from_file.cpp
For the source code, take a look in Appendix A: 13_squint_with_your_eyes.txt
13_squint_with_your_eyes.ppm
Another example.
9 Animation with Standard Library
Below is four example of animation you can do… of course the animation might be more releated
to graphs then images.
You can animate shapes, color transition, opacity and movment.
A C++ program that creates a simple animation using a random walker algorithm. It reads an image
file in PPM format, generates a sequence of images, and saves them in a specified directory. The
user can then use a tool like FFmpeg to convert the image sequence into a video format.
The program begins by defining several helper functions for tasks such as reading and writing
PPM images, updating the positions of the walkers, and blending two images together. The ‘main’
function reads an image from a file, creates a second image buffer, and then initializes the walker
positions to the center of the image. It then iterates over a loop for a large number of steps, moving
the walkers randomly in one of the four cardinal directions and updating the image buffer with the
color from the first image at the new walker positions.
After every 100 steps, the program saves the current state of the image buffer as a new PPM file.
The animation created by this program consists of two walkers moving randomly over the image,
revealing its contents as they traverse it.
For the source code, take a look in Appendix A: 14_animation05.cpp
An animation program that generates a series of images based on input data from a text file. The
text file contains information about the background and rectangles to be drawn on the images.
The program begins by including necessary libraries and defining functions that will be used
later on. Functions include ‘startsWithCaseInsensitive’ for checking if a string starts with a
specific substring, ‘get_index’ and ‘calc_size’ for converting 2D coordinates into 1D indices, and
‘clear_image’ for initializing an image with a specified background color.
The program also contains functions for parsing the input text file, such as ‘parse_bginfo_line’
and ‘parse_rect_line’, which extract relevant information from the input lines. Another important
function is ‘blend_colors’, which combines two colors based on their alpha values. The ‘draw_-
filled_rect’ function is responsible for drawing filled rectangles on the image using the ‘blend_-
colors’ function. The ‘get_filname’ function generates a filename for the output image, and the
‘save_image’ function saves the image to a file.
The ‘main’ function of the program begins by creating an output directory and opening the input
text file. The program then iterates through each line of the text file, checking if the line starts
with ‘r’ for rectangle or ‘b’ for background. If it starts with ‘r’, the program parses the rectangle
information, draws the rectangle on the image, and saves the image. If the line starts with ‘b’, the
program parses the background information, resizes the image, sets the background color, and saves
9 Animation with Standard Library 30
the image. The program prints the filenames of the saved images to the console and closes the input
file at the end.
For the source code, take a look in Appendix A: 14_animation11.cpp
Works the same as 14_animation11.cpp. Uses cricles instead of rectangles.
For the source code, take a look in Appendix A: 14_animation12.cpp
Works the same as 14_animation11.cpp. Uses triangles instead of rectangles.
For the source code, take a look in Appendix A: 14_animation13.cpp
Just experiment and use what you think looks good.
10 Drawing Charts and a Font
The flood-fill algorithm is a popular technique in computer graphics and image processing for filling
an area with a specified color. This algorithm works by starting at a seed pixel and recursively or
iteratively filling neighboring pixels that share the same color as the seed pixel, ultimately replacing
them with a new target color. The process continues until all the connected pixels sharing the
original color are filled with the new color. The flood-fill algorithm has several variations, such as
4-way and 8-way connectivity, which determine how pixels are considered neighbors based on their
relative positions.
Flood-fill algorithms have various applications, particularly in image editing software, computer
games, and pattern recognition tasks. In image editing software, the flood-fill tool, commonly
known as the paint bucket, is used to fill areas with a uniform color or pattern. This tool allows
users to easily modify images by changing the color of specific regions or creating new shapes. In
computer games, the flood-fill algorithm can be employed for tasks like procedural map generation,
pathfinding, or detecting connected components in a game world. In pattern recognition, flood-fill
algorithms can be used to identify and isolate distinct regions or objects within an image based on
their color or texture properties.
Despite its popularity and numerous applications, the flood-fill algorithm does have some limita-
tions. Its performance can be affected by the size of the area to be filled and the complexity of the
image. Recursive implementations of the flood-fill algorithm are prone to stack overflows when
dealing with large areas, while iterative implementations can be memory-intensive. Additionally,
the algorithm may fail to provide the desired output if there are gaps or holes in the boundaries of
the region to be filled. In such cases, modifications to the algorithm, like tolerance-based flood-fill
techniques, can be applied to address these issues and achieve more accurate results.
A program that demonstrates the creation and manipulation of a radar chart, which is a graphical
representation of multivariate data in the form of a two-dimensional chart. This code can be
compiled using the command provided at the beginning of the code.
The program begins by including the required header files and defining a set of functions to
manipulate images, such as calculating the index, clearing the image, drawing shapes, and clipping
lines. Some functions, like ‘get_index’ and ‘calc_size’, are utility functions that help with image
manipulation, while others, like ‘draw_circle’ and ‘draw_filled_circle’, are responsible for drawing
specific shapes on the image.
The ‘floodfill_algorithm’ function is an implementation of the flood-fill algorithm that fills an
enclosed area of an image with a specified color. The ‘get_all_ys’ and ‘draw_line_coords’ functions
are used for drawing polygons on the image. The ‘draw_polygon’ and ‘draw_filled_polygon’
functions use these helper functions to draw and fill polygons, respectively.
10 Drawing Charts and a Font 32
The ‘draw_line’ function takes an image, a set of coordinates, a color, and the width and height of
the image, and draws a line on the image using the given coordinates and color. The ‘find_region’
and ‘clip_line’ functions are used to clip lines based on the width and height of the image, ensuring
that lines do not extend beyond the boundaries of the image.
For the source code, take a look in Appendix A: 15_radarchart.cpp
15_radarchart.ppm
As 15_radarchart.ppm width is 1920 pixels and height is 1080, the size of the PPM is getting a bit big
to write as a textfile. That is why save_image()-function saves the PPM as a P6 with the RGB as 3
byte binary data.
This code is written in C++ and is used to generate a radial chart with three colored segments
representing three different categories of data. The chart consists of 52 wedges, each representing a
week. The data for each category is provided in three arrays ‘a1’, ‘a2’, and ‘a3’. The chart is then
saved as an image in PPM (Portable Pixmap) format.
The program begins by including the necessary header files and defining some utility functions for
working with images, such as ‘get_index’, ‘calc_size’, ‘clear_image’, and others. These functions
are used for creating and manipulating the image data structure, a vector of tuples representing
RGB colors. Functions like ‘draw_filled_circle’, ‘draw_filled_wedge’, and ‘save_image’ are used
to draw and save the final image.
The ‘main’ function starts by initializing the image data structure and setting up color tuples
for the background and three data categories. It calculates the center of the image, the radius,
and other necessary parameters for drawing the radial chart. It then draws a filled circle with a
specific background color and iterates through the 52 wedges, drawing filled wedges for each of
the three categories using the data provided in ‘a1’, ‘a2’, and ‘a3’. The wedges are drawn using
the ‘draw_filled_wedge’ function, which in turn uses the ‘draw_line_coords’ function to create
line coordinates for the wedges. After drawing all the wedges, the image is saved to a file named
“15_weekchart.ppm” using the ‘save_image’ function.
For the source code, take a look in Appendix A: 15_weekchart.cpp
15_weekchart.ppm
10 Drawing Charts and a Font 33
This code generates images of hand-drawn styled letters and numbers. The program defines a set of
functions to draw each character, using the Bresenham’s line algorithm to get the points of the lines
that make up the characters. It also defines functions to draw filled circles, clear the image, and save
the image in the PPM (Portable Pixmap) format.
The main function (draw_and_save_font) iterates through each character, draws it with the specified
color, width, height, margin, and line size, and saves the resulting image to a PPM file.
Each draw_font_ function has two main components:
10 Drawing Charts and a Font 34
• An array of points that define the character’s shape, where the points are represented by their
relative X and Y coordinates.
• An array of line segments that connect these points, where each line segment is represented
by a pair of indices corresponding to the points array.
In each function, the code iterates through the line segments, calculates the coordinates of the actual
points on the image canvas by scaling and translating the relative coordinates, and adds the points
to the points vector.
The draw function takes the points vector and the other parameters, and updates the image by either
drawing a single pixel (when the line size is 1) or drawing a filled circle centered at each point.
Finally, the save_image function writes the image data to a PPM file, using the specified filename.
Here’s a brief explanation of the purpose of each function:
• draw_font_: Draws the specified character by adding its line points to the points vector.
• get_line_points: Uses Bresenham’s line algorithm to get the points of a line segment.
• draw_filled_circle: Draws a filled circle centered at the specified point with the specified
radius.
• clear_image: Resets the image to a white background.
• save_image: Saves the image to a PPM file with the specified filename.
• draw: Updates the image with the specified points, color, line size, etc.
• draw_and_save_font: Main function that iterates through each character, draws it, and saves
the image to a file.
16_draw_bar_chart.ppm
16_draw_pie_chart.ppm
The program starts by including necessary headers and defining functions to perform operations
such as calculating width and margin based on height, calculating the index of a 2D point in a 1D
array, and clearing the image by setting a background color. Functions are also defined for drawing
lines between two points and drawing filled circles.
There are several functions dedicated to drawing individual characters like ‘M’, ‘A’, ‘R’, and ‘S’.
These functions first define an array of points representing the outline of each character and then
another array of lines connecting those points. Using the ‘get_line_points’ function, lines are drawn
between the specified points to create the shape of the characters.
The ‘draw_filled_circle’ function takes in the center coordinates of a circle, its radius, and a color,
and then fills the circle with that color. The ‘draw_filled_circle2’ function is a slightly modified
version of ‘draw_filled_circle’ without the margin parameter.
The ‘get_all_ys’ function collects all the y-coordinates from a set of coordinates, sorts them, and
removes duplicates. The ‘draw_line_coords’ function is a helper function for drawing lines between
two points and storing the resulting coordinates in a vector.
The ‘stamp’ function is used to place one image (letter) onto another image (donut chart) at a
specified offset. The ‘draw_filled_circle_segment’ function draws a filled segment of a circle, given
the start and end angles.
Finally, the ‘main’ function of the program sets up the dimensions and colors for the donut chart
and uses the functions defined earlier to draw the chart and letters. The resulting image is then
saved as a PPM file, which can be opened with an image viewer that supports the format.
16_draw_donut_chart.ppm
The ‘calc_size’ function calculates the size of the image, taking into account the width, height, and
margin. The ‘clear_image’ function initializes the image vector by setting the color of each pixel to
a light brownish color. The ‘stamp’ function stamps the input image (i.e., the letters) onto another
image at a specified position.
The ‘get_line_points’ function calculates the points along a line using Bresenham’s line algorithm,
given the coordinates of the two endpoints and a color. This function is used in the ’draw_font*’_-
functions, where each function (e.g., ‘draw_font_M’, ‘draw_font_A’, etc.) is responsible for
drawing the respective letter using lines. Each of these functions sets up arrays containing the
coordinates of the points and lines that make up the letter, and then calls ‘get_line_points’ to
calculate the points along each line.
The ‘draw_filled_circle’ and ‘draw_filled_rect’ functions draw filled circles and rectangles,
respectively, on the image. The ‘save_image’ function saves the image as a PPM file, given the
image data, its dimensions, and the output filename.
The draw function is used to draw a set of points on the image. The points are drawn as filled
circles with a specified line size. Finally, the ‘main’ function initializes the image, sets the colors
and dimensions for the table, and calls the various drawing functions to create the image. It then
saves the image to a file named “table.ppm”.
16_draw_table.ppm
pixel, a random number is generated using the previously configured random number generator,
and the ‘color’ tuple is set to contain the random number for all three channels (red, green, and
blue). This creates a grayscale color, as all channels have the same value. The ‘color’ tuple is then
assigned to the corresponding position in the ‘image’ vector using the ‘get_index’ function, which
converts 2D coordinates (x, y) into a 1D index suitable for accessing the vector.
By the end of the function, the ‘image’ vector will contain a representation of a noise image with
the specified width and height, where each pixel is a randomly generated grayscale value.
‘blended_two_images’ blends two images together using a specified alpha value. It takes five input
parameters: two vectors of tuples representing the colors of the two images, the width and height
of the images, and a float value called alpha.
First, the function initializes three tuple variables ‘color1’, ‘color2’, and three float variables ‘r’,
‘g’, and ‘b’. The tuples represent colors from the first and second images, while the float variables
represent the blended color components - red, green, and blue.
The function then uses two nested loops to iterate over the width and height of the images. The
outer loop iterates over the height of the images, and the inner loop iterates over the width. Inside
the inner loop, the function extracts the colors at the current position ‘(x, y)’ from both images using
the ‘get_index’ function, which computes the index in the vector based on the x, y coordinates and
the width.
Next, the function calculates the blended color components (red, green, and blue) using the alpha
value. The blending operation is performed by multiplying each color component of the second
image by the alpha value and adding the product of the color component from the first image and
(1.0 - alpha). This is done for all three color components - red, green, and blue.
After calculating the blended color components, the function stores the blended color as a tuple in
the first vector at the same position ‘(x, y)’. This overwrites the original color in the first image with
the blended color. Once the loops have finished, the first vector will contain the resulting blended
image.
The function starts with two nested loops to iterate over the width and height of the image. Inside
the inner loop, the function sets the initial values of the ‘mask’ and ‘image’ vectors at the current
position ‘(x, y)’ to the predefined ‘pink’ color and the ‘from-color’, respectively.
The function then initializes several variables for drawing a circle using Bresenham’s circle
algorithm. It declares a lambda function ‘drawline’ that is used to draw horizontal lines at the
specified positions. It loops over the circle, drawing lines for each quadrant, and updates the mask
vector accordingly.
After completing the circle drawing, the function starts another pair of nested loops to iterate over
the width and height of the image once more. Inside the inner loop, the function checks if the current
position ‘(x, y)’ in the ‘mask’ vector is not equal to the predefined ‘pink’ color. If this condition
is true, it calculates the distance from the center of the image and computes the resulting color
components based on the distance and the input ‘from-color’ and ‘to-color’. The function then
assigns the computed color to the ‘image’ vector at the current position ‘(x, y)’.
If the condition is false, meaning that the ‘mask’ vector has the ‘pink’ color at the current position
‘(x, y)’, the function assigns the ‘to-color’ to the ‘image’ vector at the current position. This way,
the final image vector will contain a radial gradient image generated using the input colors.
‘height’. This process repeats for each line segment, resulting in a repeating texture pattern drawn
on the image vector.
In summary, the ‘generate_repeating_texture_image’ function creates a repeating texture image
by drawing a series of line segments on an image vector using a predefined background color and
an input color for the texture pattern. The function achieves this by iterating through a series of
coordinates and line segment indices, drawing the texture pattern on the image vector using the
‘draw_line’ function.
‘do_cookie_cut’ extracts a rectangular region, referred to as a “cookie,” from a larger image. The
function takes eight input parameters: a vector of tuples representing the colors of the input image,
the width and height of the input image (w and h), a vector of tuples representing the colors of the
output “cookie” image, the width and height of the “cookie” image (cw and ch), and the starting x
and y coordinates (startx and starty) of the region to extract from the input image.
The function initializes two variables, ‘cx’ and ‘cy’, which will be used to store the x and y
coordinates of the “cookie” image as it is being constructed. It then uses two nested loops to iterate
over the rectangular region defined by the starting coordinates (startx and starty) and the width and
height of the “cookie” image (cw and ch).
Inside the inner loop, the function retrieves the color from the input image at the current position
‘(x, y)’ using the ‘get_index’ function, which computes the index in the vector based on the x, y
coordinates and the input image width (w). The retrieved color is then assigned to the “cookie”
image vector at the position (cx, cy) using the get_index function with the “cookie” image width
(cw).
After each iteration of the inner loop, the function increments the x-coordinate of the “cookie” image
(cx) by 1. After each iteration of the outer loop, the function increments the y-coordinate of the
“cookie” image (cy) by 1 and resets the x-coordinate (cx) back to 0.
‘add_honeycomb’ overlays a texture image onto an input image using an alpha channel image to
control the blending. The function takes four input parameters: a vector of tuples representing the
colors of the input image, a vector of tuples representing the colors of the alpha channel image, a
vector of tuples representing the colors of the texture image, and the width and height of the images
11 Presentation, Collaboration, and Investigation 45
(w and h). The width and height are assumed to be the same for all three images.
First, the function initializes three color tuple variables (color1, color2, and color3) and a pink color
tuple, which will be used later to determine if a pixel should be affected by the texture overlay.
The function then iterates over the width and height of the input image using two nested loops.
Inside the inner loop, the function checks if the current pixel in the texture image is not equal to the
pink color. If it is not pink, the pixel will be affected by the texture overlay.
Next, the function retrieves the colors from the input image, texture image, and alpha channel image
at the current position ‘(x, y)’ using the ‘get_index’ function. The retrieved colors are assigned to
the corresponding color tuple variables (color1, color2, and color3).
The function then calculates the blended color by multiplying the texture color (color2) with the
alpha value (color3) and adding the input image color (color1) multiplied by the inverse of the alpha
value (1.0f - color3). This process is done separately for the red, green, and blue channels, resulting
in the final blended color components (ir, ig, and ib).
Finally, the blended color is assigned to the input image vector at the current position ‘(x, y)’ using
the ‘get_index’ function. This process updates the input image with the texture overlay, effectively
modifying the input image in-place.
‘stamp_cookie’ pastes a smaller image, referred to as a “cookie,” onto a larger image at a specified
position. The function takes eight input parameters: a vector of tuples representing the colors of
the input image, the width and height of the input image (w and h), a vector of tuples representing
the colors of the “cookie” image, the width and height of the “cookie” image (cw and ch), and the
starting x and y coordinates (startx and starty) of the position where the “cookie” image should be
pasted onto the input image.
The function initializes two variables, ‘cx’ and ‘cy’, which will be used to store the x and y
coordinates of the “cookie” image as it is being pasted onto the input image. It then uses two nested
loops to iterate over the rectangular region defined by the starting coordinates (startx and starty)
and the width and height of the “cookie” image (cw and ch).
Inside the inner loop, the function retrieves the color from the “cookie” image at the current position
‘(cx, cy)’ using the ‘get_index’ function, which computes the index in the vector based on the x,
y coordinates and the “cookie” image width (cw). The retrieved color is then assigned to the input
11 Presentation, Collaboration, and Investigation 46
image vector at the position ‘(x, y)’ using the ‘get_index’ function with the input image width (w).
After each iteration of the inner loop, the function increments the x-coordinate of the “cookie” image
(cx) by 1. After each iteration of the outer loop, the function increments the y-coordinate of the
“cookie” image (cy) by 1 and resets the x-coordinate (cx) back to 0.
The ‘draw_hexagon’ function is designed to draw a hexagon with a specified color onto an image.
The function takes eight parameters: a vector of tuples representing the colors of the input image, a
tuple representing the color of the hexagon, the x and y coordinates of the hexagon’s center (centerx
and centery), the hexagon’s radius, the width and height of the input image, and the “circle radius”
(cradius) used for drawing the lines that make up the hexagon.
First, the function initializes some variables used for calculating the hexagon’s vertices. It computes
the upper-left corner of a bounding box around the hexagon, given by ‘(ux, uy)’. It also initializes
six points (pt1x, pt1y) to (pt6x, pt6y), all initially set to ‘(ux, uy)’.
Next, the function calculates some auxiliary variables (A, B, C) using trigonometric formulas
involving the given hexagon radius and a constant PI value. The purpose of these calculations
is to help determine the coordinates of the hexagon’s vertices.
Using the auxiliary variables, the function computes the coordinates of each vertex of the hexagon
(pt1 to pt6). Each vertex’s x and y coordinates are updated based on the initial ‘(ux, uy)’ position
and the auxiliary variables.
The function then creates a vector of tuples called ‘points’ that will be used to store the points along
the lines that form the hexagon. For each pair of adjacent vertices, the function generates the line
points between them using the ‘get_line_points’ function and stores the result in the ‘points’ vector.
Then, the ‘draw’ function is called to draw the line using the points, the input image, the specified
color, the image dimensions, and the “circle radius” (cradius). After drawing each line, the function
clears the ‘points’ vector to prepare it for the next line.
The ‘flood_fill’ function is a simple recursive algorithm used to replace a specific color in an image
with another color within a connected region. It takes six parameters: a vector of tuples representing
the colors of the input image, the x and y coordinates of the starting point, tuples representing the
old and new colors, and the width of the input image.
The function begins by checking if the color at the current coordinates (x, y) in the image is equal
to the old color specified. If the colors match, it replaces the old color at that position with the new
color. Then, the function recursively calls itself to perform the flood fill operation in four directions:
right (x+1, y), down (x, y+1), left (x-1, y), and up (x, y-1).
11 Presentation, Collaboration, and Investigation 47
This process continues until the function reaches pixels with a color different from the old color,
effectively filling the connected region of pixels with the new color.
An image is being created with various hexagons drawn on it. The code starts by declaring a vector
of tuples called ‘image8’, which will represent the colors in the image. The ‘image8’ vector is
resized to fit the dimensions of the image, which are calculated using the ‘calc_size(width, height)’
function.
Next, the ‘fcolor’ tuple is created using the ‘std::make_tuple’ function with RGB values (1.0f, 1.0f,
1.0f), representing the color white. The ‘draw_hexagon’ function is then called four times with
different parameters, each time drawing a hexagon on ‘image8’ with the specified color, center
coordinates, radius, image width, image height, and circle radius used for drawing the hexagon
lines.
The first hexagon is drawn with its center at (784, 340) and a radius of 190. The second hexagon is
drawn with its center at (520, 500) and a radius of 143. The third hexagon is drawn with its center
at (730, 610) and a radius of 107. Finally, the fourth hexagon is drawn with its center at (900, 680)
and a radius of 76.
The ‘blend_hexagon’ function is designed to blend two images, represented by the vectors ‘blend1’
and ‘blend2’, based on a specific color condition. The function takes in four parameters: the two
image vectors ‘blend1’ and ‘blend2’, and the dimensions of the images, ‘width’ and ‘height’.
First, the function initializes two color tuples, ‘color1’ and ‘color2’. ‘color1’ is initialized to (0.0f,
0.0f, 0.0f), which represents black, while ‘color2’ is initialized to (1.0f, 1.0f, 1.0f), which represents
white. The function also initializes three float variables, ‘r’, ‘g’, and ‘b’, and an ‘alpha’ variable with
a value of 0.8f. The ‘alpha’ value will be used to blend the colors from the two images.
The function then iterates through all the pixels in the images using nested for-loops. For each pixel,
it checks if the color of the corresponding pixel in ‘blend2’ is equal to ‘color2’, which is white. If
the condition is met, it retrieves the color of the corresponding pixel in ‘blend1’ and blends it with
black (0.0f, 0.0f, 0.0f), using the ‘alpha’ value to determine the degree of blending.
After blending the colors, the result is stored back in the ‘blend1’ image at the corresponding pixel
11 Presentation, Collaboration, and Investigation 48
position. The blending is performed by multiplying each color component (red, green, and blue) of
the color from ‘blend1’ by the ‘alpha’ value, then adding the product of the black color component
and (1.0f - ‘alpha’). The new color tuple is created using the ‘std::make_tuple’ function and is
assigned to the corresponding pixel in the ‘blend1’ image.
The ‘draw_label_lines’ function is designed to draw multiple lines on an image with a specific color
and thickness. The function accepts five parameters: a reference to the image vector, a reference
to the color tuple, the width and height of the image, and the thickness of the lines represented as
radius.
First, the function initializes a ‘coords’ tuple, which will store the coordinates of the starting and
ending points of the lines to be drawn. It also initializes a ‘points’ vector, which will store the points
on the line.
This code defines a function called ‘draw_labels’ that takes three arguments: a reference to a vector
11 Presentation, Collaboration, and Investigation 49
of tuples called ‘image’, a reference to a tuple called ‘color’, and two integers called ‘width’ and
‘height’. The function is designed to draw labels on an image using a specified color.
The image is represented by a vector of tuples, where each tuple contains three floating-point values
representing the red, green, and blue channels of a pixel. The ‘color’ tuple also contains three
floating-point values that represent the red, green, and blue channels of the desired color for the
labels.
The ‘draw_labels’ function begins by defining a hard-coded label called ‘lable_10’, which is a
series of 0s and 1s that represent the pixel values of an image. This label was created in a graphics
application and converted to a binary format to be used in this function. The 0s represent transparent
pixels, while the 1s represent the color specified by the ‘color’ argument.
The purpose of the function is to draw this ‘lable_10’ on the ‘image’ using the specified ‘color’,
‘width’, and ‘height’. However, the provided code only defines the ‘lable_10’ data and does not
include the necessary steps to draw the label on the image. The actual drawing process would
involve iterating through the lable_10 data, and for each 1 encountered, setting the corresponding
pixel in the ‘image’ vector to the specified ‘color’.
This C++ code generates a linear gradient image. It consists of two main parts: the declaration and
initialization of variables, and the definition of the ‘generate_linear_gradient_image’ function.
In the first part of the code, a vector of tuples called ‘image2’ is created to store the linear gradient
image data. Each tuple holds three float values representing the red, green, and blue channels of
a pixel. The width and height of the image are assumed to be already defined with values of 1600
and 900 pixels, respectively. The ‘image2’ vector is resized to the appropriate size using the ‘calc_-
size(width, height)’ function. The code then defines two tuples, ‘fcolor’ and ‘tcolor’, representing
the starting and ending colors of the gradient, and calls the ‘generate_linear_gradient_image’
function.
The ‘generate_linear_gradient_image’ function is defined to create the linear gradient image. It
takes a reference to a vector of tuples (‘image’), references to the starting and ending colors (‘fcolor’
and ‘tcolor’), and the width and height of the image as its parameters. The function calculates the
color of each pixel in the image by interpolating between the starting and ending colors based on
11 Presentation, Collaboration, and Investigation 51
‘blended_two_images’ takes two input images and blends them together based on a specified alpha
value. The images are passed as vectors of tuples (float, float, float), representing the red, green, and
blue (RGB) color values of each pixel. The function also takes the width and height of the images
and an alpha value, which is a float between 0 and 1.
The function starts by initializing three tuples named ‘color1’, ‘color2’, and three float variables ‘r’,
‘g’, and ‘b’ that will be used to store the RGB values of each pixel in the two images and the resultant
blended image. Two nested for loops are then used to iterate through each pixel in the input images.
The outer loop iterates through the rows (height), while the inner loop iterates through the columns
(width).
For each pixel, the corresponding color values are retrieved from the input images using the ‘get_-
index’ function and stored in ‘color1’ and ‘color2’. The red, green, and blue values of the blended
image are calculated by multiplying the corresponding color values from the second image by the
alpha value, and the color values from the first image by (1 - alpha), then summing them. These
blended RGB values are then stored in the first image vector using the ‘get_index’ function again.
Once the loops have finished iterating through all the pixels, the function has effectively modified
the first input image vector to store the blended image, while the second input image vector remains
unchanged.
11 Presentation, Collaboration, and Investigation 52
‘generate_radial_gradient_image’ creates a radial gradient image with a specified size and two
colors. The radial gradient image is stored as a vector of tuples (float, float, float), representing the
red, green, and blue (RGB) color values of each pixel.
The function takes the following parameters: a reference to the image vector, references to two color
tuples (fcolor and tcolor), and the width and height of the image. The function starts by initializing
some variables: ‘color’ (a tuple to store the current pixel’s color), ‘pink’ (a pre-defined color tuple),
‘mask’ (a vector to store a circular mask), ‘distanceFromCenter’, ‘resultRed’, ‘resultGreen’, and
‘resultBlue’.
The first nested for loops fill the ‘mask’ and ‘image’ vectors with the ‘pink’ color and ‘fcolor’
respectively. Then, the function calculates the midpoint of the image (x0, y0) and initializes variables
‘d’, ‘xx’, and ‘yy’ to draw a circle using Bresenham’s circle algorithm.
A lambda function ‘drawline’ is defined within the function to draw horizontal lines between two
points (sx, ex) at the given y-coordinate (ny) in the ‘mask’ vector. The while loop uses Bresenham’s
circle algorithm to create a circular mask by drawing lines in the ‘mask’ vector using the ‘drawline’
function.
Finally, another set of nested for loops iterates through each pixel in the image. For each pixel, it
checks if the corresponding mask pixel is not equal to the ‘pink’ color. If so, it calculates the distance
from the center of the image to the current pixel and computes the interpolated color values based on
the distance and input colors (fcolor and tcolor). The resulting color tuple is assigned to the ‘image’
vector at the current position. If the mask pixel is equal to the ‘pink’ color, the ‘tcolor’ is assigned
directly to the ‘image’ vector.
The function takes the following parameters: a reference to the image vector, a reference to the
color tuple, and the width and height of the image. It begins by initializing a background color tuple
named ‘bgcolor’ to be a pinkish color. Then, using two nested for loops, it fills the ‘image’ vector
with this background color.
The function proceeds to define two integer arrays ‘arr’ and ‘arr2’ with hardcoded coordinates and
indices, representing the positions and connections of points in the pattern. The ‘coords’ tuple is
initialized to store the coordinates of the line endpoints in the pattern.
Next, the function iterates through the 13 hardcoded points using a for loop. During each iteration,
it creates a ‘coords’ tuple using the coordinates from the ‘arr’ array based on the indices found in
the ‘arr2’ array. The ‘draw_line’ function is then called with the ‘image’ vector, ‘coords’ tuple,
input color, width, and height as parameters. This function draws lines between the coordinates
specified by the ‘coords’ tuple in the image vector using the input color.
‘do_cookie_cut’ extracts a rectangular section from a source image and stores it in another image,
often referred to as ‘cookie-cutting’. Both the source image and the resulting image are stored as
vectors of tuples (float, float, float), representing the red, green, and blue (RGB) color values of each
pixel.
The function takes the following parameters: a reference to the source image vector, the width and
height of the source image (w, h), a reference to the resulting image vector, the width and height of
the resulting image (cw, ch), and the starting x and y coordinates (startx, starty) of the rectangular
section to be extracted from the source image. It initializes two variables, cx and cy, to keep track
of the current x and y coordinates in the resulting image.
The function uses two nested for loops to iterate through the rectangular section of the source image,
starting from the specified starting coordinates (startx, starty) and covering the width and height
of the resulting image (cw, ch). For each pixel in the section, it copies the color value from the
source image to the corresponding position in the resulting image, using the ‘get_index’ function
to convert the 2D coordinates to a linear index. The cx and cy variables are updated accordingly to
move through the resulting image.
‘add_honeycomb’ combines three images: a base image, an alpha image, and a texture image. The
base image and the texture image are combined using the red channel of the alpha image as a weight.
All three images are stored as vectors of tuples (float, float, float), representing the red, green, and
blue (RGB) color values of each pixel.
The function takes the following parameters: references to the base image vector, alpha image vector,
texture image vector, and the width and height of the images (w, h). It initializes several tuple
11 Presentation, Collaboration, and Investigation 55
variables to store the color values of the three images at each pixel and a pink color tuple (1.0f, 0.0f,
1.0f) to check against the texture image.
Using two nested for loops, the function iterates through each pixel of the images. If the color value
of the texture image at the current pixel is not pink, the function retrieves the color values of the
base, texture, and alpha images at the current pixel. It then calculates the new red, green, and blue
color values for the base image by interpolating between the texture and base images’ color values
using the red channel of the alpha image as a weight. The resulting color value is assigned back to
the base image at the current pixel.
‘stamp_cookie’ places a smaller ‘cookie’ image onto a larger base image at a specified position. The
base image and the cookie image are stored as vectors of tuples (float, float, float), representing the
red, green, and blue (RGB) color values of each pixel.
The function takes the following parameters: references to the base image vector, its width and
height (w, h), the cookie image vector, its width and height (cw, ch), and the starting x and y
coordinates (startx, starty) for placing the cookie image onto the base image.
The function initializes two integer variables, cx and cy, to keep track of the current position within
the cookie image. It then uses two nested for loops to iterate through each pixel of the area where
the cookie image will be placed on the base image.
For each pixel in the specified area, the function retrieves the color value from the cookie image at the
current cx and cy coordinates and assigns it to the base image at the current x and y coordinates. The
cx variable is incremented for each iteration of the inner loop, while the cy variable is incremented
for each iteration of the outer loop. After the inner loop is completed, the cx variable is reset to 0 to
start processing the next row of the cookie image.
The code creates an image of a doughnut shape with various shades of gray and white, as well as
11 Presentation, Collaboration, and Investigation 56
some additional labels. The doughnut consists of a series of filled wedges and lines drawn on a base
image.
The base image, ‘image7’, is initialized as a vector of tuples (float, float, float), representing the red,
green, and blue (RGB) color values of each pixel. The base image is then resized to the desired width
and height.
The image is first cleared to a solid color (magenta) using the ‘clear_image’ function. Next, the
doughnut shape is constructed by drawing filled wedges and lines with different shades of gray and
white. The ‘draw_filled_wedge’ function is used to draw the filled wedges, while the ‘draw_line’
function is used to draw the lines. Each of these functions takes the image, coordinates, and color
information as input.
Finally, the ‘draw_labels’ function is called to add labels to the image. This function takes the image,
color (white), width, and height as input.
The code adds the previously created doughnut shape to the ‘image1’ by copying the non-magenta
pixels from ‘image7’ to ‘image1’. The magenta color (1.0f, 0.0f, 1.0f) is used as a background color
in ‘image7’ and is not copied to ‘image1’.
The code first defines the magenta color as ‘fcolor’, which will be used to identify the background
pixels that should not be copied.
Then, two nested loops iterate over the height and width of the images. For each pixel coordinate (x,
y), the code checks if the pixel in ‘image7’ is not magenta (i.e., not equal to ‘fcolor’). If the condition
is true, the non-magenta pixel from ‘image7’ is copied to the corresponding position in ‘image1’.
In summary, the code adds the doughnut shape from ‘image7’ to ‘image1’ by copying only the
non-magenta pixels from ‘image7’ to their corresponding positions in ‘image1’.
11.8 Collaboration
We can use 2D charts and diagrams to help us understand and solve problems collaboratively. For
example, we can use a chart to visualize the relationships between different elements in a problem
or a diagram to explore the potential solutions to a problem.
2D charts and diagrams are also helpful for communicating our ideas to others. We can use them
to explain our thinking process or present our findings clearly and concisely.
When working with 2D graphs and diagrams, it is vital to know the different types of data they
can represent. For instance, some charts are better suited for displaying quantitative data, while
others are more effective for visualizing qualitative data. Additionally, we must be careful when
interpreting data from 2D graphs and diagrams, as they can sometimes be misleading.
Despite these limitations, 2D graphs and diagrams are powerful tools that can help us think more
creatively and solve problems more effectively. With a bit of practice, we can learn to use them in
various ways to improve our collaborative problem-solving skills.
Peacock chart in PPM, take a look in Appendix A: 17_colab_peacock.cpp
peacock graph
11.9 Investigation
There is a reason that businesses, law enforcement agencies, military intelligence use data visualiza-
tion when investigating crimes or irregularities - it works. By taking large data sets and representing
them in an easily digestible format, investigators can quickly identify patterns and relationships
that would otherwise be difficult to spot. The right data can help investigators piece together what
happened and who was involved.
Also for a security incident a simple graph can give you some important information as when
something happend and the amout of actvity. Also what kind of activity in the log.
Investigating log
12 PPM++ header-only library
Hello everyone,
I am pleased to announce the release of my c++ header-only library for 2D graphics. This library is
designed to make it easy to create beautiful and performant 2D graphics applications using c++17.
It is available on Github under the MIT license. I would love to hear your feedback!
You’ll find the header-only library here: https://gist.github.com/chbtoys/cdd6a85e321593ea0a1e7141d0a09fbc
… and a test.cpp here: https://gist.github.com/chbtoys/a665b52f86768b8e601c82b47ce18e49
Or clone from Github.com.
1 https://imagemagick.org/index.php
2 https://ffmpeg.org/
14 Appendix A: Source Code Listings
01_tuples.cpp - 1521 bytes.
33 y=7;x=2;
34 std::cout << "Index: " << get_index(x,y,width) << " (for X:" << x << " Y:" << y << \
35 ")" << std::endl;
36 y=9;x=8;
37 std::cout << "Index: " << get_index(x,y,width) << " (for X:" << x << " Y:" << y << \
38 ")" << std::endl << std::endl;
39
40 std::cout << " 0123456789" << std::endl;
41 std::cout << "0+---------- I: 0" << std::endl;
42 std::cout << "1-----+----- I: 15" << std::endl;
43 std::cout << "2---+------- I: 23" << std::endl;
44 std::cout << "3--+-------- I: 32" << std::endl;
45 std::cout << "4---+------- I: 43" << std::endl;
46 std::cout << "5----------- N/A" << std::endl;
47 std::cout << "6------+---- I: 66" << std::endl;
48 std::cout << "7--+-------- I: 72" << std::endl;
49 std::cout << "8----------- N/A" << std::endl;
50 std::cout << "9--------+-- I: 98" << std::endl;
51
52 return 0;
53 }
62 {
63 std::vector<std::tuple<float, float, float>> image;
64 std::tuple<float, float, float> color=std::make_tuple(0.0f,0.0f,0.06666666667f);
65 int width=640;
66 int height=360;
67
68 image.resize(calc_size(width, height));
69 std::cout << "Created a vector with the size: " << calc_size(width, height) << std:\
70 :endl;
71 clear_image(image,color,width,height);
72 std::cout << "Cleared image with dark blue color." << std::endl;
73 first_draw(image,width,height);
74 std::cout << "Drawing the first image pixel by pixel" << std::endl;
75 save_image(image,width,height,"04_helloworld.ppm");
76 std::cout << "Saved: 04_helloworld.ppm" << std::endl;
77
78 // Create square (for 08; blending colors).
79 std::vector<std::tuple<float, float, float>> square;
80 width=256;height=256;
81 square.resize(calc_size(width, height));
82 first_draw(square,width,height);
83 save_image(square,width,height,"04_helloworld_square.ppm");
84
85 return 0;
86 }
16 if(mainStr.find(toMatch) == 0)
17 return true;
18 else
19 return false;
20 }
21
22 int get_index(int x, int y, int width)
23 {
24 return x+width*y;
25 }
26
27 int calc_size(int width, int height)
28 {
29 return width*height;
30 }
31
32 void clear_image(std::vector<std::tuple<float, float, float>> &image, std::tuple<flo\
33 at, float, float> &color, int width, int height)
34 {
35 for (int y=0;y<height;++y) {
36 for (int x=0;x<width;++x) {
37 image[get_index(x,y,width)]=color;
38 }
39 }
40 }
41
42 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
43 height, std::string filename)
44 {
45 std::tuple<float, float, float> color;
46 std::ofstream out(filename, std::ofstream::out);
47 out << "P3\n" << width << " " << height << "\n255\n";
48 for (int i=0;i<(width*height);++i)
49 {
50 color=image[i];
51 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
52 " " << int(std::get<2>(color)*255.0f) << '\n';
53 }
54 out.close();
55 }
56
57 std::tuple<int,int> get_width_and_height(const std::string str)
58 {
14 Appendix A: Source Code Listings 67
59 size_t start;
60 size_t end = 0;
61 std::vector<std::string> out;
62
63 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
64 {
65 end = str.find(' ', start);
66 out.push_back(str.substr(start, end - start));
67 }
68
69 int w=stoi(out[0]);
70 int h=stoi(out[1]);
71
72 return std::make_tuple(w,h);
73 }
74
75 std::tuple<int,int,int> get_color(const std::string str)
76 {
77 size_t start;
78 size_t end = 0;
79 std::vector<std::string> out;
80
81 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
82 {
83 end = str.find(' ', start);
84 out.push_back(str.substr(start, end - start));
85 }
86
87 int r=stoi(out[0]);
88 int g=stoi(out[1]);
89 int b=stoi(out[2]);
90
91 return std::make_tuple(r,g,b);
92 }
93
94 void read_image(std::vector<std::tuple<float, float, float>> &image, int &width, int\
95 &height, std::string filename)
96 {
97 std::ifstream infile(filename);
98 std::tuple<int, int, int> rcolor;
99 std::tuple<float, float, float> wcolor;
100 std::tuple<int,int> widthnheight;
101 std::string line;
14 Appendix A: Source Code Listings 68
145 break;
146 case 1:
147 x1-=1;
148 x2+=1;
149 break;
150 case 2:
151 y1+=1;
152 y2-=1;
153 break;
154 case 3:
155 y1-=1;
156 y2+=1;
157 break;
158 }
159
160 if (x1 < 0) {
161 x1 = 0;
162 } else if (x1 > width-1) {
163 x1=width-1;
164 }
165
166 if (x2 < 0) {
167 x2 = 0;
168 } else if (x2 > width-1) {
169 x2=width-1;
170 }
171
172 if (y1 < 0) {
173 y1 = 0;
174 } else if (y1 > height-1) {
175 y1 = height-1;
176 }
177
178 if (y2 < 0) {
179 y2 = 0;
180 } else if (y2 > height-1) {
181 y2 = height-1;
182 }
183
184 walk1=std::make_tuple(x1,y1);
185 walk2=std::make_tuple(x2,y2);
186 }
187
14 Appendix A: Source Code Listings 70
77 {
78 std::tuple<float, float, float> color;
79 int c=0;
80
81 for (int y=0;y<height;++y)
82 {
83 for (int x=0;x<width;++x) {
84 c = x | y;// OR
85 color=std::make_tuple(float(c/255.0f), float(c/255.0f), float(c/255.0f));
86 image[get_index(x, y, width)]=color;
87 }
88 }
89 }
90
91 int main()
92 {
93 std::vector<std::tuple<float, float, float>> image;
94 std::tuple<float, float, float> color=std::make_tuple(0.0f,0.0f,0.06666666667f);
95 int width=256;
96 int height=256;
97
98 image.resize(calc_size(width, height));
99 std::cout << "Created a vector with the size: " << calc_size(width, height) << std:\
100 :endl;
101 clear_image(image,color,width,height);
102 std::cout << "Cleared image with dark blue color." << std::endl;
103 // XOR Texture
104 draw_xor(image,width,height);
105 std::cout << "XOR Texture drawn." << std::endl;
106 save_image(image,width,height,"06_xor_texture.ppm");
107 std::cout << "Saved: 06_xor_texture.ppm" << std::endl;
108 // AND Texture
109 draw_and(image,width,height);
110 std::cout << "AND Texture drawn." << std::endl;
111 save_image(image,width,height,"06_and_texture.ppm");
112 std::cout << "Saved: 06_and_texture.ppm" << std::endl;
113 // OR Texture
114 draw_or(image,width,height);
115 std::cout << "OR Texture drawn." << std::endl;
116 save_image(image,width,height,"06_or_texture.ppm");
117 std::cout << "Saved: 06_or_texture.ppm" << std::endl;
118
119 return 0;
14 Appendix A: Source Code Listings 74
120 }
40 color=image[i];
41 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
42 " " << int(std::get<2>(color)*255.0f) << '\n';
43 }
44 out.close();
45 }
46
47 void generate_noise(std::vector<double> &noise, int width, int height)
48 {
49 std::random_device rd;
50 std::mt19937 mt(rd());
51 std::uniform_real_distribution<> dist(0.0, 1.0);
52
53 for (int y=0;y<height;++y) {
54 for (int x=0;x<width;++x) {
55 noise[get_index(x,y,width)]=dist(mt);
56 }
57 }
58 }
59
60 double smooth_noise(double x, double y, int width, int height, std::vector<double> &\
61 noise)
62 {
63 // Get fractional part of X and Y.
64 double fractionX = x - int(x);
65 double fractionY = y - int(y);
66
67 // Wrap around.
68 int x1 = (int(x) + width) % width;
69 int y1 = (int(y) + height) % height;
70
71 // Neighbor values.
72 int x2 = (x1 + width - 1) % width;
73 int y2 = (y1 + height - 1) % height;
74
75 // Smoth the noise with bilinear interpolation.
76 double value=0.0;
77 value += fractionX * fractionY * noise[get_index(x1,y1,width)];
78 value += (1 - fractionX) * fractionY * noise[get_index(x2,y1,width)];
79 value += fractionX * (1 - fractionY) * noise[get_index(x1,y2,width)];
80 value += (1 - fractionX) * (1 - fractionY) * noise[get_index(x2,y2,width)];
81
82 return value;
14 Appendix A: Source Code Listings 76
83 }
84
85 double turbulence(double x, double y, int width, int height, double size, std::vecto\
86 r<double> &noise)
87 {
88 double value = 0.0;
89 double initialSize = size;
90
91 while (size >= 1)
92 {
93 value += smooth_noise(x/size,y/size,width,height,noise) * size;
94 size /= 2.0;
95 }
96
97 return (128.0 * value / initialSize);
98 }
99
100 void generate_cloud(std::vector<std::tuple<float, float, float>> &image, int width, \
101 int height, std::vector<double> &noise)
102 {
103 std::tuple<float, float, float> color;
104 int c=0;
105
106 for (int y=0;y<height;++y)
107 {
108 for (int x=0;x<width;++x) {
109 c=int(turbulence(double(x),double(y),width,height,64,noise));
110 color=std::make_tuple(float(c/255.0f), float(c/255.0f), float(c/255.0f));
111 image[get_index(x, y, width)]=color;
112 }
113 }
114 }
115
116 void generate_marble(std::vector<std::tuple<float, float, float>> &image, int width,\
117 int height, std::vector<double> &noise)
118 {
119 std::tuple<float, float, float> color;
120
121 // xPeriod and yPeriod together define the angle of the lines.
122 // xPeriod and yPeriod both 0 ==> it becomes a normal clouds or turbulence pattern.
123 double xPeriod = 5.0; // Defines repetition of marble lines in x direction.
124 double yPeriod = 10.0; // Defines repetition of marble lines in y direction.
125 // turbulencePower = 0 ==> it becomes a normal sine pattern.
14 Appendix A: Source Code Listings 77
43 int w=stoi(out[0]);
44 int h=stoi(out[1]);
45
46 return std::make_tuple(w,h);
47 }
48
49 std::tuple<int,int,int> get_color(const std::string str)
50 {
51 size_t start;
52 size_t end = 0;
53 std::vector<std::string> out;
54
55 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
56 {
57 end = str.find(' ', start);
58 out.push_back(str.substr(start, end - start));
59 }
60
61 int r=stoi(out[0]);
62 int g=stoi(out[1]);
63 int b=stoi(out[2]);
64
65 return std::make_tuple(r,g,b);
66 }
67
68 void read_image(std::vector<std::tuple<float, float, float>> &image, int &width, int\
69 &height, std::string filename)
70 {
71 std::ifstream infile(filename);
72 std::tuple<int, int, int> rcolor;
73 std::tuple<float, float, float> wcolor;
74 std::tuple<int,int> widthnheight;
75 std::string line;
76 int state=0;
77 bool done = false;
78
79 while (getline(infile, line))
80 {
81 if (startsWithCaseInsensitive(line,"P3") && state == 0) {
82 state=1;
83 }
84
85 if (!startsWithCaseInsensitive(line,"#") && !startsWithCaseInsensitive(line,"P3") \
14 Appendix A: Source Code Listings 81
86 && state == 1) {
87 widthnheight=get_width_and_height(line);
88 width=std::get<0>(widthnheight);
89 height=std::get<1>(widthnheight);
90 state=2;
91 }
92
93 if (startsWithCaseInsensitive(line,"255") && state == 2) {
94 state=3;
95 }
96
97 if (!(line.compare("255") == 0) && state == 3) {
98 rcolor=get_color(line);
99 wcolor=std::make_tuple(float(std::get<0>(rcolor)/255.0f), float(std::get<1>(
100 r)/255.0f), float(std::get<2>(rcolor)/255.0f));
101 image.push_back(wcolor);
102 done = true;
103 }
104 }
105 infile.close();
106 }
107
108 void negative_image(std::vector<std::tuple<float, float, float>> &image, int width, \
109 int height)
110 {
111 std::tuple<float, float, float> oldColor=std::make_tuple(0.0f,0.0f,0.0f);
112 for (int y=0;y<height;++y) {
113 for (int x=0;x<width;++x) {
114 oldColor=image[get_index(x,y,width)];
115 image[get_index(x,y,width)]=std::make_tuple(1.0f-std::get<0>(oldColor), 1.0f
116 :get<1>(oldColor), 1.0f-std::get<2>(oldColor));
117 }
118 }
119 }
120
121 void double_as_dark(std::vector<std::tuple<float, float, float>> &image, int width, \
122 int height)
123 {
124 std::tuple<float, float, float> oldColor=std::make_tuple(0.0f,0.0f,0.0f);
125 for (int y=0;y<height;++y) {
126 for (int x=0;x<width;++x) {
127 oldColor=image[get_index(x,y,width)];
128 image[get_index(x,y,width)]=std::make_tuple(std::get<0>(oldColor) / 2.0f, st
14 Appendix A: Source Code Listings 82
258 ), std::get<2>(color));
259 }
260 }
261 }
262
263 void bgr_image(std::vector<std::tuple<float, float, float>> &image, int width, int h\
264 eight)
265 {
266 std::tuple<float, float, float> color=std::make_tuple(0.0f,0.0f,0.0f);
267 for (int y=0;y<height;++y) {
268 for (int x=0;x<width;++x) {
269 color=image[get_index(x,y,width)];
270 image[get_index(x,y,width)]=std::make_tuple(std::get<2>(color), std::get<1>(
271 ), std::get<0>(color));
272 }
273 }
274 }
275
276 void rrb_image(std::vector<std::tuple<float, float, float>> &image, int width, int h\
277 eight)
278 {
279 std::tuple<float, float, float> color=std::make_tuple(0.0f,0.0f,0.0f);
280 for (int y=0;y<height;++y) {
281 for (int x=0;x<width;++x) {
282 color=image[get_index(x,y,width)];
283 image[get_index(x,y,width)]=std::make_tuple(std::get<0>(color), std::get<0>(
284 ), std::get<2>(color));
285 }
286 }
287 }
288
289 void blended_two_images(std::vector<std::tuple<float, float, float>> &blend1,std::ve\
290 ctor<std::tuple<float, float, float>> &blend2,int width,int height,float alpha)
291 {
292 std::tuple<float, float, float> color1=std::make_tuple(0.0f,0.0f,0.0f);
293 std::tuple<float, float, float> color2=std::make_tuple(0.0f,0.0f,0.0f);
294 float r=0.0f; float g=0.0f; float b=0.0f;
295
296 for (int y=0;y<height;++y) {
297 for (int x=0;x<width;++x) {
298 color1=blend1[get_index(x,y,width)];
299 color2=blend2[get_index(x,y,width)];
300 r = (std::get<0>(color2) * alpha) + (std::get<0>(color1) * (1.0f - alpha));
14 Appendix A: Source Code Listings 86
344 save_image(image,width,height,"08_double_as_dark.ppm");
345
346 // OneFive times as dark.
347 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
348 image.clear();
349 read_image(image, width, height, "04_helloworld.ppm");
350 std::cout << "Making a 1.5 times as dark image." << std::endl;
351 onefive_as_dark(image,width,height);
352 std::cout << "Saving: '08_onefive_as_dark.ppm'." << std::endl;
353 save_image(image,width,height,"08_onefive_as_dark.ppm");
354
355 // Twice as bright.
356 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
357 image.clear();
358 read_image(image, width, height, "04_helloworld.ppm");
359 std::cout << "Twice as bright image." << std::endl;
360 twice_as_bright(image,width,height);
361 std::cout << "Saving: '08_twice_as_bright.ppm'." << std::endl;
362 save_image(image,width,height,"08_twice_as_bright.ppm");
363
364 // Add for brighter.
365 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
366 image.clear();
367 read_image(image, width, height, "04_helloworld.ppm");
368 std::cout << "Add for brighter image." << std::endl;
369 add_for_brighter(image,width,height);
370 std::cout << "Saving: '08_add_for_brighter.ppm'." << std::endl;
371 save_image(image,width,height,"08_add_for_brighter.ppm");
372
373 // Sub for darker.
374 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
375 image.clear();
376 read_image(image, width, height, "04_helloworld.ppm");
377 std::cout << "Sub for darker image." << std::endl;
378 sub_for_darker(image,width,height);
379 std::cout << "Saving: '08_sub_for_darker.ppm'." << std::endl;
380 save_image(image,width,height,"08_sub_for_darker.ppm");
381
382 // Greyscale image.
383 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
384 image.clear();
385 read_image(image, width, height, "04_helloworld.ppm");
386 std::cout << "Greyscale image." << std::endl;
14 Appendix A: Source Code Listings 88
387 greyscale_image(image,width,height);
388 std::cout << "Saving: '08_greyscale_image.ppm'." << std::endl;
389 save_image(image,width,height,"08_greyscale_image.ppm");
390
391 // Swapping and removing color channels.
392 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
393 image.clear();
394 read_image(image, width, height, "04_helloworld.ppm");
395 std::cout << "Swapping and removing color channels." << std::endl;
396 zero_gb_image(image,width,height);
397 std::cout << "Saving: '08_zero_gb_image.ppm'." << std::endl;
398 save_image(image,width,height,"08_zero_gb_image.ppm");
399 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
400 image.clear();
401 read_image(image, width, height, "04_helloworld.ppm");
402 std::cout << "Swapping and removing color channels." << std::endl;
403 r_zero_b_image(image,width,height);
404 std::cout << "Saving: '08_r_zero_b_image.ppm'." << std::endl;
405 save_image(image,width,height,"08_r_zero_b_image.ppm");
406 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
407 image.clear();
408 read_image(image, width, height, "04_helloworld.ppm");
409 std::cout << "Swapping and removing color channels." << std::endl;
410 rg_zero_image(image,width,height);
411 std::cout << "Saving: '08_rg_zero_image.ppm'." << std::endl;
412 save_image(image,width,height,"08_rg_zero_image.ppm");
413 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
414 image.clear();
415 read_image(image, width, height, "04_helloworld.ppm");
416 std::cout << "Swapping and removing color channels." << std::endl;
417 grb_image(image,width,height);
418 std::cout << "Saving: '08_grb_image.ppm'." << std::endl;
419 save_image(image,width,height,"08_grb_image.ppm");
420 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
421 image.clear();
422 read_image(image, width, height, "04_helloworld.ppm");
423 std::cout << "Swapping and removing color channels." << std::endl;
424 bgr_image(image,width,height);
425 std::cout << "Saving: '08_bgr_image.ppm'." << std::endl;
426 save_image(image,width,height,"08_bgr_image.ppm");
427 std::cout << "Reverting to: '04_helloworld.ppm'." << std::endl;
428 image.clear();
429 read_image(image, width, height, "04_helloworld.ppm");
14 Appendix A: Source Code Listings 89
430 std::cout << "Swapping and removing color channels." << std::endl;
431 rrb_image(image,width,height);
432 std::cout << "Saving: '08_rrb_image.ppm'." << std::endl << std::endl;
433 save_image(image,width,height,"08_rrb_image.ppm");
434
435 // Blend colors
436 std::vector<std::tuple<float, float, float>> blend1;
437 std::vector<std::tuple<float, float, float>> blend2;
438 read_image(blend1, width, height, "06_xor_texture.ppm");
439 read_image(blend2, width, height, "04_helloworld_square.ppm");
440 std::cout << "Blended two images." << std::endl;
441 blended_two_images(blend1,blend2,width,height,0.5);
442 std::cout << "Saving: '08_blended_two_images.ppm'." << std::endl << std::endl;
443 save_image(blend1,width,height,"08_blended_two_images.ppm");
444 blend1.clear(); blend2.clear();
445 read_image(blend1, width, height, "05_randomwalker.ppm");
446 read_image(blend2, width, height, "04_helloworld.ppm");
447 std::cout << "Blended two images2." << std::endl;
448 blended_two_images(blend1,blend2,width,height,0.2);
449 std::cout << "Saving: '08_blended_two_images2.ppm'." << std::endl << std::endl;
450 save_image(blend1,width,height,"08_blended_two_images2.ppm");
451
452 return 0;
453 }
17 {
18 return width*height;
19 }
20
21 void clear_image(std::vector<std::tuple<float, float, float>> &image, int width, int\
22 height)
23 {
24 for (int y=0;y<height;++y) {
25 for (int x=0;x<width;++x) {
26 image[get_index(x,y,width)]=std::make_tuple(1.0f, 1.0f, 1.0f);
27 }
28 }
29 }
30
31 std::tuple<float, float, float> h_to_rgb(float h)
32 {
33 float r=0.0f; float g=0.0f; float b=0.0f; float H=0.0f; float s=0.9f; float v=1.0f;
34 float f=0.0f; float p=0.0f; float q=0.0f; float t=0.0f;
35 int i=0;
36
37 H=h*360;
38
39 if (H == 360)
40 H = 0;
41 else
42 H = H / 60;
43
44 i = (int)std::trunc(H);
45 f = H - i;
46
47 p = v * (1.0 - s);
48 q = v * (1.0 - (s * f));
49 t = v * (1.0 - (s * (1.0 - f)));
50
51 switch (i)
52 {
53 case 0:
54 r = v;
55 g = t;
56 b = p;
57 break;
58 case 1:
59 r = q;
14 Appendix A: Source Code Listings 91
60 g = v;
61 b = p;
62 break;
63 case 2:
64 r = p;
65 g = v;
66 b = t;
67 break;
68 case 3:
69 r = p;
70 g = q;
71 b = v;
72 break;
73 case 4:
74 r = t;
75 g = p;
76 b = v;
77 break;
78 default:
79 r = v;
80 g = p;
81 b = q;
82 break;
83 }
84
85 return std::make_tuple(r,g,b);
86 }
87
88 void draw_line(std::vector<std::tuple<float, float, float>> &image, std::tuple<int, \
89 int, int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
90 {
91 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
92 int y2=std::get<3>(coords);
93 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
94 dx = x2 - x1; dy = y2 - y1;
95 if (((x1 >= 0) && (x1 < width)) && ((x2 >= 0) && (x2 < width)) && ((y1 >= 0) && (y1\
96 < height)) && ((y2 >= 0) && (y2 < height))) {
97 if (dx == 0)
98 {
99 if (y2 < y1) std::swap(y1, y2);
100 for (y = y1; y <= y2; y++)
101 image[get_index(x1,y,width)]=color;
102 return;
14 Appendix A: Source Code Listings 92
103 }
104 if (dy == 0)
105 {
106 if (x2 < x1) std::swap(x1, x2);
107 for (x = x1; x <= x2; x++)
108 image[get_index(x,y1,width)]=color;
109 return;
110 }
111 dx1 = abs(dx); dy1 = abs(dy);
112 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
113 if (dy1 <= dx1)
114 {
115 if (dx >= 0)
116 {
117 x = x1; y = y1; xe = x2;
118 }
119 else
120 {
121 x = x2; y = y2; xe = x1;
122 }
123 image[get_index(x,y,width)]=color;
124 for (i = 0; x<xe; i++)
125 {
126 x = x + 1;
127 if (px<0)
128 px = px + 2 * dy1;
129 else
130 {
131 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
132 px = px + 2 * (dy1 - dx1);
133 }
134 image[get_index(x,y,width)]=color;
135 }
136 }
137 else
138 {
139 if (dy >= 0)
140 {
141 x = x1; y = y1; ye = y2;
142 }
143 else
144 {
145 x = x2; y = y2; ye = y1;
14 Appendix A: Source Code Listings 93
146 }
147 image[get_index(x,y,width)]=color;
148 for (i = 0; y<ye; i++)
149 {
150 y = y + 1;
151 if (py <= 0)
152 py = py + 2 * dx1;
153 else
154 {
155 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
156 py = py + 2 * (dx1 - dy1);
157 }
158 image[get_index(x,y,width)]=color;
159 }
160 }
161 }
162 }
163
164 int find_region(int x, int y, int width, int height)
165 {
166 int code=0;
167 if(y >= height)
168 code |= 1; //top
169 else if(y < 0)
170 code |= 2; //bottom
171 if(x >= width)
172 code |= 4; //right
173 else if (x < 0)
174 code |= 8; //left
175 return(code);
176 }
177
178 bool clip_line(std::tuple<int, int, int, int> &coords1, std::tuple<int, int, int, in\
179 t> &coords2, int width, int height)
180 {
181 int x1=std::get<0>(coords1); int y1=std::get<1>(coords1); int x2=std::get<2>(coords\
182 1); int y2=std::get<3>(coords1);
183 int x3=0; int y3=0; int x4=0; int y4=0;
184 int code1=0, code2=0, codeout=0;
185 bool accept = 0, done=0;
186 code1 = find_region(x1, y1, width, height); //the region outcodes for the endpoints
187 code2 = find_region(x2, y2, width, height);
188 do //In theory, this can never end up in an infinite loop, it'll always come in one\
14 Appendix A: Source Code Listings 94
232 {
233 x3 = x1;
234 x4 = x2;
235 y3 = y1;
236 y4 = y2;
237 coords2=std::make_tuple(x3,y3,x4,y4);
238 return 1;
239 }
240 else
241 {
242 x3 = x4 = y3 = y4 = 0;
243 coords2=std::make_tuple(x3,y3,x4,y4);
244 return 0;
245 }
246 }
247
248 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
249 height, std::string filename)
250 {
251 std::tuple<float, float, float> color;
252 std::ofstream out(filename, std::ofstream::out);
253 out << "P3\n" << width << " " << height << "\n255\n";
254 for (int i=0;i<(width*height);++i)
255 {
256 color=image[i];
257 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
258 " " << int(std::get<2>(color)*255.0f) << '\n';
259 }
260 out.close();
261 }
262
263 int main()
264 {
265 // Draw random lines (with line clipping).
266 std::vector<std::tuple<float, float, float>> image;
267
268 std::random_device rd;
269 std::mt19937 mt(rd());
270
271 std::uniform_int_distribution<> dist1(-100,740);
272 std::uniform_int_distribution<> dist2(-100,460);
273 std::uniform_real_distribution<float> dist3(0.0, 1.0);
274
14 Appendix A: Source Code Listings 96
318
319 for (int x=0;x<width;++x) {
320 y=639-(319.0-(339.0*pow(1.0-(1.0/339.0),x))*sin(2*M_PI*x*(15.0/numb_of_samples)-1.\
321 0)+0);
322 if (x == 0) {ox=x;oy=y;}
323 coords1=std::make_tuple(x,y,ox,oy);
324 draw_line(image,coords1,black,width,height);
325 ox=x;oy=y;
326 }
327
328 for (int x=0;x<width;++x) {
329 y=319.0-(339.0*pow(1.0-(1.0/339.0),x));
330 if (x == 0) {ox=x;oy=y;}
331 coords1=std::make_tuple(x,y,ox,oy);
332 draw_line(image,coords1,grey,width,height);
333 ox=x;oy=y;
334 }
335
336 save_image(image,width,height,"09_damped_sine.ppm");
337
338 return 0;
339 }
19 }
20
21 void clear_image(std::vector<std::tuple<float, float, float>> &image, int width, int\
22 height)
23 {
24 for (int y=0;y<height;++y) {
25 for (int x=0;x<width;++x) {
26 image[get_index(x,y,width)]=std::make_tuple(1.0f, 1.0f, 1.0f);
27 }
28 }
29 }
30
31 void draw_line(std::vector<std::tuple<float, float, float>> &image, std::tuple<int, \
32 int, int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
33 {
34 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
35 int y2=std::get<3>(coords);
36 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
37 dx = x2 - x1; dy = y2 - y1;
38 if (dx == 0)
39 {
40 if (y2 < y1) std::swap(y1, y2);
41 for (y = y1; y <= y2; y++)
42 image[get_index(x1,y,width)]=color;
43 return;
44 }
45 if (dy == 0)
46 {
47 if (x2 < x1) std::swap(x1, x2);
48 for (x = x1; x <= x2; x++)
49 image[get_index(x,y1,width)]=color;
50 return;
51 }
52 dx1 = abs(dx); dy1 = abs(dy);
53 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
54 if (dy1 <= dx1)
55 {
56 if (dx >= 0)
57 {
58 x = x1; y = y1; xe = x2;
59 }
60 else
61 {
14 Appendix A: Source Code Listings 99
105 {
106 int code=0;
107 if(y >= height)
108 code |= 1; //top
109 else if(y < 0)
110 code |= 2; //bottom
111 if(x >= width)
112 code |= 4; //right
113 else if (x < 0)
114 code |= 8; //left
115 return(code);
116 }
117
118 bool clip_line(std::tuple<int, int, int, int> &coords1, std::tuple<int, int, int, in\
119 t> &coords2, int width, int height)
120 {
121 int x1=std::get<0>(coords1); int y1=std::get<1>(coords1); int x2=std::get<2>(coords\
122 1); int y2=std::get<3>(coords1);
123 int x3=0; int y3=0; int x4=0; int y4=0;
124 int code1=0, code2=0, codeout=0;
125 bool accept = 0, done=0;
126 code1 = find_region(x1, y1, width, height); //the region outcodes for the endpoints
127 code2 = find_region(x2, y2, width, height);
128 do //In theory, this can never end up in an infinite loop, it'll always come in one\
129 of the trivial cases eventually
130 {
131 if(!(code1 | code2)) accept = done = 1; //accept because both endpoints are in sc\
132 reen or on the border, trivial accept
133 else if(code1 & code2) done = 1; //the line isn't visible on screen, trivial reject
134 else //if no trivial reject or accept, continue the loop
135 {
136 int x, y;
137 codeout = code1 ? code1 : code2;
138 if(codeout & 1) //top
139 {
140 x = x1 + (x2 - x1) * (height - y1) / (y2 - y1);
141 y = height - 1;
142 }
143 else if(codeout & 2) //bottom
144 {
145 x = x1 + (x2 - x1) * -y1 / (y2 - y1);
146 y = 0;
147 }
14 Appendix A: Source Code Listings 101
234 }
235 degrees=45.0;
236 get_angle_line(coords,x_cen,y_cen,degrees,length);
237 if (clip_line(coords,coords,width,height)) {
238 draw_line(image,coords,color,width,height);
239 }
240 degrees=90.0;
241 get_angle_line(coords,x_cen,y_cen,degrees,length);
242 if (clip_line(coords,coords,width,height)) {
243 draw_line(image,coords,color,width,height);
244 }
245 degrees=135.0;
246 get_angle_line(coords,x_cen,y_cen,degrees,length);
247 if (clip_line(coords,coords,width,height)) {
248 draw_line(image,coords,color,width,height);
249 }
250 degrees=180.0;
251 get_angle_line(coords,x_cen,y_cen,degrees,length);
252 if (clip_line(coords,coords,width,height)) {
253 draw_line(image,coords,color,width,height);
254 }
255 degrees=225.0;
256 get_angle_line(coords,x_cen,y_cen,degrees,length);
257 if (clip_line(coords,coords,width,height)) {
258 draw_line(image,coords,color,width,height);
259 }
260 degrees=270.0;
261 get_angle_line(coords,x_cen,y_cen,degrees,length);
262 if (clip_line(coords,coords,width,height)) {
263 draw_line(image,coords,color,width,height);
264 }
265 degrees=315.0;
266 get_angle_line(coords,x_cen,y_cen,degrees,length);
267 if (clip_line(coords,coords,width,height)) {
268 draw_line(image,coords,color,width,height);
269 }
270
271 save_image(image,width,height,"09_angle_lines.ppm");
272
273 return 0;
274 }
14 Appendix A: Source Code Listings 104
43 y2 = std::lerp(py1,py2,t);
44 x = std::lerp(x1,x2,t);
45 y = std::lerp(y1,y2,t);
46 xy.push_back(std::make_tuple(x,y));
47 t+=delta;
48 }
49 }
50
51 void cubic_bezier_curves(int px0, int py0, int px1, int py1, int px2, int py2, int p\
52 x3, int py3, int split, std::vector<std::tuple<int,int>>& xy)
53 {
54 float t=0.0;
55 float delta=(float(1)/float(split));
56 int x=0;
57 int y=0;
58 int x1=0;
59 int y1=0;
60 int x2=0;
61 int y2=0;
62 int x3=0;
63 int y3=0;
64 int x4=0;
65 int y4=0;
66 int xx1=0;
67 int yy1=0;
68 int xx2=0;
69 int yy2=0;
70 for (int i=0;i<split;++i)
71 {
72 x1 = std::lerp(px0,px1,t);
73 y1 = std::lerp(py0,py1,t);
74 x2 = std::lerp(px1,px2,t);
75 y2 = std::lerp(py1,py2,t);
76
77 x3 = std::lerp(px1,px2,t);
78 y3 = std::lerp(py1,py2,t);
79 x4 = std::lerp(px2,px3,t);
80 y4 = std::lerp(py2,py3,t);
81
82 xx1 = std::lerp(x1,x2,t);
83 yy1 = std::lerp(y1,y2,t);
84 xx2 = std::lerp(x3,x4,t);
85 yy2 = std::lerp(y3,y4,t);
14 Appendix A: Source Code Listings 106
86
87 x = std::lerp(xx1,xx2,t);
88 y = std::lerp(yy1,yy2,t);
89 xy.push_back(std::make_tuple(x,y));
90 t+=delta;
91 }
92 }
93
94 int get_index(int x, int y, int width)
95 {
96 return x+width*y;
97 }
98
99 int calc_size(int width, int height)
100 {
101 return width*height;
102 }
103
104 void clear_image(std::vector<std::tuple<float, float, float>> &image, int width, int\
105 height)
106 {
107 for (int y=0;y<height;++y) {
108 for (int x=0;x<width;++x) {
109 image[get_index(x,y,width)]=std::make_tuple(1.0f, 1.0f, 1.0f);
110 }
111 }
112 }
113
114 void draw_line(std::vector<std::tuple<float, float, float>> &image, std::tuple<int, \
115 int, int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
116 {
117 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
118 int y2=std::get<3>(coords);
119 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
120 dx = x2 - x1; dy = y2 - y1;
121 if (dx == 0)
122 {
123 if (y2 < y1) std::swap(y1, y2);
124 for (y = y1; y <= y2; y++)
125 image[get_index(x1,y,width)]=color;
126 return;
127 }
128 if (dy == 0)
14 Appendix A: Source Code Listings 107
129 {
130 if (x2 < x1) std::swap(x1, x2);
131 for (x = x1; x <= x2; x++)
132 image[get_index(x,y1,width)]=color;
133 return;
134 }
135 dx1 = abs(dx); dy1 = abs(dy);
136 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
137 if (dy1 <= dx1)
138 {
139 if (dx >= 0)
140 {
141 x = x1; y = y1; xe = x2;
142 }
143 else
144 {
145 x = x2; y = y2; xe = x1;
146 }
147 image[get_index(x,y,width)]=color;
148 for (i = 0; x<xe; i++)
149 {
150 x = x + 1;
151 if (px<0)
152 px = px + 2 * dy1;
153 else
154 {
155 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
156 px = px + 2 * (dy1 - dx1);
157 }
158 image[get_index(x,y,width)]=color;
159 }
160 }
161 else
162 {
163 if (dy >= 0)
164 {
165 x = x1; y = y1; ye = y2;
166 }
167 else
168 {
169 x = x2; y = y2; ye = y1;
170 }
171 image[get_index(x,y,width)]=color;
14 Appendix A: Source Code Listings 108
258 draw_line(image,coords,color,width,height);
259 quadratic_bezier_curves(340,90,480,2,620,90,10,xy);
260 color=std::make_tuple(0.0, 0.0, 0.0);
261 draw_xy_dots(image,color,xy,width,height);
262 xy.clear();
263 color=std::make_tuple(0.0, 0.8784313725, 0.0);
264 draw_marker(340,90,image,color,width,height);
265 color=std::make_tuple(0.0, 0.8784313725, 0.0);
266 draw_marker(480,2,image,color,width,height);
267 color=std::make_tuple(0.0, 0.8784313725, 0.0);
268 draw_marker(620,90,image,color,width,height);
269
270 // Draw dots in a curve 2.
271 color=std::make_tuple(0.9296875, 0.9296875, 0.9296875);
272 coords=std::make_tuple(200,270,293,182);
273 draw_line(image,coords,color,width,height);
274 coords=std::make_tuple(386,357,480,270);
275 draw_line(image,coords,color,width,height);
276 cubic_bezier_curves(200,270,293,182,386,357,480,270,10,xy);
277 color=std::make_tuple(0.0, 0.0, 0.0);
278 draw_xy_dots(image,color,xy,width,height);
279 xy.clear();
280 color=std::make_tuple(0.0, 0.8784313725, 0.0);
281 draw_marker(200,270,image,color,width,height);
282 color=std::make_tuple(0.0, 0.8784313725, 0.0);
283 draw_marker(293,182,image,color,width,height);
284 color=std::make_tuple(0.0, 0.8784313725, 0.0);
285 draw_marker(386,357,image,color,width,height);
286 color=std::make_tuple(0.0, 0.8784313725, 0.0);
287 draw_marker(480,270,image,color,width,height);
288
289 save_image(image,width,height,"10_curved_dots.ppm");
290
291 return 0;
292 }
14 Appendix A: Source Code Listings 111
43 y2 = std::lerp(py1,py2,t);
44 x = std::lerp(x1,x2,t);
45 y = std::lerp(y1,y2,t);
46 xy.push_back(std::make_tuple(x,y));
47 t+=delta;
48 }
49 }
50
51 void cubic_bezier_curves(int px0, int py0, int px1, int py1, int px2, int py2, int p\
52 x3, int py3, int split, std::vector<std::tuple<int,int>>& xy)
53 {
54 float t=0.0;
55 float delta=(float(1)/float(split));
56 int x=0;
57 int y=0;
58 int x1=0;
59 int y1=0;
60 int x2=0;
61 int y2=0;
62 int x3=0;
63 int y3=0;
64 int x4=0;
65 int y4=0;
66 int xx1=0;
67 int yy1=0;
68 int xx2=0;
69 int yy2=0;
70 for (int i=0;i<split;++i)
71 {
72 x1 = std::lerp(px0,px1,t);
73 y1 = std::lerp(py0,py1,t);
74 x2 = std::lerp(px1,px2,t);
75 y2 = std::lerp(py1,py2,t);
76
77 x3 = std::lerp(px1,px2,t);
78 y3 = std::lerp(py1,py2,t);
79 x4 = std::lerp(px2,px3,t);
80 y4 = std::lerp(py2,py3,t);
81
82 xx1 = std::lerp(x1,x2,t);
83 yy1 = std::lerp(y1,y2,t);
84 xx2 = std::lerp(x3,x4,t);
85 yy2 = std::lerp(y3,y4,t);
14 Appendix A: Source Code Listings 113
86
87 x = std::lerp(xx1,xx2,t);
88 y = std::lerp(yy1,yy2,t);
89 xy.push_back(std::make_tuple(x,y));
90 t+=delta;
91 }
92 }
93
94 int get_index(int x, int y, int width)
95 {
96 return x+width*y;
97 }
98
99 int calc_size(int width, int height)
100 {
101 return width*height;
102 }
103
104 void clear_image(std::vector<std::tuple<float, float, float>> &image, int width, int\
105 height)
106 {
107 for (int y=0;y<height;++y) {
108 for (int x=0;x<width;++x) {
109 image[get_index(x,y,width)]=std::make_tuple(1.0f, 1.0f, 1.0f);
110 }
111 }
112 }
113
114 void draw_line(std::vector<std::tuple<float, float, float>> &image, std::tuple<int, \
115 int, int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
116 {
117 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
118 int y2=std::get<3>(coords);
119 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
120 dx = x2 - x1; dy = y2 - y1;
121 if (dx == 0)
122 {
123 if (y2 < y1) std::swap(y1, y2);
124 for (y = y1; y <= y2; y++)
125 image[get_index(x1,y,width)]=color;
126 return;
127 }
128 if (dy == 0)
14 Appendix A: Source Code Listings 114
129 {
130 if (x2 < x1) std::swap(x1, x2);
131 for (x = x1; x <= x2; x++)
132 image[get_index(x,y1,width)]=color;
133 return;
134 }
135 dx1 = abs(dx); dy1 = abs(dy);
136 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
137 if (dy1 <= dx1)
138 {
139 if (dx >= 0)
140 {
141 x = x1; y = y1; xe = x2;
142 }
143 else
144 {
145 x = x2; y = y2; xe = x1;
146 }
147 image[get_index(x,y,width)]=color;
148 for (i = 0; x<xe; i++)
149 {
150 x = x + 1;
151 if (px<0)
152 px = px + 2 * dy1;
153 else
154 {
155 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
156 px = px + 2 * (dy1 - dx1);
157 }
158 image[get_index(x,y,width)]=color;
159 }
160 }
161 else
162 {
163 if (dy >= 0)
164 {
165 x = x1; y = y1; ye = y2;
166 }
167 else
168 {
169 x = x2; y = y2; ye = y1;
170 }
171 image[get_index(x,y,width)]=color;
14 Appendix A: Source Code Listings 115
215 image[get_index(std::get<0>(pt),std::get<1>(pt),width)]=color;
216 }
217 }
218
219 void draw_marker(int x, int y, std::vector<std::tuple<float, float, float>> &image, \
220 std::tuple<float,float,float> &color, int width, int height)
221 {
222 image[get_index(x-1,y-1,width)]=color;
223 image[get_index(x,y-1,width)]=color;
224 image[get_index(x+1,y-1,width)]=color;
225 image[get_index(x+1,y,width)]=color;
226 image[get_index(x+1,y+1,width)]=color;
227 image[get_index(x,y+1,width)]=color;
228 image[get_index(x-1,y+1,width)]=color;
229 image[get_index(x-1,y,width)]=color;
230
231 color=std::make_tuple(1.0f, 1.0f, 1.0f);
232 image[get_index(x,y,width)]=color;
233 }
234
235 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
236 height, std::string filename)
237 {
238 std::tuple<float, float, float> color;
239 std::ofstream out(filename, std::ofstream::out);
240 out << "P3\n" << width << " " << height << "\n255\n";
241 for (int i=0;i<(width*height);++i)
242 {
243 color=image[i];
244 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
245 " " << int(std::get<2>(color)*255.0f) << '\n';
246 }
247 out.close();
248 }
249
250 int main()
251 {
252 int width=640;
253 int height=360;
254 std::vector<std::tuple<float, float, float>> image;
255 std::tuple<float,float,float> color;
256
257 image.resize(calc_size(width, height));
14 Appendix A: Source Code Listings 117
258 clear_image(image,width,height);
259
260 std::vector<std::tuple<int,int>> xy;
261 std::tuple<int, int, int, int> coords;
262
263 // Draw a line with Bezier.
264 color=std::make_tuple(0.9296875, 0.9296875, 0.9296875);
265 coords=std::make_tuple(20,90,300,90);
266 draw_line(image,coords,color,width,height);
267 linear_bezier_curves(coords,40,xy);
268 color=std::make_tuple(0.7019607843, 0.2196078431, 0.6078431373);
269 draw_xy_line(image,color,xy,width,height,300,90);
270 xy.clear();
271 coords=std::make_tuple(20,90,300,90);
272 linear_bezier_curves(coords,10,xy);
273 color=std::make_tuple(0.8784313725, 0.8784313725, 0.0);
274 draw_xy_dots(image,color,xy,width,height);
275 xy.clear();
276 color=std::make_tuple(0.0, 0.8784313725, 0.0);
277 draw_marker(20,90,image,color,width,height);
278 color=std::make_tuple(0.0, 0.8784313725, 0.0);
279 draw_marker(300,90,image,color,width,height);
280
281 // Draw line as a curve 1.
282 color=std::make_tuple(0.9296875, 0.9296875, 0.9296875);
283 coords=std::make_tuple(340,90,480,2);
284 draw_line(image,coords,color,width,height);
285 coords=std::make_tuple(480,2,620,90);
286 draw_line(image,coords,color,width,height);
287 quadratic_bezier_curves(340,90,480,2,620,90,40,xy);
288 color=std::make_tuple(0.7019607843, 0.2196078431, 0.6078431373);
289 draw_xy_line(image,color,xy,width,height,620,90);
290 xy.clear();
291 quadratic_bezier_curves(340,90,480,2,620,90,10,xy);
292 color=std::make_tuple(0.8784313725, 0.8784313725, 0.0);
293 draw_xy_dots(image,color,xy,width,height);
294 xy.clear();
295 color=std::make_tuple(0.0, 0.8784313725, 0.0);
296 draw_marker(340,90,image,color,width,height);
297 color=std::make_tuple(0.0, 0.8784313725, 0.0);
298 draw_marker(480,2,image,color,width,height);
299 color=std::make_tuple(0.0, 0.8784313725, 0.0);
300 draw_marker(620,90,image,color,width,height);
14 Appendix A: Source Code Listings 118
301
302 // Draw line as a curve 2.
303 xy.clear();
304 color=std::make_tuple(0.9296875, 0.9296875, 0.9296875);
305 coords=std::make_tuple(200,270,293,182);
306 draw_line(image,coords,color,width,height);
307 coords=std::make_tuple(386,357,480,270);
308 draw_line(image,coords,color,width,height);
309 cubic_bezier_curves(200,270,293,182,386,357,480,270,40,xy);
310 color=std::make_tuple(0.7019607843, 0.2196078431, 0.6078431373);
311 draw_xy_line(image,color,xy,width,height,480,270);
312 xy.clear();
313 cubic_bezier_curves(200,270,293,182,386,357,480,270,10,xy);
314 color=std::make_tuple(0.8784313725, 0.8784313725, 0.0);
315 draw_xy_dots(image,color,xy,width,height);
316 xy.clear();
317 color=std::make_tuple(0.0, 0.8784313725, 0.0);
318 draw_marker(200,270,image,color,width,height);
319 color=std::make_tuple(0.0, 0.8784313725, 0.0);
320 draw_marker(293,182,image,color,width,height);
321 color=std::make_tuple(0.0, 0.8784313725, 0.0);
322 draw_marker(386,357,image,color,width,height);
323 color=std::make_tuple(0.0, 0.8784313725, 0.0);
324 draw_marker(480,270,image,color,width,height);
325
326 save_image(image,width,height,"10_curved_lines.ppm");
327
328 return 0;
329 }
12 return x+width*y;
13 }
14
15 int calc_size(int width, int height)
16 {
17 return width*height;
18 }
19
20 void clear_image(std::vector<std::tuple<float, float, float>> &image, int width, int\
21 height)
22 {
23 for (int y=0;y<height;++y) {
24 for (int x=0;x<width;++x) {
25 image[get_index(x,y,width)]=std::make_tuple(1.0f, 1.0f, 1.0f);
26 }
27 }
28 }
29
30 void draw_line(std::vector<std::tuple<float, float, float>> &image, std::tuple<int, \
31 int, int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
32 {
33 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
34 int y2=std::get<3>(coords);
35 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
36 dx = x2 - x1; dy = y2 - y1;
37 if (dx == 0)
38 {
39 if (y2 < y1) std::swap(y1, y2);
40 for (y = y1; y <= y2; y++)
41 image[get_index(x1,y,width)]=color;
42 return;
43 }
44 if (dy == 0)
45 {
46 if (x2 < x1) std::swap(x1, x2);
47 for (x = x1; x <= x2; x++)
48 image[get_index(x,y1,width)]=color;
49 return;
50 }
51 dx1 = abs(dx); dy1 = abs(dy);
52 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
53 if (dy1 <= dx1)
54 {
14 Appendix A: Source Code Listings 120
55 if (dx >= 0)
56 {
57 x = x1; y = y1; xe = x2;
58 }
59 else
60 {
61 x = x2; y = y2; xe = x1;
62 }
63 image[get_index(x,y,width)]=color;
64 for (i = 0; x<xe; i++)
65 {
66 x = x + 1;
67 if (px<0)
68 px = px + 2 * dy1;
69 else
70 {
71 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
72 px = px + 2 * (dy1 - dx1);
73 }
74 image[get_index(x,y,width)]=color;
75 }
76 }
77 else
78 {
79 if (dy >= 0)
80 {
81 x = x1; y = y1; ye = y2;
82 }
83 else
84 {
85 x = x2; y = y2; ye = y1;
86 }
87 image[get_index(x,y,width)]=color;
88 for (i = 0; y<ye; i++)
89 {
90 y = y + 1;
91 if (py <= 0)
92 py = py + 2 * dx1;
93 else
94 {
95 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
96 py = py + 2 * (dx1 - dy1);
97 }
14 Appendix A: Source Code Listings 121
98 image[get_index(x,y,width)]=color;
99 }
100 }
101 }
102
103 void draw_rect(int x, int y, int w, int h, std::vector<std::tuple<float, float, floa\
104 t>> &image, std::tuple<float,float,float> &color, int width, int height)
105 {
106 w=w-1;
107 h=h-1;
108 std::tuple<int, int, int, int> coords=std::make_tuple(x, y, x+w, y);
109 draw_line(image, coords, color, width, height);
110 coords=std::make_tuple(x+w, y, x+w, y+h);
111 draw_line(image, coords, color, width, height);
112 coords=std::make_tuple(x+w, y+h, x, y+h);
113 draw_line(image, coords, color, width, height);
114 coords=std::make_tuple(x, y+h, x, y);
115 draw_line(image, coords, color, width, height);
116 }
117
118 void draw_filled_rect(int x, int y, int w, int h, std::vector<std::tuple<float, floa\
119 t, float>> &image, std::tuple<float,float,float> &color, int width, int height)
120 {
121 int x2 = x + w;
122 int y2 = y + h;
123
124 if (x < 0) {x = 0;}
125 if (x >= width) {x = width;}
126 if (y < 0) {y = 0;}
127 if (y >= height) {y = height;}
128
129 if (x2 < 0) {x2 = 0;}
130 if (x2 >= width) {x2 = width;}
131 if (y2 < 0) {y2 = 0;}
132 if (y2 >= height) {y2 = height;}
133
134 for (int i = y; i < y2; i++) {
135 for (int j = x; j < x2; j++) {
136 image[get_index(j,i,width)]=color;
137 }
138 }
139 }
140
14 Appendix A: Source Code Listings 122
86
87 return std::make_tuple(x1,y1,x2,y2,rf,gf,bf,af);
88 }
89
90 std::tuple<float,float,float> blend_colors(std::tuple<float,float,float> &colorBGRGB\
91 , std::tuple<float,float,float,float> &colorRGBA)
92 {
93 float r=0.0f; float g=0.0f; float b=0.0f;
94 r = (std::get<0>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<0>(colorBGRGB) * \
95 (1.0 - std::get<3>(colorRGBA)));
96 g = (std::get<1>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<1>(colorBGRGB) * \
97 (1.0 - std::get<3>(colorRGBA)));
98 b = (std::get<2>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<2>(colorBGRGB) * \
99 (1.0 - std::get<3>(colorRGBA)));
100
101 return std::make_tuple(r,g,b);
102 }
103
104 void draw_filled_rect(int x1,int y1,int x2,int y2, std::vector<std::tuple<float, flo\
105 at, float>> &image, std::tuple<float,float,float,float> &colorRGBA, int width, int h
106 eight)
107 {
108 for (int i = y1; i < y2; i++) {
109 for (int j = x1; j < x2; j++) {
110 image[get_index(j,i,width)]=blend_colors(image[get_index(j,i,width)],colorRG
111 }
112 }
113 }
114
115 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
116 height, std::string filename)
117 {
118 std::tuple<float, float, float> color;
119 std::ofstream out(filename, std::ofstream::out);
120 out << "P3\n" << width << " " << height << "\n255\n";
121 for (int i=0;i<(width*height);++i)
122 {
123 color=image[i];
124 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
125 " " << int(std::get<2>(color)*255.0f) << '\n';
126 }
127 out.close();
128 }
14 Appendix A: Source Code Listings 126
129
130 int main()
131 {
132 std::ifstream infile("11_squint_with_your_eyes.txt");
133 std::string line;
134 std::tuple<int,int,int,int,float,float,float,float> rect;
135 std::tuple<int,int,float,float,float> bginfo;
136 std::tuple<float,float,float> colorBGRGB;
137 std::tuple<float,float,float,float> colorRGBA;
138 int width,height,x1,y1,x2,y2;
139 float rf,gf,bf,af;
140 float bg_rf,bg_gf,bg_bf;
141 std::vector<std::tuple<float, float, float>> image;
142 while (getline(infile, line))
143 {
144 if (startsWithCaseInsensitive(line,"r")) {
145 rect=parse_rect_line(line);
146 std::tie(x1,y1,x2,y2,rf,gf,bf,af) = rect;
147 colorRGBA=std::make_tuple(rf,gf,bf,af);
148 draw_filled_rect(x1,y1,x2,y2,image,colorRGBA,width,height);
149 }
150
151 if (startsWithCaseInsensitive(line,"b")) {
152 bginfo=parse_bginfo_line(line,width,height);
153 std::tie(width,height,bg_rf,bg_gf,bg_bf) = bginfo;
154 image.resize(calc_size(width, height));
155 colorBGRGB=std::make_tuple(bg_rf,bg_gf,bg_bf);
156 clear_image(image,colorBGRGB,width,height);
157 }
158 }
159 infile.close();
160
161 save_image(image,width,height,"11_squint_with_your_eyes.ppm");
162
163 return 0;
164 }
14 Appendix A: Source Code Listings 127
12 return x+width*y;
13 }
14
15 int calc_size(int width, int height)
16 {
17 return width*height;
18 }
19
20 void clear_image(std::vector<std::tuple<float, float, float>> &image, int width, int\
21 height)
22 {
23 for (int y=0;y<height;++y) {
24 for (int x=0;x<width;++x) {
25 image[get_index(x,y,width)]=std::make_tuple(1.0f, 1.0f, 1.0f);
26 }
27 }
28 }
29
30 void draw_circle(int x, int y, int radius, std::vector<std::tuple<float, float, floa\
31 t>> &image, std::tuple<float, float, float> &color, int width, int height)
32 {
33 int x0 = 0;
34 int y0 = radius;
35 int d = 3 - 2 * radius;
36 int xx=0;
37 int yy=0;
38 unsigned char mask=255;
39 if (!radius) return;
40
41 while (y0 >= x0)
42 {
43 if (mask & 0x01) {xx=x + x0;yy=y - y0;image[get_index(xx, yy, width)]=color;}
44 if (mask & 0x02) {xx=x + y0;yy=y - x0;image[get_index(xx, yy, width)]=color;}
45 if (mask & 0x04) {xx=x + y0;yy=y + x0;image[get_index(xx, yy, width)]=color;}
46 if (mask & 0x08) {xx=x + x0;yy=y + y0;image[get_index(xx, yy, width)]=color;}
47 if (mask & 0x10) {xx=x - x0;yy=y + y0;image[get_index(xx, yy, width)]=color;}
48 if (mask & 0x20) {xx=x - y0;yy=y + x0;image[get_index(xx, yy, width)]=color;}
49 if (mask & 0x40) {xx=x - y0;yy=y - x0;image[get_index(xx, yy, width)]=color;}
50 if (mask & 0x80) {xx=x - x0;yy=y - y0;image[get_index(xx, yy, width)]=color;}
51 if (d < 0) d += 4 * x0++ + 6;
52 else d += 4 * (x0++ - y0--) + 10;
53 }
54 }
14 Appendix A: Source Code Listings 140
55
56 void draw_filled_circle(int x, int y, int radius, std::vector<std::tuple<float, floa\
57 t, float>> &image, std::tuple<float, float, float> &color, int width, int height)
58 {
59 int x0 = 0;
60 int y0 = radius;
61 int d = 3 - 2 * radius;
62 if (!radius) return;
63
64 auto drawline = [&](int sx, int ex, int ny)
65 {
66 for (int i = sx; i <= ex; i++)
67 image[get_index(i, ny, width)]=color;
68 };
69
70 while (y0 >= x0)
71 {
72 drawline(x - x0, x + x0, y - y0);
73 drawline(x - y0, x + y0, y - x0);
74 drawline(x - x0, x + x0, y + y0);
75 drawline(x - y0, x + y0, y + x0);
76 if (d < 0) d += 4 * x0++ + 6;
77 else d += 4 * (x0++ - y0--) + 10;
78 }
79 }
80
81 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
82 height, std::string filename)
83 {
84 std::tuple<float, float, float> color;
85 std::ofstream out(filename, std::ofstream::out);
86 out << "P3\n" << width << " " << height << "\n255\n";
87 for (int i=0;i<(width*height);++i)
88 {
89 color=image[i];
90 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
91 " " << int(std::get<2>(color)*255.0f) << '\n';
92 }
93 out.close();
94 }
95
96 int main()
97 {
14 Appendix A: Source Code Listings 141
98 int width=640;
99 int height=360;
100 int x1=0,y=0,r=0,x2=0;
101
102 r=((height/2)*0.8)/2;
103 y=height/2;
104 x1=((width-(((height/2)*0.8)*3))/2)+r;
105 x2=width-x1;
106
107 std::vector<std::tuple<float, float, float>> image;
108 std::tuple<float,float,float> color=std::make_tuple(0.0f,0.0f,0.0f);
109
110 image.resize(calc_size(width, height));
111 clear_image(image,width,height);
112
113 draw_circle(x1,y,r,image,color,width,height);
114 draw_filled_circle(x2,y,r,image,color,width,height);
115
116 save_image(image,width,height,"12_circle.ppm");
117
118 return 0;
119 }
19 else
20 return false;
21 }
22
23 int get_index(int x, int y, int width)
24 {
25 return x+width*y;
26 }
27
28 int calc_size(int width, int height)
29 {
30 return width*height;
31 }
32
33 void clear_image(std::vector<std::tuple<float, float, float>> &image, std::tuple<flo\
34 at,float,float> &color, int width, int height)
35 {
36 for (int y=0;y<height;++y) {
37 for (int x=0;x<width;++x) {
38 image[get_index(x,y,width)]=color;
39 }
40 }
41 }
42
43 std::tuple<int,int,int,float,float,float,float> parse_circle_line(const std::string \
44 str)
45 {
46 size_t start;
47 size_t end = 0;
48 std::vector<std::string> out;
49
50 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
51 {
52 end = str.find(' ', start);
53 out.push_back(str.substr(start, end - start));
54 }
55
56 int dx=stoi(out[1]);
57 int dy=stoi(out[2]);
58 int r=stoi(out[3]);
59 float rf=stof(out[4]);
60 float gf=stof(out[5]);
61 float bf=stof(out[6]);
14 Appendix A: Source Code Listings 143
62 float af=stof(out[7]);
63
64 return std::make_tuple(dx,dy,r,rf,gf,bf,af);
65 }
66
67 std::tuple<int,int,float,float,float> parse_bginfo_line(const std::string str, int &\
68 width, int &height)
69 {
70 size_t start;
71 size_t end = 0;
72 std::vector<std::string> out;
73
74 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
75 {
76 end = str.find(' ', start);
77 out.push_back(str.substr(start, end - start));
78 }
79
80 width=stoi(out[1]);
81 height=stoi(out[2]);
82 float rf=stof(out[3]);
83 float gf=stof(out[4]);
84 float bf=stof(out[5]);
85
86 return std::make_tuple(width,height,rf,gf,bf);
87 }
88
89 std::tuple<float,float,float> blend_colors(std::tuple<float,float,float> &colorBGRGB\
90 , std::tuple<float,float,float,float> &colorRGBA)
91 {
92 float r=0.0f; float g=0.0f; float b=0.0f;
93 r = (std::get<0>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<0>(colorBGRGB) * \
94 (1.0 - std::get<3>(colorRGBA)));
95 g = (std::get<1>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<1>(colorBGRGB) * \
96 (1.0 - std::get<3>(colorRGBA)));
97 b = (std::get<2>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<2>(colorBGRGB) * \
98 (1.0 - std::get<3>(colorRGBA)));
99
100 return std::make_tuple(r,g,b);
101 }
102
103 int find_region(int x, int y, int width, int height)
104 {
14 Appendix A: Source Code Listings 144
148 {
149 y = y1 + (y2 - y1) * (width - x1) / (x2 - x1);
150 x = width - 1;
151 }
152 else //left
153 {
154 y = y1 + (y2 - y1) * -x1 / (x2 - x1);
155 x = 0;
156 }
157 if(codeout == code1) //first endpoint was clipped
158 {
159 x1 = x; y1 = y;
160 code1 = find_region(x1, y1, width, height);
161 }
162 else //second endpoint was clipped
163 {
164 x2 = x; y2 = y;
165 code2 = find_region(x2, y2, width, height);
166 }
167 }
168 }
169 while(done == 0);
170 if(accept)
171 {
172 x3 = x1;
173 x4 = x2;
174 y3 = y1;
175 y4 = y2;
176 coords2=std::make_tuple(x3,y3,x4,y4);
177 return 1;
178 }
179 else
180 {
181 x3 = x4 = y3 = y4 = 0;
182 coords2=std::make_tuple(x3,y3,x4,y4);
183 return 0;
184 }
185 }
186
187 void draw_filled_circle(int x, int y, int radius, std::vector<std::tuple<float, floa\
188 t, float>> &image, std::tuple<float, float, float, float> &colorRGBA, int width, int
189 height)
190 {
14 Appendix A: Source Code Listings 146
191 int x0 = 0;
192 int y0 = radius;
193 int d = 3 - 2 * radius;
194 std::tuple<int, int, int, int> coords1;
195 std::tuple<int, int, int, int> coords2;
196 if (!radius) return;
197
198 auto drawline = [&](int sx, int ex, int ny)
199 {
200 coords1=std::make_tuple(sx,ny,ex,ny);
201 if (clip_line(coords1,coords2,width,height)) {
202 sx=std::get<0>(coords2);
203 ny=std::get<1>(coords2);
204 ex=std::get<2>(coords2);
205 for (int i = sx; i <= ex; i++) {
206 image[get_index(i, ny, width)]=blend_colors(image[get_index(i, ny, w
207 RGBA);
208 }
209 }
210 };
211
212 while (y0 >= x0)
213 {
214 drawline(x - x0, x + x0, y - y0);
215 drawline(x - y0, x + y0, y - x0);
216 drawline(x - x0, x + x0, y + y0);
217 drawline(x - y0, x + y0, y + x0);
218 if (d < 0) d += 4 * x0++ + 6;
219 else d += 4 * (x0++ - y0--) + 10;
220 }
221 }
222
223 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
224 height, std::string filename)
225 {
226 std::tuple<float, float, float> color;
227 std::ofstream out(filename, std::ofstream::out);
228 out << "P3\n" << width << " " << height << "\n255\n";
229 for (int i=0;i<(width*height);++i)
230 {
231 color=image[i];
232 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
233 " " << int(std::get<2>(color)*255.0f) << '\n';
14 Appendix A: Source Code Listings 147
234 }
235 out.close();
236 }
237
238 int main()
239 {
240 std::ifstream infile("12_squint_with_your_eyes.txt");
241 std::string line;
242 std::tuple<int,int,int,float,float,float,float> circle;
243 std::tuple<int,int,float,float,float> bginfo;
244 std::tuple<float,float,float> colorBGRGB;
245 std::tuple<float,float,float,float> colorRGBA;
246 int width,height,xx,yy,r;
247 float rf,gf,bf,af;
248 float bg_rf,bg_gf,bg_bf;
249 std::vector<std::tuple<float, float, float>> image;
250 while (getline(infile, line))
251 {
252 if (startsWithCaseInsensitive(line,"c")) {
253 circle=parse_circle_line(line);
254 std::tie(xx,yy,r,rf,gf,bf,af) = circle;
255 colorRGBA=std::make_tuple(rf,gf,bf,af);
256 draw_filled_circle(xx,yy,r,image,colorRGBA,width,height);
257 }
258 if (startsWithCaseInsensitive(line,"b")) {
259 bginfo=parse_bginfo_line(line,width,height);
260 std::tie(width,height,bg_rf,bg_gf,bg_bf) = bginfo;
261 image.resize(calc_size(width, height));
262 colorBGRGB=std::make_tuple(bg_rf,bg_gf,bg_bf);
263 clear_image(image,colorBGRGB,width,height);
264 }
265 }
266 infile.close();
267
268 save_image(image,width,height,"12_squint_with_your_eyes.ppm");
269
270 return 0;
271 }
14 Appendix A: Source Code Listings 148
55 {
56 if (x2 < x1) std::swap(x1, x2);
57 for (x = x1; x <= x2; x++)
58 coords.push_back(std::make_tuple(x,y1));
59 return;
60 }
61 dx1 = abs(dx); dy1 = abs(dy);
62 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
63 if (dy1 <= dx1)
64 {
65 if (dx >= 0)
66 {
67 x = x1; y = y1; xe = x2;
68 }
69 else
70 {
71 x = x2; y = y2; xe = x1;
72 }
73 coords.push_back(std::make_tuple(x,y));
74 for (i = 0; x<xe; i++)
75 {
76 x = x + 1;
77 if (px<0)
78 px = px + 2 * dy1;
79 else
80 {
81 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
82 px = px + 2 * (dy1 - dx1);
83 }
84 coords.push_back(std::make_tuple(x,y));
85 }
86 }
87 else
88 {
89 if (dy >= 0)
90 {
91 x = x1; y = y1; ye = y2;
92 }
93 else
94 {
95 x = x2; y = y2; ye = y1;
96 }
97 coords.push_back(std::make_tuple(x,y));
14 Appendix A: Source Code Listings 162
141 }
142
143 void draw_filled_wedge(int x_cen,int y_cen,int rad,int start_ang,int end_ang,std::ve\
144 ctor<std::tuple<float, float, float>> &image,std::tuple<float, float, float> &color,
145 int width, int height)
146 {
147 std::vector<std::tuple<int,int>> coords;
148
149 float ang=(((start_ang<=end_ang)?start_ang:end_ang)*(M_PI/180));
150 float range=(((end_ang>start_ang)?end_ang:start_ang)*(M_PI/180));
151 float x=(rad*cos(ang));
152 float y=(rad*sin(ang));
153 do
154 {
155 coords.push_back(std::make_tuple((int)(x_cen+x+0.5),(int)(y_cen-y+0.5)));
156 ang+=0.001;
157 x=(rad*cos(ang));
158 y=(rad*sin(ang));
159 }
160 while(ang<=range);
161
162 std::tuple<int,int> co1=coords.front();
163 std::tuple<int,int> co2=coords.back();
164
165 draw_line_coords(x_cen,y_cen,std::get<0>(co1),std::get<1>(co1),coords);
166 draw_line_coords(x_cen,y_cen,std::get<0>(co2),std::get<1>(co2),coords);
167
168 std::vector<int> ys;
169 std::vector<int> xs;
170 get_all_ys(ys,coords);
171 std::vector<std::tuple<int,int,int,int>> lines;
172
173 for (int search=0;search<=ys.size();++search)
174 {
175 for (auto& c : coords) {
176 if (std::get<1>(c) == ys[search]) {
177 xs.push_back(std::get<0>(c));
178 }
179 }
180 sort(xs.begin(), xs.end());
181 lines.push_back(std::make_tuple(xs.front(),ys[search],xs.back(),ys[search]));
182 xs.clear();
183 }
14 Appendix A: Source Code Listings 164
184
185 auto drawline = [&](int sx, int ex, int ny)
186 {
187 for (int i = sx; i <= ex; i++)
188 image[get_index(i, ny, width)]=color;
189 };
190
191 for (auto& l : lines) {
192 drawline(std::get<0>(l),std::get<2>(l),std::get<1>(l));
193 }
194 }
195
196 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
197 height, std::string filename)
198 {
199 std::tuple<float, float, float> color;
200 std::ofstream out(filename, std::ofstream::out);
201 out << "P3\n" << width << " " << height << "\n255\n";
202 for (int i=0;i<(width*height);++i)
203 {
204 color=image[i];
205 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
206 " " << int(std::get<2>(color)*255.0f) << '\n';
207 }
208 out.close();
209 }
210
211 int main()
212 {
213 int width=640;
214 int height=360;
215
216 std::vector<std::tuple<float, float, float>> image;
217 std::tuple<float,float,float> color=std::make_tuple(0.0f,0.0f,0.0f);
218
219 image.resize(calc_size(width, height));
220 clear_image(image,width,height);
221
222 int x_cen,y_cen,rad,start_ang,end_ang;
223 x_cen=width/2;
224 y_cen=height/2;
225 rad=y_cen*0.8;
226 start_ang=0;
14 Appendix A: Source Code Listings 165
227 end_ang=348;
228 image[get_index(x_cen,y_cen, width)]=color;
229 draw_filled_wedge(x_cen,y_cen,rad,start_ang,end_ang,image,color,width,height);
230 color=std::make_tuple(0.5f,0.5f,0.5f);
231 draw_filled_wedge(x_cen,y_cen,rad/2,start_ang,end_ang,image,color,width,height);
232 color=std::make_tuple(0.8f,0.0f,0.8f);
233 draw_wedge(x_cen,y_cen,rad,start_ang,end_ang,image,color,width,height);
234
235 save_image(image,width,height,"12_wedge.ppm");
236
237 return 0;
238 }
29
30 void draw_line(int x1, int y1, int x2, int y2, std::vector<std::tuple<float, float, \
31 float>> &image, std::tuple<float,float,float> &color, int width, int height)
32 {
33 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
34 dx = x2 - x1; dy = y2 - y1;
35 if (dx == 0)
36 {
37 if (y2 < y1) std::swap(y1, y2);
38 for (y = y1; y <= y2; y++)
39 image[get_index(x1,y,width)]=color;
40 return;
41 }
42 if (dy == 0)
43 {
44 if (x2 < x1) std::swap(x1, x2);
45 for (x = x1; x <= x2; x++)
46 image[get_index(x,y1,width)]=color;
47 return;
48 }
49 dx1 = abs(dx); dy1 = abs(dy);
50 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
51 if (dy1 <= dx1)
52 {
53 if (dx >= 0)
54 {
55 x = x1; y = y1; xe = x2;
56 }
57 else
58 {
59 x = x2; y = y2; xe = x1;
60 }
61 image[get_index(x,y,width)]=color;
62 for (i = 0; x<xe; i++)
63 {
64 x = x + 1;
65 if (px<0)
66 px = px + 2 * dy1;
67 else
68 {
69 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
70 px = px + 2 * (dy1 - dx1);
71 }
14 Appendix A: Source Code Listings 167
72 image[get_index(x,y,width)]=color;
73 }
74 }
75 else
76 {
77 if (dy >= 0)
78 {
79 x = x1; y = y1; ye = y2;
80 }
81 else
82 {
83 x = x2; y = y2; ye = y1;
84 }
85 image[get_index(x,y,width)]=color;
86 for (i = 0; y<ye; i++)
87 {
88 y = y + 1;
89 if (py <= 0)
90 py = py + 2 * dx1;
91 else
92 {
93 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
94 py = py + 2 * (dx1 - dy1);
95 }
96 image[get_index(x,y,width)]=color;
97 }
98 }
99 }
100
101 void draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, std::vector<std::\
102 tuple<float, float, float>> &image, std::tuple<float,float,float> &color, int width,
103 int height)
104 {
105 draw_line(x1, y1, x2, y2, image, color, width, height);
106 draw_line(x2, y2, x3, y3, image, color, width, height);
107 draw_line(x3, y3, x1, y1, image, color, width, height);
108 }
109
110 void draw_filled_triangle(int x1, int y1, int x2, int y2, int x3, int y3, std::vecto\
111 r<std::tuple<float, float, float>> &image, std::tuple<float,float,float> &color, int
112 width, int height)
113 {
114 auto SWAP = [](int &x, int &y) { int t = x; x = y; y = t; };
14 Appendix A: Source Code Listings 168
115 auto drawline = [&](int sx, int ex, int ny) { for (int i = sx; i <= ex; i++) image[\
116 get_index(i,ny,width)]=color;};
117
118 int t1x, t2x, y, minx, maxx, t1xp, t2xp;
119 bool changed1 = false;
120 bool changed2 = false;
121 int signx1, signx2, dx1, dy1, dx2, dy2;
122 int e1, e2;
123 if (y1>y2) { SWAP(y1, y2); SWAP(x1, x2); }
124 if (y1>y3) { SWAP(y1, y3); SWAP(x1, x3); }
125 if (y2>y3) { SWAP(y2, y3); SWAP(x2, x3); }
126
127 t1x = t2x = x1; y = y1;
128 dx1 = (int)(x2 - x1); if (dx1<0) { dx1 = -dx1; signx1 = -1; }
129 else signx1 = 1;
130 dy1 = (int)(y2 - y1);
131
132 dx2 = (int)(x3 - x1); if (dx2<0) { dx2 = -dx2; signx2 = -1; }
133 else signx2 = 1;
134 dy2 = (int)(y3 - y1);
135
136 if (dy1 > dx1) {
137 SWAP(dx1, dy1);
138 changed1 = true;
139 }
140 if (dy2 > dx2) {
141 SWAP(dy2, dx2);
142 changed2 = true;
143 }
144
145 e2 = (int)(dx2 >> 1);
146 if (y1 == y2) goto next;
147 e1 = (int)(dx1 >> 1);
148
149 for (int i = 0; i < dx1;) {
150 t1xp = 0; t2xp = 0;
151 if (t1x<t2x) { minx = t1x; maxx = t2x; }
152 else { minx = t2x; maxx = t1x; }
153 while (i<dx1) {
154 i++;
155 e1 += dy1;
156 while (e1 >= dx1) {
157 e1 -= dx1;
14 Appendix A: Source Code Listings 169
244
245 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
246 height, std::string filename)
247 {
248 std::tuple<float, float, float> color;
249 std::ofstream out(filename, std::ofstream::out);
250 out << "P3\n" << width << " " << height << "\n255\n";
251 for (int i=0;i<(width*height);++i)
252 {
253 color=image[i];
254 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
255 " " << int(std::get<2>(color)*255.0f) << '\n';
256 }
257 out.close();
258 }
259
260 int main()
261 {
262 int width=640;
263 int height=360;
264 int x11=0,x12=0,x13=0,x21=0,x22=0,x23=0,y1=0,y2=0;
265
266 x11=((width-(((height/2)*0.8)*3))/2)+(((height/2)*0.8)/2);
267 x12=x11+(((height/2)*0.8)/2);
268 x13=x11-(((height/2)*0.8)/2);
269 x21=width-x11;
270 x22=x21+(((height/2)*0.8)/2);
271 x23=x21-(((height/2)*0.8)/2);
272 y1=(height-((height/2)*0.8))/2;
273 y2=y1+((height/2)*0.8);
274
275 std::vector<std::tuple<float, float, float>> image;
276 std::tuple<float,float,float> color=std::make_tuple(1.0f,1.0f,1.0f);
277
278 image.resize(calc_size(width, height));
279 clear_image(image,color,width,height);
280
281 color=std::make_tuple(0.0f,0.0f,0.0f);
282 draw_triangle(x11,y1,x12,y2,x13,y2,image,color,width,height);
283 draw_filled_triangle(x21,y1,x22,y2,x23,y2,image,color,width,height);
284
285 save_image(image,width,height,"13_trangles.ppm");
286
14 Appendix A: Source Code Listings 172
287 return 0;
288 }
43 }
44 }
45 }
46
47 std::string get_filname(int ctr)
48 {
49 std::stringstream ss;
50 ss << "anim05/" << std::setfill ('0') << std::setw(4) << ctr << "-swye05.ppm";
51
52 return ss.str();
53 }
54
55 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
56 height, std::string filename)
57 {
58 std::tuple<float, float, float> color;
59 std::ofstream out(filename, std::ofstream::out);
60 out << "P3\n" << width << " " << height << "\n255\n";
61 for (int i=0;i<(width*height);++i)
62 {
63 color=image[i];
64 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
65 " " << int(std::get<2>(color)*255.0f) << '\n';
66 }
67 out.close();
68 }
69
70 std::tuple<int,int> get_width_and_height(const std::string str)
71 {
72 size_t start;
73 size_t end = 0;
74 std::vector<std::string> out;
75
76 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
77 {
78 end = str.find(' ', start);
79 out.push_back(str.substr(start, end - start));
80 }
81
82 int w=stoi(out[0]);
83 int h=stoi(out[1]);
84
85 return std::make_tuple(w,h);
14 Appendix A: Source Code Listings 186
86 }
87
88 std::tuple<int,int,int> get_color(const std::string str)
89 {
90 size_t start;
91 size_t end = 0;
92 std::vector<std::string> out;
93
94 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
95 {
96 end = str.find(' ', start);
97 out.push_back(str.substr(start, end - start));
98 }
99
100 int r=stoi(out[0]);
101 int g=stoi(out[1]);
102 int b=stoi(out[2]);
103
104 return std::make_tuple(r,g,b);
105 }
106
107 void read_image(std::vector<std::tuple<float, float, float>> &image, int &width, int\
108 &height, std::string filename)
109 {
110 std::ifstream infile(filename);
111 std::tuple<int, int, int> rcolor;
112 std::tuple<float, float, float> wcolor;
113 std::tuple<int,int> widthnheight;
114 std::string line;
115 int state=0;
116 bool done = false;
117
118 while (getline(infile, line))
119 {
120 if (startsWithCaseInsensitive(line,"P3") && state == 0) {
121 state=1;
122 }
123
124 if (!startsWithCaseInsensitive(line,"#") && !startsWithCaseInsensitive(line,"P3") \
125 && state == 1) {
126 widthnheight=get_width_and_height(line);
127 width=std::get<0>(widthnheight);
128 height=std::get<1>(widthnheight);
14 Appendix A: Source Code Listings 187
129 state=2;
130 }
131
132 if (startsWithCaseInsensitive(line,"255") && state == 2) {
133 state=3;
134 }
135
136 if (!(line.compare("255") == 0) && state == 3) {
137 rcolor=get_color(line);
138 wcolor=std::make_tuple(float(std::get<0>(rcolor)/255.0f), float(std::get<1>(
139 r)/255.0f), float(std::get<2>(rcolor)/255.0f));
140 image.push_back(wcolor);
141 done = true;
142 }
143 }
144 infile.close();
145 }
146
147 void update_x_and_y(int r, std::tuple<int,int> &walk1, std::tuple<int,int> &walk2, i\
148 nt width, int height)
149 {
150 int x1,y1,x2,y2;
151 std::tie(x1,y1) = walk1;
152 std::tie(x2,y2) = walk2;
153
154 switch(r) {
155 case 0:
156 x1+=1;
157 x2-=1;
158 break;
159 case 1:
160 x1-=1;
161 x2+=1;
162 break;
163 case 2:
164 y1+=1;
165 y2-=1;
166 break;
167 case 3:
168 y1-=1;
169 y2+=1;
170 break;
171 }
14 Appendix A: Source Code Listings 188
172
173 if (x1 < 0) {
174 x1 = 0;
175 } else if (x1 > width-1) {
176 x1=width-1;
177 }
178
179 if (x2 < 0) {
180 x2 = 0;
181 } else if (x2 > width-1) {
182 x2=width-1;
183 }
184
185 if (y1 < 0) {
186 y1 = 0;
187 } else if (y1 > height-1) {
188 y1 = height-1;
189 }
190
191 if (y2 < 0) {
192 y2 = 0;
193 } else if (y2 > height-1) {
194 y2 = height-1;
195 }
196
197 walk1=std::make_tuple(x1,y1);
198 walk2=std::make_tuple(x2,y2);
199 }
200
201 void blended_two_images(std::vector<std::tuple<float, float, float>> &blend1,std::ve\
202 ctor<std::tuple<float, float, float>> &blend2,int width,int height,float alpha)
203 {
204 std::tuple<float, float, float> color1=std::make_tuple(0.0f,0.0f,0.0f);
205 std::tuple<float, float, float> color2=std::make_tuple(0.0f,0.0f,0.0f);
206 float r=0.0f; float g=0.0f; float b=0.0f;
207
208 for (int y=0;y<height;++y) {
209 for (int x=0;x<width;++x) {
210 color1=blend1[get_index(x,y,width)];
211 color2=blend2[get_index(x,y,width)];
212 r = (std::get<0>(color2) * alpha) + (std::get<0>(color1) * (1.0f - alpha));
213 g = (std::get<1>(color2) * alpha) + (std::get<1>(color1) * (1.0f - alpha));
214 b = (std::get<2>(color2) * alpha) + (std::get<2>(color1) * (1.0f - alpha));
14 Appendix A: Source Code Listings 189
258
259 int main()
260 {
261 fs::create_directory("anim05");
262 std::vector<std::tuple<float, float, float>> image1;
263 std::vector<std::tuple<float, float, float>> image2;
264 std::tuple<float, float, float> color=std::make_tuple(0.0f,0.0f,0.06666666667f);
265 int width=0;
266 int height=0;
267
268 read_image(image1, width, height, "ppm/04_helloworld.ppm");
269
270 image2.resize(calc_size(width, height));
271 clear_image(image2,color,width,height);
272 blended_two_images(image2,image1,width,height,0.2);
273 // Random Walker
274 walker(image1,image2,width,height);
275
276 // ffmpeg -framerate 15 -i %4d-swye05.ppm -c:v libx264 -r 30 swye05.mp4
277
278 return 0;
279 }
62 float rf=stof(out[3]);
63 float gf=stof(out[4]);
64 float bf=stof(out[5]);
65
66 return std::make_tuple(width,height,rf,gf,bf);
67 }
68
69 std::tuple<int,int,int,int,float,float,float,float> parse_rect_line(const std::strin\
70 g str)
71 {
72 size_t start;
73 size_t end = 0;
74 std::vector<std::string> out;
75
76 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
77 {
78 end = str.find(' ', start);
79 out.push_back(str.substr(start, end - start));
80 }
81
82 int x1=stoi(out[1]);
83 int y1=stoi(out[2]);
84 int x2=stoi(out[3]);
85 int y2=stoi(out[4]);
86 float rf=stof(out[5]);
87 float gf=stof(out[6]);
88 float bf=stof(out[7]);
89 float af=stof(out[8]);
90
91 return std::make_tuple(x1,y1,x2,y2,rf,gf,bf,af);
92 }
93
94 std::tuple<float,float,float> blend_colors(std::tuple<float,float,float> &colorBGRGB\
95 , std::tuple<float,float,float,float> &colorRGBA)
96 {
97 float r=0.0f; float g=0.0f; float b=0.0f;
98 r = (std::get<0>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<0>(colorBGRGB) * \
99 (1.0 - std::get<3>(colorRGBA)));
100 g = (std::get<1>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<1>(colorBGRGB) * \
101 (1.0 - std::get<3>(colorRGBA)));
102 b = (std::get<2>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<2>(colorBGRGB) * \
103 (1.0 - std::get<3>(colorRGBA)));
104
14 Appendix A: Source Code Listings 193
43 }
44 }
45 }
46
47 std::tuple<int,int,int,float,float,float,float> parse_circle_line(const std::string \
48 str)
49 {
50 size_t start;
51 size_t end = 0;
52 std::vector<std::string> out;
53
54 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
55 {
56 end = str.find(' ', start);
57 out.push_back(str.substr(start, end - start));
58 }
59
60 int dx=stoi(out[1]);
61 int dy=stoi(out[2]);
62 int r=stoi(out[3]);
63 float rf=stof(out[4]);
64 float gf=stof(out[5]);
65 float bf=stof(out[6]);
66 float af=stof(out[7]);
67
68 return std::make_tuple(dx,dy,r,rf,gf,bf,af);
69 }
70
71 std::tuple<int,int,float,float,float> parse_bginfo_line(const std::string str, int &\
72 width, int &height)
73 {
74 size_t start;
75 size_t end = 0;
76 std::vector<std::string> out;
77
78 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
79 {
80 end = str.find(' ', start);
81 out.push_back(str.substr(start, end - start));
82 }
83
84 width=stoi(out[1]);
85 height=stoi(out[2]);
14 Appendix A: Source Code Listings 197
86 float rf=stof(out[3]);
87 float gf=stof(out[4]);
88 float bf=stof(out[5]);
89
90 return std::make_tuple(width,height,rf,gf,bf);
91 }
92
93 std::tuple<float,float,float> blend_colors(std::tuple<float,float,float> &colorBGRGB\
94 , std::tuple<float,float,float,float> &colorRGBA)
95 {
96 float r=0.0f; float g=0.0f; float b=0.0f;
97 r = (std::get<0>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<0>(colorBGRGB) * \
98 (1.0 - std::get<3>(colorRGBA)));
99 g = (std::get<1>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<1>(colorBGRGB) * \
100 (1.0 - std::get<3>(colorRGBA)));
101 b = (std::get<2>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<2>(colorBGRGB) * \
102 (1.0 - std::get<3>(colorRGBA)));
103
104 return std::make_tuple(r,g,b);
105 }
106
107 int find_region(int x, int y, int width, int height)
108 {
109 int code=0;
110 if(y >= height)
111 code |= 1; //top
112 else if(y < 0)
113 code |= 2; //bottom
114 if(x >= width)
115 code |= 4; //right
116 else if (x < 0)
117 code |= 8; //left
118 return(code);
119 }
120
121 bool clip_line(std::tuple<int, int, int, int> &coords1, std::tuple<int, int, int, in\
122 t> &coords2, int width, int height)
123 {
124 int x1=std::get<0>(coords1); int y1=std::get<1>(coords1); int x2=std::get<2>(coords\
125 1); int y2=std::get<3>(coords1);
126 int x3=0; int y3=0; int x4=0; int y4=0;
127 int code1=0, code2=0, codeout=0;
128 bool accept = 0, done=0;
14 Appendix A: Source Code Listings 198
129 code1 = find_region(x1, y1, width, height); //the region outcodes for the endpoints
130 code2 = find_region(x2, y2, width, height);
131 do //In theory, this can never end up in an infinite loop, it'll always come in one\
132 of the trivial cases eventually
133 {
134 if(!(code1 | code2)) accept = done = 1; //accept because both endpoints are in sc\
135 reen or on the border, trivial accept
136 else if(code1 & code2) done = 1; //the line isn't visible on screen, trivial reject
137 else //if no trivial reject or accept, continue the loop
138 {
139 int x, y;
140 codeout = code1 ? code1 : code2;
141 if(codeout & 1) //top
142 {
143 x = x1 + (x2 - x1) * (height - y1) / (y2 - y1);
144 y = height - 1;
145 }
146 else if(codeout & 2) //bottom
147 {
148 x = x1 + (x2 - x1) * -y1 / (y2 - y1);
149 y = 0;
150 }
151 else if(codeout & 4) //right
152 {
153 y = y1 + (y2 - y1) * (width - x1) / (x2 - x1);
154 x = width - 1;
155 }
156 else //left
157 {
158 y = y1 + (y2 - y1) * -x1 / (x2 - x1);
159 x = 0;
160 }
161 if(codeout == code1) //first endpoint was clipped
162 {
163 x1 = x; y1 = y;
164 code1 = find_region(x1, y1, width, height);
165 }
166 else //second endpoint was clipped
167 {
168 x2 = x; y2 = y;
169 code2 = find_region(x2, y2, width, height);
170 }
171 }
14 Appendix A: Source Code Listings 199
172 }
173 while(done == 0);
174 if(accept)
175 {
176 x3 = x1;
177 x4 = x2;
178 y3 = y1;
179 y4 = y2;
180 coords2=std::make_tuple(x3,y3,x4,y4);
181 return 1;
182 }
183 else
184 {
185 x3 = x4 = y3 = y4 = 0;
186 coords2=std::make_tuple(x3,y3,x4,y4);
187 return 0;
188 }
189 }
190
191 void draw_filled_circle(int x, int y, int radius, std::vector<std::tuple<float, floa\
192 t, float>> &image, std::tuple<float, float, float, float> &colorRGBA, int width, int
193 height)
194 {
195 int x0 = 0;
196 int y0 = radius;
197 int d = 3 - 2 * radius;
198 std::tuple<int, int, int, int> coords1;
199 std::tuple<int, int, int, int> coords2;
200 if (!radius) return;
201
202 auto drawline = [&](int sx, int ex, int ny)
203 {
204 coords1=std::make_tuple(sx,ny,ex,ny);
205 if (clip_line(coords1,coords2,width,height)) {
206 sx=std::get<0>(coords2);
207 ny=std::get<1>(coords2);
208 ex=std::get<2>(coords2);
209 for (int i = sx; i <= ex; i++) {
210 image[get_index(i, ny, width)]=blend_colors(image[get_index(i, ny, w
211 RGBA);
212 }
213 }
214 };
14 Appendix A: Source Code Listings 200
215
216 while (y0 >= x0)
217 {
218 drawline(x - x0, x + x0, y - y0);
219 drawline(x - y0, x + y0, y - x0);
220 drawline(x - x0, x + x0, y + y0);
221 drawline(x - y0, x + y0, y + x0);
222 if (d < 0) d += 4 * x0++ + 6;
223 else d += 4 * (x0++ - y0--) + 10;
224 }
225 }
226
227 std::string get_filname(int ctr)
228 {
229 std::stringstream ss;
230 ss << "anim12/" << std::setfill ('0') << std::setw(3) << ctr << "-swye12.ppm";
231
232 return ss.str();
233 }
234
235 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
236 height, std::string filename)
237 {
238 std::tuple<float, float, float> color;
239 std::ofstream out(filename, std::ofstream::out);
240 out << "P3\n" << width << " " << height << "\n255\n";
241 for (int i=0;i<(width*height);++i)
242 {
243 color=image[i];
244 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
245 " " << int(std::get<2>(color)*255.0f) << '\n';
246 }
247 out.close();
248 }
249
250 int main()
251 {
252 fs::create_directory("anim12");
253 std::ifstream infile("12_squint_with_your_eyes.txt");
254 std::string line;
255 std::tuple<int,int,int,float,float,float,float> circle;
256 std::tuple<int,int,float,float,float> bginfo;
257 std::tuple<float,float,float> colorBGRGB;
14 Appendix A: Source Code Listings 201
43 }
44 }
45 }
46
47 std::tuple<int,int,float,float,float> parse_bginfo_line(const std::string str, int w\
48 idth, int height)
49 {
50 size_t start;
51 size_t end = 0;
52 std::vector<std::string> out;
53
54 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
55 {
56 end = str.find(' ', start);
57 out.push_back(str.substr(start, end - start));
58 }
59
60 width=stoi(out[1]);
61 height=stoi(out[2]);
62 float rf=stof(out[3]);
63 float gf=stof(out[4]);
64 float bf=stof(out[5]);
65
66 return std::make_tuple(width,height,rf,gf,bf);
67 }
68
69 std::tuple<int,int,int,int,float,float,float,float> parse_triangle_line(const std::s\
70 tring str)
71 {
72 size_t start;
73 size_t end = 0;
74 std::vector<std::string> out;
75
76 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
77 {
78 end = str.find(' ', start);
79 out.push_back(str.substr(start, end - start));
80 }
81
82 int x1=stoi(out[1]);
83 int y1=stoi(out[2]);
84 int x2=stoi(out[3]);
85 int y2=stoi(out[4]);
14 Appendix A: Source Code Listings 204
86 float rf=stof(out[5]);
87 float gf=stof(out[6]);
88 float bf=stof(out[7]);
89 float af=stof(out[8]);
90
91 return std::make_tuple(x1,y1,x2,y2,rf,gf,bf,af);
92 }
93
94 std::tuple<float,float,float> blend_colors(std::tuple<float,float,float> &colorBGRGB\
95 , std::tuple<float,float,float,float> &colorRGBA)
96 {
97 float r=0.0f; float g=0.0f; float b=0.0f;
98 r = (std::get<0>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<0>(colorBGRGB) * \
99 (1.0 - std::get<3>(colorRGBA)));
100 g = (std::get<1>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<1>(colorBGRGB) * \
101 (1.0 - std::get<3>(colorRGBA)));
102 b = (std::get<2>(colorRGBA) * std::get<3>(colorRGBA)) + (std::get<2>(colorBGRGB) * \
103 (1.0 - std::get<3>(colorRGBA)));
104
105 return std::make_tuple(r,g,b);
106 }
107
108 int find_region(int x, int y, int width, int height)
109 {
110 int code=0;
111 if(y >= height)
112 code |= 1; //top
113 else if(y < 0)
114 code |= 2; //bottom
115 if(x >= width)
116 code |= 4; //right
117 else if (x < 0)
118 code |= 8; //left
119 return(code);
120 }
121
122 bool clip_line(std::tuple<int, int, int, int> &coords1, std::tuple<int, int, int, in\
123 t> &coords2, int width, int height)
124 {
125 int x1=std::get<0>(coords1); int y1=std::get<1>(coords1); int x2=std::get<2>(coords\
126 1); int y2=std::get<3>(coords1);
127 int x3=0; int y3=0; int x4=0; int y4=0;
128 int code1=0, code2=0, codeout=0;
14 Appendix A: Source Code Listings 205
172 }
173 }
174 while(done == 0);
175 if(accept)
176 {
177 x3 = x1;
178 x4 = x2;
179 y3 = y1;
180 y4 = y2;
181 coords2=std::make_tuple(x3,y3,x4,y4);
182 return 1;
183 }
184 else
185 {
186 x3 = x4 = y3 = y4 = 0;
187 coords2=std::make_tuple(x3,y3,x4,y4);
188 return 0;
189 }
190 }
191
192 void draw_filled_triangle(int x1, int y1, int x2, int y2, int x3, int y3, std::vecto\
193 r<std::tuple<float, float, float>> &image, std::tuple<float,float,float,float> &colo
194 rRGBA, int width, int height)
195 {
196 std::tuple<int, int, int, int> coords1;
197 std::tuple<int, int, int, int> coords2;
198 auto SWAP = [](int &x, int &y) { int t = x; x = y; y = t; };
199 auto drawline = [&](int sx, int ex, int ny)
200 {
201 coords1=std::make_tuple(sx,ny,ex,ny);
202 if (clip_line(coords1,coords2,width,height)) {
203 sx=std::get<0>(coords2);
204 ny=std::get<1>(coords2);
205 ex=std::get<2>(coords2);
206 for (int i = sx; i <= ex; i++) {
207 image[get_index(i, ny, width)]=blend_colors(image[get_index(i, ny, w
208 RGBA);
209 }
210 }
211 };
212
213 int t1x, t2x, y, minx, maxx, t1xp, t2xp;
214 bool changed1 = false;
14 Appendix A: Source Code Listings 207
258 }
259 next1:
260 while (1) {
261 e2 += dy2;
262 while (e2 >= dx2) {
263 e2 -= dx2;
264 if (changed2) t2xp = signx2;
265 else goto next2;
266 }
267 if (changed2) break;
268 else t2x += signx2;
269 }
270 next2:
271 if (minx>t1x) minx = t1x;
272 if (minx>t2x) minx = t2x;
273 if (maxx<t1x) maxx = t1x;
274 if (maxx<t2x) maxx = t2x;
275 drawline(minx, maxx, y);
276 if (!changed1) t1x += signx1;
277 t1x += t1xp;
278 if (!changed2) t2x += signx2;
279 t2x += t2xp;
280 y += 1;
281 if (y == y2) break;
282
283 }
284 next:
285 dx1 = (int)(x3 - x2); if (dx1<0) { dx1 = -dx1; signx1 = -1; }
286 else signx1 = 1;
287 dy1 = (int)(y3 - y2);
288 t1x = x2;
289
290 if (dy1 > dx1) {
291 SWAP(dy1, dx1);
292 changed1 = true;
293 }
294 else changed1 = false;
295
296 e1 = (int)(dx1 >> 1);
297
298 for (int i = 0; i <= dx1; i++) {
299 t1xp = 0; t2xp = 0;
300 if (t1x<t2x) { minx = t1x; maxx = t2x; }
14 Appendix A: Source Code Listings 209
344
345 return ss.str();
346 }
347
348 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
349 height, std::string filename)
350 {
351 std::tuple<float, float, float> color;
352 std::ofstream out(filename, std::ofstream::out);
353 out << "P3\n" << width << " " << height << "\n255\n";
354 for (int i=0;i<(width*height);++i)
355 {
356 color=image[i];
357 out << int(std::get<0>(color)*255.0f) << " " << int(std::get<1>(color)*255.0f) << \
358 " " << int(std::get<2>(color)*255.0f) << '\n';
359 }
360 out.close();
361 }
362
363 int main()
364 {
365 fs::create_directory("anim13");
366 std::ifstream infile("13_squint_with_your_eyes.txt");
367 std::string line;
368 std::tuple<int,int,int,int,float,float,float,float> triangle;
369 std::tuple<int,int,float,float,float> bginfo;
370 std::tuple<float,float,float> colorBGRGB;
371 std::tuple<float,float,float,float> colorRGBA;
372 int width,height,x1,y1,x2,y2;
373 float rf,gf,bf,af;
374 float bg_rf,bg_gf,bg_bf;
375 std::vector<std::tuple<float, float, float>> image;
376 int ctr=0;
377 std::string fn="";
378 while (getline(infile, line))
379 {
380 if (startsWithCaseInsensitive(line,"t")) {
381 triangle=parse_triangle_line(line);
382 std::tie(x1,y1,x2,y2,rf,gf,bf,af) = triangle;
383 colorRGBA=std::make_tuple(rf,gf,bf,af);
384 draw_filled_triangle(x1,y2,x2,y1,x1,y1,image,colorRGBA,width,height);
385 fn=get_filname(ctr++);
386 std::cout << fn << std::endl;
14 Appendix A: Source Code Listings 211
387 save_image(image,width,height,fn);
388 draw_filled_triangle(x1,y2,x2,y1,x2,y2,image,colorRGBA,width,height);
389 fn=get_filname(ctr++);
390 std::cout << fn << std::endl;
391 save_image(image,width,height,fn);
392 }
393
394 if (startsWithCaseInsensitive(line,"b")) {
395 bginfo=parse_bginfo_line(line,width,height);
396 std::tie(width,height,bg_rf,bg_gf,bg_bf) = bginfo;
397 image.resize(calc_size(width, height));
398 colorBGRGB=std::make_tuple(bg_rf,bg_gf,bg_bf);
399 clear_image(image,colorBGRGB,width,height);
400 fn=get_filname(ctr++);
401 std::cout << fn << std::endl;
402 save_image(image,width,height,fn);
403 }
404 }
405 infile.close();
406
407 // ffmpeg -framerate 15 -i %4d-swye13.ppm -c:v libx264 -r 30 swye13.mp4
408
409 return 0;
410 }
60 {
61 int x0 = 0;
62 int y0 = radius;
63 int d = 3 - 2 * radius;
64 if (!radius) return;
65
66 auto drawline = [&](int sx, int ex, int ny)
67 {
68 for (int i = sx; i <= ex; i++)
69 image[get_index(i, ny, width)]=color;
70 };
71
72 while (y0 >= x0)
73 {
74 drawline(x - x0, x + x0, y - y0);
75 drawline(x - y0, x + y0, y - x0);
76 drawline(x - x0, x + x0, y + y0);
77 drawline(x - y0, x + y0, y + x0);
78 if (d < 0) d += 4 * x0++ + 6;
79 else d += 4 * (x0++ - y0--) + 10;
80 }
81 }
82
83 void floodfill_algorithm(int x, int y, std::vector<std::tuple<float, float, float>> \
84 &image, std::tuple<float, float, float> &ocolor, std::tuple<float, float, float> &nc
85 olor, int &width, int &height)
86 {
87 if ((x > 0) && (x < width) && (y > 0) && (y < height)) {
88 if (image[get_index(x,y,width)] == ocolor)
89 {
90 image[get_index(x,y,width)]=ncolor;
91 floodfill_algorithm(x+1,y,image,ocolor,ncolor,width,height);
92 floodfill_algorithm(x-1,y,image,ocolor,ncolor,width,height);
93 floodfill_algorithm(x,y+1,image,ocolor,ncolor,width,height);
94 floodfill_algorithm(x,y-1,image,ocolor,ncolor,width,height);
95 }
96 else return;
97 }
98 }
99
100 void get_all_ys(std::vector<int> &ys,std::vector<std::tuple<int,int>> &coords)
101 {
102 for (auto& c : coords) {
14 Appendix A: Source Code Listings 214
103 ys.push_back(std::get<1>(c));
104 }
105
106 sort(ys.begin(), ys.end());
107 ys.erase( unique( ys.begin(), ys.end() ), ys.end() );
108 }
109
110 void draw_line_coords(int x1, int y1, int x2, int y2,std::vector<std::tuple<int,int>\
111 > &coords)
112 {
113 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
114 dx = x2 - x1; dy = y2 - y1;
115 if (dx == 0)
116 {
117 if (y2 < y1) std::swap(y1, y2);
118 for (y = y1; y <= y2; y++)
119 coords.push_back(std::make_tuple(x1,y));
120 return;
121 }
122 if (dy == 0)
123 {
124 if (x2 < x1) std::swap(x1, x2);
125 for (x = x1; x <= x2; x++)
126 coords.push_back(std::make_tuple(x,y1));
127 return;
128 }
129 dx1 = abs(dx); dy1 = abs(dy);
130 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
131 if (dy1 <= dx1)
132 {
133 if (dx >= 0)
134 {
135 x = x1; y = y1; xe = x2;
136 }
137 else
138 {
139 x = x2; y = y2; xe = x1;
140 }
141 coords.push_back(std::make_tuple(x,y));
142 for (i = 0; x<xe; i++)
143 {
144 x = x + 1;
145 if (px<0)
14 Appendix A: Source Code Listings 215
146 px = px + 2 * dy1;
147 else
148 {
149 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
150 px = px + 2 * (dy1 - dx1);
151 }
152 coords.push_back(std::make_tuple(x,y));
153 }
154 }
155 else
156 {
157 if (dy >= 0)
158 {
159 x = x1; y = y1; ye = y2;
160 }
161 else
162 {
163 x = x2; y = y2; ye = y1;
164 }
165 coords.push_back(std::make_tuple(x,y));
166 for (i = 0; y<ye; i++)
167 {
168 y = y + 1;
169 if (py <= 0)
170 py = py + 2 * dx1;
171 else
172 {
173 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
174 py = py + 2 * (dx1 - dy1);
175 }
176 coords.push_back(std::make_tuple(x,y));
177 }
178 }
179 }
180
181 void draw_polygon(std::vector<std::tuple<int, int, int, int>> &polygon,std::vector<s\
182 td::tuple<float, float, float>> &image,std::tuple<float, float, float> &color, int w
183 idth, int height)
184 {
185 std::vector<std::tuple<int,int>> coords;
186
187 for (auto& po : polygon) {
188 draw_line_coords(std::get<0>(po),std::get<1>(po),std::get<2>(po),std::get<3>(po),c\
14 Appendix A: Source Code Listings 216
189 oords);
190 }
191
192 for (auto & e : coords) {
193 image[get_index(std::get<0>(e),std::get<1>(e),width)]=color;
194 }
195 }
196
197 void draw_filled_polygon(std::vector<std::tuple<int, int, int, int>> &polygon,std::v\
198 ector<std::tuple<float, float, float>> &image,std::tuple<float, float, float> &color
199 , int width, int height)
200 {
201 std::vector<std::tuple<int,int>> coords;
202
203 for (auto& po : polygon) {
204 draw_line_coords(std::get<0>(po),std::get<1>(po),std::get<2>(po),std::get<3>(po),c\
205 oords);
206 }
207
208 std::vector<int> ys;
209 std::vector<int> xs;
210 get_all_ys(ys,coords);
211 std::vector<std::tuple<int,int,int,int>> lines;
212
213 for (int search=0;search<=ys.size();++search)
214 {
215 for (auto& c : coords) {
216 if (std::get<1>(c) == ys[search]) {
217 xs.push_back(std::get<0>(c));
218 }
219 }
220 sort(xs.begin(), xs.end());
221 lines.push_back(std::make_tuple(xs.front(),ys[search],xs.back(),ys[search]));
222 xs.clear();
223 }
224
225 auto drawline = [&](int sx, int ex, int ny)
226 {
227 for (int i = sx; i <= ex; i++)
228 image[get_index(i, ny, width)]=color;
229 };
230
231 for (auto& l : lines) {
14 Appendix A: Source Code Listings 217
232 drawline(std::get<0>(l),std::get<2>(l),std::get<1>(l));
233 }
234 }
235
236 void draw_line(std::vector<std::tuple<float, float, float>> &image, std::tuple<int, \
237 int, int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
238 {
239 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
240 int y2=std::get<3>(coords);
241 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
242 dx = x2 - x1; dy = y2 - y1;
243 if (dx == 0)
244 {
245 if (y2 < y1) std::swap(y1, y2);
246 for (y = y1; y <= y2; y++)
247 image[get_index(x1,y,width)]=color;
248 return;
249 }
250 if (dy == 0)
251 {
252 if (x2 < x1) std::swap(x1, x2);
253 for (x = x1; x <= x2; x++)
254 image[get_index(x,y1,width)]=color;
255 return;
256 }
257 dx1 = abs(dx); dy1 = abs(dy);
258 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
259 if (dy1 <= dx1)
260 {
261 if (dx >= 0)
262 {
263 x = x1; y = y1; xe = x2;
264 }
265 else
266 {
267 x = x2; y = y2; xe = x1;
268 }
269 image[get_index(x,y,width)]=color;
270 for (i = 0; x<xe; i++)
271 {
272 x = x + 1;
273 if (px<0)
274 px = px + 2 * dy1;
14 Appendix A: Source Code Listings 218
275 else
276 {
277 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
278 px = px + 2 * (dy1 - dx1);
279 }
280 image[get_index(x,y,width)]=color;
281 }
282 }
283 else
284 {
285 if (dy >= 0)
286 {
287 x = x1; y = y1; ye = y2;
288 }
289 else
290 {
291 x = x2; y = y2; ye = y1;
292 }
293 image[get_index(x,y,width)]=color;
294 for (i = 0; y<ye; i++)
295 {
296 y = y + 1;
297 if (py <= 0)
298 py = py + 2 * dx1;
299 else
300 {
301 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
302 py = py + 2 * (dx1 - dy1);
303 }
304 image[get_index(x,y,width)]=color;
305 }
306 }
307 }
308
309 int find_region(int x, int y, int width, int height)
310 {
311 int code=0;
312 if(y >= height)
313 code |= 1; //top
314 else if(y < 0)
315 code |= 2; //bottom
316 if(x >= width)
317 code |= 4; //right
14 Appendix A: Source Code Listings 219
361 x = 0;
362 }
363 if(codeout == code1) //first endpoint was clipped
364 {
365 x1 = x; y1 = y;
366 code1 = find_region(x1, y1, width, height);
367 }
368 else //second endpoint was clipped
369 {
370 x2 = x; y2 = y;
371 code2 = find_region(x2, y2, width, height);
372 }
373 }
374 }
375 while(done == 0);
376 if(accept)
377 {
378 x3 = x1;
379 x4 = x2;
380 y3 = y1;
381 y4 = y2;
382 coords2=std::make_tuple(x3,y3,x4,y4);
383 return 1;
384 }
385 else
386 {
387 x3 = x4 = y3 = y4 = 0;
388 coords2=std::make_tuple(x3,y3,x4,y4);
389 return 0;
390 }
391 }
392
393 void get_angle_line(std::tuple<int, int, int, int> &coords,int x_cen,int y_cen,doubl\
394 e degrees,int length)
395 {
396 double angle = degrees * (M_PI / 180);
397 coords=std::make_tuple(x_cen,y_cen,int(double(x_cen) + cos(angle)*double(length)),i\
398 nt(double(y_cen) + sin(angle)*double(length)));
399 }
400
401 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
402 height, std::string filename)
403 {
14 Appendix A: Source Code Listings 221
447 polygon.push_back(coord);
448 coord=std::make_tuple(888,540,807,388);
449 polygon.push_back(coord);
450 coord=std::make_tuple(807,388,959,252);
451 polygon.push_back(coord);
452 coord=std::make_tuple(959,252,1214,285);
453 polygon.push_back(coord);
454 coord=std::make_tuple(1214,285,1248,540);
455 polygon.push_back(coord);
456
457 draw_filled_polygon(polygon,image,color,width,height);
458 color=std::make_tuple(1.0,0.0,1.0);
459 draw_polygon(polygon,image,color,width,height);
460
461 //
462
463 color=std::make_tuple(0.0,0.0,0.0);
464 get_angle_line(coord,x_cen,y_cen,degrees,length);
465 if (clip_line(coord,coord,width,height)) {
466 draw_line(image,coord,color,width,height);
467 }
468 degrees=45.0;
469 get_angle_line(coord,x_cen,y_cen,degrees,length);
470 if (clip_line(coord,coord,width,height)) {
471 draw_line(image,coord,color,width,height);
472 }
473 degrees=90.0;
474 get_angle_line(coord,x_cen,y_cen,degrees,length);
475 if (clip_line(coord,coord,width,height)) {
476 draw_line(image,coord,color,width,height);
477 }
478 degrees=135.0;
479 get_angle_line(coord,x_cen,y_cen,degrees,length);
480 if (clip_line(coord,coord,width,height)) {
481 draw_line(image,coord,color,width,height);
482 }
483 degrees=180.0;
484 get_angle_line(coord,x_cen,y_cen,degrees,length);
485 if (clip_line(coord,coord,width,height)) {
486 draw_line(image,coord,color,width,height);
487 }
488 degrees=225.0;
489 get_angle_line(coord,x_cen,y_cen,degrees,length);
14 Appendix A: Source Code Listings 223
490 if (clip_line(coord,coord,width,height)) {
491 draw_line(image,coord,color,width,height);
492 }
493 degrees=270.0;
494 get_angle_line(coord,x_cen,y_cen,degrees,length);
495 if (clip_line(coord,coord,width,height)) {
496 draw_line(image,coord,color,width,height);
497 }
498 degrees=315.0;
499 get_angle_line(coord,x_cen,y_cen,degrees,length);
500 if (clip_line(coord,coord,width,height)) {
501 draw_line(image,coord,color,width,height);
502 }
503
504 // 432;72
505 draw_circle((width/2),(height/2),72,image,color,width,height);
506 draw_circle((width/2),(height/2),72*2,image,color,width,height);
507 draw_circle((width/2),(height/2),72*3,image,color,width,height);
508 draw_circle((width/2),(height/2),72*4,image,color,width,height);
509 draw_circle((width/2),(height/2),72*5,image,color,width,height);
510 draw_circle((width/2),(height/2),72*6,image,color,width,height);
511
512 color=std::make_tuple(1.0,1.0,1.0);
513 draw_filled_circle(x_cen,y_cen,71,image,color,width,height);
514
515 //
516 std::tuple<float,float,float> ncolor=std::make_tuple(0.8470588235,0.8509803922,0.91\
517 37254902);
518 floodfill_algorithm(x_cen,y_cen,image,color,ncolor,width,height);
519
520 save_image(image,width,height,"15_radarchart.ppm");
521
522 return 0;
523 }
14 Appendix A: Source Code Listings 224
86 }
87 dx1 = abs(dx); dy1 = abs(dy);
88 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
89 if (dy1 <= dx1)
90 {
91 if (dx >= 0)
92 {
93 x = x1; y = y1; xe = x2;
94 }
95 else
96 {
97 x = x2; y = y2; xe = x1;
98 }
99 coords.push_back(std::make_tuple(x,y));
100 for (i = 0; x<xe; i++)
101 {
102 x = x + 1;
103 if (px<0)
104 px = px + 2 * dy1;
105 else
106 {
107 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
108 px = px + 2 * (dy1 - dx1);
109 }
110 coords.push_back(std::make_tuple(x,y));
111 }
112 }
113 else
114 {
115 if (dy >= 0)
116 {
117 x = x1; y = y1; ye = y2;
118 }
119 else
120 {
121 x = x2; y = y2; ye = y1;
122 }
123 coords.push_back(std::make_tuple(x,y));
124 for (i = 0; y<ye; i++)
125 {
126 y = y + 1;
127 if (py <= 0)
128 py = py + 2 * dx1;
14 Appendix A: Source Code Listings 227
129 else
130 {
131 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
132 py = py + 2 * (dx1 - dy1);
133 }
134 coords.push_back(std::make_tuple(x,y));
135 }
136 }
137 }
138
139 void draw_wedge(int x_cen,int y_cen,int rad,int start_ang,int end_ang,std::vector<st\
140 d::tuple<float, float, float>> &image,std::tuple<float, float, float> &color, int wi
141 dth, int height)
142 {
143 std::vector<std::tuple<int,int>> coords;
144
145 float ang=(((start_ang<=end_ang)?start_ang:end_ang)*(M_PI/180));
146 float range=(((end_ang>start_ang)?end_ang:start_ang)*(M_PI/180));
147 float x=(rad*cos(ang));
148 float y=(rad*sin(ang));
149 do
150 {
151 coords.push_back(std::make_tuple((int)(x_cen+x+0.5),(int)(y_cen-y+0.5)));
152 ang+=0.001;
153 x=(rad*cos(ang));
154 y=(rad*sin(ang));
155 }
156 while(ang<=range);
157
158 std::tuple<int,int> co1=coords.front();
159 std::tuple<int,int> co2=coords.back();
160
161 draw_line_coords(x_cen,y_cen,std::get<0>(co1),std::get<1>(co1),coords);
162 draw_line_coords(x_cen,y_cen,std::get<0>(co2),std::get<1>(co2),coords);
163
164 for (auto & e : coords) {
165 image[get_index(std::get<0>(e),std::get<1>(e),width)]=color;
166 }
167 }
168
169 void draw_filled_wedge(int x_cen,int y_cen,int rad,int start_ang,int end_ang,std::ve\
170 ctor<std::tuple<float, float, float>> &image,std::tuple<float, float, float> &color,
171 int width, int height)
14 Appendix A: Source Code Listings 228
172 {
173 std::vector<std::tuple<int,int>> coords;
174
175 float ang=(((start_ang<=end_ang)?start_ang:end_ang)*(M_PI/180));
176 float range=(((end_ang>start_ang)?end_ang:start_ang)*(M_PI/180));
177 float x=(rad*cos(ang));
178 float y=(rad*sin(ang));
179 do
180 {
181 coords.push_back(std::make_tuple((int)(x_cen+x+0.5),(int)(y_cen-y+0.5)));
182 ang+=0.001;
183 x=(rad*cos(ang));
184 y=(rad*sin(ang));
185 }
186 while(ang<=range);
187
188 std::tuple<int,int> co1=coords.front();
189 std::tuple<int,int> co2=coords.back();
190
191 draw_line_coords(x_cen,y_cen,std::get<0>(co1),std::get<1>(co1),coords);
192 draw_line_coords(x_cen,y_cen,std::get<0>(co2),std::get<1>(co2),coords);
193
194 std::vector<int> ys;
195 std::vector<int> xs;
196 get_all_ys(ys,coords);
197 std::vector<std::tuple<int,int,int,int>> lines;
198
199 for (int search=0;search<=ys.size();++search)
200 {
201 for (auto& c : coords) {
202 if (std::get<1>(c) == ys[search]) {
203 xs.push_back(std::get<0>(c));
204 }
205 }
206 sort(xs.begin(), xs.end());
207 lines.push_back(std::make_tuple(xs.front(),ys[search],xs.back(),ys[search]));
208 xs.clear();
209 }
210
211 auto drawline = [&](int sx, int ex, int ny)
212 {
213 for (int i = sx; i <= ex; i++)
214 image[get_index(i, ny, width)]=color;
14 Appendix A: Source Code Listings 229
215 };
216
217 for (auto& l : lines) {
218 drawline(std::get<0>(l),std::get<2>(l),std::get<1>(l));
219 }
220 }
221
222 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
223 height, std::string filename)
224 {
225 std::tuple<float, float, float> color;
226 std::ofstream out(filename, std::ios_base::out | std::ios_base::binary);
227 out << "P6" << std::endl << width << ' ' << height << std::endl << "255" << std::en\
228 dl;
229
230 for (int i=0;i<(width*height);++i)
231 {
232 color=image[i];
233 out << char(std::get<0>(color)*255.0f) << char(std::get<1>(color)*255.0f) << char(\
234 std::get<2>(color)*255.0f);
235 }
236 out.close();
237 }
238
239 int main()
240 {
241 int width=1920;
242 int height=1080;
243
244 float a1[] = {0.89,1.00,0.86,0.84,0.80,0.87,0.86,0.92,0.82,0.91,0.85,0.80,1.00,0.87\
245 ,0.85,0.93,0.97,0.94,1.00,0.91,0.85,0.92,0.96,0.82,0.94,0.83,0.93,0.95,1.00,0.98,0.9
246 6,0.97,0.80,1.00,0.93,0.86,0.90,0.93,0.92,0.90,0.92,0.98,0.84,1.00,0.92,0.92,0.83,0.
247 89,0.90,0.99,0.97,0.92};
248 float a2[] = {0.70,0.51,0.69,0.52,0.56,0.59,0.50,0.68,0.73,0.46,0.40,0.56,0.41,0.54\
249 ,0.64,0.45,0.56,0.45,0.41,0.60,0.68,0.45,0.65,0.60,0.65,0.66,0.57,0.47,0.47,0.58,0.5
250 7,0.48,0.41,0.62,0.50,0.46,0.75,0.50,0.71,0.56,0.57,0.53,0.75,0.45,0.51,0.47,0.71,0.
251 74,0.51,0.72,0.56,0.71};
252 float a3[] = {0.21,0.11,0.13,0.21,0.04,0.21,0.24,0.26,0.32,0.28,0.09,0.15,0.19,0.28\
253 ,0.22,0.25,0.03,0.22,0.18,0.15,0.31,0.08,0.27,0.07,0.08,0.10,0.08,0.23,0.17,0.11,0.3
254 4,0.29,0.10,0.09,0.06,0.31,0.32,0.22,0.26,0.21,0.14,0.13,0.08,0.15,0.27,0.04,0.06,0.
255 17,0.10,0.02,0.12,0.17};
256
257 std::vector<std::tuple<float, float, float>> image;
14 Appendix A: Source Code Listings 230
43
44 in >> width >> height >> max;
45
46 if (max != 255) {
47 std::cout << "Not 8 bit per rgb color." << std::endl;
48 exit(1);
49 }
50
51 if (magic == "P6")
52 {
53 // Move curser once to skip '\n'
54 in.seekg(1, in.cur);
55
56 for (int i = 0; i < width * height; ++i)
57 {
58 in.read(reinterpret_cast<char *>(buffer), 3);
59 color=std::make_tuple(float(float(buffer[0])/255.0),float(float(buffer[1])/2
60 ,float(float(buffer[2])/255.0));
61 image.push_back(color);
62 }
63 } else {
64 std::cout << "Not a P6 file." << std::endl;
65 exit(1);
66 }
67
68 in.close();
69 }
70
71 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
72 height, std::string filename)
73 {
74 std::tuple<float, float, float> color;
75 std::ofstream out(filename, std::ios_base::out | std::ios_base::binary);
76 out << "P6" << std::endl << width << ' ' << height << std::endl << "255" << std::en\
77 dl;
78
79 for (int i=0;i<(width*height);++i)
80 {
81 color=image[i];
82 out << char(std::get<0>(color)*255.0f) << char(std::get<1>(color)*255.0f) << char(\
83 std::get<2>(color)*255.0f);
84 }
85 out.close();
14 Appendix A: Source Code Listings 233
86 }
87
88 int main()
89 {
90 std::vector<std::tuple<float, float, float>> image;
91 int width,height;
92
93 std::cout << "loading: 15_read_p6_ppm.ppm" << std::endl;
94 load_image(image,width,height,"15_read_p6_ppm.ppm");
95 std::cout << "15_read_p6_ppm.ppm - w: " << width << " " << "h: " << height << std::\
96 endl;
97
98 std::cout << "saving: 15_read_p6_ppm_.ppm." << std::endl;
99 save_image(image,width,height,"15_read_p6_ppm_.ppm");
100
101 return 0;
102 }
24 }
25
26 int calc_size(int width, int height, int margin)
27 {
28 return (width+margin)*(height+margin);
29 }
30
31 void clear_image(std::vector<std::tuple<float, float, float>> &image, int width, int\
32 height, int margin)
33 {
34 for (int y=0;y<(height+margin);++y) {
35 for (int x=0;x<(width+margin);++x) {
36 image[get_index(x,y,(width+margin))]=std::make_tuple(1.0f, 1.0f, 1.0f);
37 }
38 }
39 }
40
41 void draw_filled_circle(int x, int y, int radius, std::vector<std::tuple<float, floa\
42 t, float>> &image, std::tuple<float, float, float> &color, int width, int height, in
43 t margin)
44 {
45 int x0 = 0;
46 int y0 = radius;
47 int d = 3 - 2 * radius;
48 if (!radius) return;
49
50 auto drawline = [&](int sx, int ex, int ny)
51 {
52 for (int i = sx; i <= ex; i++)
53 image[get_index(i, ny, width+margin)]=color;
54 };
55
56 while (y0 >= x0)
57 {
58 drawline(x - x0, x + x0, y - y0);
59 drawline(x - y0, x + y0, y - x0);
60 drawline(x - x0, x + x0, y + y0);
61 drawline(x - y0, x + y0, y + x0);
62 if (d < 0) d += 4 * x0++ + 6;
63 else d += 4 * (x0++ - y0--) + 10;
64 }
65 }
66
14 Appendix A: Source Code Listings 235
196 }
197 }
198
199 void draw_font_D(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
200 oat> &color, int width, int height, int margin)
201 {
202 // D
203 //points
204 float arr[4][2] = {{0.0,0.0},{0.0,1.0},{1.0,1.0},{1.0,0.4}};
205 //lines
206 int arr2[4][2] = {{0,1},{1,2},{2,3},{3,0}};
207 std::tuple<int, int, int, int> coords;
208 int halfmargin=margin/2;
209
210 for (int i=0;i<4;++i) {
211 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
212 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
213 rr2[i][1]][1])+halfmargin);
214 get_line_points(points,coords,color,width,height,margin);
215 }
216 }
217
218 void draw_font_E(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
219 oat> &color, int width, int height, int margin)
220 {
221 // E
222 //points
223 float arr[6][2] = {{1.0,0.0},{0.0,0.0},{0.0,0.5},{0.5,0.5},{0.0,1.0},{1.0,1.0}};
224 //lines
225 int arr2[4][2] = {{0,1},{1,2},{2,3},{4,5}};
226 std::tuple<int, int, int, int> coords;
227 int halfmargin=margin/2;
228
229 for (int i=0;i<4;++i) {
230 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
231 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
232 rr2[i][1]][1])+halfmargin);
233 get_line_points(points,coords,color,width,height,margin);
234 }
235 }
236
237 void draw_font_F(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
238 oat> &color, int width, int height, int margin)
14 Appendix A: Source Code Listings 239
239 {
240 // F
241 //points
242 float arr[5][2] = {{1.0,0.0},{0.0,0.0},{0.0,0.4},{0.5,0.4},{0.0,1.0}};
243 //lines
244 int arr2[4][2] = {{0,1},{1,2},{2,3},{2,4}};
245 std::tuple<int, int, int, int> coords;
246 int halfmargin=margin/2;
247
248 for (int i=0;i<4;++i) {
249 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
250 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
251 rr2[i][1]][1])+halfmargin);
252 get_line_points(points,coords,color,width,height,margin);
253 }
254 }
255
256 void draw_font_G(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
257 oat> &color, int width, int height, int margin)
258 {
259 // G
260 //points
261 float arr[6][2] = {{1.0,0.0},{0.0,0.0},{0.0,1.0},{1.0,1.0},{1.0,0.6},{0.5,0.6}};
262 //lines
263 int arr2[5][2] = {{0,1},{1,2},{2,3},{3,4},{4,5}};
264 std::tuple<int, int, int, int> coords;
265 int halfmargin=margin/2;
266
267 for (int i=0;i<5;++i) {
268 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
269 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
270 rr2[i][1]][1])+halfmargin);
271 get_line_points(points,coords,color,width,height,margin);
272 }
273 }
274
275 void draw_font_H(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
276 oat> &color, int width, int height, int margin)
277 {
278 // H
279 //points
280 float arr[6][2] = {{0.0,0.0},{0.0,1.0},{1.0,0.0},{1.0,1.0},{0.0,0.6},{1.0,0.6}};
281 //lines
14 Appendix A: Source Code Listings 240
368 }
369
370 void draw_font_M(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
371 oat> &color, int width, int height, int margin)
372 {
373 // M
374 //points
375 float arr[5][2] = {{0.0,1.0},{0.0,0.0},{0.5,0.3},{1.0,0.0},{1.0,1.0}};
376 //lines
377 int arr2[4][2] = {{0,1},{1,2},{2,3},{3,4}};
378 std::tuple<int, int, int, int> coords;
379 int halfmargin=margin/2;
380
381 for (int i=0;i<4;++i) {
382 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
383 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
384 rr2[i][1]][1])+halfmargin);
385 get_line_points(points,coords,color,width,height,margin);
386 }
387 }
388
389 void draw_font_N(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
390 oat> &color, int width, int height, int margin)
391 {
392 // N
393 //points
394 float arr[6][2] = {{0.0,0.0},{0.0,1.0},{1.0,0.0},{1.0,1.0},{0.0,0.0},{1.0,1.0}};
395 //lines
396 int arr2[3][2] = {{0,1},{2,3},{4,5}};
397 std::tuple<int, int, int, int> coords;
398 int halfmargin=margin/2;
399
400 for (int i=0;i<3;++i) {
401 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
402 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
403 rr2[i][1]][1])+halfmargin);
404 get_line_points(points,coords,color,width,height,margin);
405 }
406 }
407
408 void draw_font_O(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
409 oat> &color, int width, int height, int margin)
410 {
14 Appendix A: Source Code Listings 243
411 // O
412 //points
413 float arr[4][2] = {{1.0,0.0},{1.0,1.0},{0.0,1.0},{0.0,0.0}};
414 //lines
415 int arr2[4][2] = {{0,1},{1,2},{2,3},{3,0}};
416 std::tuple<int, int, int, int> coords;
417 int halfmargin=margin/2;
418
419 for (int i=0;i<4;++i) {
420 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
421 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
422 rr2[i][1]][1])+halfmargin);
423 get_line_points(points,coords,color,width,height,margin);
424 }
425 }
426
427 void draw_font_P(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
428 oat> &color, int width, int height, int margin)
429 {
430 // P
431 //points
432 float arr[5][2] = {{0.0,1.0},{0.0,0.0},{1.0,0.0},{1.0,0.3},{0.0,0.6}};
433 //lines
434 int arr2[4][2] = {{0,1},{1,2},{2,3},{3,4}};
435 std::tuple<int, int, int, int> coords;
436 int halfmargin=margin/2;
437
438 for (int i=0;i<4;++i) {
439 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
440 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
441 rr2[i][1]][1])+halfmargin);
442 get_line_points(points,coords,color,width,height,margin);
443 }
444 }
445
446 void draw_font_Q(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
447 oat> &color, int width, int height, int margin)
448 {
449 // Q
450 //points
451 float arr[7][2] = {{1.0,0.6},{1.0,0.0},{0.0,0.0},{0.0,1.0},{0.5,1.0},{0.5,0.6},{1.0\
452 ,1.0}};
453 //lines
14 Appendix A: Source Code Listings 244
540 }
541
542 void draw_font_V(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
543 oat> &color, int width, int height, int margin)
544 {
545 // V
546 //points
547 float arr[3][2] = {{0.0,0.0},{0.5,1.0},{1.0,0.0}};
548 //lines
549 int arr2[2][2] = {{0,1},{1,2}};
550 std::tuple<int, int, int, int> coords;
551 int halfmargin=margin/2;
552
553 for (int i=0;i<2;++i) {
554 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
555 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
556 rr2[i][1]][1])+halfmargin);
557 get_line_points(points,coords,color,width,height,margin);
558 }
559 }
560
561 void draw_font_W(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
562 oat> &color, int width, int height, int margin)
563 {
564 // W
565 //points
566 float arr[5][2] = {{0.0,0.0},{0.0,1.0},{0.5,0.7},{1.0,1.0},{1.0,0.0}};
567 //lines
568 int arr2[4][2] = {{0,1},{1,2},{2,3},{3,4}};
569 std::tuple<int, int, int, int> coords;
570 int halfmargin=margin/2;
571
572 for (int i=0;i<4;++i) {
573 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
574 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
575 rr2[i][1]][1])+halfmargin);
576 get_line_points(points,coords,color,width,height,margin);
577 }
578 }
579
580 void draw_font_X(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
581 oat> &color, int width, int height, int margin)
582 {
14 Appendix A: Source Code Listings 247
583 // X
584 //points
585 float arr[5][2] = {{0.5,0.6},{0.0,0.0},{1.0,0.0},{1.0,1.0},{0.0,1.0}};
586 //lines
587 int arr2[4][2] = {{0,1},{0,2},{0,3},{0,4}};
588 std::tuple<int, int, int, int> coords;
589 int halfmargin=margin/2;
590
591 for (int i=0;i<4;++i) {
592 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
593 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
594 rr2[i][1]][1])+halfmargin);
595 get_line_points(points,coords,color,width,height,margin);
596 }
597 }
598
599 void draw_font_Y(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
600 oat> &color, int width, int height, int margin)
601 {
602 // Y
603 //points
604 float arr[4][2] = {{0.5,0.6},{0.0,0.0},{1.0,0.0},{0.5,1.0}};
605 //lines
606 int arr2[3][2] = {{0,1},{0,2},{0,3}};
607 std::tuple<int, int, int, int> coords;
608 int halfmargin=margin/2;
609
610 for (int i=0;i<3;++i) {
611 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
612 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
613 rr2[i][1]][1])+halfmargin);
614 get_line_points(points,coords,color,width,height,margin);
615 }
616 }
617
618 void draw_font_Z(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
619 oat> &color, int width, int height, int margin)
620 {
621 // Z
622 //points
623 float arr[4][2] = {{0.0,0.0},{1.0,0.0},{0.0,1.0},{1.0,1.0}};
624 //lines
625 int arr2[3][2] = {{0,1},{1,2},{2,3}};
14 Appendix A: Source Code Listings 248
712
713 void draw_font_4(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
714 oat> &color, int width, int height, int margin)
715 {
716 // 4
717 //points
718 float arr[5][2] = {{0.0,0.0},{0.0,0.4},{1.0,0.6},{1.0,0.0},{1.0,1.0}};
719 //lines
720 int arr2[3][2] = {{0,1},{1,2},{3,4}};
721 std::tuple<int, int, int, int> coords;
722 int halfmargin=margin/2;
723
724 for (int i=0;i<3;++i) {
725 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
726 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
727 rr2[i][1]][1])+halfmargin);
728 get_line_points(points,coords,color,width,height,margin);
729 }
730 }
731
732 void draw_font_5(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
733 oat> &color, int width, int height, int margin)
734 {
735 // 5
736 //points
737 float arr[6][2] = {{1.0,0.0},{0.0,0.0},{0.0,0.5},{1.0,0.6},{1.0,1.0},{0.0,1.0}};
738 //lines
739 int arr2[5][2] = {{0,1},{1,2},{2,3},{3,4},{4,5}};
740 std::tuple<int, int, int, int> coords;
741 int halfmargin=margin/2;
742
743 for (int i=0;i<5;++i) {
744 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
745 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
746 rr2[i][1]][1])+halfmargin);
747 get_line_points(points,coords,color,width,height,margin);
748 }
749 }
750
751 void draw_font_6(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
752 oat> &color, int width, int height, int margin)
753 {
754 // 6
14 Appendix A: Source Code Listings 251
755 //points
756 float arr[6][2] = {{1.0,0.0},{0.0,0.0},{0.0,0.4},{1.0,0.6},{1.0,1.0},{0.0,1.0}};
757 //lines
758 int arr2[5][2] = {{0,1},{1,5},{5,4},{3,4},{3,2}};
759 std::tuple<int, int, int, int> coords;
760 int halfmargin=margin/2;
761
762 for (int i=0;i<5;++i) {
763 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
764 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
765 rr2[i][1]][1])+halfmargin);
766 get_line_points(points,coords,color,width,height,margin);
767 }
768 }
769
770 void draw_font_7(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
771 oat> &color, int width, int height, int margin)
772 {
773 // 7
774 //points
775 float arr[3][2] = {{0.0,0.0},{1.0,0.0},{1.0,1.0}};
776 //lines
777 int arr2[2][2] = {{0,1},{1,2}};
778 std::tuple<int, int, int, int> coords;
779 int halfmargin=margin/2;
780
781 for (int i=0;i<2;++i) {
782 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
783 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
784 rr2[i][1]][1])+halfmargin);
785 get_line_points(points,coords,color,width,height,margin);
786 }
787 }
788
789 void draw_font_8(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
790 oat> &color, int width, int height, int margin)
791 {
792 // 8
793 //points
794 float arr[6][2] = {{0.1,0.4},{0.9,0.6},{1.0,0.0},{0.0,0.0},{0.0,1.0},{1.0,1.0}};
795 //lines
796 int arr2[7][2] = {{0,1},{1,2},{2,3},{3,0},{0,4},{4,5},{5,1}};
797 std::tuple<int, int, int, int> coords;
14 Appendix A: Source Code Listings 252
841 rr2[i][1]][1])+halfmargin);
842 get_line_points(points,coords,color,width,height,margin);
843 }
844 }
845
846 void draw_font_PROCENT(std::vector<std::tuple<int,int>> &points, std::tuple<float,fl\
847 oat,float> &color, int width, int height, int margin)
848 {
849 // %
850 //points
851 float arr[10][2] = {{0.0,0.0},{0.3,0.0},{0.3,0.3},{0.0,0.3},{1.0,1.0},{0.7,1.0},{0.\
852 7,0.7},{1.0,0.7},{0.0,1.0},{1.0,0.0}};
853 //lines
854 int arr2[9][2] = {{0,1},{1,2},{2,3},{3,0},{4,5},{5,6},{6,7},{7,4},{8,9}};
855 std::tuple<int, int, int, int> coords;
856 int halfmargin=margin/2;
857
858 for (int i=0;i<9;++i) {
859 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
860 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
861 rr2[i][1]][1])+halfmargin);
862 get_line_points(points,coords,color,width,height,margin);
863 }
864 }
865
866 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
867 height, int margin, std::string filename)
868 {
869 std::tuple<float, float, float> color;
870 std::ofstream out(filename, std::ios_base::out | std::ios_base::binary);
871 out << "P6" << std::endl << (width+margin) << ' ' << (height+margin) << std::endl <\
872 < "255" << std::endl;
873
874 for (int i=0;i<((width+margin)*(height+margin));++i)
875 {
876 color=image[i];
877 out << char(std::get<0>(color)*255.0f) << char(std::get<1>(color)*255.0f) << char(\
878 std::get<2>(color)*255.0f);
879 }
880 out.close();
881 }
882
883 void draw(std::vector<std::tuple<int,int>> points,std::vector<std::tuple<float, floa\
14 Appendix A: Source Code Listings 254
884 t, float>> &image, std::tuple<float,float,float> color, int width, int height, int m
885 argin, int linesize)
886 {
887 for (auto& p : points) {
888 if (linesize == 1) {
889 image[get_index(std::get<0>(p),std::get<1>(p),width+margin)]=std::make_tuple
890 , 0.0f, 0.0f);
891 } else {
892 draw_filled_circle(std::get<0>(p),std::get<1>(p),linesize,image,color,width,
893 t,margin);
894 }
895 }
896 }
897
898 void draw_and_save_font(std::vector<std::tuple<float, float, float>> &image, std::tu\
899 ple<float,float,float> color, int width, int height, int margin, int linesize)
900 {
901 std::vector<std::tuple<int,int>> points;
902 draw_font_A(points,color,width,height,margin);
903 draw(points,image,color,width,height,margin,linesize);
904 save_image(image,width,height,margin,"15_draw_font_A.ppm");
905 points.clear();clear_image(image,width,height,margin);
906 draw_font_B(points,color,width,height,margin);
907 draw(points,image,color,width,height,margin,linesize);
908 save_image(image,width,height,margin,"15_draw_font_B.ppm");
909 points.clear();clear_image(image,width,height,margin);
910 draw_font_C(points,color,width,height,margin);
911 draw(points,image,color,width,height,margin,linesize);
912 save_image(image,width,height,margin,"15_draw_font_C.ppm");
913 points.clear();clear_image(image,width,height,margin);
914 draw_font_D(points,color,width,height,margin);
915 draw(points,image,color,width,height,margin,linesize);
916 save_image(image,width,height,margin,"15_draw_font_D.ppm");
917 points.clear();clear_image(image,width,height,margin);
918 draw_font_E(points,color,width,height,margin);
919 draw(points,image,color,width,height,margin,linesize);
920 save_image(image,width,height,margin,"15_draw_font_E.ppm");
921 points.clear();clear_image(image,width,height,margin);
922 draw_font_F(points,color,width,height,margin);
923 draw(points,image,color,width,height,margin,linesize);
924 save_image(image,width,height,margin,"15_draw_font_F.ppm");
925 points.clear();clear_image(image,width,height,margin);
926 draw_font_G(points,color,width,height,margin);
14 Appendix A: Source Code Listings 255
927 draw(points,image,color,width,height,margin,linesize);
928 save_image(image,width,height,margin,"15_draw_font_G.ppm");
929 points.clear();clear_image(image,width,height,margin);
930 draw_font_H(points,color,width,height,margin);
931 draw(points,image,color,width,height,margin,linesize);
932 save_image(image,width,height,margin,"15_draw_font_H.ppm");
933 points.clear();clear_image(image,width,height,margin);
934 draw_font_I(points,color,width,height,margin);
935 draw(points,image,color,width,height,margin,linesize);
936 save_image(image,width,height,margin,"15_draw_font_I.ppm");
937 points.clear();clear_image(image,width,height,margin);
938 draw_font_J(points,color,width,height,margin);
939 draw(points,image,color,width,height,margin,linesize);
940 save_image(image,width,height,margin,"15_draw_font_J.ppm");
941 points.clear();clear_image(image,width,height,margin);
942 draw_font_K(points,color,width,height,margin);
943 draw(points,image,color,width,height,margin,linesize);
944 save_image(image,width,height,margin,"15_draw_font_K.ppm");
945 points.clear();clear_image(image,width,height,margin);
946 draw_font_L(points,color,width,height,margin);
947 draw(points,image,color,width,height,margin,linesize);
948 save_image(image,width,height,margin,"15_draw_font_L.ppm");
949 points.clear();clear_image(image,width,height,margin);
950 draw_font_M(points,color,width,height,margin);
951 draw(points,image,color,width,height,margin,linesize);
952 save_image(image,width,height,margin,"15_draw_font_M.ppm");
953 points.clear();clear_image(image,width,height,margin);
954 draw_font_N(points,color,width,height,margin);
955 draw(points,image,color,width,height,margin,linesize);
956 save_image(image,width,height,margin,"15_draw_font_N.ppm");
957 points.clear();clear_image(image,width,height,margin);
958 draw_font_O(points,color,width,height,margin);
959 draw(points,image,color,width,height,margin,linesize);
960 save_image(image,width,height,margin,"15_draw_font_O.ppm");
961 points.clear();clear_image(image,width,height,margin);
962 draw_font_P(points,color,width,height,margin);
963 draw(points,image,color,width,height,margin,linesize);
964 save_image(image,width,height,margin,"15_draw_font_P.ppm");
965 points.clear();clear_image(image,width,height,margin);
966 draw_font_Q(points,color,width,height,margin);
967 draw(points,image,color,width,height,margin,linesize);
968 save_image(image,width,height,margin,"15_draw_font_Q.ppm");
969 points.clear();clear_image(image,width,height,margin);
14 Appendix A: Source Code Listings 256
970 draw_font_R(points,color,width,height,margin);
971 draw(points,image,color,width,height,margin,linesize);
972 save_image(image,width,height,margin,"15_draw_font_R.ppm");
973 points.clear();clear_image(image,width,height,margin);
974 draw_font_S(points,color,width,height,margin);
975 draw(points,image,color,width,height,margin,linesize);
976 save_image(image,width,height,margin,"15_draw_font_S.ppm");
977 points.clear();clear_image(image,width,height,margin);
978 draw_font_T(points,color,width,height,margin);
979 draw(points,image,color,width,height,margin,linesize);
980 save_image(image,width,height,margin,"15_draw_font_T.ppm");
981 points.clear();clear_image(image,width,height,margin);
982 draw_font_U(points,color,width,height,margin);
983 draw(points,image,color,width,height,margin,linesize);
984 save_image(image,width,height,margin,"15_draw_font_U.ppm");
985 points.clear();clear_image(image,width,height,margin);
986 draw_font_V(points,color,width,height,margin);
987 draw(points,image,color,width,height,margin,linesize);
988 save_image(image,width,height,margin,"15_draw_font_V.ppm");
989 points.clear();clear_image(image,width,height,margin);
990 draw_font_W(points,color,width,height,margin);
991 draw(points,image,color,width,height,margin,linesize);
992 save_image(image,width,height,margin,"15_draw_font_W.ppm");
993 points.clear();clear_image(image,width,height,margin);
994 draw_font_X(points,color,width,height,margin);
995 draw(points,image,color,width,height,margin,linesize);
996 save_image(image,width,height,margin,"15_draw_font_X.ppm");
997 points.clear();clear_image(image,width,height,margin);
998 draw_font_Y(points,color,width,height,margin);
999 draw(points,image,color,width,height,margin,linesize);
1000 save_image(image,width,height,margin,"15_draw_font_Y.ppm");
1001 points.clear();clear_image(image,width,height,margin);
1002 draw_font_Z(points,color,width,height,margin);
1003 draw(points,image,color,width,height,margin,linesize);
1004 save_image(image,width,height,margin,"15_draw_font_Z.ppm");
1005 points.clear();clear_image(image,width,height,margin);
1006 draw_font_0(points,color,width,height,margin);
1007 draw(points,image,color,width,height,margin,linesize);
1008 save_image(image,width,height,margin,"15_draw_font_0.ppm");
1009 points.clear();clear_image(image,width,height,margin);
1010 draw_font_1(points,color,width,height,margin);
1011 draw(points,image,color,width,height,margin,linesize);
1012 save_image(image,width,height,margin,"15_draw_font_1.ppm");
14 Appendix A: Source Code Listings 257
1013 points.clear();clear_image(image,width,height,margin);
1014 draw_font_2(points,color,width,height,margin);
1015 draw(points,image,color,width,height,margin,linesize);
1016 save_image(image,width,height,margin,"15_draw_font_2.ppm");
1017 points.clear();clear_image(image,width,height,margin);
1018 draw_font_3(points,color,width,height,margin);
1019 draw(points,image,color,width,height,margin,linesize);
1020 save_image(image,width,height,margin,"15_draw_font_3.ppm");
1021 points.clear();clear_image(image,width,height,margin);
1022 draw_font_4(points,color,width,height,margin);
1023 draw(points,image,color,width,height,margin,linesize);
1024 save_image(image,width,height,margin,"15_draw_font_4.ppm");
1025 points.clear();clear_image(image,width,height,margin);
1026 draw_font_5(points,color,width,height,margin);
1027 draw(points,image,color,width,height,margin,linesize);
1028 save_image(image,width,height,margin,"15_draw_font_5.ppm");
1029 points.clear();clear_image(image,width,height,margin);
1030 draw_font_6(points,color,width,height,margin);
1031 draw(points,image,color,width,height,margin,linesize);
1032 save_image(image,width,height,margin,"15_draw_font_6.ppm");
1033 points.clear();clear_image(image,width,height,margin);
1034 draw_font_7(points,color,width,height,margin);
1035 draw(points,image,color,width,height,margin,linesize);
1036 save_image(image,width,height,margin,"15_draw_font_7.ppm");
1037 points.clear();clear_image(image,width,height,margin);
1038 draw_font_8(points,color,width,height,margin);
1039 draw(points,image,color,width,height,margin,linesize);
1040 save_image(image,width,height,margin,"15_draw_font_8.ppm");
1041 points.clear();clear_image(image,width,height,margin);
1042 draw_font_9(points,color,width,height,margin);
1043 draw(points,image,color,width,height,margin,linesize);
1044 save_image(image,width,height,margin,"15_draw_font_9.ppm");
1045 points.clear();clear_image(image,width,height,margin);
1046 draw_font_QA(points,color,width,height,margin);
1047 draw(points,image,color,width,height,margin,linesize);
1048 save_image(image,width,height,margin,"15_draw_font_questionmark.ppm");
1049 points.clear();clear_image(image,width,height,margin);
1050 draw_font_PROCENT(points,color,width,height,margin);
1051 draw(points,image,color,width,height,margin,linesize);
1052 save_image(image,width,height,margin,"15_draw_font_procent.ppm");
1053 }
1054
1055 int main()
14 Appendix A: Source Code Listings 258
1056 {
1057 int width=0;int height=40;
1058 int margin=0;
1059 int linesize=3;
1060 std::vector<std::tuple<float, float, float>> image;
1061 std::tuple<float,float,float> color=std::make_tuple(0.0f,0.0f,0.0f);
1062
1063 get_width_from_height(width,height);
1064 get_margin_from_height(margin,height);
1065 std::cout << "w: " << width << " h: " << height << " m: " << margin << " ls: " << l\
1066 inesize << std::endl;
1067
1068 image.resize(calc_size(width, height, margin));
1069 clear_image(image,width,height,margin);
1070
1071 draw_and_save_font(image,color,width,height,margin,linesize);
1072
1073 return 0;
1074 }
22 {
23 for (int y=0;y<(height+margin);++y) {
24 for (int x=0;x<(width+margin);++x) {
25 image[get_index(x,y,(width+margin))]=std::make_tuple(0.262745098f, 0.2627450
26 0.262745098f);
27 }
28 }
29 }
30
31 void draw_filled_rect(int x, int y, int w, int h, std::vector<std::tuple<float, floa\
32 t, float>> &image, std::tuple<float,float,float> &color, int width, int height)
33 {
34 int x2 = x + w;
35 int y2 = y + h;
36
37 if (x < 0) {x = 0;}
38 if (x >= width) {x = width;}
39 if (y < 0) {y = 0;}
40 if (y >= height) {y = height;}
41
42 if (x2 < 0) {x2 = 0;}
43 if (x2 >= width) {x2 = width;}
44 if (y2 < 0) {y2 = 0;}
45 if (y2 >= height) {y2 = height;}
46
47 for (int i = y; i < y2; i++) {
48 for (int j = x; j < x2; j++) {
49 image[get_index(j,i,width)]=color;
50 }
51 }
52 }
53
54 void draw_line(std::vector<std::tuple<float, float, float>> &image, std::tuple<int, \
55 int, int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
56 {
57 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
58 int y2=std::get<3>(coords);
59 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
60 dx = x2 - x1; dy = y2 - y1;
61 if (dx == 0)
62 {
63 if (y2 < y1) std::swap(y1, y2);
64 for (y = y1; y <= y2; y++)
14 Appendix A: Source Code Listings 260
65 image[get_index(x1,y,width)]=color;
66 return;
67 }
68 if (dy == 0)
69 {
70 if (x2 < x1) std::swap(x1, x2);
71 for (x = x1; x <= x2; x++)
72 image[get_index(x,y1,width)]=color;
73 return;
74 }
75 dx1 = abs(dx); dy1 = abs(dy);
76 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
77 if (dy1 <= dx1)
78 {
79 if (dx >= 0)
80 {
81 x = x1; y = y1; xe = x2;
82 }
83 else
84 {
85 x = x2; y = y2; xe = x1;
86 }
87 image[get_index(x,y,width)]=color;
88 for (i = 0; x<xe; i++)
89 {
90 x = x + 1;
91 if (px<0)
92 px = px + 2 * dy1;
93 else
94 {
95 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
96 px = px + 2 * (dy1 - dx1);
97 }
98 image[get_index(x,y,width)]=color;
99 }
100 }
101 else
102 {
103 if (dy >= 0)
104 {
105 x = x1; y = y1; ye = y2;
106 }
107 else
14 Appendix A: Source Code Listings 261
108 {
109 x = x2; y = y2; ye = y1;
110 }
111 image[get_index(x,y,width)]=color;
112 for (i = 0; y<ye; i++)
113 {
114 y = y + 1;
115 if (py <= 0)
116 py = py + 2 * dx1;
117 else
118 {
119 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
120 py = py + 2 * (dx1 - dy1);
121 }
122 image[get_index(x,y,width)]=color;
123 }
124 }
125 }
126
127 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
128 height, std::string filename)
129 {
130 std::tuple<float, float, float> color;
131 std::ofstream out(filename, std::ios_base::out | std::ios_base::binary);
132 out << "P6" << std::endl << width << ' ' << height << std::endl << "255" << std::en\
133 dl;
134
135 for (int i=0;i<(width*height);++i)
136 {
137 color=image[i];
138 out << char(std::get<0>(color)*255.0f) << char(std::get<1>(color)*255.0f) << char(\
139 std::get<2>(color)*255.0f);
140 }
141 out.close();
142 }
143
144 int main()
145 {
146 std::vector<std::tuple<float, float, float>> image;
147 std::tuple<int, int, int, int> coords;
148 std::tuple<float,float,float> color=std::make_tuple(1.0f,0.7647058824f,0.6235294118\
149 f);
150 int width=1600,height=900;
14 Appendix A: Source Code Listings 262
194 draw_filled_rect(580+(1*136),714,33,3,image,color,width,height);
195 draw_filled_rect(610+(1*136),717,3,10,image,color,width,height);
196 draw_filled_rect(613+(1*136),724,8,3,image,color,width,height);
197 draw_filled_rect(611+(1*136),715,3,3,image,color,width,height);
198 draw_filled_rect(612+(1*136),716,3,3,image,color,width,height);
199 draw_filled_rect(613+(1*136),717,3,3,image,color,width,height);
200 draw_filled_rect(614+(1*136),718,3,3,image,color,width,height);
201 draw_filled_rect(615+(1*136),719,3,3,image,color,width,height);
202 draw_filled_rect(616+(1*136),720,3,3,image,color,width,height);
203 draw_filled_rect(617+(1*136),721,3,3,image,color,width,height);
204 draw_filled_rect(618+(1*136),722,3,3,image,color,width,height);
205 draw_filled_rect(619+(1*136),723,3,3,image,color,width,height);
206
207 // icon 3
208 draw_filled_rect(577+(2*136),714,3,39,image,color,width,height);
209 draw_filled_rect(571+(2*136),753,35,3,image,color,width,height);
210 draw_filled_rect(571+(2*136),756,3,14,image,color,width,height);
211 draw_filled_rect(574+(2*136),767,32,3,image,color,width,height);
212 draw_filled_rect(603+(2*136),756,3,11,image,color,width,height);
213 draw_filled_rect(577+(2*136),770,3,7,image,color,width,height);
214 draw_filled_rect(580+(2*136),774,43,3,image,color,width,height);
215 draw_filled_rect(620+(2*136),724,3,53,image,color,width,height);
216 draw_filled_rect(580+(2*136),714,33,3,image,color,width,height);
217 draw_filled_rect(610+(2*136),717,3,10,image,color,width,height);
218 draw_filled_rect(613+(2*136),724,8,3,image,color,width,height);
219 draw_filled_rect(611+(2*136),715,3,3,image,color,width,height);
220 draw_filled_rect(612+(2*136),716,3,3,image,color,width,height);
221 draw_filled_rect(613+(2*136),717,3,3,image,color,width,height);
222 draw_filled_rect(614+(2*136),718,3,3,image,color,width,height);
223 draw_filled_rect(615+(2*136),719,3,3,image,color,width,height);
224 draw_filled_rect(616+(2*136),720,3,3,image,color,width,height);
225 draw_filled_rect(617+(2*136),721,3,3,image,color,width,height);
226 draw_filled_rect(618+(2*136),722,3,3,image,color,width,height);
227 draw_filled_rect(619+(2*136),723,3,3,image,color,width,height);
228
229 // icon 4
230 draw_filled_rect(577+(3*136),714,3,39,image,color,width,height);
231 draw_filled_rect(571+(3*136),753,35,3,image,color,width,height);
232 draw_filled_rect(571+(3*136),756,3,14,image,color,width,height);
233 draw_filled_rect(574+(3*136),767,32,3,image,color,width,height);
234 draw_filled_rect(603+(3*136),756,3,11,image,color,width,height);
235 draw_filled_rect(577+(3*136),770,3,7,image,color,width,height);
236 draw_filled_rect(580+(3*136),774,43,3,image,color,width,height);
14 Appendix A: Source Code Listings 264
237 draw_filled_rect(620+(3*136),724,3,53,image,color,width,height);
238 draw_filled_rect(580+(3*136),714,33,3,image,color,width,height);
239 draw_filled_rect(610+(3*136),717,3,10,image,color,width,height);
240 draw_filled_rect(613+(3*136),724,8,3,image,color,width,height);
241 draw_filled_rect(611+(3*136),715,3,3,image,color,width,height);
242 draw_filled_rect(612+(3*136),716,3,3,image,color,width,height);
243 draw_filled_rect(613+(3*136),717,3,3,image,color,width,height);
244 draw_filled_rect(614+(3*136),718,3,3,image,color,width,height);
245 draw_filled_rect(615+(3*136),719,3,3,image,color,width,height);
246 draw_filled_rect(616+(3*136),720,3,3,image,color,width,height);
247 draw_filled_rect(617+(3*136),721,3,3,image,color,width,height);
248 draw_filled_rect(618+(3*136),722,3,3,image,color,width,height);
249 draw_filled_rect(619+(3*136),723,3,3,image,color,width,height);
250
251 // 35%
252 coords=std::make_tuple(579,234,586,234);
253 draw_line(image,coords,color,width,height);
254 coords=std::make_tuple(586,252,586,234);
255 draw_line(image,coords,color,width,height);
256 coords=std::make_tuple(586,252,579,252);
257 draw_line(image,coords,color,width,height);
258 coords=std::make_tuple(586,242,580,242);
259 draw_line(image,coords,color,width,height);
260 coords=std::make_tuple(591,234,598,234);
261 draw_line(image,coords,color,width,height);
262 coords=std::make_tuple(591,242,598,242);
263 draw_line(image,coords,color,width,height);
264 coords=std::make_tuple(591,242,598,242);
265 draw_line(image,coords,color,width,height);
266 coords=std::make_tuple(591,252,598,252);
267 draw_line(image,coords,color,width,height);
268 coords=std::make_tuple(591,234,591,242);
269 draw_line(image,coords,color,width,height);
270 coords=std::make_tuple(598,242,598,252);
271 draw_line(image,coords,color,width,height);
272 coords=std::make_tuple(602,251,617,233);
273 draw_line(image,coords,color,width,height);
274 coords=std::make_tuple(602,234,608,234);
275 draw_line(image,coords,color,width,height);
276 coords=std::make_tuple(602,234,602,239);
277 draw_line(image,coords,color,width,height);
278 coords=std::make_tuple(602,239,608,239);
279 draw_line(image,coords,color,width,height);
14 Appendix A: Source Code Listings 265
280 coords=std::make_tuple(608,239,608,234);
281 draw_line(image,coords,color,width,height);
282 coords=std::make_tuple(611,246,616,246);
283 draw_line(image,coords,color,width,height);
284 coords=std::make_tuple(611,251,616,251);
285 draw_line(image,coords,color,width,height);
286 coords=std::make_tuple(611,251,611,246);
287 draw_line(image,coords,color,width,height);
288 coords=std::make_tuple(616,251,616,246);
289 draw_line(image,coords,color,width,height);
290
291 // 23%
292 coords=std::make_tuple(715,409,722,409);
293 draw_line(image,coords,color,width,height);
294 coords=std::make_tuple(715,426,722,426);
295 draw_line(image,coords,color,width,height);
296 coords=std::make_tuple(722,409,722,417);
297 draw_line(image,coords,color,width,height);
298 coords=std::make_tuple(722,417,715,426);
299 draw_line(image,coords,color,width,height);
300 coords=std::make_tuple(726,409,733,409);
301 draw_line(image,coords,color,width,height);
302 coords=std::make_tuple(726,417,733,417);
303 draw_line(image,coords,color,width,height);
304 coords=std::make_tuple(726,426,733,426);
305 draw_line(image,coords,color,width,height);
306 coords=std::make_tuple(733,426,733,409);
307 draw_line(image,coords,color,width,height);
308 coords=std::make_tuple(737,409,737,414);
309 draw_line(image,coords,color,width,height);
310 coords=std::make_tuple(737,414,743,414);
311 draw_line(image,coords,color,width,height);
312 coords=std::make_tuple(743,414,743,409);
313 draw_line(image,coords,color,width,height);
314 coords=std::make_tuple(743,409,737,409);
315 draw_line(image,coords,color,width,height);
316 coords=std::make_tuple(746,421,746,426);
317 draw_line(image,coords,color,width,height);
318 coords=std::make_tuple(746,426,751,426);
319 draw_line(image,coords,color,width,height);
320 coords=std::make_tuple(751,426,751,421);
321 draw_line(image,coords,color,width,height);
322 coords=std::make_tuple(751,421,746,421);
14 Appendix A: Source Code Listings 266
323 draw_line(image,coords,color,width,height);
324 coords=std::make_tuple(737,426,751,409);
325 draw_line(image,coords,color,width,height);
326
327 // 10%
328 coords=std::make_tuple(853,537,853,555);
329 draw_line(image,coords,color,width,height);
330 coords=std::make_tuple(857,537,857,555);
331 draw_line(image,coords,color,width,height);
332 coords=std::make_tuple(857,555,867,555);
333 draw_line(image,coords,color,width,height);
334 coords=std::make_tuple(867,555,867,537);
335 draw_line(image,coords,color,width,height);
336 coords=std::make_tuple(867,537,857,537);
337 draw_line(image,coords,color,width,height);
338 coords=std::make_tuple(871,555,886,537);
339 draw_line(image,coords,color,width,height);
340 coords=std::make_tuple(871,537,871,543);
341 draw_line(image,coords,color,width,height);
342 coords=std::make_tuple(871,543,877,543);
343 draw_line(image,coords,color,width,height);
344 coords=std::make_tuple(877,543,877,537);
345 draw_line(image,coords,color,width,height);
346 coords=std::make_tuple(877,537,871,537);
347 draw_line(image,coords,color,width,height);
348 coords=std::make_tuple(880,549,880,555);
349 draw_line(image,coords,color,width,height);
350 coords=std::make_tuple(880,555,885,555);
351 draw_line(image,coords,color,width,height);
352 coords=std::make_tuple(885,555,885,549);
353 draw_line(image,coords,color,width,height);
354 coords=std::make_tuple(885,549,880,549);
355 draw_line(image,coords,color,width,height);
356
357 // 32%
358 coords=std::make_tuple(993,272,986,272);
359 draw_line(image,coords,color,width,height);
360 coords=std::make_tuple(993,280,986,280);
361 draw_line(image,coords,color,width,height);
362 coords=std::make_tuple(993,291,986,291);
363 draw_line(image,coords,color,width,height);
364 coords=std::make_tuple(993,291,993,272);
365 draw_line(image,coords,color,width,height);
14 Appendix A: Source Code Listings 267
366 coords=std::make_tuple(997,272,1005,272);
367 draw_line(image,coords,color,width,height);
368 coords=std::make_tuple(1005,272,1005,280);
369 draw_line(image,coords,color,width,height);
370 coords=std::make_tuple(1005,280,997,291);
371 draw_line(image,coords,color,width,height);
372 coords=std::make_tuple(997,291,1005,291);
373 draw_line(image,coords,color,width,height);
374 coords=std::make_tuple(1007,291,1023,272);
375 draw_line(image,coords,color,width,height);
376 coords=std::make_tuple(1008,272,1008,277);
377 draw_line(image,coords,color,width,height);
378 coords=std::make_tuple(1008,272,1008,277);
379 draw_line(image,coords,color,width,height);
380 coords=std::make_tuple(1008,277,1013,277);
381 draw_line(image,coords,color,width,height);
382 coords=std::make_tuple(1013,277,1013,272);
383 draw_line(image,coords,color,width,height);
384 coords=std::make_tuple(1013,272,1008,272);
385 draw_line(image,coords,color,width,height);
386 coords=std::make_tuple(1016,284,1016,289);
387 draw_line(image,coords,color,width,height);
388 coords=std::make_tuple(1016,289,1022,289);
389 draw_line(image,coords,color,width,height);
390 coords=std::make_tuple(1022,289,1022,284);
391 draw_line(image,coords,color,width,height);
392 coords=std::make_tuple(1022,284,1016,284);
393 draw_line(image,coords,color,width,height);
394
395 std::cout << "saving: 16_draw_bar_chart.ppm." << std::endl;
396 save_image(image,width,height,"16_draw_bar_chart.ppm");
397
398 return 0;
399 }
14 Appendix A: Source Code Listings 268
43 image[get_index(x,y,width)]=letter[get_index(inputx,inputy,inputwidth)];
44 inputx++;
45 }
46 inputy++;
47 inputx=0;
48 }
49 }
50
51 void clear_image(std::vector<std::tuple<float, float, float>> &image, int width, int\
52 height, int margin)
53 {
54 for (int y=0;y<(height+margin);++y) {
55 for (int x=0;x<(width+margin);++x) {
56 image[get_index(x,y,(width+margin))]=std::make_tuple(1.0f,0.7647058824f,0.62
57 118f);
58 }
59 }
60 }
61
62 void get_line_points(std::vector<std::tuple<int,int>> &points, std::tuple<int, int, \
63 int, int> &coords, std::tuple<float,float,float> &color, int width, int height, int
64 margin)
65 {
66 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
67 int y2=std::get<3>(coords);
68 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
69 dx = x2 - x1; dy = y2 - y1;
70 if (dx == 0)
71 {
72 if (y2 < y1) std::swap(y1, y2);
73 for (y = y1; y <= y2; y++)
74 points.push_back(std::make_tuple(x1,y));
75 return;
76 }
77 if (dy == 0)
78 {
79 if (x2 < x1) std::swap(x1, x2);
80 for (x = x1; x <= x2; x++)
81 points.push_back(std::make_tuple(x,y1));
82 return;
83 }
84 dx1 = abs(dx); dy1 = abs(dy);
85 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
14 Appendix A: Source Code Listings 270
172 }
173
174 void draw_font_R(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
175 oat> &color, int width, int height, int margin)
176 {
177 // R
178 //points
179 float arr[6][2] = {{0.0,1.0},{0.0,0.0},{1.0,0.0},{1.0,0.3},{0.0,0.6},{1.0,1.0}};
180 //lines
181 int arr2[5][2] = {{0,1},{1,2},{2,3},{3,4},{4,5}};
182 std::tuple<int, int, int, int> coords;
183 int halfmargin=margin/2;
184
185 for (int i=0;i<5;++i) {
186 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
187 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
188 rr2[i][1]][1])+halfmargin);
189 get_line_points(points,coords,color,width,height,margin);
190 }
191 }
192
193 void draw_font_S(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
194 oat> &color, int width, int height, int margin)
195 {
196 // S
197 //points
198 float arr[6][2] = {{1.0,0.0},{0.0,0.0},{0.0,0.4},{1.0,0.6},{1.0,1.0},{0.0,1.0}};
199 //lines
200 int arr2[5][2] = {{0,1},{1,2},{2,3},{3,4},{4,5}};
201 std::tuple<int, int, int, int> coords;
202 int halfmargin=margin/2;
203
204 for (int i=0;i<5;++i) {
205 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
206 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
207 rr2[i][1]][1])+halfmargin);
208 get_line_points(points,coords,color,width,height,margin);
209 }
210 }
211
212 void draw_font_V(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
213 oat> &color, int width, int height, int margin)
214 {
14 Appendix A: Source Code Listings 273
215 // V
216 //points
217 float arr[3][2] = {{0.0,0.0},{0.5,1.0},{1.0,0.0}};
218 //lines
219 int arr2[2][2] = {{0,1},{1,2}};
220 std::tuple<int, int, int, int> coords;
221 int halfmargin=margin/2;
222
223 for (int i=0;i<2;++i) {
224 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
225 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
226 rr2[i][1]][1])+halfmargin);
227 get_line_points(points,coords,color,width,height,margin);
228 }
229 }
230
231 void draw_font_E(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
232 oat> &color, int width, int height, int margin)
233 {
234 // E
235 //points
236 float arr[6][2] = {{1.0,0.0},{0.0,0.0},{0.0,0.5},{0.5,0.5},{0.0,1.0},{1.0,1.0}};
237 //lines
238 int arr2[4][2] = {{0,1},{1,2},{2,3},{4,5}};
239 std::tuple<int, int, int, int> coords;
240 int halfmargin=margin/2;
241
242 for (int i=0;i<4;++i) {
243 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
244 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
245 rr2[i][1]][1])+halfmargin);
246 get_line_points(points,coords,color,width,height,margin);
247 }
248 }
249
250 void draw_font_N(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
251 oat> &color, int width, int height, int margin)
252 {
253 // N
254 //points
255 float arr[6][2] = {{0.0,0.0},{0.0,1.0},{1.0,0.0},{1.0,1.0},{0.0,0.0},{1.0,1.0}};
256 //lines
257 int arr2[3][2] = {{0,1},{2,3},{4,5}};
14 Appendix A: Source Code Listings 274
344
345 void draw_font_T(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
346 oat> &color, int width, int height, int margin)
347 {
348 // T
349 //points
350 float arr[3][2] = {{0.0,0.0},{1.0,0.0},{1.0,1.0}};
351 //lines
352 int arr2[2][2] = {{0,1},{1,2}};
353 std::tuple<int, int, int, int> coords;
354 int halfmargin=margin/2;
355
356 for (int i=0;i<2;++i) {
357 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
358 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
359 rr2[i][1]][1])+halfmargin);
360 get_line_points(points,coords,color,width,height,margin);
361 }
362 }
363
364 void draw_filled_circle(int x, int y, int radius, std::vector<std::tuple<float, floa\
365 t, float>> &image, std::tuple<float, float, float> &color, int width, int height, in
366 t margin)
367 {
368 int x0 = 0;
369 int y0 = radius;
370 int d = 3 - 2 * radius;
371 if (!radius) return;
372
373 auto drawline = [&](int sx, int ex, int ny)
374 {
375 for (int i = sx; i <= ex; i++)
376 image[get_index(i, ny, width+margin)]=color;
377 };
378
379 while (y0 >= x0)
380 {
381 drawline(x - x0, x + x0, y - y0);
382 drawline(x - y0, x + y0, y - x0);
383 drawline(x - x0, x + x0, y + y0);
384 drawline(x - y0, x + y0, y + x0);
385 if (d < 0) d += 4 * x0++ + 6;
386 else d += 4 * (x0++ - y0--) + 10;
14 Appendix A: Source Code Listings 277
387 }
388 }
389
390 void get_all_ys(std::vector<int> &ys,std::vector<std::tuple<int,int>> &coords)
391 {
392 for (auto& c : coords) {
393 ys.push_back(std::get<1>(c));
394 }
395
396 sort(ys.begin(), ys.end());
397 ys.erase( unique( ys.begin(), ys.end() ), ys.end() );
398 }
399
400 void draw_line_coords(int x1, int y1, int x2, int y2,std::vector<std::tuple<int,int>\
401 > &coords)
402 {
403 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
404 dx = x2 - x1; dy = y2 - y1;
405 if (dx == 0)
406 {
407 if (y2 < y1) std::swap(y1, y2);
408 for (y = y1; y <= y2; y++)
409 coords.push_back(std::make_tuple(x1,y));
410 return;
411 }
412 if (dy == 0)
413 {
414 if (x2 < x1) std::swap(x1, x2);
415 for (x = x1; x <= x2; x++)
416 coords.push_back(std::make_tuple(x,y1));
417 return;
418 }
419 dx1 = abs(dx); dy1 = abs(dy);
420 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
421 if (dy1 <= dx1)
422 {
423 if (dx >= 0)
424 {
425 x = x1; y = y1; xe = x2;
426 }
427 else
428 {
429 x = x2; y = y2; xe = x1;
14 Appendix A: Source Code Listings 278
430 }
431 coords.push_back(std::make_tuple(x,y));
432 for (i = 0; x<xe; i++)
433 {
434 x = x + 1;
435 if (px<0)
436 px = px + 2 * dy1;
437 else
438 {
439 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
440 px = px + 2 * (dy1 - dx1);
441 }
442 coords.push_back(std::make_tuple(x,y));
443 }
444 }
445 else
446 {
447 if (dy >= 0)
448 {
449 x = x1; y = y1; ye = y2;
450 }
451 else
452 {
453 x = x2; y = y2; ye = y1;
454 }
455 coords.push_back(std::make_tuple(x,y));
456 for (i = 0; y<ye; i++)
457 {
458 y = y + 1;
459 if (py <= 0)
460 py = py + 2 * dx1;
461 else
462 {
463 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
464 py = py + 2 * (dx1 - dy1);
465 }
466 coords.push_back(std::make_tuple(x,y));
467 }
468 }
469 }
470
471 void draw_filled_wedge(int x_cen,int y_cen,int rad,int start_ang,int end_ang,std::ve\
472 ctor<std::tuple<float, float, float>> &image,std::tuple<float, float, float> &color,
14 Appendix A: Source Code Listings 279
645 clear_image(f_t,fwidth,fheight,margin);
646 draw_font_T(points,color2,fwidth,fheight,margin);
647 draw(points,f_t,color2,fwidth,fheight,margin,linesize);
648 points.clear();
649
650 image.resize(calc_size(width, height, margin));
651 clear_image(image,width,height,margin);
652
653 draw_filled_wedge(width/2,height/2,(height/2)*0.5,0,90,image,color1,width,height);
654 draw_filled_wedge(width/2,height/2,(height/2)*0.5,90,180,image,color2,width,height);
655 draw_filled_wedge(width/2,height/2,(height/2)*0.5,180,270,image,color3,width,height\
656 );
657 draw_filled_wedge(width/2,height/2,(height/2)*0.5,270,360,image,color4,width,height\
658 );
659
660 stamp(image,f_m,330,303,(fwidth+margin),(fheight+margin),width);
661 stamp(image,f_a,330+(1*(fwidth+margin)),303,(fwidth+margin),(fheight+margin),width);
662 stamp(image,f_r,330+(2*(fwidth+margin)),303,(fwidth+margin),(fheight+margin),width);
663 stamp(image,f_s,330+(3*(fwidth+margin)),303,(fwidth+margin),(fheight+margin),width);
664
665 stamp(image,f_v,330,554,(fwidth+margin),(fheight+margin),width);
666 stamp(image,f_e,330+(1*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width);
667 stamp(image,f_n,330+(2*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width);
668 stamp(image,f_u,330+(3*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width);
669 stamp(image,f_s,330+(4*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width);
670
671 stamp(image,f_m,1100,303,(fwidth+margin),(fheight+margin),width);
672 stamp(image,f_e,1100+(1*(fwidth+margin)),303,(fwidth+margin),(fheight+margin),width\
673 );
674 stamp(image,f_r,1100+(2*(fwidth+margin)),303,(fwidth+margin),(fheight+margin),width\
675 );
676 stamp(image,f_c,1100+(3*(fwidth+margin)),303,(fwidth+margin),(fheight+margin),width\
677 );
678 stamp(image,f_u,1100+(4*(fwidth+margin)),303,(fwidth+margin),(fheight+margin),width\
679 );
680 stamp(image,f_r,1100+(5*(fwidth+margin)),303,(fwidth+margin),(fheight+margin),width\
681 );
682 stamp(image,f_y,1100+(6*(fwidth+margin)),303,(fwidth+margin),(fheight+margin),width\
683 );
684
685 stamp(image,f_n,1100,554,(fwidth+margin),(fheight+margin),width);
686 stamp(image,f_e,1100+(1*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width\
687 );
14 Appendix A: Source Code Listings 284
688 stamp(image,f_p,1100+(2*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width\
689 );
690 stamp(image,f_t,1100+(3*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width\
691 );
692 stamp(image,f_u,1100+(4*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width\
693 );
694 stamp(image,f_n,1100+(5*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width\
695 );
696 stamp(image,f_e,1100+(6*(fwidth+margin)),554,(fwidth+margin),(fheight+margin),width\
697 );
698
699 std::cout << "saving: 16_draw_pie_chart.ppm." << std::endl;
700 save_image(image,width,height,"16_draw_pie_chart.ppm");
701
702 return 0;
703 }
25 return x+width*y;
26 }
27
28 int calc_size(int width, int height, int margin)
29 {
30 return (width+margin)*(height+margin);
31 }
32
33 void stamp(std::vector<std::tuple<float, float, float>> &image, std::vector<std::tup\
34 le<float, float, float>> &letter, int offsetx, int offsety, int inputwidth, int inpu
35 theight, int width)
36 {
37 int inputx=0;
38 int inputy=0;
39 for (int y = offsety; y < offsety+inputheight; ++y)
40 {
41 for (int x = offsetx; x < offsetx+inputwidth; ++x)
42 {
43 image[get_index(x,y,width)]=letter[get_index(inputx,inputy,inputwidth)];
44 inputx++;
45 }
46 inputy++;
47 inputx=0;
48 }
49 }
50
51 void clear_image(std::vector<std::tuple<float, float, float>> &image, int width, int\
52 height, int margin)
53 {
54 for (int y=0;y<(height+margin);++y) {
55 for (int x=0;x<(width+margin);++x) {
56 image[get_index(x,y,(width+margin))]=std::make_tuple(1.0f,0.7647058824f,0.62
57 118f);
58 }
59 }
60 }
61
62 void get_line_points(std::vector<std::tuple<int,int>> &points, std::tuple<int, int, \
63 int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
64 {
65 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
66 int y2=std::get<3>(coords);
67 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
14 Appendix A: Source Code Listings 286
68 dx = x2 - x1; dy = y2 - y1;
69 if (dx == 0)
70 {
71 if (y2 < y1) std::swap(y1, y2);
72 for (y = y1; y <= y2; y++)
73 points.push_back(std::make_tuple(x1,y));
74 return;
75 }
76 if (dy == 0)
77 {
78 if (x2 < x1) std::swap(x1, x2);
79 for (x = x1; x <= x2; x++)
80 points.push_back(std::make_tuple(x,y1));
81 return;
82 }
83 dx1 = abs(dx); dy1 = abs(dy);
84 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
85 if (dy1 <= dx1)
86 {
87 if (dx >= 0)
88 {
89 x = x1; y = y1; xe = x2;
90 }
91 else
92 {
93 x = x2; y = y2; xe = x1;
94 }
95 points.push_back(std::make_tuple(x,y));
96 for (i = 0; x<xe; i++)
97 {
98 x = x + 1;
99 if (px<0)
100 px = px + 2 * dy1;
101 else
102 {
103 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
104 px = px + 2 * (dy1 - dx1);
105 }
106 points.push_back(std::make_tuple(x,y));
107 }
108 }
109 else
110 {
14 Appendix A: Source Code Listings 287
240
241 for (int i=0;i<4;++i) {
242 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
243 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
244 rr2[i][1]][1])+halfmargin);
245 get_line_points(points,coords,color,width,height);
246 }
247 }
248
249 void draw_font_N(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
250 oat> &color, int width, int height, int margin)
251 {
252 // N
253 //points
254 float arr[6][2] = {{0.0,0.0},{0.0,1.0},{1.0,0.0},{1.0,1.0},{0.0,0.0},{1.0,1.0}};
255 //lines
256 int arr2[3][2] = {{0,1},{2,3},{4,5}};
257 std::tuple<int, int, int, int> coords;
258 int halfmargin=margin/2;
259
260 for (int i=0;i<3;++i) {
261 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
262 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
263 rr2[i][1]][1])+halfmargin);
264 get_line_points(points,coords,color,width,height);
265 }
266 }
267
268 void draw_font_U(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
269 oat> &color, int width, int height, int margin)
270 {
271 // U
272 //points
273 float arr[4][2] = {{0.0,0.0},{0.0,1.0},{1.0,1.0},{1.0,0.5}};
274 //lines
275 int arr2[3][2] = {{0,1},{1,2},{2,3}};
276 std::tuple<int, int, int, int> coords;
277 int halfmargin=margin/2;
278
279 for (int i=0;i<3;++i) {
280 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
281 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
282 rr2[i][1]][1])+halfmargin);
14 Appendix A: Source Code Listings 291
283 get_line_points(points,coords,color,width,height);
284 }
285 }
286
287 void draw_font_C(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
288 oat> &color, int width, int height, int margin)
289 {
290 // C
291 //points
292 float arr[4][2] = {{0.5,0.0},{0.0,0.0},{0.0,1.0},{1.0,1.0}};
293 //lines
294 int arr2[3][2] = {{0,1},{1,2},{2,3}};
295 std::tuple<int, int, int, int> coords;
296 int halfmargin=margin/2;
297
298 for (int i=0;i<3;++i) {
299 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
300 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
301 rr2[i][1]][1])+halfmargin);
302 get_line_points(points,coords,color,width,height);
303 }
304 }
305
306 void draw_font_Y(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
307 oat> &color, int width, int height, int margin)
308 {
309 // Y
310 //points
311 float arr[4][2] = {{0.5,0.6},{0.0,0.0},{1.0,0.0},{0.5,1.0}};
312 //lines
313 int arr2[3][2] = {{0,1},{0,2},{0,3}};
314 std::tuple<int, int, int, int> coords;
315 int halfmargin=margin/2;
316
317 for (int i=0;i<3;++i) {
318 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
319 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
320 rr2[i][1]][1])+halfmargin);
321 get_line_points(points,coords,color,width,height);
322 }
323 }
324
325 void draw_font_P(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
14 Appendix A: Source Code Listings 292
412 }
413
414 void get_all_ys(std::vector<int> &ys,std::vector<std::tuple<int,int>> &coords)
415 {
416 for (auto& c : coords) {
417 ys.push_back(std::get<1>(c));
418 }
419
420 sort(ys.begin(), ys.end());
421 ys.erase( unique( ys.begin(), ys.end() ), ys.end() );
422 }
423
424 void draw_line_coords(int x1, int y1, int x2, int y2,std::vector<std::tuple<int,int>\
425 > &coords)
426 {
427 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
428 dx = x2 - x1; dy = y2 - y1;
429 if (dx == 0)
430 {
431 if (y2 < y1) std::swap(y1, y2);
432 for (y = y1; y <= y2; y++)
433 coords.push_back(std::make_tuple(x1,y));
434 return;
435 }
436 if (dy == 0)
437 {
438 if (x2 < x1) std::swap(x1, x2);
439 for (x = x1; x <= x2; x++)
440 coords.push_back(std::make_tuple(x,y1));
441 return;
442 }
443 dx1 = abs(dx); dy1 = abs(dy);
444 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
445 if (dy1 <= dx1)
446 {
447 if (dx >= 0)
448 {
449 x = x1; y = y1; xe = x2;
450 }
451 else
452 {
453 x = x2; y = y2; xe = x1;
454 }
14 Appendix A: Source Code Listings 295
455 coords.push_back(std::make_tuple(x,y));
456 for (i = 0; x<xe; i++)
457 {
458 x = x + 1;
459 if (px<0)
460 px = px + 2 * dy1;
461 else
462 {
463 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
464 px = px + 2 * (dy1 - dx1);
465 }
466 coords.push_back(std::make_tuple(x,y));
467 }
468 }
469 else
470 {
471 if (dy >= 0)
472 {
473 x = x1; y = y1; ye = y2;
474 }
475 else
476 {
477 x = x2; y = y2; ye = y1;
478 }
479 coords.push_back(std::make_tuple(x,y));
480 for (i = 0; y<ye; i++)
481 {
482 y = y + 1;
483 if (py <= 0)
484 py = py + 2 * dx1;
485 else
486 {
487 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
488 py = py + 2 * (dx1 - dy1);
489 }
490 coords.push_back(std::make_tuple(x,y));
491 }
492 }
493 }
494
495 void draw_filled_wedge(int x_cen,int y_cen,int rad,int start_ang,int end_ang,std::ve\
496 ctor<std::tuple<float, float, float>> &image,std::tuple<float, float, float> &color,
497 int width, int height)
14 Appendix A: Source Code Listings 296
498 {
499 std::vector<std::tuple<int,int>> coords;
500
501 float ang=(((start_ang<=end_ang)?start_ang:end_ang)*(M_PI/180));
502 float range=(((end_ang>start_ang)?end_ang:start_ang)*(M_PI/180));
503 float x=(rad*cos(ang));
504 float y=(rad*sin(ang));
505 do
506 {
507 coords.push_back(std::make_tuple((int)(x_cen+x+0.5),(int)(y_cen-y+0.5)));
508 ang+=0.001;
509 x=(rad*cos(ang));
510 y=(rad*sin(ang));
511 }
512 while(ang<=range);
513
514 std::tuple<int,int> co1=coords.front();
515 std::tuple<int,int> co2=coords.back();
516
517 draw_line_coords(x_cen,y_cen,std::get<0>(co1),std::get<1>(co1),coords);
518 draw_line_coords(x_cen,y_cen,std::get<0>(co2),std::get<1>(co2),coords);
519
520 std::vector<int> ys;
521 std::vector<int> xs;
522 get_all_ys(ys,coords);
523 std::vector<std::tuple<int,int,int,int>> lines;
524
525 for (int search=0;search<=ys.size();++search)
526 {
527 for (auto& c : coords) {
528 if (std::get<1>(c) == ys[search]) {
529 xs.push_back(std::get<0>(c));
530 }
531 }
532 sort(xs.begin(), xs.end());
533 lines.push_back(std::make_tuple(xs.front(),ys[search],xs.back(),ys[search]));
534 xs.clear();
535 }
536
537 auto drawline = [&](int sx, int ex, int ny)
538 {
539 for (int i = sx; i <= ex; i++)
540 image[get_index(i, ny, width)]=color;
14 Appendix A: Source Code Listings 297
541 };
542
543 for (auto& l : lines) {
544 drawline(std::get<0>(l),std::get<2>(l),std::get<1>(l));
545 }
546 }
547
548 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
549 height, std::string filename)
550 {
551 std::tuple<float, float, float> color;
552 std::ofstream out(filename, std::ios_base::out | std::ios_base::binary);
553 out << "P6" << std::endl << width << ' ' << height << std::endl << "255" << std::en\
554 dl;
555
556 for (int i=0;i<(width*height);++i)
557 {
558 color=image[i];
559 out << char(std::get<0>(color)*255.0f) << char(std::get<1>(color)*255.0f) << char(\
560 std::get<2>(color)*255.0f);
561 }
562 out.close();
563 }
564
565 void draw(std::vector<std::tuple<int,int>> points,std::vector<std::tuple<float, floa\
566 t, float>> &image, std::tuple<float,float,float> color, int width, int height, int m
567 argin, int linesize)
568 {
569 for (auto& p : points) {
570 if (linesize == 1) {
571 image[get_index(std::get<0>(p),std::get<1>(p),width+margin)]=std::make_tuple
572 , 0.0f, 0.0f);
573 } else {
574 draw_filled_circle(std::get<0>(p),std::get<1>(p),linesize,image,color,width,
575 t,margin);
576 }
577 }
578 }
579
580 void draw2(std::vector<std::tuple<int,int>> points,std::vector<std::tuple<float, flo\
581 at, float>> &image, std::tuple<float,float,float> color, int width, int height, int
582 linesize)
583 {
14 Appendix A: Source Code Listings 298
627 draw_font_A(points,color2,fwidth,fheight,margin);
628 draw(points,f_a,color2,fwidth,fheight,margin,linesize);
629 points.clear();
630 std::vector<std::tuple<float, float, float>> f_r;
631 f_r.resize(calc_size(fwidth, fheight, margin));
632 clear_image(f_r,fwidth,fheight,margin);
633 draw_font_R(points,color2,fwidth,fheight,margin);
634 draw(points,f_r,color2,fwidth,fheight,margin,linesize);
635 points.clear();
636 std::vector<std::tuple<float, float, float>> f_s;
637 f_s.resize(calc_size(fwidth, fheight, margin));
638 clear_image(f_s,fwidth,fheight,margin);
639 draw_font_S(points,color2,fwidth,fheight,margin);
640 draw(points,f_s,color2,fwidth,fheight,margin,linesize);
641 points.clear();
642 std::vector<std::tuple<float, float, float>> f_v;
643 f_v.resize(calc_size(fwidth, fheight, margin));
644 clear_image(f_v,fwidth,fheight,margin);
645 draw_font_V(points,color2,fwidth,fheight,margin);
646 draw(points,f_v,color2,fwidth,fheight,margin,linesize);
647 points.clear();
648 std::vector<std::tuple<float, float, float>> f_e;
649 f_e.resize(calc_size(fwidth, fheight, margin));
650 clear_image(f_e,fwidth,fheight,margin);
651 draw_font_E(points,color2,fwidth,fheight,margin);
652 draw(points,f_e,color2,fwidth,fheight,margin,linesize);
653 points.clear();
654 std::vector<std::tuple<float, float, float>> f_n;
655 f_n.resize(calc_size(fwidth, fheight, margin));
656 clear_image(f_n,fwidth,fheight,margin);
657 draw_font_N(points,color2,fwidth,fheight,margin);
658 draw(points,f_n,color2,fwidth,fheight,margin,linesize);
659 points.clear();
660 std::vector<std::tuple<float, float, float>> f_u;
661 f_u.resize(calc_size(fwidth, fheight, margin));
662 clear_image(f_u,fwidth,fheight,margin);
663 draw_font_U(points,color2,fwidth,fheight,margin);
664 draw(points,f_u,color2,fwidth,fheight,margin,linesize);
665 points.clear();
666 std::vector<std::tuple<float, float, float>> f_c;
667 f_c.resize(calc_size(fwidth, fheight, margin));
668 clear_image(f_c,fwidth,fheight,margin);
669 draw_font_C(points,color2,fwidth,fheight,margin);
14 Appendix A: Source Code Listings 300
670 draw(points,f_c,color2,fwidth,fheight,margin,linesize);
671 points.clear();
672 std::vector<std::tuple<float, float, float>> f_y;
673 f_y.resize(calc_size(fwidth, fheight, margin));
674 clear_image(f_y,fwidth,fheight,margin);
675 draw_font_Y(points,color2,fwidth,fheight,margin);
676 draw(points,f_y,color2,fwidth,fheight,margin,linesize);
677 points.clear();
678 std::vector<std::tuple<float, float, float>> f_p;
679 f_p.resize(calc_size(fwidth, fheight, margin));
680 clear_image(f_p,fwidth,fheight,margin);
681 draw_font_P(points,color2,fwidth,fheight,margin);
682 draw(points,f_p,color2,fwidth,fheight,margin,linesize);
683 points.clear();
684 std::vector<std::tuple<float, float, float>> f_t;
685 f_t.resize(calc_size(fwidth, fheight, margin));
686 clear_image(f_t,fwidth,fheight,margin);
687 draw_font_T(points,color2,fwidth,fheight,margin);
688 draw(points,f_t,color2,fwidth,fheight,margin,linesize);
689 points.clear();
690
691 image.resize(calc_size(width, height, margin));
692 clear_image(image,width,height,margin);
693
694 // 320, 640, 960, 1280
695 draw_filled_circle2(320,height*0.4,92,image,color1,width,height);
696 draw_filled_circle2(320,height*0.4,78,image,color2,width,height);
697 draw_filled_circle2(320,height*0.4,72,image,color1,width,height);
698 draw_filled_wedge(320,height*0.4,62,0,360,image,color2,width,height);
699 draw_filled_circle2(320,height*0.4,31,image,color1,width,height);
700 coords=std::make_tuple(320,436,320,436+38);
701 get_line_points(points,coords,color2,width,height);
702 draw2(points,image,color2,width,height,3);
703 draw_filled_circle2(320,436+38+8,8,image,color2,width,height);
704 draw_filled_circle2(320,436+38+8,3,image,color0,width,height);
705
706 draw_filled_circle2(640,height*0.4,92,image,color1,width,height);
707 draw_filled_circle2(640,height*0.4,78,image,color2,width,height);
708 draw_filled_circle2(640,height*0.4,72,image,color1,width,height);
709 draw_filled_wedge(640,height*0.4,62,90,360,image,color2,width,height);
710 draw_filled_circle2(640,height*0.4,31,image,color1,width,height);
711 coords=std::make_tuple(640,436,640,436+38);
712 get_line_points(points,coords,color2,width,height);
14 Appendix A: Source Code Listings 301
713 draw2(points,image,color2,width,height,3);
714 draw_filled_circle2(640,436+38+8,8,image,color2,width,height);
715 draw_filled_circle2(640,436+38+8,3,image,color0,width,height);
716
717 draw_filled_circle2(960,height*0.4,92,image,color1,width,height);
718 draw_filled_circle2(960,height*0.4,78,image,color2,width,height);
719 draw_filled_circle2(960,height*0.4,72,image,color1,width,height);
720 draw_filled_wedge(960,height*0.4,62,180,360,image,color2,width,height);
721 draw_filled_circle2(960,height*0.4,31,image,color1,width,height);
722 coords=std::make_tuple(960,436,960,436+38);
723 get_line_points(points,coords,color2,width,height);
724 draw2(points,image,color2,width,height,3);
725 draw_filled_circle2(960,436+38+8,8,image,color2,width,height);
726 draw_filled_circle2(960,436+38+8,3,image,color0,width,height);
727
728 draw_filled_circle2(1280,height*0.4,92,image,color1,width,height);
729 draw_filled_circle2(1280,height*0.4,78,image,color2,width,height);
730 draw_filled_circle2(1280,height*0.4,72,image,color1,width,height);
731 draw_filled_wedge(1280,height*0.4,62,270,360,image,color2,width,height);
732 draw_filled_circle2(1280,height*0.4,31,image,color1,width,height);
733 coords=std::make_tuple(1280,436,1280,436+38);
734 get_line_points(points,coords,color2,width,height);
735 draw2(points,image,color2,width,height,3);
736 draw_filled_circle2(1280,436+38+8,8,image,color2,width,height);
737 draw_filled_circle2(1280,436+38+8,3,image,color0,width,height);
738
739 // Labels
740 stamp(image,f_m,320-(4*label_x),512,(fwidth+margin),(fheight+margin),width);
741 stamp(image,f_a,320-(4*label_x)+(1*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
742 rgin),width);
743 stamp(image,f_r,320-(4*label_x)+(2*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
744 rgin),width);
745 stamp(image,f_s,320-(4*label_x)+(3*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
746 rgin),width);
747
748 stamp(image,f_v,640-(5*label_x),512,(fwidth+margin),(fheight+margin),width);
749 stamp(image,f_e,640-(5*label_x)+(1*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
750 rgin),width);
751 stamp(image,f_n,640-(5*label_x)+(2*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
752 rgin),width);
753 stamp(image,f_u,640-(5*label_x)+(3*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
754 rgin),width);
755 stamp(image,f_s,640-(5*label_x)+(4*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
14 Appendix A: Source Code Listings 302
756 rgin),width);
757
758 stamp(image,f_n,960-(7*label_x),512,(fwidth+margin),(fheight+margin),width);
759 stamp(image,f_e,960-(7*label_x)+(1*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
760 rgin),width);
761 stamp(image,f_p,960-(7*label_x)+(2*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
762 rgin),width);
763 stamp(image,f_t,960-(7*label_x)+(3*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
764 rgin),width);
765 stamp(image,f_u,960-(7*label_x)+(4*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
766 rgin),width);
767 stamp(image,f_n,960-(7*label_x)+(5*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
768 rgin),width);
769 stamp(image,f_e,960-(7*label_x)+(6*(fwidth+margin)),512,(fwidth+margin),(fheight+ma\
770 rgin),width);
771
772 stamp(image,f_m,1280-(7*label_x),512,(fwidth+margin),(fheight+margin),width);
773 stamp(image,f_e,1280-(7*label_x)+(1*(fwidth+margin)),512,(fwidth+margin),(fheight+m\
774 argin),width);
775 stamp(image,f_r,1280-(7*label_x)+(2*(fwidth+margin)),512,(fwidth+margin),(fheight+m\
776 argin),width);
777 stamp(image,f_c,1280-(7*label_x)+(3*(fwidth+margin)),512,(fwidth+margin),(fheight+m\
778 argin),width);
779 stamp(image,f_u,1280-(7*label_x)+(4*(fwidth+margin)),512,(fwidth+margin),(fheight+m\
780 argin),width);
781 stamp(image,f_r,1280-(7*label_x)+(5*(fwidth+margin)),512,(fwidth+margin),(fheight+m\
782 argin),width);
783 stamp(image,f_y,1280-(7*label_x)+(6*(fwidth+margin)),512,(fwidth+margin),(fheight+m\
784 argin),width);
785
786 std::cout << "saving: 16_draw_donut_chart.ppm." << std::endl;
787 save_image(image,width,height,"16_draw_donut_chart.ppm");
788
789 return 0;
790 }
14 Appendix A: Source Code Listings 303
43 le<float, float, float>> &letter, int offsetx, int offsety, int inputwidth, int inpu
44 theight, int width)
45 {
46 int inputx=0;
47 int inputy=0;
48 for (int y = offsety; y < offsety+inputheight; ++y)
49 {
50 for (int x = offsetx; x < offsetx+inputwidth; ++x)
51 {
52 image[get_index(x,y,width)]=letter[get_index(inputx,inputy,inputwidth)];
53 inputx++;
54 }
55 inputy++;
56 inputx=0;
57 }
58 }
59
60 void get_line_points(std::vector<std::tuple<int,int>> &points, std::tuple<int, int, \
61 int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
62 {
63 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
64 int y2=std::get<3>(coords);
65 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
66 dx = x2 - x1; dy = y2 - y1;
67 if (dx == 0)
68 {
69 if (y2 < y1) std::swap(y1, y2);
70 for (y = y1; y <= y2; y++)
71 points.push_back(std::make_tuple(x1,y));
72 return;
73 }
74 if (dy == 0)
75 {
76 if (x2 < x1) std::swap(x1, x2);
77 for (x = x1; x <= x2; x++)
78 points.push_back(std::make_tuple(x,y1));
79 return;
80 }
81 dx1 = abs(dx); dy1 = abs(dy);
82 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
83 if (dy1 <= dx1)
84 {
85 if (dx >= 0)
14 Appendix A: Source Code Listings 305
86 {
87 x = x1; y = y1; xe = x2;
88 }
89 else
90 {
91 x = x2; y = y2; xe = x1;
92 }
93 points.push_back(std::make_tuple(x,y));
94 for (i = 0; x<xe; i++)
95 {
96 x = x + 1;
97 if (px<0)
98 px = px + 2 * dy1;
99 else
100 {
101 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
102 px = px + 2 * (dy1 - dx1);
103 }
104 points.push_back(std::make_tuple(x,y));
105 }
106 }
107 else
108 {
109 if (dy >= 0)
110 {
111 x = x1; y = y1; ye = y2;
112 }
113 else
114 {
115 x = x2; y = y2; ye = y1;
116 }
117 points.push_back(std::make_tuple(x,y));
118 for (i = 0; y<ye; i++)
119 {
120 y = y + 1;
121 if (py <= 0)
122 py = py + 2 * dx1;
123 else
124 {
125 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
126 py = py + 2 * (dx1 - dy1);
127 }
128 points.push_back(std::make_tuple(x,y));
14 Appendix A: Source Code Listings 306
129 }
130 }
131 }
132
133 void draw_font_M(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
134 oat> &color, int width, int height, int margin)
135 {
136 // M
137 //points
138 float arr[5][2] = {{0.0,1.0},{0.0,0.0},{0.5,0.3},{1.0,0.0},{1.0,1.0}};
139 //lines
140 int arr2[4][2] = {{0,1},{1,2},{2,3},{3,4}};
141 std::tuple<int, int, int, int> coords;
142 int halfmargin=margin/2;
143
144 for (int i=0;i<4;++i) {
145 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
146 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
147 rr2[i][1]][1])+halfmargin);
148 get_line_points(points,coords,color,width,height);
149 }
150 }
151
152 void draw_font_A(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
153 oat> &color, int width, int height, int margin)
154 {
155 // A
156 //points
157 float arr[4][2] = {{0.0,1.0},{0.5,0.0},{1.0,1.0},{0.0,0.6}};
158 //lines
159 int arr2[3][2] = {{0,1},{1,2},{2,3}};
160 std::tuple<int, int, int, int> coords;
161 int halfmargin=margin/2;
162
163 for (int i=0;i<3;++i) {
164 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
165 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0])+halfmargin, int(height*arr[a
166 rr2[i][1]][1])+halfmargin);
167 get_line_points(points,coords,color,width,height);
168 }
169 }
170
171 void draw_font_R(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
14 Appendix A: Source Code Listings 307
215 //lines
216 int arr2[4][2] = {{0,1},{1,2},{2,3},{4,5}};
217 std::tuple<int, int, int, int> coords;
218 int halfmargin=margin/2;
219
220 for (int i=0;i<4;++i) {
221 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
222 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
223 rr2[i][1]][1])+halfmargin);
224 get_line_points(points,coords,color,width,height);
225 }
226 }
227
228 void draw_font_U(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
229 oat> &color, int width, int height, int margin)
230 {
231 // U
232 //points
233 float arr[4][2] = {{0.0,0.0},{0.0,1.0},{1.0,1.0},{1.0,0.5}};
234 //lines
235 int arr2[3][2] = {{0,1},{1,2},{2,3}};
236 std::tuple<int, int, int, int> coords;
237 int halfmargin=margin/2;
238
239 for (int i=0;i<3;++i) {
240 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
241 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
242 rr2[i][1]][1])+halfmargin);
243 get_line_points(points,coords,color,width,height);
244 }
245 }
246
247 void draw_font_C(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
248 oat> &color, int width, int height, int margin)
249 {
250 // C
251 //points
252 float arr[4][2] = {{0.5,0.0},{0.0,0.0},{0.0,1.0},{1.0,1.0}};
253 //lines
254 int arr2[3][2] = {{0,1},{1,2},{2,3}};
255 std::tuple<int, int, int, int> coords;
256 int halfmargin=margin/2;
257
14 Appendix A: Source Code Listings 309
301 }
302 }
303
304 void draw_font_N(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
305 oat> &color, int width, int height, int margin)
306 {
307 // N
308 //points
309 float arr[6][2] = {{0.0,0.0},{0.0,1.0},{1.0,0.0},{1.0,1.0},{0.0,0.0},{1.0,1.0}};
310 //lines
311 int arr2[3][2] = {{0,1},{2,3},{4,5}};
312 std::tuple<int, int, int, int> coords;
313 int halfmargin=margin/2;
314
315 for (int i=0;i<3;++i) {
316 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
317 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
318 rr2[i][1]][1])+halfmargin);
319 get_line_points(points,coords,color,width,height);
320 }
321 }
322
323 void draw_font_0(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
324 oat> &color, int width, int height, int margin)
325 {
326 // 0
327 //points
328 float arr[6][2] = {{0.0,0.0},{0.0,1.0},{1.0,1.0},{1.0,0.0},{0.0,1.0},{1.0,0.0}};
329 //lines
330 int arr2[5][2] = {{0,1},{1,2},{2,3},{3,0},{4,5}};
331 std::tuple<int, int, int, int> coords;
332 int halfmargin=margin/2;
333
334 for (int i=0;i<5;++i) {
335 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
336 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
337 rr2[i][1]][1])+halfmargin);
338 get_line_points(points,coords,color,width,height);
339 }
340 }
341
342 void draw_font_1(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
343 oat> &color, int width, int height, int margin)
14 Appendix A: Source Code Listings 311
344 {
345 // 1
346 //points
347 float arr[3][2] = {{0.0,0.0},{0.5,0.0},{0.5,1.0}};
348 //lines
349 int arr2[2][2] = {{0,1},{1,2}};
350 std::tuple<int, int, int, int> coords;
351 int halfmargin=margin/2;
352
353 for (int i=0;i<2;++i) {
354 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
355 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
356 rr2[i][1]][1])+halfmargin);
357 get_line_points(points,coords,color,width,height);
358 }
359 }
360
361 void draw_font_2(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
362 oat> &color, int width, int height, int margin)
363 {
364 // 2
365 //points
366 float arr[6][2] = {{0.0,0.0},{1.0,0.0},{1.0,0.4},{0.0,0.6},{0.0,1.0},{1.0,1.0}};
367 //lines
368 int arr2[5][2] = {{0,1},{1,2},{2,3},{3,4},{4,5}};
369 std::tuple<int, int, int, int> coords;
370 int halfmargin=margin/2;
371
372 for (int i=0;i<5;++i) {
373 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
374 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
375 rr2[i][1]][1])+halfmargin);
376 get_line_points(points,coords,color,width,height);
377 }
378 }
379
380 void draw_font_3(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
381 oat> &color, int width, int height, int margin)
382 {
383 // 3
384 //points
385 float arr[6][2] = {{0.0,0.0},{1.0,0.0},{1.0,0.4},{0.5,0.4},{0.0,1.0},{1.0,1.0}};
386 //lines
14 Appendix A: Source Code Listings 312
473 }
474
475 void draw_font_8(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
476 oat> &color, int width, int height, int margin)
477 {
478 // 8
479 //points
480 float arr[6][2] = {{0.1,0.4},{0.9,0.6},{1.0,0.0},{0.0,0.0},{0.0,1.0},{1.0,1.0}};
481 //lines
482 int arr2[7][2] = {{0,1},{1,2},{2,3},{3,0},{0,4},{4,5},{5,1}};
483 std::tuple<int, int, int, int> coords;
484 int halfmargin=margin/2;
485
486 for (int i=0;i<7;++i) {
487 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
488 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
489 rr2[i][1]][1])+halfmargin);
490 get_line_points(points,coords,color,width,height);
491 }
492 }
493
494 void draw_font_9(std::vector<std::tuple<int,int>> &points, std::tuple<float,float,fl\
495 oat> &color, int width, int height, int margin)
496 {
497 // 9
498 //points
499 float arr[5][2] = {{1.0,1.0},{1.0,0.0},{0.0,0.0},{0.0,0.6},{1.0,0.4}};
500 //lines
501 int arr2[4][2] = {{0,1},{1,2},{2,3},{3,4}};
502 std::tuple<int, int, int, int> coords;
503 int halfmargin=margin/2;
504
505 for (int i=0;i<4;++i) {
506 coords=std::make_tuple(int(width*arr[arr2[i][0]][0])+halfmargin, int(height*arr[ar\
507 r2[i][0]][1])+halfmargin, int(width*arr[arr2[i][1]][0]+halfmargin), int(height*arr[a
508 rr2[i][1]][1])+halfmargin);
509 get_line_points(points,coords,color,width,height);
510 }
511 }
512
513 void draw_filled_circle(int x, int y, int radius, std::vector<std::tuple<float, floa\
514 t, float>> &image, std::tuple<float, float, float> &color, int width, int height, in
515 t margin)
14 Appendix A: Source Code Listings 315
516 {
517 int x0 = 0;
518 int y0 = radius;
519 int d = 3 - 2 * radius;
520 if (!radius) return;
521
522 auto drawline = [&](int sx, int ex, int ny)
523 {
524 for (int i = sx; i <= ex; i++)
525 image[get_index(i, ny, width+margin)]=color;
526 };
527
528 while (y0 >= x0)
529 {
530 drawline(x - x0, x + x0, y - y0);
531 drawline(x - y0, x + y0, y - x0);
532 drawline(x - x0, x + x0, y + y0);
533 drawline(x - y0, x + y0, y + x0);
534 if (d < 0) d += 4 * x0++ + 6;
535 else d += 4 * (x0++ - y0--) + 10;
536 }
537 }
538
539 void draw_filled_rect(int x, int y, int w, int h, std::vector<std::tuple<float, floa\
540 t, float>> &image, std::tuple<float,float,float> &color, int width, int height)
541 {
542 int x2 = x + w;
543 int y2 = y + h;
544
545 if (x < 0) {x = 0;}
546 if (x >= width) {x = width;}
547 if (y < 0) {y = 0;}
548 if (y >= height) {y = height;}
549
550 if (x2 < 0) {x2 = 0;}
551 if (x2 >= width) {x2 = width;}
552 if (y2 < 0) {y2 = 0;}
553 if (y2 >= height) {y2 = height;}
554
555 for (int i = y; i < y2; i++) {
556 for (int j = x; j < x2; j++) {
557 image[get_index(j,i,width)]=color;
558 }
14 Appendix A: Source Code Listings 316
559 }
560 }
561
562 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
563 height, std::string filename)
564 {
565 std::tuple<float, float, float> color;
566 std::ofstream out(filename, std::ios_base::out | std::ios_base::binary);
567 out << "P6" << std::endl << width << ' ' << height << std::endl << "255" << std::en\
568 dl;
569
570 for (int i=0;i<(width*height);++i)
571 {
572 color=image[i];
573 out << char(std::get<0>(color)*255.0f) << char(std::get<1>(color)*255.0f) << char(\
574 std::get<2>(color)*255.0f);
575 }
576 out.close();
577 }
578
579 void draw(std::vector<std::tuple<int,int>> points,std::vector<std::tuple<float, floa\
580 t, float>> &image, std::tuple<float,float,float> color, int width, int height, int m
581 argin, int linesize)
582 {
583 for (auto& p : points) {
584 if (linesize == 1) {
585 image[get_index(std::get<0>(p),std::get<1>(p),width+margin)]=color;
586 } else {
587 draw_filled_circle(std::get<0>(p),std::get<1>(p),linesize,image,color,width,
588 t,margin);
589 }
590 }
591 }
592
593 int main()
594 {
595 std::vector<std::tuple<float, float, float>> image;
596 std::vector<std::tuple<int,int>> points;
597 std::tuple<float,float,float> color1=std::make_tuple(1.0f,1.0f,1.0f);
598 std::tuple<float,float,float> color2=std::make_tuple(0.262745098f,0.262745098f,0.26\
599 2745098f);
600 std::tuple<float,float,float> color3=std::make_tuple(0.0f,0.0f,0.0f);
601 int width=1600,height=900;
14 Appendix A: Source Code Listings 317
645 clear_image(f_u,fwidth,fheight,margin);
646 draw_font_U(points,color3,fwidth,fheight,margin);
647 draw(points,f_u,color3,fwidth,fheight,margin,linesize);
648 points.clear();
649 std::vector<std::tuple<float, float, float>> f_c;
650 f_c.resize(calc_size(fwidth, fheight, margin));
651 clear_image(f_c,fwidth,fheight,margin);
652 draw_font_C(points,color3,fwidth,fheight,margin);
653 draw(points,f_c,color3,fwidth,fheight,margin,linesize);
654 points.clear();
655 std::vector<std::tuple<float, float, float>> f_y;
656 f_y.resize(calc_size(fwidth, fheight, margin));
657 clear_image(f_y,fwidth,fheight,margin);
658 draw_font_Y(points,color3,fwidth,fheight,margin);
659 draw(points,f_y,color3,fwidth,fheight,margin,linesize);
660 points.clear();
661 std::vector<std::tuple<float, float, float>> f_t;
662 f_t.resize(calc_size(fwidth, fheight, margin));
663 clear_image(f_t,fwidth,fheight,margin);
664 draw_font_T(points,color3,fwidth,fheight,margin);
665 draw(points,f_t,color3,fwidth,fheight,margin,linesize);
666 points.clear();
667 std::vector<std::tuple<float, float, float>> f_n;
668 f_n.resize(calc_size(fwidth, fheight, margin));
669 clear_image(f_n,fwidth,fheight,margin);
670 draw_font_N(points,color3,fwidth,fheight,margin);
671 draw(points,f_n,color3,fwidth,fheight,margin,linesize);
672 points.clear();
673 std::vector<std::tuple<float, float, float>> f_1;
674 f_1.resize(calc_size(fwidth, fheight, margin));
675 clear_image(f_1,fwidth,fheight,margin);
676 draw_font_1(points,color3,fwidth,fheight,margin);
677 draw(points,f_1,color3,fwidth,fheight,margin,linesize);
678 points.clear();
679 std::vector<std::tuple<float, float, float>> f_2;
680 f_2.resize(calc_size(fwidth, fheight, margin));
681 clear_image(f_2,fwidth,fheight,margin);
682 draw_font_2(points,color3,fwidth,fheight,margin);
683 draw(points,f_2,color3,fwidth,fheight,margin,linesize);
684 points.clear();
685 std::vector<std::tuple<float, float, float>> f_3;
686 f_3.resize(calc_size(fwidth, fheight, margin));
687 clear_image(f_3,fwidth,fheight,margin);
14 Appendix A: Source Code Listings 319
688 draw_font_3(points,color3,fwidth,fheight,margin);
689 draw(points,f_3,color3,fwidth,fheight,margin,linesize);
690 points.clear();
691
692 std::vector<std::tuple<float, float, float>> f_w0;
693 f_w0.resize(calc_size(fwidth, fheight, margin));
694 clear_image(f_w0,fwidth,fheight,margin);
695 draw_font_0(points,color2,fwidth,fheight,margin);
696 draw(points,f_w0,color2,fwidth,fheight,margin,linesize);
697 points.clear();
698 std::vector<std::tuple<float, float, float>> f_w1;
699 f_w1.resize(calc_size(fwidth, fheight, margin));
700 clear_image(f_w1,fwidth,fheight,margin);
701 draw_font_1(points,color2,fwidth,fheight,margin);
702 draw(points,f_w1,color2,fwidth,fheight,margin,linesize);
703 points.clear();
704 std::vector<std::tuple<float, float, float>> f_w2;
705 f_w2.resize(calc_size(fwidth, fheight, margin));
706 clear_image(f_w2,fwidth,fheight,margin);
707 draw_font_2(points,color2,fwidth,fheight,margin);
708 draw(points,f_w2,color2,fwidth,fheight,margin,linesize);
709 points.clear();
710 std::vector<std::tuple<float, float, float>> f_w3;
711 f_w3.resize(calc_size(fwidth, fheight, margin));
712 clear_image(f_w3,fwidth,fheight,margin);
713 draw_font_3(points,color2,fwidth,fheight,margin);
714 draw(points,f_w3,color2,fwidth,fheight,margin,linesize);
715 points.clear();
716 std::vector<std::tuple<float, float, float>> f_w4;
717 f_w4.resize(calc_size(fwidth, fheight, margin));
718 clear_image(f_w4,fwidth,fheight,margin);
719 draw_font_4(points,color2,fwidth,fheight,margin);
720 draw(points,f_w4,color2,fwidth,fheight,margin,linesize);
721 points.clear();
722 std::vector<std::tuple<float, float, float>> f_w5;
723 f_w5.resize(calc_size(fwidth, fheight, margin));
724 clear_image(f_w5,fwidth,fheight,margin);
725 draw_font_5(points,color2,fwidth,fheight,margin);
726 draw(points,f_w5,color2,fwidth,fheight,margin,linesize);
727 points.clear();
728 std::vector<std::tuple<float, float, float>> f_w6;
729 f_w6.resize(calc_size(fwidth, fheight, margin));
730 clear_image(f_w6,fwidth,fheight,margin);
14 Appendix A: Source Code Listings 320
731 draw_font_6(points,color2,fwidth,fheight,margin);
732 draw(points,f_w6,color2,fwidth,fheight,margin,linesize);
733 points.clear();
734 std::vector<std::tuple<float, float, float>> f_w7;
735 f_w7.resize(calc_size(fwidth, fheight, margin));
736 clear_image(f_w7,fwidth,fheight,margin);
737 draw_font_7(points,color2,fwidth,fheight,margin);
738 draw(points,f_w7,color2,fwidth,fheight,margin,linesize);
739 points.clear();
740 std::vector<std::tuple<float, float, float>> f_w8;
741 f_w8.resize(calc_size(fwidth, fheight, margin));
742 clear_image(f_w8,fwidth,fheight,margin);
743 draw_font_8(points,color2,fwidth,fheight,margin);
744 draw(points,f_w8,color2,fwidth,fheight,margin,linesize);
745 points.clear();
746 std::vector<std::tuple<float, float, float>> f_w9;
747 f_w9.resize(calc_size(fwidth, fheight, margin));
748 clear_image(f_w9,fwidth,fheight,margin);
749 draw_font_9(points,color2,fwidth,fheight,margin);
750 draw(points,f_w9,color2,fwidth,fheight,margin,linesize);
751 points.clear();
752
753 draw_filled_rect(402,322,796,5,image,color1,width,height);
754 draw_filled_rect(402,418,796,5,image,color1,width,height);
755 draw_filled_rect(402,514,796,5,image,color1,width,height);
756 draw_filled_rect(402,611,796,5,image,color1,width,height);
757 draw_filled_rect(402,707,796,5,image,color1,width,height);
758 draw_filled_rect(402,322,5,390,image,color1,width,height);
759 draw_filled_rect(557,322,5,390,image,color1,width,height);
760 draw_filled_rect(769,322,5,390,image,color1,width,height);
761 draw_filled_rect(970,322,5,390,image,color1,width,height);
762 draw_filled_rect(1193,322,5,390,image,color1,width,height);
763
764 // Labels
765 stamp(image,f_m,420,460,(fwidth+margin),(fheight+margin),width);
766 stamp(image,f_e,420+(1*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width);
767 stamp(image,f_r,420+(2*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width);
768 stamp(image,f_c,420+(3*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width);
769 stamp(image,f_u,420+(4*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width);
770 stamp(image,f_r,420+(5*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width);
771 stamp(image,f_y,420+(6*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width);
772
773 stamp(image,f_m,446,560,(fwidth+margin),(fheight+margin),width);
14 Appendix A: Source Code Listings 321
774 stamp(image,f_a,446+(1*(fwidth+margin)),560,(fwidth+margin),(fheight+margin),width);
775 stamp(image,f_r,446+(2*(fwidth+margin)),560,(fwidth+margin),(fheight+margin),width);
776 stamp(image,f_s,446+(3*(fwidth+margin)),560,(fwidth+margin),(fheight+margin),width);
777
778 stamp(image,f_s,426,660,(fwidth+margin),(fheight+margin),width);
779 stamp(image,f_a,426+(1*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width);
780 stamp(image,f_t,426+(2*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width);
781 stamp(image,f_u,426+(3*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width);
782 stamp(image,f_r,426+(4*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width);
783 stamp(image,f_n,426+(5*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width);
784
785 stamp(image,f_a,646,370,(fwidth+margin),(fheight+margin),width);
786 stamp(image,f_1,646+(1*(fwidth+margin)),370,(fwidth+margin),(fheight+margin),width);
787
788 stamp(image,f_a,846,370,(fwidth+margin),(fheight+margin),width);
789 stamp(image,f_2,846+(1*(fwidth+margin)),370,(fwidth+margin),(fheight+margin),width);
790
791 stamp(image,f_a,1056,370,(fwidth+margin),(fheight+margin),width);
792 stamp(image,f_3,1056+(1*(fwidth+margin)),370,(fwidth+margin),(fheight+margin),width\
793 );
794
795 stamp(image,f_w1,626,460,(fwidth+margin),(fheight+margin),width);
796 stamp(image,f_w0,626+(1*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width\
797 );
798 stamp(image,f_w8,626+(2*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width\
799 );
800 stamp(image,f_w4,626+(3*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width\
801 );
802
803 stamp(image,f_w6,836,460,(fwidth+margin),(fheight+margin),width);
804 stamp(image,f_w5,836+(1*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width\
805 );
806 stamp(image,f_w0,836+(2*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width\
807 );
808 stamp(image,f_w2,836+(3*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),width\
809 );
810
811 stamp(image,f_w6,1036,460,(fwidth+margin),(fheight+margin),width);
812 stamp(image,f_w8,1036+(1*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),widt\
813 h);
814 stamp(image,f_w0,1036+(2*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),widt\
815 h);
816 stamp(image,f_w0,1036+(3*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),widt\
14 Appendix A: Source Code Listings 322
817 h);
818 stamp(image,f_w0,1036+(4*(fwidth+margin)),460,(fwidth+margin),(fheight+margin),widt\
819 h);
820
821 stamp(image,f_w6,646,560,(fwidth+margin),(fheight+margin),width);
822 stamp(image,f_w4,646+(1*(fwidth+margin)),560,(fwidth+margin),(fheight+margin),width\
823 );
824
825 stamp(image,f_w5,846,560,(fwidth+margin),(fheight+margin),width);
826 stamp(image,f_w0,846+(1*(fwidth+margin)),560,(fwidth+margin),(fheight+margin),width\
827 );
828 stamp(image,f_w0,846+(2*(fwidth+margin)),560,(fwidth+margin),(fheight+margin),width\
829 );
830
831 stamp(image,f_w1,1046,560,(fwidth+margin),(fheight+margin),width);
832 stamp(image,f_w5,1046+(1*(fwidth+margin)),560,(fwidth+margin),(fheight+margin),widt\
833 h);
834 stamp(image,f_w4,1046+(2*(fwidth+margin)),560,(fwidth+margin),(fheight+margin),widt\
835 h);
836 stamp(image,f_w1,1046+(3*(fwidth+margin)),560,(fwidth+margin),(fheight+margin),widt\
837 h);
838
839 stamp(image,f_w1,626,660,(fwidth+margin),(fheight+margin),width);
840 stamp(image,f_w0,626+(1*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width\
841 );
842 stamp(image,f_w2,626+(2*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width\
843 );
844 stamp(image,f_w4,626+(3*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width\
845 );
846
847 stamp(image,f_w4,836,660,(fwidth+margin),(fheight+margin),width);
848 stamp(image,f_w0,836+(1*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width\
849 );
850 stamp(image,f_w9,836+(2*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width\
851 );
852 stamp(image,f_w6,836+(3*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),width\
853 );
854
855 stamp(image,f_w8,1046,660,(fwidth+margin),(fheight+margin),width);
856 stamp(image,f_w1,1046+(1*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),widt\
857 h);
858 stamp(image,f_w9,1046+(2*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),widt\
859 h);
14 Appendix A: Source Code Listings 323
860 stamp(image,f_w2,1046+(3*(fwidth+margin)),660,(fwidth+margin),(fheight+margin),widt\
861 h);
862
863 std::cout << "saving: 16_draw_table.ppm." << std::endl;
864 save_image(image,width,height,"16_draw_table.ppm");
865
866 return 0;
867 }
33 }
34
35 void draw_line(std::vector<std::tuple<float, float, float>> &image, std::tuple<int, \
36 int, int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
37 {
38 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
39 int y2=std::get<3>(coords);
40 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
41 dx = x2 - x1; dy = y2 - y1;
42
43 if (dx == 0)
44 {
45 if (y2 < y1) std::swap(y1, y2);
46 for (y = y1; y <= y2; y++)
47 image[get_index(x1,y,width)]=color;
48 return;
49 }
50 if (dy == 0)
51 {
52 if (x2 < x1) std::swap(x1, x2);
53 for (x = x1; x <= x2; x++)
54 image[get_index(x,y1,width)]=color;
55 return;
56 }
57 dx1 = abs(dx); dy1 = abs(dy);
58 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
59 if (dy1 <= dx1)
60 {
61 if (dx >= 0)
62 {
63 x = x1; y = y1; xe = x2;
64 }
65 else
66 {
67 x = x2; y = y2; xe = x1;
68 }
69 image[get_index(x,y,width)]=color;
70 for (i = 0; x<xe; i++)
71 {
72 x = x + 1;
73 if (px<0)
74 px = px + 2 * dy1;
75 else
14 Appendix A: Source Code Listings 325
76 {
77 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
78 px = px + 2 * (dy1 - dx1);
79 }
80 image[get_index(x,y,width)]=color;
81 }
82 }
83 else
84 {
85 if (dy >= 0)
86 {
87 x = x1; y = y1; ye = y2;
88 }
89 else
90 {
91 x = x2; y = y2; ye = y1;
92 }
93 image[get_index(x,y,width)]=color;
94 for (i = 0; y<ye; i++)
95 {
96 y = y + 1;
97 if (py <= 0)
98 py = py + 2 * dx1;
99 else
100 {
101 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
102 py = py + 2 * (dx1 - dy1);
103 }
104 image[get_index(x,y,width)]=color;
105 }
106 }
107 }
108
109 void draw_filled_circle(int x, int y, int radius, std::vector<std::tuple<float, floa\
110 t, float>> &image, std::tuple<float, float, float> &color, int width, int height)
111 {
112 int x0 = 0;
113 int y0 = radius;
114 int d = 3 - 2 * radius;
115 if (!radius) return;
116
117 auto drawline = [&](int sx, int ex, int ny)
118 {
14 Appendix A: Source Code Listings 326
162 {
163 if (dx >= 0)
164 {
165 x = x1; y = y1; xe = x2;
166 }
167 else
168 {
169 x = x2; y = y2; xe = x1;
170 }
171 points.push_back(std::make_tuple(x,y));
172 for (i = 0; x<xe; i++)
173 {
174 x = x + 1;
175 if (px<0)
176 px = px + 2 * dy1;
177 else
178 {
179 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
180 px = px + 2 * (dy1 - dx1);
181 }
182 points.push_back(std::make_tuple(x,y));
183 }
184 }
185 else
186 {
187 if (dy >= 0)
188 {
189 x = x1; y = y1; ye = y2;
190 }
191 else
192 {
193 x = x2; y = y2; ye = y1;
194 }
195 points.push_back(std::make_tuple(x,y));
196 for (i = 0; y<ye; i++)
197 {
198 y = y + 1;
199 if (py <= 0)
200 py = py + 2 * dx1;
201 else
202 {
203 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
204 py = py + 2 * (dx1 - dy1);
14 Appendix A: Source Code Listings 328
205 }
206 points.push_back(std::make_tuple(x,y));
207 }
208 }
209 }
210
211 void draw(std::vector<std::tuple<int,int>> points,std::vector<std::tuple<float, floa\
212 t, float>> &image, std::tuple<float,float,float> color, int width, int height, int r
213 adius)
214 {
215 for (auto& p : points) {
216 if (radius == 1) {
217 image[get_index(std::get<0>(p),std::get<1>(p),width)]=std::make_tuple(0.0f,
218 0.0f);
219 } else {
220 draw_filled_circle(std::get<0>(p),std::get<1>(p),radius,image,color,width,he
221 }
222 }
223 }
224
225 void draw_labels(std::vector<std::tuple<float, float, float>> &image, std::tuple<flo\
226 at,float,float> &color, int width, int height)
227 {
228 // These pixels are drawn in a graphics application and converted to 1's and 0's to\
229 render them here.
230
231 // 16_lable_10.png
232 // 60 29
233 // 870 657
234 char lable_10[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,\
235 0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,
236 0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,
237 0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,
238 0,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,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,0,
274 1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,
275 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0};
276 int xx=0; int yy=0;
277 for (int y=657;y<(657+29);++y)
278 {
279 for (int x=870;x<(870+60);x++) {
280 if (lable_10[get_index(xx,yy,60)] == 1) {
281 image[get_index(x,y,width)]=color;
282 }
283 xx++;
284 }
285 yy++;
286 xx=0;
287 }
288
289 // 16_lable_15.png
290 // 80 39
14 Appendix A: Source Code Listings 330
334 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
335 0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,
336 0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
337 0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
338 0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
339 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,
340 0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,
341 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
366 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0};
367 xx=0; yy=0;
368 for (int y=576;y<(576+39);++y)
369 {
370 for (int x=691;x<(691+80);x++) {
371 if (lable_15[get_index(xx,yy,80)] == 1) {
372 image[get_index(x,y,width)]=color;
373 }
374 xx++;
375 }
376 yy++;
14 Appendix A: Source Code Listings 332
377 xx=0;
378 }
379
380 // 16_lable_30.png
381 // 101 49
382 // 473 459
383 char lable_30[]={0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
384 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,
385 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,
386 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,
387 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
388 0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
389 1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
390 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,
391 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
498 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,
499 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,
500 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,
501 0,0};
502 xx=0; yy=0;
503 for (int y=459;y<(459+49);++y)
504 {
505 for (int x=473;x<(473+101);x++) {
14 Appendix A: Source Code Listings 335
506 if (lable_30[get_index(xx,yy,101)] == 1) {
507 image[get_index(x,y,width)]=color;
508 }
509 xx++;
510 }
511 yy++;
512 xx=0;
513 }
514
515 // 16_lable_45.png
516 // 124 58
517 // 726 287
518 char lable_45[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
519 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
520 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
521 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,
522 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
523 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,1,1,1,1,1,1,1,
688 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
689 0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0};
690 xx=0; yy=0;
691 for (int y=287;y<(287+58);++y)
692 {
693 for (int x=726;x<(726+124);x++) {
694 if (lable_45[get_index(xx,yy,124)] == 1) {
695 image[get_index(x,y,width)]=color;
696 }
697 xx++;
698 }
699 yy++;
700 xx=0;
701 }
702
703 // 16_lable_jupiter.png
704 // 73 17
705 // 691 700
706 char lable_jupiter[]={0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1\
707 ,1,1,0,0,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,0
708 ,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0
709 ,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0
710 ,0,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,0,0
711 ,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0,0,0,0,1,1,1
712 ,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1
713 ,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1
714 ,1,0,0,0,1,1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0,0,0,0,0
1201 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1202 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
1203 xx=0; yy=0;
1204 for (int y=68;y<(68+53);++y)
1205 {
1206 for (int x=1112;x<(1112+357);x++) {
1207 if (lable_market_size[get_index(xx,yy,357)] == 1) {
1208 image[get_index(x,y,width)]=color;
1209 }
1210 xx++;
1211 }
1212 yy++;
1213 xx=0;
1214 }
1215
1216 // 16_lable_mars.png
1217 // 53 18
1218 // 1163 700
1219 char lable_mars[]={0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,\
1220 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,
1221 1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1222 1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,
1223 1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,
1224 0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,0,
1225 0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,
1226 1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,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1,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,
1239 0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,
1240 0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,
1241 1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0};
1242 xx=0; yy=0;
1243 for (int y=700;y<(700+18);++y)
1244 {
1245 for (int x=1163;x<(1163+53);x++) {
1246 if (lable_mars[get_index(xx,yy,53)] == 1) {
1247 image[get_index(x,y,width)]=color;
1248 }
1249 xx++;
1250 }
1251 yy++;
1252 xx=0;
1253 }
1254
1255 // 16_lable_mercury.png
1256 // 88 17
1257 // 462 700
1258 char lable_mercury[]={0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,1,1\
1259 ,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1
1260 ,1,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,0
1261 ,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1
1262 ,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1
1263 ,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,1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0,0,0,1,1,1,1,0,0,0,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1
1287 ,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,0
1288 ,0,0,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0
1289 ,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0
1290 ,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1
1291 ,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,1,1,1
1292 ,1,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0
1293 ,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0};
1294 xx=0; yy=0;
1295 for (int y=700;y<(700+17);++y)
1296 {
1297 for (int x=462;x<(462+88);x++) {
1298 if (lable_mercury[get_index(xx,yy,88)] == 1) {
1299 image[get_index(x,y,width)]=color;
1300 }
1301 xx++;
1302 }
1303 yy++;
1304 xx=0;
1305 }
1306
1307 // 16_lable_venus.png
1308 // 58 17
1309 // 1158 345
1310 char lable_venus[]={1,1,1,0,0,0,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1\
1311 ,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,1,1,1
1312 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get_index(x,y,width)]=color;
1340 }
1341 xx++;
1342 }
1343 yy++;
1344 xx=0;
1345 }
1346 }
1347
1348 void draw_label_lines(std::vector<std::tuple<float, float, float>> &image, std::tupl\
1349 e<float,float,float> &color, int width, int height, int radius)
1350 {
1351 std::tuple<int, int, int, int> coords;
1352 std::vector<std::tuple<int,int>> points;
1353 coords=std::make_tuple(976,668,1212,668);
1354 get_line_points(points,coords);
1355 draw(points,image,color,width,height,radius);
1356 points.clear();
1357 coords=std::make_tuple(973,314,1212,314);
1358 get_line_points(points,coords);
1359 draw(points,image,color,width,height,radius);
1360 points.clear();
1361 coords=std::make_tuple(676,685,676,723);
1362 get_line_points(points,coords);
1363 draw(points,image,color,width,height,radius);
1364 points.clear();
1365 coords=std::make_tuple(448,602,448,723);
14 Appendix A: Source Code Listings 355
1366 get_line_points(points,coords);
1367 draw(points,image,color,width,height,radius);
1368 points.clear();
1369 }
1370
1371 void draw_hexagon(std::vector<std::tuple<float, float, float>> &image, std::tuple<fl\
1372 oat,float,float> &color, int centerx, int centery, int radius, int width, int height
1373 , int cradius)
1374 {
1375 std::tuple<int, int, int, int> coords;
1376 float ux = centerx - radius;
1377 float uy = centery - radius;
1378 float pt1x=ux, pt1y=uy, pt2x=ux, pt2y=uy, pt3x=ux, pt3y=uy, pt4x=ux, pt4y=uy, pt5x=\
1379 ux, pt5y=uy, pt6x=ux, pt6y=uy;
1380
1381 float const PI = 3.14159265;
1382 float A, B, C;
1383 A = radius/2;
1384 C = A / sin(30*PI/180);
1385 B = C * cos(30*PI/180);
1386
1387 pt1x += 0; pt1y += B;
1388 pt2x += A; pt2y += 0;
1389 pt3x += A+C; pt3y += 0;
1390 pt4x += 2*C; pt4y += B;
1391 pt5x += A+C; pt5y += 2*B;
1392 pt6x += A; pt6y += 2*B;
1393
1394 std::vector<std::tuple<int,int>> points;
1395 coords=std::make_tuple(pt1x,pt1y,pt2x,pt2y);
1396 get_line_points(points,coords);
1397 draw(points,image,color,width,height,cradius);
1398 points.clear();
1399 coords=std::make_tuple(pt2x,pt2y,pt3x,pt3y);
1400 get_line_points(points,coords);
1401 draw(points,image,color,width,height,cradius);
1402 points.clear();
1403 coords=std::make_tuple(pt3x,pt3y,pt4x,pt4y);
1404 get_line_points(points,coords);
1405 draw(points,image,color,width,height,cradius);
1406 points.clear();
1407 coords=std::make_tuple(pt4x,pt4y,pt5x,pt5y);
1408 get_line_points(points,coords);
14 Appendix A: Source Code Listings 356
1409 draw(points,image,color,width,height,cradius);
1410 points.clear();
1411 coords=std::make_tuple(pt5x,pt5y,pt6x,pt6y);
1412 get_line_points(points,coords);
1413 draw(points,image,color,width,height,cradius);
1414 points.clear();
1415 coords=std::make_tuple(pt6x,pt6y,pt1x,pt1y);
1416 get_line_points(points,coords);
1417 draw(points,image,color,width,height,cradius);
1418 points.clear();
1419 }
1420
1421 void generate_noise_image(std::vector<std::tuple<float, float, float>> &image, int w\
1422 idth, int height)
1423 {
1424 std::tuple<float, float, float> color;
1425 float rndnum=0.0f;
1426
1427 std::random_device rd;
1428 std::mt19937 mt(rd());
1429 std::uniform_real_distribution<float> dist(0.0f, 1.0f);
1430
1431 for (int y=0;y<height;++y) {
1432 for (int x=0;x<width;++x) {
1433 rndnum=dist(mt);
1434 color=std::make_tuple(rndnum,rndnum,rndnum);
1435 image[get_index(x,y,width)]=color;
1436 }
1437 }
1438 }
1439
1440 void generate_linear_gradient_image(std::vector<std::tuple<float, float, float>> &im\
1441 age, std::tuple<float, float, float> &fcolor, std::tuple<float, float, float> &tcolo
1442 r, int width, int height)
1443 {
1444 std::tuple<float, float, float> color;
1445 double resultRed=0.0f;
1446 double resultGreen=0.0f;
1447 double resultBlue=0.0f;
1448 double fr,fg,fb,tr,tg,tb;
1449 double percent=0.0f;
1450 std::tie(fr,fg,fb)=fcolor;
1451 std::tie(tr,tg,tb)=tcolor;
14 Appendix A: Source Code Listings 357
1452
1453 for (int y=0;y<height;++y) {
1454 percent=double(y)/double(height);
1455 resultRed = fr + percent * (tr - fr);
1456 resultGreen = fg + percent * (tg - fg);
1457 resultBlue = fb + percent * (tb - fb);
1458 color=std::make_tuple(resultRed,resultGreen,resultBlue);
1459 for (int x=0;x<width;++x) {
1460 image[get_index(x,y,width)]=color;
1461 }
1462 }
1463 }
1464
1465 void blended_two_images(std::vector<std::tuple<float, float, float>> &blend1,std::ve\
1466 ctor<std::tuple<float, float, float>> &blend2,int width,int height,float alpha)
1467 {
1468 std::tuple<float, float, float> color1=std::make_tuple(0.0f,0.0f,0.0f);
1469 std::tuple<float, float, float> color2=std::make_tuple(0.0f,0.0f,0.0f);
1470 float r=0.0f; float g=0.0f; float b=0.0f;
1471
1472 for (int y=0;y<height;++y) {
1473 for (int x=0;x<width;++x) {
1474 color1=blend1[get_index(x,y,width)];
1475 color2=blend2[get_index(x,y,width)];
1476 r = (std::get<0>(color2) * alpha) + (std::get<0>(color1) * (1.0f - alpha));
1477 g = (std::get<1>(color2) * alpha) + (std::get<1>(color1) * (1.0f - alpha));
1478 b = (std::get<2>(color2) * alpha) + (std::get<2>(color1) * (1.0f - alpha));
1479 blend1[get_index(x,y,width)]=std::make_tuple(r, g, b);
1480 }
1481 }
1482 }
1483
1484 void blend_hexagon(std::vector<std::tuple<float, float, float>> &blend1,std::vector<\
1485 std::tuple<float, float, float>> &blend2,int width,int height)
1486 {
1487 std::tuple<float, float, float> color1=std::make_tuple(0.0f,0.0f,0.0f);
1488 std::tuple<float, float, float> color2=std::make_tuple(1.0f,1.0f,1.0f);
1489 float r=0.0f; float g=0.0f; float b=0.0f; float alpha=0.8f;
1490
1491 for (int y=0;y<height;++y) {
1492 for (int x=0;x<width;++x) {
1493 if (blend2[get_index(x,y,width)] == color2)
1494 {
14 Appendix A: Source Code Listings 358
1495 color1=blend1[get_index(x,y,width)];
1496 r = (std::get<0>(color1) * alpha) + (0.0f * (1.0f - alpha));
1497 g = (std::get<1>(color1) * alpha) + (0.0f * (1.0f - alpha));
1498 b = (std::get<2>(color1) * alpha) + (0.0f * (1.0f - alpha));
1499 blend1[get_index(x,y,width)]=std::make_tuple(r,g,b);
1500 }
1501 }
1502 }
1503 }
1504
1505 double distance(int x1, int y1, int x2, int y2)
1506 {
1507 return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0);
1508 }
1509
1510 void generate_radial_gradient_image(std::vector<std::tuple<float, float, float>> &im\
1511 age, std::tuple<float, float, float> &fcolor, std::tuple<float, float, float> &tcolo
1512 r, int width, int height)
1513 {
1514 std::tuple<float, float, float> color;
1515 std::tuple<float, float, float> pink=std::tuple(1.0f,0.0f,1.0f);
1516 std::vector<std::tuple<float, float, float>> mask;
1517 mask.resize(calc_size(width,height));
1518 double distanceFromCenter=0.0f;
1519 double resultRed=0.0f;
1520 double resultGreen=0.0f;
1521 double resultBlue=0.0f;
1522
1523 for (int y=0;y<height;++y)
1524 {
1525 for (int x=0;x<width;++x)
1526 {
1527 mask[get_index(x,y,width)]=pink;
1528 image[get_index(x,y,width)]=fcolor;
1529 }
1530 }
1531
1532 int x0 = 0;
1533 int y0 = (height/2);
1534 int d = 3 - 2 * (height/2);
1535 int xx=(width/2)-1;
1536 int yy=(height/2)-1;
1537
14 Appendix A: Source Code Listings 359
1581 {
1582 std::tuple<float, float, float> bgcolor=std::make_tuple(1.0f,0.0f,1.0f);
1583 // 0,0 0,22 18,32 36,22 54,32 54,54 36,64 18,54 18,32 36,0 36,22 72,0 72,22 54,32 7\
1584 2,64 54,54 0,64 18,54
1585 for (int y=0;y<height;++y) {
1586 for (int x=0;x<width;++x) {
1587 image[get_index(x,y,width)]=bgcolor;
1588 }
1589 }
1590
1591 int arr[13][2] = {{0,0},{0,22},{18,32},{36,22},{54,32},{54,54},{36,64},{18,54},{36,\
1592 0},{72,0},{72,22},{72,64},{0,64}};
1593 int arr2[13][2] = {{0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,2},{8,3},{9,10},{10\
1594 ,4},{11,5},{12,7}};
1595 std::tuple<int, int, int, int> coords;
1596
1597 for (int i=0;i<13;++i) {
1598 coords=std::make_tuple(int(arr[arr2[i][0]][0]), int(arr[arr2[i][0]][1]), int(arr[a\
1599 rr2[i][1]][0]), int(arr[arr2[i][1]][1]));
1600 draw_line(image,coords,color,width,height);
1601 }
1602 }
1603
1604 void render_repeating_texture_image(std::vector<std::tuple<float, float, float>> &te\
1605 xture, int tw, int th,std::vector<std::tuple<float, float, float>> &image, int iw, i
1606 nt ih)
1607 {
1608 for (int y=0;y<ih;++y) {
1609 for (int x=0;x<iw;++x) {
1610 image[get_index(x,y,iw)]=texture[get_index(x%(tw-1),y%(th-1),tw)];
1611 }
1612 }
1613 }
1614
1615 void do_cookie_cut(std::vector<std::tuple<float, float, float>> &image, int w, int h\
1616 , std::vector<std::tuple<float, float, float>> &cookie, int cw, int ch, int startx,
1617 int starty)
1618 {
1619 int cx=0;int cy=0;
1620 for (int y=starty;y<(starty+ch);++y) {
1621 for (int x=startx;x<(startx+cw);++x) {
1622 cookie[get_index(cx,cy,cw)]=image[get_index(x,y,w)];
1623 cx++;
14 Appendix A: Source Code Listings 361
1624 }
1625 cy++;
1626 cx=0;
1627 }
1628 }
1629
1630 void add_honeycomb(std::vector<std::tuple<float, float, float>> &image, std::vector<\
1631 std::tuple<float, float, float>> &alpha, std::vector<std::tuple<float, float, float>
1632 > &texture, int w, int h)
1633 {
1634 std::tuple<float, float, float> color1;
1635 std::tuple<float, float, float> color2;
1636 std::tuple<float, float, float> color3;
1637 std::tuple<float, float, float> pink=std::make_tuple(1.0f,0.0f,1.0f);
1638 float ir,ig,ib;
1639
1640 for (int y=0;y<h;++y) {
1641 for (int x=0;x<w;++x) {
1642 if (texture[get_index(x,y,w)] != pink) {
1643 color1=image[get_index(x,y,w)];
1644 color2=texture[get_index(x,y,w)];
1645 color3=alpha[get_index(x,y,w)];
1646 ir = ((std::get<0>(color2) * std::get<0>(color3)) + (std::get<0>(col
1647 - std::get<0>(color3))));
1648 ig = ((std::get<1>(color2) * std::get<0>(color3)) + (std::get<1>(col
1649 - std::get<0>(color3))));
1650 ib = ((std::get<2>(color2) * std::get<0>(color3)) + (std::get<2>(col
1651 - std::get<0>(color3))));
1652 image[get_index(x,y,w)]=std::make_tuple(ir,ig,ib);
1653 }
1654 }
1655 }
1656 }
1657
1658 void add_white_heaxagon_border(std::vector<std::tuple<float, float, float>> &image1,\
1659 std::vector<std::tuple<float, float, float>> &image2,int width,int height)
1660 {
1661 std::tuple<float, float, float> color=std::make_tuple(1.0f,1.0f,1.0f);
1662
1663 for (int y=0;y<height;++y) {
1664 for (int x=0;x<width;++x) {
1665 if (image2[get_index(x,y,width)] == color)
1666 {
14 Appendix A: Source Code Listings 362
1667 image1[get_index(x,y,width)]=color;
1668 }
1669 }
1670 }
1671 }
1672
1673 void stamp_cookie(std::vector<std::tuple<float, float, float>> &image, int w, int h,\
1674 std::vector<std::tuple<float, float, float>> &cookie, int cw, int ch, int startx, i
1675 nt starty)
1676 {
1677 int cx=0;int cy=0;
1678 for (int y=starty;y<(starty+ch);++y) {
1679 for (int x=startx;x<(startx+cw);++x) {
1680 image[get_index(x,y,w)]=cookie[get_index(cx,cy,cw)];
1681 cx++;
1682 }
1683 cy++;
1684 cx=0;
1685 }
1686 }
1687
1688 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
1689 height, std::string filename)
1690 {
1691 std::tuple<float, float, float> color;
1692 std::ofstream out(filename, std::ios_base::out | std::ios_base::binary);
1693 out << "P6" << std::endl << width << ' ' << height << std::endl << "255" << std::en\
1694 dl;
1695
1696 for (int i=0;i<(width*height);++i)
1697 {
1698 color=image[i];
1699 out << char(std::get<0>(color)*255.0f) << char(std::get<1>(color)*255.0f) << char(\
1700 std::get<2>(color)*255.0f);
1701 }
1702 out.close();
1703 }
1704
1705 int main()
1706 {
1707 std::vector<std::tuple<float, float, float>> image1;
1708 int width=1600,height=900;
1709
14 Appendix A: Source Code Listings 363
1710 image1.resize(calc_size(width,height));
1711
1712 generate_noise_image(image1, width, height);
1713
1714 std::cout << "saving: 16_draw_market_size1.ppm." << std::endl;
1715 save_image(image1,width,height,"16_draw_market_size1.ppm");
1716
1717 std::vector<std::tuple<float, float, float>> image2;
1718 image2.resize(calc_size(width,height));
1719
1720 std::tuple<float, float, float> fcolor=std::make_tuple(0.5294117647f,0.8235294118f,\
1721 0.8078431373f);
1722 std::tuple<float, float, float> tcolor=std::make_tuple(0.2588235294f,0.2196078431f,\
1723 0.3921568627f);
1724 generate_linear_gradient_image(image2,fcolor,tcolor,width,height);
1725
1726 std::cout << "saving: 16_draw_market_size2.ppm." << std::endl;
1727 save_image(image2,width,height,"16_draw_market_size2.ppm");
1728
1729 blended_two_images(image1,image2,width,height,0.9);
1730
1731 std::cout << "saving: 16_draw_market_size3.ppm." << std::endl;
1732 save_image(image1,width,height,"16_draw_market_size3.ppm");
1733
1734 // radial gradient
1735 std::vector<std::tuple<float, float, float>> image3;
1736 image3.resize(calc_size(900,900));
1737
1738 fcolor=std::make_tuple(1.0f,1.0f,1.0f);
1739 tcolor=std::make_tuple(0.0f,0.0f,0.0f);
1740
1741 generate_radial_gradient_image(image3,fcolor,tcolor,900,900);
1742
1743 std::cout << "saving: 16_draw_market_size4.ppm." << std::endl;
1744 save_image(image3,900,900,"16_draw_market_size4.ppm");
1745
1746 // Repeating texture generation
1747 std::vector<std::tuple<float, float, float>> image4;
1748 image4.resize(calc_size(73,65));
1749
1750 fcolor=std::make_tuple(0.5294117647f,0.8235294118f,0.8078431373f);
1751 generate_repeating_texture_image(image4,fcolor,73,65);
1752
14 Appendix A: Source Code Listings 364
1796 flood_fill(image7,784,340,tcolor,fcolor,width);
1797 flood_fill(image7,520,500,tcolor,fcolor,width);
1798 flood_fill(image7,730,610,tcolor,fcolor,width);
1799 flood_fill(image7,900,680,tcolor,fcolor,width);
1800
1801 std::cout << "saving: 16_draw_market_size10.ppm." << std::endl;
1802 save_image(image7,width,height,"16_draw_market_size10.ppm");
1803
1804 std::vector<std::tuple<float, float, float>> image8;
1805 image8.resize(calc_size(width,height));
1806 fcolor=std::make_tuple(1.0f,1.0f,1.0f);
1807 draw_hexagon(image8,fcolor,784,340,190,width,height,2);
1808 draw_hexagon(image8,fcolor,520,500,143,width,height,2);
1809 draw_hexagon(image8,fcolor,730,610,107,width,height,2);
1810 draw_hexagon(image8,fcolor,900,680,76,width,height,2);
1811
1812 std::cout << "saving: 16_draw_market_size11.ppm." << std::endl;
1813 save_image(image8,width,height,"16_draw_market_size11.ppm");
1814
1815 blend_hexagon(image1,image7,width,height);
1816
1817 std::cout << "saving: 16_draw_market_size12.ppm." << std::endl;
1818 save_image(image1,width,height,"16_draw_market_size12.ppm");
1819
1820 add_white_heaxagon_border(image1,image8,width,height);
1821
1822 std::cout << "saving: 16_draw_market_size13.ppm." << std::endl;
1823 save_image(image1,width,height,"16_draw_market_size13.ppm");
1824
1825 // Add label lines
1826 fcolor=std::make_tuple(1.0f,1.0f,1.0f);
1827 draw_label_lines(image1,fcolor,width,height,2);
1828
1829 std::cout << "saving: 16_draw_market_size14.ppm." << std::endl;
1830 save_image(image1,width,height,"16_draw_market_size14.ppm");
1831
1832 // Add labels
1833 draw_labels(image1,fcolor,width,height);
1834
1835 std::cout << "saving: 16_draw_market_size15.ppm." << std::endl;
1836 save_image(image1,width,height,"16_draw_market_size15.ppm");
1837
1838 return 0;
14 Appendix A: Source Code Listings 366
1839 }
83 if (dy == 0)
84 {
85 if (x2 < x1) std::swap(x1, x2);
86 for (x = x1; x <= x2; x++)
87 coords.push_back(std::make_tuple(x,y1));
88 return;
89 }
90 dx1 = abs(dx); dy1 = abs(dy);
91 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
92 if (dy1 <= dx1)
93 {
94 if (dx >= 0)
95 {
96 x = x1; y = y1; xe = x2;
97 }
98 else
99 {
100 x = x2; y = y2; xe = x1;
101 }
102 coords.push_back(std::make_tuple(x,y));
103 for (i = 0; x<xe; i++)
104 {
105 x = x + 1;
106 if (px<0)
107 px = px + 2 * dy1;
108 else
109 {
110 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
111 px = px + 2 * (dy1 - dx1);
112 }
113 coords.push_back(std::make_tuple(x,y));
114 }
115 }
116 else
117 {
118 if (dy >= 0)
119 {
120 x = x1; y = y1; ye = y2;
121 }
122 else
123 {
124 x = x2; y = y2; ye = y1;
125 }
14 Appendix A: Source Code Listings 369
126 coords.push_back(std::make_tuple(x,y));
127 for (i = 0; y<ye; i++)
128 {
129 y = y + 1;
130 if (py <= 0)
131 py = py + 2 * dx1;
132 else
133 {
134 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
135 py = py + 2 * (dx1 - dy1);
136 }
137 coords.push_back(std::make_tuple(x,y));
138 }
139 }
140 }
141
142 void draw_filled_wedge(int x_cen,int y_cen,int rad,int start_ang,int end_ang,std::ve\
143 ctor<std::tuple<float, float, float>> &image,std::tuple<float, float, float> &color,
144 int width, int height)
145 {
146 std::vector<std::tuple<int,int>> coords;
147
148 float ang=(((start_ang<=end_ang)?start_ang:end_ang)*(M_PI/180));
149 float range=(((end_ang>start_ang)?end_ang:start_ang)*(M_PI/180));
150 float x=(rad*cos(ang));
151 float y=(rad*sin(ang));
152 do
153 {
154 coords.push_back(std::make_tuple((int)(x_cen+x+0.5),(int)(y_cen-y+0.5)));
155 ang+=0.001;
156 x=(rad*cos(ang));
157 y=(rad*sin(ang));
158 }
159 while(ang<=range);
160
161 std::tuple<int,int> co1=coords.front();
162 std::tuple<int,int> co2=coords.back();
163
164 draw_line_coords(x_cen,y_cen,std::get<0>(co1),std::get<1>(co1),coords);
165 draw_line_coords(x_cen,y_cen,std::get<0>(co2),std::get<1>(co2),coords);
166
167 std::vector<int> ys;
168 std::vector<int> xs;
14 Appendix A: Source Code Listings 370
169 get_all_ys(ys,coords);
170 std::vector<std::tuple<int,int,int,int>> lines;
171
172 for (int search=0;search<=ys.size();++search)
173 {
174 for (auto& c : coords) {
175 if (std::get<1>(c) == ys[search]) {
176 xs.push_back(std::get<0>(c));
177 }
178 }
179 sort(xs.begin(), xs.end());
180 lines.push_back(std::make_tuple(xs.front(),ys[search],xs.back(),ys[search]));
181 xs.clear();
182 }
183
184 auto drawline = [&](int sx, int ex, int ny)
185 {
186 for (int i = sx; i <= ex; i++)
187 image[get_index(i, ny, width)]=color;
188 };
189
190 for (auto& l : lines) {
191 drawline(std::get<0>(l),std::get<2>(l),std::get<1>(l));
192 }
193 }
194
195 void draw_line(std::vector<std::tuple<float, float, float>> &image, std::tuple<int, \
196 int, int, int> &coords, std::tuple<float,float,float> &color, int width, int height)
197 {
198 int x1=std::get<0>(coords); int y1=std::get<1>(coords); int x2=std::get<2>(coords);\
199 int y2=std::get<3>(coords);
200 int x, y, dx, dy, dx1, dy1, px, py, xe, ye, i;
201 dx = x2 - x1; dy = y2 - y1;
202
203 if (dx == 0)
204 {
205 if (y2 < y1) std::swap(y1, y2);
206 for (y = y1; y <= y2; y++)
207 image[get_index(x1,y,width)]=color;
208 return;
209 }
210 if (dy == 0)
211 {
14 Appendix A: Source Code Listings 371
255 {
256 y = y + 1;
257 if (py <= 0)
258 py = py + 2 * dx1;
259 else
260 {
261 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
262 py = py + 2 * (dx1 - dy1);
263 }
264 image[get_index(x,y,width)]=color;
265 }
266 }
267 }
268
269 void generate_noise_image(std::vector<std::tuple<float, float, float>> &image, int w\
270 idth, int height)
271 {
272 std::tuple<float, float, float> color;
273 float rndnum=0.0f;
274
275 std::random_device rd;
276 std::mt19937 mt(rd());
277 std::uniform_real_distribution<float> dist(0.0f, 1.0f);
278
279 for (int y=0;y<height;++y) {
280 for (int x=0;x<width;++x) {
281 rndnum=dist(mt);
282 color=std::make_tuple(rndnum,rndnum,rndnum);
283 image[get_index(x,y,width)]=color;
284 }
285 }
286 }
287
288 void generate_linear_gradient_image(std::vector<std::tuple<float, float, float>> &im\
289 age, std::tuple<float, float, float> &fcolor, std::tuple<float, float, float> &tcolo
290 r, int width, int height)
291 {
292 std::tuple<float, float, float> color;
293 double resultRed=0.0f;
294 double resultGreen=0.0f;
295 double resultBlue=0.0f;
296 double fr,fg,fb,tr,tg,tb;
297 double percent=0.0f;
14 Appendix A: Source Code Listings 373
298 std::tie(fr,fg,fb)=fcolor;
299 std::tie(tr,tg,tb)=tcolor;
300
301 for (int y=0;y<height;++y) {
302 percent=double(y)/double(height);
303 resultRed = fr + percent * (tr - fr);
304 resultGreen = fg + percent * (tg - fg);
305 resultBlue = fb + percent * (tb - fb);
306 color=std::make_tuple(resultRed,resultGreen,resultBlue);
307 for (int x=0;x<width;++x) {
308 image[get_index(x,y,width)]=color;
309 }
310 }
311 }
312
313 void blended_two_images(std::vector<std::tuple<float, float, float>> &blend1,std::ve\
314 ctor<std::tuple<float, float, float>> &blend2,int width,int height,float alpha)
315 {
316 std::tuple<float, float, float> color1=std::make_tuple(0.0f,0.0f,0.0f);
317 std::tuple<float, float, float> color2=std::make_tuple(0.0f,0.0f,0.0f);
318 float r=0.0f; float g=0.0f; float b=0.0f;
319
320 for (int y=0;y<height;++y) {
321 for (int x=0;x<width;++x) {
322 color1=blend1[get_index(x,y,width)];
323 color2=blend2[get_index(x,y,width)];
324 r = (std::get<0>(color2) * alpha) + (std::get<0>(color1) * (1.0f - alpha));
325 g = (std::get<1>(color2) * alpha) + (std::get<1>(color1) * (1.0f - alpha));
326 b = (std::get<2>(color2) * alpha) + (std::get<2>(color1) * (1.0f - alpha));
327 blend1[get_index(x,y,width)]=std::make_tuple(r, g, b);
328 }
329 }
330 }
331
332 double distance(int x1, int y1, int x2, int y2)
333 {
334 return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0);
335 }
336
337 void generate_radial_gradient_image(std::vector<std::tuple<float, float, float>> &im\
338 age, std::tuple<float, float, float> &fcolor, std::tuple<float, float, float> &tcolo
339 r, int width, int height)
340 {
14 Appendix A: Source Code Listings 374
384 }
385
386 for (int y=0;y<height;++y)
387 {
388 for (int x=0;x<width;++x)
389 {
390 if (mask[get_index(x,y,width)] != pink) {
391 distanceFromCenter = (distance(x, y, width/2, height/2)/(height/2));
392 resultRed = std::get<0>(fcolor) + distanceFromCenter * (std::get<0>(
393 d::get<0>(fcolor));
394 resultGreen = std::get<1>(fcolor) + distanceFromCenter * (std::get<1
395 std::get<1>(fcolor));
396 resultBlue = std::get<2>(fcolor) + distanceFromCenter * (std::get<2>
397 td::get<2>(fcolor));
398 color=std::tuple(resultRed,resultGreen,resultBlue);
399 image[get_index(x,y,width)]=color;
400 } else {
401 image[get_index(x,y,width)]=tcolor;
402 }
403 }
404 }
405 }
406
407 void generate_repeating_texture_image(std::vector<std::tuple<float, float, float>> &\
408 image, std::tuple<float, float, float> &color, int width, int height)
409 {
410 std::tuple<float, float, float> bgcolor=std::make_tuple(1.0f,0.0f,1.0f);
411 // 0,0 0,22 18,32 36,22 54,32 54,54 36,64 18,54 18,32 36,0 36,22 72,0 72,22 54,32 7\
412 2,64 54,54 0,64 18,54
413 for (int y=0;y<height;++y) {
414 for (int x=0;x<width;++x) {
415 image[get_index(x,y,width)]=bgcolor;
416 }
417 }
418
419 int arr[13][2] = {{0,0},{0,22},{18,32},{36,22},{54,32},{54,54},{36,64},{18,54},{36,\
420 0},{72,0},{72,22},{72,64},{0,64}};
421 int arr2[13][2] = {{0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,2},{8,3},{9,10},{10\
422 ,4},{11,5},{12,7}};
423 std::tuple<int, int, int, int> coords;
424
425 for (int i=0;i<13;++i) {
426 coords=std::make_tuple(int(arr[arr2[i][0]][0]), int(arr[arr2[i][0]][1]), int(arr[a\
14 Appendix A: Source Code Listings 376
513 ,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0
514 ,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1
515 ,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,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1
574 ,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1
575 ,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1
576 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0
577 ,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0
578 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0};
579 int xx=0; int yy=0;
580 for (int y=577;y<(577+38);++y)
581 {
582 for (int x=1198;x<(1198+79);x++) {
583 if (lable_investment_10[get_index(xx,yy,79)] == 1) {
584 image[get_index(x,y,width)]=color;
585 }
586 xx++;
587 }
588 yy++;
589 xx=0;
590 }
591
592 // 16_lable_investment_20.png
593 // 80 38
594 // 338 615
595 char lable_investment_20[]={0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
596 ,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0
597 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
598 ,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0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672 if (lable_investment_20[get_index(xx,yy,80)] == 1) {
673 image[get_index(x,y,width)]=color;
674 }
675 xx++;
676 }
677 yy++;
678 xx=0;
679 }
680
681 // 16_lable_investment_30.png
682 // 81 38
683 // 1196 345
684 char lable_investment_30[]={0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
14 Appendix A: Source Code Listings 382
685 ,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0
686 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
687 ,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0
688 ,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1
689 ,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
690 ,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0
691 ,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0
692 ,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0
693 ,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
694 ,1,1,1,1,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0
753 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1
754 ,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0
755 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0
756 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
757 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0};
758 xx=0; yy=0;
759 for (int y=345;y<(345+38);++y)
760 {
761 for (int x=1196;x<(1196+81);x++) {
762 if (lable_investment_30[get_index(xx,yy,81)] == 1) {
763 image[get_index(x,y,width)]=color;
764 }
765 xx++;
766 }
767 yy++;
768 xx=0;
769 }
770
14 Appendix A: Source Code Listings 384
771 // 16_lable_investment_40.png
772 // 81 38
773 // 337 430
774 char lable_investment_40[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0\
775 ,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0
776 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
777 ,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0
778 ,0,0,0,0,0,0,0,0,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int y=430;y<(430+38);++y)
850 {
851 for (int x=337;x<(337+81);x++) {
852 if (lable_investment_40[get_index(xx,yy,81)] == 1) {
853 image[get_index(x,y,width)]=color;
854 }
855 xx++;
856 }
14 Appendix A: Source Code Listings 386
857 yy++;
858 xx=0;
859 }
860
861 // 16_lable_investment_investment.png
862 // 338 52
863 // 1114 128
864 char lable_investment_investment[]={1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
865 ,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0
866 ,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1
867 ,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
868 ,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0
869 ,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
870 ,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0
871 ,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1
872 ,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
873 ,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1277 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
1278 ,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1279 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1280 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1281 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1282 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
1283 xx=0; yy=0;
1284 for (int y=128;y<(128+52);++y)
1285 {
1286 for (int x=1114;x<(1114+338);x++) {
14 Appendix A: Source Code Listings 396
1287 if (lable_investment_investment[get_index(xx,yy,338)] == 1) {
1288 image[get_index(x,y,width)]=color;
1289 }
1290 xx++;
1291 }
1292 yy++;
1293 xx=0;
1294 }
1295
1296 // 16_lable_investment_jupiter.png
1297 // 84 20
1298 // 1194 440
1299 char lable_investment_jupiter[]={0,0,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,\
1300 0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,
1301 1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,
1337 1,1,1,0,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,
1338 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1339 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
1340 xx=0; yy=0;
1341 for (int y=440;y<(440+20);++y)
1342 {
1343 for (int x=1194;x<(1194+84);x++) {
1344 if (lable_investment_jupiter[get_index(xx,yy,84)] == 1) {
1345 image[get_index(x,y,width)]=color;
1346 }
1347 xx++;
1348 }
1349 yy++;
1350 xx=0;
1351 }
1352
1353 // 16_lable_investment_mercury.png
1354 // 101 20
1355 // 337 519
1356 char lable_investment_mercury[]={0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,\
1357 1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,0,0,
1358 0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,
1359 1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,
1360 1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,
1361 1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,
1362 1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,1,1,1,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1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,
1398 0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,
1399 0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,
1400 0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,
1401 1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,
1402 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1403 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,
1404 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
1405 xx=0; yy=0;
1406 for (int y=519;y<(519+20);++y)
1407 {
1408 for (int x=337;x<(337+101);x++) {
1409 if (lable_investment_mercury[get_index(xx,yy,101)] == 1) {
1410 image[get_index(x,y,width)]=color;
1411 }
1412 xx++;
1413 }
1414 yy++;
1415 xx=0;
14 Appendix A: Source Code Listings 399
1416 }
1417
1418 // 16_lable_investment_saturn.png
1419 // 81 20
1420 // 1197 665
1421 char lable_investment_saturn[]={0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0\
1422 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1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0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,1,1
1458 ,1,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0
14 Appendix A: Source Code Listings 400
1459 ,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,1,1,1};
1460 xx=0; yy=0;
1461 for (int y=665;y<(665+20);++y)
1462 {
1463 for (int x=1197;x<(1197+81);x++) {
1464 if (lable_investment_saturn[get_index(xx,yy,81)] == 1) {
1465 image[get_index(x,y,width)]=color;
1466 }
1467 xx++;
1468 }
1469 yy++;
1470 xx=0;
1471 }
1472
1473 // 16_lable_investment_venus.png
1474 // 66 20
1475 // 336 705
1476 char lable_investment_venus[]={1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,\
1477 0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,
1478 1,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,
1479 1,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,
1480 1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,
1481 1,1,1,1,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,
1482 0,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,1,1,1,0,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506 1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,
1507 0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0};
1508 xx=0; yy=0;
1509 for (int y=705;y<(705+20);++y)
1510 {
1511 for (int x=336;x<(336+66);x++) {
1512 if (lable_investment_venus[get_index(xx,yy,66)] == 1) {
1513 image[get_index(x,y,width)]=color;
1514 }
1515 xx++;
1516 }
1517 yy++;
1518 xx=0;
1519 }
1520 }
1521
1522 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
1523 height, std::string filename)
1524 {
1525 std::tuple<float, float, float> color;
1526 std::ofstream out(filename, std::ios_base::out | std::ios_base::binary);
1527 out << "P6" << std::endl << width << ' ' << height << std::endl << "255" << std::en\
1528 dl;
1529
1530 for (int i=0;i<(width*height);++i)
1531 {
1532 color=image[i];
1533 out << char(std::get<0>(color)*255.0f) << char(std::get<1>(color)*255.0f) << char(\
1534 std::get<2>(color)*255.0f);
1535 }
1536 out.close();
1537 }
1538
1539 int main()
1540 {
1541 std::vector<std::tuple<float, float, float>> image1;
1542 int width=1600,height=900;
1543
1544 image1.resize(calc_size(width,height));
14 Appendix A: Source Code Listings 402
1545
1546 generate_noise_image(image1, width, height);
1547
1548 std::cout << "saving: 16_draw_investment1.ppm." << std::endl;
1549 save_image(image1,width,height,"16_draw_investment1.ppm");
1550
1551 std::vector<std::tuple<float, float, float>> image2;
1552 image2.resize(calc_size(width,height));
1553
1554 std::tuple<float, float, float> fcolor=std::make_tuple(0.5294117647f,0.8235294118f,\
1555 0.8078431373f);
1556 std::tuple<float, float, float> tcolor=std::make_tuple(0.2588235294f,0.2196078431f,\
1557 0.3921568627f);
1558 generate_linear_gradient_image(image2,fcolor,tcolor,width,height);
1559
1560 std::cout << "saving: 16_draw_investment2.ppm." << std::endl;
1561 save_image(image2,width,height,"16_draw_investment2.ppm");
1562
1563 blended_two_images(image1,image2,width,height,0.9);
1564
1565 std::cout << "saving: 16_draw_investment3.ppm." << std::endl;
1566 save_image(image1,width,height,"16_draw_investment3.ppm");
1567
1568 // radial gradient
1569 std::vector<std::tuple<float, float, float>> image3;
1570 image3.resize(calc_size(900,900));
1571
1572 fcolor=std::make_tuple(1.0f,1.0f,1.0f);
1573 tcolor=std::make_tuple(0.0f,0.0f,0.0f);
1574
1575 generate_radial_gradient_image(image3,fcolor,tcolor,900,900);
1576
1577 std::cout << "saving: 16_draw_investment4.ppm." << std::endl;
1578 save_image(image3,900,900,"16_draw_investment4.ppm");
1579
1580 // Repeating texture generation
1581 std::vector<std::tuple<float, float, float>> image4;
1582 image4.resize(calc_size(73,65));
1583
1584 fcolor=std::make_tuple(0.5294117647f,0.8235294118f,0.8078431373f);
1585 generate_repeating_texture_image(image4,fcolor,73,65);
1586
1587 std::cout << "saving: 16_draw_investment5.ppm." << std::endl;
14 Appendix A: Source Code Listings 403
1588 save_image(image4,73,65,"16_draw_investment5.ppm");
1589
1590 // Render repeating texture
1591 std::vector<std::tuple<float, float, float>> image5;
1592 image5.resize(calc_size(900,900));
1593
1594 render_repeating_texture_image(image4,73,65,image5,900,900);
1595
1596 std::cout << "saving: 16_draw_investment6.ppm." << std::endl;
1597 save_image(image5,900,900,"16_draw_investment6.ppm");
1598
1599 // Do cookie cut
1600 std::vector<std::tuple<float, float, float>> image6;
1601 image6.resize(calc_size(900,900));
1602
1603 do_cookie_cut(image1,width,height,image6,900,900,350,0);
1604
1605 std::cout << "saving: 16_draw_investment7.ppm." << std::endl;
1606 save_image(image6,900,900,"16_draw_investment7.ppm");
1607
1608 // Add honeycomb
1609 add_honeycomb(image6,image3,image5,900,900);
1610
1611 std::cout << "saving: 16_draw_investment8.ppm." << std::endl;
1612 save_image(image6,900,900,"16_draw_investment8.ppm");
1613
1614 // Stamp cookie
1615 stamp_cookie(image1,width,height,image6,900,900,350,0);
1616
1617 std::cout << "saving: 16_draw_investment9.ppm." << std::endl;
1618 save_image(image1,width,height,"16_draw_investment9.ppm");
1619
1620 // Create Doughnut
1621 std::vector<std::tuple<float, float, float>> image7;
1622 std::tuple<int, int, int, int> coords;
1623 image7.resize(calc_size(width,height));
1624 fcolor=std::make_tuple(1.0f,0.0f,1.0f);
1625 clear_image(image7,fcolor,width,height);
1626 fcolor=std::make_tuple(1.0f,1.0f,1.0f);
1627 draw_filled_wedge(801,491,209,0,79,image7,fcolor,width,height);
1628 draw_filled_wedge(801,491,209,331,360,image7,fcolor,width,height);
1629 coords=std::make_tuple(988,412,1277,412);
1630 draw_line(image7,coords,fcolor,width,height);
14 Appendix A: Source Code Listings 404
1631 coords=std::make_tuple(988,413,1277,413);
1632 draw_line(image7,coords,fcolor,width,height);
1633 // fcolor=std::make_tuple(1.0f,0.0f,1.0f);
1634 // draw_filled_wedge(801,491,156,0,60,image7,fcolor,width,height);
1635 // draw_filled_wedge(801,491,156,312,360,image7,fcolor,width,height);
1636 fcolor=std::make_tuple(0.8f,0.8f,0.8f);
1637 draw_filled_wedge(801,491,200,79,223,image7,fcolor,width,height);
1638 coords=std::make_tuple(604,489,335,489);
1639 draw_line(image7,coords,fcolor,width,height);
1640 coords=std::make_tuple(604,490,335,490);
1641 draw_line(image7,coords,fcolor,width,height);
1642 // fcolor=std::make_tuple(1.0f,0.0f,1.0f);
1643 // draw_filled_wedge(801,491,156,60,204,image7,fcolor,width,height);
1644 fcolor=std::make_tuple(0.8509803922f,0.8509803922f,0.8509803922f);
1645 draw_filled_wedge(801,491,203,223,294,image7,fcolor,width,height);
1646 coords=std::make_tuple(737,679,335,679);
1647 draw_line(image7,coords,fcolor,width,height);
1648 coords=std::make_tuple(737,680,335,680);
1649 draw_line(image7,coords,fcolor,width,height);
1650 fcolor=std::make_tuple(0.9411764706f,0.9411764706f,0.9411764706f);
1651 draw_filled_wedge(801,491,206,294,331,image7,fcolor,width,height);
1652 coords=std::make_tuple(938,640,1277,640);
1653 draw_line(image7,coords,fcolor,width,height);
1654 coords=std::make_tuple(938,641,1277,641);
1655 draw_line(image7,coords,fcolor,width,height);
1656 fcolor=std::make_tuple(1.0f,0.0f,1.0f);
1657 draw_filled_circle(801,491,153,image7,fcolor,width,height);
1658
1659 fcolor=std::make_tuple(1.0f,1.0f,1.0f);
1660 draw_labels(image7,fcolor,width,height);
1661
1662 std::cout << "saving: 16_draw_investment10.ppm." << std::endl;
1663 save_image(image7,width,height,"16_draw_investment10.ppm");
1664
1665 // Add doughnut to image1
1666 fcolor=std::make_tuple(1.0f,0.0f,1.0f);
1667 for (int y=0;y<height;++y) {
1668 for (int x=0;x<width;++x) {
1669 if (image7[get_index(x,y,width)] != fcolor) {
1670 image1[get_index(x,y,width)]=image7[get_index(x,y,width)];
1671 }
1672 }
1673 }
14 Appendix A: Source Code Listings 405
1674
1675 std::cout << "saving: 16_draw_investment11.ppm." << std::endl;
1676 save_image(image1,width,height,"16_draw_investment11.ppm");
1677
1678 return 0;
1679 }
35 height)
36 {
37 for (int y=0;y<height;++y) {
38 for (int x=0;x<width;++x) {
39 image[get_index(x,y,width)]=std::make_tuple(0.0f, 0.0f, 0.0f);
40 }
41 }
42 }
43
44 void generate_noise_image(std::vector<std::tuple<float, float, float>> &image, int w\
45 idth, int height)
46 {
47 std::tuple<float, float, float> color;
48 float rndnum=0.0f;
49
50 std::random_device rd;
51 std::mt19937 mt(rd());
52 std::uniform_real_distribution<float> dist(0.0f, 1.0f);
53
54 for (int y=0;y<height;++y) {
55 for (int x=0;x<width;++x) {
56 rndnum=dist(mt);
57 color=std::make_tuple(rndnum,rndnum,rndnum);
58 image[get_index(x,y,width)]=color;
59 }
60 }
61 }
62
63 void generate_linear_gradient_image(std::vector<std::tuple<float, float, float>> &im\
64 age, std::tuple<float, float, float> &fcolor, std::tuple<float, float, float> &tcolo
65 r, int width, int height)
66 {
67 std::tuple<float, float, float> color;
68 double resultRed=0.0f;
69 double resultGreen=0.0f;
70 double resultBlue=0.0f;
71 double fr,fg,fb,tr,tg,tb;
72 double percent=0.0f;
73 std::tie(fr,fg,fb)=fcolor;
74 std::tie(tr,tg,tb)=tcolor;
75
76 for (int y=0;y<height;++y) {
77 percent=double(y)/double(height);
14 Appendix A: Source Code Listings 407
121 if (dy == 0)
122 {
123 if (x2 < x1) std::swap(x1, x2);
124 for (x = x1; x <= x2; x++)
125 image[get_index(x,y1,width)]=color;
126 return;
127 }
128 dx1 = abs(dx); dy1 = abs(dy);
129 px = 2 * dy1 - dx1; py = 2 * dx1 - dy1;
130 if (dy1 <= dx1)
131 {
132 if (dx >= 0)
133 {
134 x = x1; y = y1; xe = x2;
135 }
136 else
137 {
138 x = x2; y = y2; xe = x1;
139 }
140 image[get_index(x,y,width)]=color;
141 for (i = 0; x<xe; i++)
142 {
143 x = x + 1;
144 if (px<0)
145 px = px + 2 * dy1;
146 else
147 {
148 if ((dx<0 && dy<0) || (dx>0 && dy>0)) y = y + 1; else y = y - 1;
149 px = px + 2 * (dy1 - dx1);
150 }
151 image[get_index(x,y,width)]=color;
152 }
153 }
154 else
155 {
156 if (dy >= 0)
157 {
158 x = x1; y = y1; ye = y2;
159 }
160 else
161 {
162 x = x2; y = y2; ye = y1;
163 }
14 Appendix A: Source Code Listings 409
164 image[get_index(x,y,width)]=color;
165 for (i = 0; y<ye; i++)
166 {
167 y = y + 1;
168 if (py <= 0)
169 py = py + 2 * dx1;
170 else
171 {
172 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; else x = x - 1;
173 py = py + 2 * (dx1 - dy1);
174 }
175 image[get_index(x,y,width)]=color;
176 }
177 }
178 }
179
180 int find_region(int x, int y, int width, int height)
181 {
182 int code=0;
183 if(y >= height)
184 code |= 1; //top
185 else if(y < 0)
186 code |= 2; //bottom
187 if(x >= width)
188 code |= 4; //right
189 else if (x < 0)
190 code |= 8; //left
191 return(code);
192 }
193
194 bool clip_line(std::tuple<int, int, int, int> &coords1, std::tuple<int, int, int, in\
195 t> &coords2, int width, int height)
196 {
197 int x1=std::get<0>(coords1); int y1=std::get<1>(coords1); int x2=std::get<2>(coords\
198 1); int y2=std::get<3>(coords1);
199 int x3=0; int y3=0; int x4=0; int y4=0;
200 int code1=0, code2=0, codeout=0;
201 bool accept = 0, done=0;
202 code1 = find_region(x1, y1, width, height); //the region outcodes for the endpoints
203 code2 = find_region(x2, y2, width, height);
204 do //In theory, this can never end up in an infinite loop, it'll always come in one\
205 of the trivial cases eventually
206 {
14 Appendix A: Source Code Listings 410
207 if(!(code1 | code2)) accept = done = 1; //accept because both endpoints are in sc\
208 reen or on the border, trivial accept
209 else if(code1 & code2) done = 1; //the line isn't visible on screen, trivial reject
210 else //if no trivial reject or accept, continue the loop
211 {
212 int x, y;
213 codeout = code1 ? code1 : code2;
214 if(codeout & 1) //top
215 {
216 x = x1 + (x2 - x1) * (height - y1) / (y2 - y1);
217 y = height - 1;
218 }
219 else if(codeout & 2) //bottom
220 {
221 x = x1 + (x2 - x1) * -y1 / (y2 - y1);
222 y = 0;
223 }
224 else if(codeout & 4) //right
225 {
226 y = y1 + (y2 - y1) * (width - x1) / (x2 - x1);
227 x = width - 1;
228 }
229 else //left
230 {
231 y = y1 + (y2 - y1) * -x1 / (x2 - x1);
232 x = 0;
233 }
234 if(codeout == code1) //first endpoint was clipped
235 {
236 x1 = x; y1 = y;
237 code1 = find_region(x1, y1, width, height);
238 }
239 else //second endpoint was clipped
240 {
241 x2 = x; y2 = y;
242 code2 = find_region(x2, y2, width, height);
243 }
244 }
245 }
246 while(done == 0);
247 if(accept)
248 {
249 x3 = x1;
14 Appendix A: Source Code Listings 411
250 x4 = x2;
251 y3 = y1;
252 y4 = y2;
253 coords2=std::make_tuple(x3,y3,x4,y4);
254 return 1;
255 }
256 else
257 {
258 x3 = x4 = y3 = y4 = 0;
259 coords2=std::make_tuple(x3,y3,x4,y4);
260 return 0;
261 }
262 }
263
264 void get_angle_line(std::tuple<int, int, int, int> &coords,int x_cen,int y_cen,doubl\
265 e degrees,int length)
266 {
267 double angle = degrees * (M_PI / 180);
268 coords=std::make_tuple(x_cen,y_cen,int(double(x_cen) + cos(angle)*double(length)),i\
269 nt(double(y_cen) + sin(angle)*double(length)));
270 }
271
272 void save_image(std::vector<std::tuple<float, float, float>> &image, int width, int \
273 height, std::string filename)
274 {
275 std::tuple<float, float, float> color;
276 std::ofstream out(filename, std::ios_base::out | std::ios_base::binary);
277 out << "P6" << std::endl << width << ' ' << height << std::endl << "255" << std::en\
278 dl;
279
280 for (int i=0;i<(width*height);++i)
281 {
282 color=image[i];
283 out << char(std::get<0>(color)*255.0f) << char(std::get<1>(color)*255.0f) << char(\
284 std::get<2>(color)*255.0f);
285 }
286 out.close();
287 }
288
289 void draw(std::vector<std::tuple<float, float, float>> &image,std::tuple<int, int, i\
290 nt, int> &coords,std::vector<std::tuple<float,float,float>> &colors,int width,int he
291 ight,int x_cen,int y_cen,double degrees,int length,int color)
292 {
14 Appendix A: Source Code Listings 412
293 get_angle_line(coords,x_cen,y_cen,degrees,length);
294 if (clip_line(coords,coords,width,height)) {
295 draw_line(image,coords,colors[color],width,height);
296 }
297 std::cout << "L " << std::get<0>(coords) << " " << std::get<1>(coords) << " " << st\
298 d::get<2>(coords) << " " << std::get<3>(coords) << " " << color << std::endl;
299 }
300
301 void parse_draw_line_from_file(const std::string str,std::vector<std::tuple<float, f\
302 loat, float>> &image,std::vector<std::tuple<float,float,float>> &colors,int width,in
303 t height)
304 {
305 size_t start;
306 size_t end = 0;
307 std::vector<std::string> out;
308
309 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
310 {
311 end = str.find(' ', start);
312 out.push_back(str.substr(start, end - start));
313 }
314
315 std::tuple<int, int, int, int> coords=std::make_tuple(stoi(out[1]),stoi(out[2]),sto\
316 i(out[3]),stoi(out[4]));
317 draw_line(image,coords,colors[stoi(out[5])],width,height);
318 }
319
320 void parse_draw_marker_from_file(const std::string str,std::vector<std::tuple<float,\
321 float, float>> &image,std::vector<std::tuple<float,float,float>> &colors,int width,
322 int height)
323 {
324 size_t start;
325 size_t end = 0;
326 std::vector<std::string> out;
327
328 while ((start = str.find_first_not_of(' ', end)) != std::string::npos)
329 {
330 end = str.find(' ', start);
331 out.push_back(str.substr(start, end - start));
332 }
333
334 int x=stoi(out[1]),y=stoi(out[2]),color=stoi(out[3]);
335
14 Appendix A: Source Code Listings 413
540 M 1258 87 2
541 M 1246 190 2
542 M 1292 112 2
543 M 1393 202 2
544 M 1461 246 2
545 M 1393 293 2
546 M 1239 261 2
547 M 1408 297 2
548 M 1325 302 2
549 M 1435 258 2
550 M 1379 216 2
551 M 1326 280 2
552 M 1356 187 2
553 M 1348 367 2
554 M 1407 193 2
555 M 1247 203 2
556 M 1343 293 2
557 M 1445 293 2
558 M 1285 350 2
559 M 1240 182 2
560 M 1452 182 2
561 M 1354 272 2
562 M 1247 147 2
563 M 1300 279 2
564 M 1312 139 2
565 M 1290 282 2
566 M 1403 218 2
567 M 1420 125 2
568 M 1385 114 2
569 M 1398 203 2
570 M 1406 177 2
571 M 1232 255 2
572 M 1396 338 2
573 M 1378 332 2
574 M 1443 198 2
575 M 1369 319 2
576 M 1246 168 2
577 M 1267 241 2
578 M 1273 95 2
579 M 1325 297 2
580 M 1290 348 2
581 M 1269 251 2
582 M 1390 301 2
14 Appendix A: Source Code Listings 429
1 // MIT No Attribution
2 //
3 // ppmpp.hpp - A header-only class to draw/read/write 2D graphics using only the sta\
4 ndard library.
5 // Version 1.0 release (3:rd of December 2022).
6 // Copyright (c) 2022-2023 Håkan Blomqvist
7 //
8 // For more information:
9 // https://leanpub.com/2dcomputergraphicsinmoderncandstandardlibrary/
10 // https://gist.github.com/chbtoys/cdd6a85e321593ea0a1e7141d0a09fbc <- ppmpp.hpp
11 // https://gist.github.com/chbtoys/a665b52f86768b8e601c82b47ce18e49 <- test.cpp
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a copy of t\
14 his
15 // software and associated documentation files (the "Software"), to deal in the Soft\
16 ware
14 Appendix A: Source Code Listings 438
17 // without restriction, including without limitation the rights to use, copy, modify,
18 // merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIE\
22 D,
23 // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
24 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 #define _USE_MATH_DEFINES
30
31 #include <iostream>
32 #include <fstream>
33 #include <tuple>
34 #include <vector>
35 #include <random>
36 #include <cmath>
37 #include <algorithm>
38
39 namespace ppm
40 {
41 // Typedef
42 typedef std::tuple<float, float, float> pixel;
43 typedef std::tuple<int, int, int, int> coord;
44 typedef std::tuple<int, int> point;
45
46 class image
47 {
48 public:
49 // Constructs an empty image.
50 image() {}
51
52 // Constructs an empty image of specified width and height.
53 image(int width, int height) {resize(width, height);}
54
55 // Constructs an image reading data from specified file
56 explicit image(std::string const& filename)
57 {
58 read(filename);
59 }
14 Appendix A: Source Code Listings 439
60
61 // Resizes the image pixel buffer.
62 void resize(int width, int height)
63 {
64 m_img.clear();
65 m_img.resize(width*height);
66 set_width(width);
67 set_height(height);
68 }
69
70 void set_width(int width)
71 {
72 m_width=width;
73 }
74
75 void set_height(int height)
76 {
77 m_height=height;
78 }
79
80 int get_width()
81 {
82 return m_width;
83 }
84
85 int get_height()
86 {
87 return m_height;
88 }
89
90 void set_pixel(int x, int y, pixel px)
91 {
92 m_img[x+m_width*y]=px;
93 }
94
95 pixel get_pixel(int x, int y)
96 {
97 return m_img[x+m_width*y];
98 }
99
100 void set_all_pixels(pixel px)
101 {
102 for (int y=0;y<m_height;++y)
14 Appendix A: Source Code Listings 440
103 {
104 for (int x=0;x<m_width;++x)
105 {
106 m_img[x+m_width*y]=px;
107 }
108 }
109 }
110
111 // Drawline
112 void draw_line(coord &coords, pixel &linecolor)
113 {
114 coord coords2;
115 if (clipline(coords,coords2)) {
116 drawline(coords2,linecolor);
117 }
118 }
119
120 // Get angled line
121 void get_angled_line(coord &coords, point ¢er, double degrees, int length)
122 {
123 double angle = degrees * (M_PI / 180);
124 coords=std::make_tuple(std::get<0>(center),std::get<1>(center),int(double(st
125 t<0>(center)) + cos(angle)*double(length)),int(double(std::get<1>(center)) + sin(ang
126 le)*double(length)));
127 }
128
129 // Draw Curves (requires C++20)
130 #if __cplusplus >= 202002L
131 void draw_bezier_quadratic(point pt0, point pt1, point pt2, int split, pixel bezie\
132 rcolor)
133 {
134 std::vector<std::tuple<int,int>> xy;
135 quadraticbeziercurves(pt0,pt1,pt2,split,xy);
136 // drawxydots(xy,beziercolor);
137 drawxyline(xy,beziercolor,pt2);
138 }
139
140 void draw_bezier_cubic(point pt0, point pt1, point pt2, point pt3, int split, pixe\
141 l beziercolor)
142 {
143 std::vector<std::tuple<int,int>> xy;
144 cubicbeziercurves(pt0,pt1,pt2,pt3,split,xy);
145 drawxyline(xy,beziercolor,pt3);
14 Appendix A: Source Code Listings 441
146 }
147 #endif
148
149 // Draw rectangles
150 void draw_rectangle(point &xy, point &wh, pixel &rectanglecolor)
151 {
152 drawrect(xy,wh,rectanglecolor);
153 }
154
155 void draw_filled_rectangle(point &xy, point &wh, pixel &rectanglecolor)
156 {
157 drawfilledrect(xy,wh,rectanglecolor);
158 }
159
160 // Draw Circles
161 void draw_circle(point &xy, int radius, pixel &circlecolor)
162 {
163 drawcircle(xy,radius,circlecolor);
164 }
165
166 void draw_filled_circle(point &xy, int radius, pixel &circlecolor)
167 {
168 drawfilledcircle(xy,radius,circlecolor);
169 }
170
171 // Draw Wedge
172 void draw_wedge(point center,int radius,int start_angle,int end_angle,pixel &wedge\
173 color)
174 {
175 drawwedge(center,radius,start_angle,end_angle,wedgecolor);
176 }
177
178 void draw_filled_wedge(point center,int radius,int start_angle,int end_angle,pixel\
179 &wedgecolor)
180 {
181 drawfilledwedge(center,radius,start_angle,end_angle,wedgecolor);
182 }
183
184 // Draw Triangles
185 void draw_triangle(point pt1, point pt2, point pt3, pixel &trianglecolor)
186 {
187 drawtriangle(pt1,pt2,pt3,trianglecolor);
188 }
14 Appendix A: Source Code Listings 442
189
190 void draw_filled_triangle(point pt1,point pt2,point pt3,pixel &color)
191 {
192 drawfilledtriangle(pt1,pt2,pt3,color);
193 }
194
195 // Blend Colors
196 pixel blend_colors(pixel &colorbackground, pixel &colorforeground, float alpha)
197 {
198 float r=0.0f; float g=0.0f; float b=0.0f;
199 r = (std::get<0>(colorforeground) * alpha) + (std::get<0>(colorbackground) *
200 - alpha));
201 g = (std::get<1>(colorforeground) * alpha) + (std::get<1>(colorbackground) *
202 - alpha));
203 b = (std::get<2>(colorforeground) * alpha) + (std::get<2>(colorbackground) *
204 - alpha));
205
206 return std::make_tuple(r,g,b);
207 }
208
209 // Read PPM Image
210 void read(std::string const& filename)
211 {
212 std::string magic;
213 int max;
214 uint8_t buffer[3];
215 pixel color;
216
217 std::ifstream in(filename, std::ifstream::binary);
218
219 if (!in.is_open())
220 {
221 std::cout << "Can't open " << filename << std::endl;
222 exit(1);
223 }
224
225 in >> magic;
226 in.seekg(1, in.cur);
227 char c;
228 in.get(c);
229 if (c == '#')
230 {
231 // We got comments in the PPM image and skip the comments
14 Appendix A: Source Code Listings 443
361 m_img[getindex(x,y)]=color;
362 }
363 }
364 }
365
366 int findregion(int x, int y, int width, int height)
367 {
368 int code=0;
369 if(y >= height)
370 code |= 1; //top
371 else if(y < 0)
372 code |= 2; //bottom
373 if(x >= width)
374 code |= 4; //right
375 else if (x < 0)
376 code |= 8; //left
377 return(code);
378 }
379
380 bool clipline(coord &coords1, coord &coords2)
381 {
382 int x1=std::get<0>(coords1); int y1=std::get<1>(coords1); int x2=std::get<2>
383 ds1); int y2=std::get<3>(coords1);
384 int x3=0; int y3=0; int x4=0; int y4=0;
385 int code1=0, code2=0, codeout=0;
386 bool accept = 0, done=0;
387 code1 = findregion(x1, y1, m_width, m_height); //the region outcodes for the
388 oints
389 code2 = findregion(x2, y2, m_width, m_height);
390 do //In theory, this can never end up in an infinite loop, it'll always come
391 ne of the trivial cases eventually
392 {
393 if(!(code1 | code2)) accept = done = 1; //accept because both endpo
394 screen or on the border, trivial accept
395 else if(code1 & code2) done = 1; //the line isn't visible on screen,
396 ect
397 else //if no trivial reject or accept, continue the loop
398 {
399 int x, y;
400 codeout = code1 ? code1 : code2;
401 if(codeout & 1) //top
402 {
403 x = x1 + (x2 - x1) * (m_height - y1) / (y2 - y1);
14 Appendix A: Source Code Listings 447
404 y = m_height - 1;
405 }
406 else if(codeout & 2) //bottom
407 {
408 x = x1 + (x2 - x1) * -y1 / (y2 - y1);
409 y = 0;
410 }
411 else if(codeout & 4) //right
412 {
413 y = y1 + (y2 - y1) * (m_width - x1) / (x2 - x1);
414 x = m_width - 1;
415 }
416 else //left
417 {
418 y = y1 + (y2 - y1) * -x1 / (x2 - x1);
419 x = 0;
420 }
421 if(codeout == code1) //first endpoint was clipped
422 {
423 x1 = x; y1 = y;
424 code1 = findregion(x1, y1, m_width, m_height);
425 }
426 else //second endpoint was clipped
427 {
428 x2 = x; y2 = y;
429 code2 = findregion(x2, y2, m_width, m_height);
430 }
431 }
432 }
433 while(done == 0);
434 if(accept)
435 {
436 x3 = x1;
437 x4 = x2;
438 y3 = y1;
439 y4 = y2;
440 coords2=std::make_tuple(x3,y3,x4,y4);
441 return 1;
442 }
443 else
444 {
445 x3 = x4 = y3 = y4 = 0;
446 coords2=std::make_tuple(x3,y3,x4,y4);
14 Appendix A: Source Code Listings 448
447 return 0;
448 }
449 }
450
451 #if __cplusplus >= 202002L
452 void quadraticbeziercurves(point pt0, point pt1, point pt2, int split, std::vector\
453 <std::tuple<int,int>>& xy)
454 {
455 double t=0.0;
456 double delta=(double(1)/double(split));
457 int x=0;
458 int y=0;
459 int x1=0;
460 int y1=0;
461 int x2=0;
462 int y2=0;
463 for (int i=0;i<split;++i)
464 {
465 x1 = std::lerp(std::get<0>(pt0),std::get<0>(pt1),t);
466 y1 = std::lerp(std::get<1>(pt0),std::get<1>(pt1),t);
467 x2 = std::lerp(std::get<0>(pt1),std::get<0>(pt2),t);
468 y2 = std::lerp(std::get<1>(pt1),std::get<1>(pt2),t);
469 x = std::lerp(x1,x2,t);
470 y = std::lerp(y1,y2,t);
471 xy.push_back(std::make_tuple(x,y));
472 t+=delta;
473 }
474 }
475
476 void cubicbeziercurves(point pt0, point pt1, point pt2, point pt3, int split, std:\
477 :vector<std::tuple<int,int>>& xy)
478 {
479 float t=0.0;
480 float delta=(float(1)/float(split));
481 int x=0;
482 int y=0;
483 int x1=0;
484 int y1=0;
485 int x2=0;
486 int y2=0;
487 int x3=0;
488 int y3=0;
489 int x4=0;
14 Appendix A: Source Code Listings 449
533 }
534
535 for (auto& li : xyxy)
536 {
537 draw_line(li,color);
538 }
539 }
540
541 void drawxydots(std::vector<point> &xy, pixel &color)
542 {
543 for (auto& pt : xy)
544 {
545 m_img[getindex(std::get<0>(pt),std::get<1>(pt))]=color;
546 }
547 }
548
549 void drawrect(point &xy, point &wh, pixel &color)
550 {
551 int x=std::get<0>(xy);int y=std::get<1>(xy);int w=std::get<0>(wh);int h=std:
552 1>(wh);
553 coord coords=std::make_tuple(x, y, x+w, y);
554 draw_line(coords, color);
555 coords=std::make_tuple(x+w, y, x+w, y+h);
556 draw_line(coords, color);
557 coords=std::make_tuple(x+w, y+h, x, y+h);
558 draw_line(coords, color);
559 coords=std::make_tuple(x, y+h, x, y);
560 draw_line(coords, color);
561 }
562
563 void drawfilledrect(point &xy, point &wh, pixel &color)
564 {
565 int x2 = std::get<0>(xy) + std::get<0>(wh);
566 int y2 = std::get<1>(xy) + std::get<1>(wh);
567
568 coord coords=std::make_tuple(0,0,0,0);
569 for (int i = std::get<1>(xy); i < y2; ++i)
570 {
571 coords=std::make_tuple(std::get<0>(xy),i,x2,i);
572 draw_line(coords, color);
573 }
574 }
575
14 Appendix A: Source Code Listings 451
705 {
706 y = y + 1;
707 if (py <= 0)
708 py = py + 2 * dx1;
709 else
710 {
711 if ((dx<0 && dy<0) || (dx>0 && dy>0)) x = x + 1; els
712 py = py + 2 * (dx1 - dy1);
713 }
714 coords.push_back(std::make_tuple(x,y));
715 }
716 }
717 }
718
719 void drawwedge(point center,int radius,int start_angle,int end_angle,pixel &color)
720 {
721 std::vector<point> coords;
722
723 float angle=(((start_angle<=end_angle)?start_angle:end_angle)*(M_PI/180));
724 float range=(((end_angle>start_angle)?end_angle:start_angle)*(M_PI/180));
725 float x=(radius*cos(angle));
726 float y=(radius*sin(angle));
727 do
728 {
729 coords.push_back(std::make_tuple((int)(std::get<0>(center)+x+0.5),(i
730 <1>(center)-y+0.5)));
731 angle+=0.001;
732 x=(radius*cos(angle));
733 y=(radius*sin(angle));
734 }
735 while(angle<=range);
736
737 point co1=coords.front();
738 point co2=coords.back();
739
740 coord line1=std::make_tuple(std::get<0>(center),std::get<1>(center),std::get
741 o1),std::get<1>(co1));
742 coord line2=std::make_tuple(std::get<0>(center),std::get<1>(center),std::get
743 o2),std::get<1>(co2));
744
745 getlinecoords(line1,coords);
746 getlinecoords(line2,coords);
747
14 Appendix A: Source Code Listings 455
877 e2 += dy2;
878 while (e2 >= dx2) {
879 e2 -= dx2;
880 if (changed2) t2xp = signx2;
881 else goto next2;
882 }
883 if (changed2) break;
884 else t2x += signx2;
885 }
886 next2:
887 if (minx>t1x) minx = t1x;
888 if (minx>t2x) minx = t2x;
889 if (maxx<t1x) maxx = t1x;
890 if (maxx<t2x) maxx = t2x;
891 coords=std::make_tuple(minx,y,maxx,y);
892 draw_line(coords,color);
893 if (!changed1) t1x += signx1;
894 t1x += t1xp;
895 if (!changed2) t2x += signx2;
896 t2x += t2xp;
897 y += 1;
898 if (y == y2) break;
899
900 }
901 next:
902 dx1 = (int)(x3 - x2); if (dx1<0) { dx1 = -dx1; signx1 = -1; }
903 else signx1 = 1;
904 dy1 = (int)(y3 - y2);
905 t1x = x2;
906
907 if (dy1 > dx1) {
908 SWAP(dy1, dx1);
909 changed1 = true;
910 }
911 else changed1 = false;
912
913 e1 = (int)(dx1 >> 1);
914
915 for (int i = 0; i <= dx1; i++) {
916 t1xp = 0; t2xp = 0;
917 if (t1x<t2x) { minx = t1x; maxx = t2x; }
918 else { minx = t2x; maxx = t1x; }
919 while (i<dx1) {
14 Appendix A: Source Code Listings 459
920 e1 += dy1;
921 while (e1 >= dx1) {
922 e1 -= dx1;
923 if (changed1) { t1xp = signx1; break; }
924 else goto next3;
925 }
926 if (changed1) break;
927 else t1x += signx1;
928 if (i<dx1) i++;
929 }
930 next3:
931 while (t2x != x3) {
932 e2 += dy2;
933 while (e2 >= dx2) {
934 e2 -= dx2;
935 if (changed2) t2xp = signx2;
936 else goto next4;
937 }
938 if (changed2) break;
939 else t2x += signx2;
940 }
941 next4:
942
943 if (minx>t1x) minx = t1x;
944 if (minx>t2x) minx = t2x;
945 if (maxx<t1x) maxx = t1x;
946 if (maxx<t2x) maxx = t2x;
947 coords=std::make_tuple(minx,y,maxx,y);
948 draw_line(coords,color);
949 if (!changed1) t1x += signx1;
950 t1x += t1xp;
951 if (!changed2) t2x += signx2;
952 t2x += t2xp;
953 y += 1;
954 if (y>y3) return;
955 }
956 }
957
958 std::vector<pixel> m_img;
959 int m_width;
960 int m_height;
961 };
962
14 Appendix A: Source Code Listings 460
40 pt1=std::make_tuple(293,182);
41 pt2=std::make_tuple(386,357);
42 pt3=std::make_tuple(480,270);
43 image2.draw_bezier_cubic(pt0,pt1,pt2,pt3,50,color);
44 #endif
45 ppm::point ptxy=std::make_tuple(500,500);
46 ppm::point ptwh=std::make_tuple(900,200);
47 image2.draw_rectangle(ptxy,ptwh,color);
48 ptxy=std::make_tuple(100,100);
49 ptwh=std::make_tuple(900,200);
50 image2.draw_filled_rectangle(ptxy,ptwh,color);
51 ptxy=std::make_tuple(945,300);
52 image2.draw_circle(ptxy,250,color);
53 ptxy=std::make_tuple(300,600);
54 image2.draw_filled_circle(ptxy,250,color);
55 ppm::pixel color4=std::make_tuple(0.8f,0.0f,0.8f);
56 ppm::pixel color5=std::make_tuple(1.0f,1.0f,1.0f);
57 ppm::pixel color3=image2.blend_colors(color4,color5,0.5f);
58 ptxy=std::make_tuple(900,900);
59 ptwh=std::make_tuple(100,100);
60 image2.draw_filled_rectangle(ptxy,ptwh,color3);
61 ppm::point pt=std::make_tuple(400,400);
62 image2.draw_wedge(pt,150,0,45,color3);
63 pt=std::make_tuple(800,800);
64 image2.draw_filled_wedge(pt,150,0,45,color5);
65 pt1=std::make_tuple(750,450);
66 pt2=std::make_tuple(350,650);
67 pt3=std::make_tuple(450,750);
68 image2.draw_triangle(pt1,pt2,pt3,color5);
69 pt1=std::make_tuple(750,450);
70 pt2=std::make_tuple(950,750);
71 pt3=std::make_tuple(1250,850);
72 image2.draw_filled_triangle(pt1,pt2,pt3,color5);
73 image2.write("test2.ppm");
74
75 return 0;
76 }