Size: 629 bytes.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
// cs/renderer/rainbow.cc
#include "cs/renderer/rainbow.h"

#include <cmath>

#include "cs/renderer/film.hh"
#include "cs/renderer/pixel.hh"

void cs::renderer::RainbowRenderer::render(Film* film) {
  for (uint32_t i = 0; i < film->width; i++) {
    float i_ratio = (i + 0.5) / (float)(film->width);
    for (uint32_t j = 0; j < film->height; j++) {
      float j_ratio = (j + 0.5) / (float)(film->height);
      Pixel pixel = cs::renderer::Pixel(
          std::roundf(i_ratio * 255),
          std::roundf(j_ratio * 255),
          std::roundf((1 - i_ratio) * 255), 255);
      film->pixels[i][j] = pixel;
      ;
    }
  }
};
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-2:8080 in 4ms.