25 lines
703 B
C++
25 lines
703 B
C++
|
|
#include<iostream>
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
//image dimensions
|
||
|
|
int image_width = 256;
|
||
|
|
int image_height = 256;
|
||
|
|
|
||
|
|
//Rendering
|
||
|
|
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
|
||
|
|
|
||
|
|
//loops through height and width of screen and assigns color to each pixel
|
||
|
|
for (int j = 0; j < image_height; j++) {
|
||
|
|
for (int i = 0; i < image_width; i++) {
|
||
|
|
auto r = double(i) / (image_width-1);
|
||
|
|
auto g = double(j) / (image_height-1);
|
||
|
|
auto b = 0.0;
|
||
|
|
|
||
|
|
int ir = int(255.999 * r);
|
||
|
|
int ig = int(255.999 * g);
|
||
|
|
int ib = int(255.999 * b);
|
||
|
|
|
||
|
|
std::cout << ir << ' ' << ig << ' ' << ib << '\n';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|