-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtr.cpp
More file actions
59 lines (50 loc) · 1.32 KB
/
Copy pathtr.cpp
File metadata and controls
59 lines (50 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
using namespace std;
class pixel_class {
private:
int red, green, blue;
public:
void loaddata(int v1, int v2, int v3);
void datatofile(fstream & ppmfile);
int getR() { return red; }
int getG() { return green; }
int getB() { return blue; }
};
void createpicture();
string filename;
pixel_class picture[250][100];
int main() {
int x, y;
fstream myfile;
createpicture();
filename = "myImage.ppm";
myfile.open(filename.c_str(), fstream::out);
myfile << "P3\n"; myfile << "# " << filename << endl;
myfile << 250 << " " << 100 << endl; myfile << 256 << endl;
for (y = 0; y < 100; y++) {
for (x = 0; x < 250; x++) {
picture[x][y].datatofile(myfile);
}
myfile << endl;
}
myfile.close();
}
void createpicture() {
int x, y;
for (y = 0; y < 100; y++) {
for (x = 0; x < 250; x++) {
picture[x][y].loaddata(255, 153, 0);
}
}
}
//--------------- methods for the pixel_class ------------
void pixel_class::loaddata(int v1, int v2, int v3) {
red = v1;
green = v2;
blue = v3;
}
void pixel_class::datatofile(fstream & ppmfile) {
// write the data for one pixel to the ppm file
ppmfile << red << " " << green;
ppmfile << " " << blue << " "; }