Skip to content

Instantly share code, notes, and snippets.

@bbagwang
Created June 16, 2019 20:14
Show Gist options
  • Save bbagwang/20dd67fe95a3b612cebebacd039829e6 to your computer and use it in GitHub Desktop.
Save bbagwang/20dd67fe95a3b612cebebacd039829e6 to your computer and use it in GitHub Desktop.
Black to White Gradient PPM
#include <iostream>
#include <fstream>
//Gradient 함수
void Gradient(int size_x, int size_y)
{
//파일 출력
std::ofstream out("Gradient.ppm");
//PPM 헤더 설정
out << "P3\n" << size_x << " " << size_y << "\n"
<< "255\n";
for (int y = 0; y < size_y; y++)
{
for (int x = 0; x < size_x; x++)
{
double opt;
opt = (x / (double)size_x)*255;
out << (int)opt << " " << (int)opt << " " << (int)opt << " ";
}
out << "\n";
}
out.close();
}
int main() {
Gradient(1024, 1024);
std::cout << "FINISHED" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment