Question: C++ Add comments to the lines Part 2: Visualization - Creating a Bar Chart. For Part 2, we will create an image in ppm format.
C++
Add comments to the lines
Part 2: Visualization - Creating a Bar Chart. For Part 2, we will create an image in ppm format. The ppm file format is a simple image format that contains data about a pixel color using three colors (RGB). We will restrict each color to be a value from 0 to 255. For example, we represent the colors red as 255 0 0, blue as 0 255 0, green as 0 0 255, and grey as 127 127 127. A bar chart will be created by setting pixel colors to represents the percentage of energy consumption per state.
-California Coal: 0.48% Natural Gas: 36.61% Petroleum: 46.95% Nuclear: 2.97% Renewables: 12.99%
-Wyoming Coal: 59.90% Natural Gas: 18.07% Petroleum: 16.13% Nuclear: 0.00% Renewables: 5.90%
PPM Image Format: Tip: The image is stored in row-major order. This means that when viewing the image, the top left coordinates (row,col) are (0,0) and the bottom right coordinates are (480,640). Consider this when controlling the output of the colors per column. The top row in the image is the 0th row, the bottom is the 480th row. The left edge is the 0th column and the right edge is the 640th column. For example, the 4 x 4 image below has 16 colors. Each color is represented as three numbers. The upper left at cell 0,0 is red and is the number 255 0 0 (the first three entries in the ppm file below). The last three values in the file, 255 255 0, encode yellow and are at coordinate (4,4). We are using ASCII (text) encoding identified by the P3 in the file header (P6 is binary). # are comments, Width Height, then maximum color value. Write 70 characters or less for each line in the ppm file. P3 #sample image 4 4 255 255 0 0 127 63 0 63 127 0 0 255 0 127 0 63 63 0 0 0 63 0 63 127 0 63 0 127 0 0 63 63 63 0 127 127 0 0 0 255 63 63 127 127 127 63 255 255 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
