Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment we will create Ascii Art out of a *.ppm image. Requirements are provided below. below is the main.cpp file MAIN.CPP: #include #include
In this assignment we will create Ascii Art out of a *.ppm image. Requirements are provided below.
below is the main.cpp file
MAIN.CPP:
#include
#include
using namespace std;
void getToData(ifstream& infile);
int main() {
ifstream infile;
infile.open("sign_1.txt");
getToData(infile);
int firstRealValue;
infile>>firstRealValue;
cout
char asciiArray[]={'@','%','#','*','+','=','-',':','.',' '};
/*ofstream myfile;
myfile.open ("example.txt");
myfile
myfile.close();*/
}
void getToData(ifstream& infile)
{
char trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
infile>>trash;
//infile>>trash;
//infile>>trash;
//infile>>trash;
//*******Trash
//cout
}
the main. cpp file is included
Requirement 1: Read in all these triplets into a 3 Dimensional Array. What are the dimensions of this array? How many For loops would you need? What would be the bounds on these for loops? After we read in the triplet: For every triplet we read in, we need to write out an ascii character to another file that represents that pixel. The following array is the one I used to map the average brightness to an ascii character: char asciiArray[1={'',' } This is a 11 element arrray. The darkest character is the @ sign and the lightest character is the space ('). So let's say the first three pixels are 255,255,255. What we want to do is first take the average of these color values to get the average brightness of the pixel, which, in this case, would be 255 -- meaning the brightest possible color. And then we would want to convert this into a value between 0 and 10 (including 10). A division and casting to an integer would do the trick but I'll let you figure that out. Finally we use that number to determine the ascii character we write out. The following code creates a file named example.txt and writes "hello world out to it. (remember to include fstream) ofstream myfile; myfile.open("example.txt"); myfileStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started