Bitmap/Write a PPM file: Difference between revisions

Content added Content deleted
m (Automated syntax highlighting fixup (second round - minor fixes))
(→‎{{header|C++}}: removed useless stuff and used C++ style casts)
Line 487: Line 487:
{{trans|C}}
{{trans|C}}
<syntaxhighlight lang="cpp">#include <fstream>
<syntaxhighlight lang="cpp">#include <fstream>
#include <cstdio>


int main() {
int main() {
constexpr auto dimx = 800u, dimy = 800u;
constexpr auto dimx = 800u, dimy = 800u;


std::ofstream ofs("first.ppm", ios_base::out | ios_base::binary);
using namespace std;
ofs << "P6\n" << dimx << ' ' << dimy << "\n255\n";
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 j = 0u; j < dimy; ++j)
for (auto i = 0u; i < dimx; ++i)
for (auto i = 0u; i < dimx; ++i)
ofs << (char) (i % 256) << (char) (j % 256) << (char) ((i * j) % 256); // red, green, blue
ofs << static_cast<char>(i % 256)
<< static_cast<char>(j % 256)
<< static_cast<char>((i * j) % 256);
}</syntaxhighlight>


ofs.close();

return EXIT_SUCCESS;
}</syntaxhighlight>
=={{header|Common Lisp}}==
=={{header|Common Lisp}}==