repl.it
@Koopolt/

raytrace demo

C++11

No description

fork
loading
Files
  • main.cpp
  • test.ppm
main.cpp
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
#include <iostream>
#include <fstream>

int main() {

  std::ofstream out_data("test.ppm");
  int nx = 200;
  int ny = 100;
  std::cout << "P3\n" << nx << " " << ny << "\n255\n";
  out_data << "P3\n" << nx << " " << ny << "\n255\n";
  for (int j = ny-1; j >= 0; j--)
  {
    for (int i = 0; i < nx; i++)
    {
      float r = float(i) / float(nx);
      float g = float(j) / float(ny);
      float b = 0.2;
      int ir = int(255.99*r);
      int ig = int(255.99*g);
      int ib = int(255.99*b);
      std::cout << ir << " " << ig << " " << ib << "\n";
      out_data << ir << " " << ig << " " << ib << "\n";
    }
  }
}