-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirishflag.cpp
More file actions
71 lines (66 loc) · 1.58 KB
/
Copy pathirishflag.cpp
File metadata and controls
71 lines (66 loc) · 1.58 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
60
61
62
63
64
65
66
67
68
69
70
71
#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 IrelandFlag();
string filename;
pixel_class picture[500][250];
int main () {
int x, y;
fstream myfile;
IrelandFlag();
filename = "Flag.ppm";
myfile.open(filename.c_str(), fstream::out);
myfile << "P3\n";
myfile << "# " << filename << endl;
myfile << 500 << " " << 250 << endl;
myfile << 256 << endl;
for(y = 0; y < 250; y++) {
for(x = 0; x < 500; x++) {
picture[x][y].datatofile(myfile);
}
myfile << endl;
}
myfile.close();
}
void IrelandFlag() {
int x, y;
// green block up to 1/3 of 500
for(y = 0; y <250; y++) {
for(x = 0; x < 167; x++) {
picture[x][y].loaddata(22,155,98);
}
}
//white block 2/3 of 500
for(y = 0; y < 250; y++) {
for(x = 167; x < 333; x++) {
picture[x][y].loaddata(255,255,255);
}
}
//orange block for th 3/3
for(y = 0; y < 250; y++) {
for(x = 333; x < 500; x++) {
picture[x][y].loaddata(255,130,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 << " ";
}