-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.cpp
More file actions
30 lines (24 loc) · 721 Bytes
/
tile.cpp
File metadata and controls
30 lines (24 loc) · 721 Bytes
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
#include "picture.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
if (argc < 2) {
cout << "Usage: tile infile.bmp [outfile.bmp]" << endl;
return 1;
}
// open the file and construct a Picture object
Picture pic(argv[1]);
// make a copy
Picture newpic(pic);
// tile the pixels
for (int row=0; row<pic.height(); row++)
for (int col=0; col<pic.width(); col++) {
Color color = pic.get(row*2%pic.height(), col*2%pic.width());
newpic.set(row, col, color);
}
// show the new picture
newpic.show();
// save it, if the optional command-line argument was provided
if (argc > 2)
newpic.save(argv[2]);
}