Anonymous user
Bitmap/Write a PPM file: Difference between revisions
→{{header|C++}}: static not needed, C++ after C#
(→{{header|C++}}: C++ entry) |
(→{{header|C++}}: static not needed, C++ after C#) |
||
Line 224:
(void) fwrite(img->buf, sizeof(pixel), n, fd);
(void) fflush(fd);
}</lang>▼
=={{header|C++}}==▼
{{trans|C}}▼
<lang cpp>#include <fstream>▼
#include <cstdio>▼
int main() {▼
constexpr auto dimx = 800u, dimy = 800u;▼
using namespace std;▼
ofstream ofs("first.ppm", ios_base::out | ios_base::binary);▼
ofs << "P6" << endl << dimx << ' ' << dimy << endl << "255" << endl;▼
static char color[3];▼
for (auto j = 0u; j < dimy; ++j)▼
for (auto i = 0u; i < dimx; ++i) {▼
color[0] = i % 256; // red▼
color[1] = j % 256; // green▼
color[2] = (i * j) % 256; // blue▼
ofs.write(color, sizeof(color));▼
}▼
ofs.close();▼
return EXIT_SUCCESS;▼
}</lang>
Line 278 ⟶ 252:
writerB.Close();
}
▲}</lang>
▲=={{header|C++}}==
▲{{trans|C}}
▲<lang cpp>#include <fstream>
▲#include <cstdio>
▲int main() {
▲ constexpr auto dimx = 800u, dimy = 800u;
▲ using namespace std;
▲ ofstream ofs("first.ppm", ios_base::out | ios_base::binary);
▲ ofs << "P6" << endl << dimx << ' ' << dimy << endl << "255" << endl;
▲ for (auto j = 0u; j < dimy; ++j)
▲ for (auto i = 0u; i < dimx; ++i) {
▲ color[0] = i % 256; // red
▲ color[1] = j % 256; // green
▲ color[2] = (i * j) % 256; // blue
▲ ofs.write(color, sizeof(color));
▲ }
▲ ofs.close();
▲ return EXIT_SUCCESS;
}</lang>
|