public void Can_save_ppm_as_png() { // Arrange // use a string builder to build a 2d image of a gradient var nx = 200; var ny = 100; var rayTracer = new RayTracer(nx, ny); for (var j = ny - 1; j >= 0; j--) { for (var i = 0; i < nx; i++) { var col = new Vec3( (float)i / (float)nx, (float)j / (float)ny, 51); var ir = Math.Round(255.99 * col.X); var ig = Math.Round(255.99 * col.Y); rayTracer.AddToImageBuffer($"{ir} {ig} {col.Z}"); } } // Act var filename = "test_ppm_as_png.png"; rayTracer.SaveImageFromPPM(filename); // Assert Assert.That(VerifyImage("can_save_ppm_as_png_expected_output.png", filename), Is.True); }
public void Can_Draw_Background() { // Arrange var nx = 200; var ny = 100; var rayTracer = new RayTracer(nx, ny); var lowerBound = new Vec3(-2, -1, -1); var dx = new Vec3(4, 0, 0); var dy = new Vec3(0, 2, 0); var origin = new Vec3(0, 0, 0); // Act for (int j = ny - 1; j >= 0; j--) { for (int i = 0; i < nx; i++) { var u = (double)i / (double)nx; var v = (double)j / (double)ny; var currentPoint = lowerBound.Add(dx.Scale(u).Add(dy.Scale(v))); var ray = new Ray(origin, currentPoint); var colour = ColourByRay(ray); var r = (int)(colour.X * 255); var g = (int)(colour.Y * 255); var b = (int)(colour.Z * 255); rayTracer.AddToImageBuffer($"{r} {g} {b}"); } } var fileName = "Can_Draw_Background.png"; rayTracer.SaveImageFromPPM(fileName); // Assert Assert.That(VerifyImage(fileName, fileName), Is.True); }