|
|
|
@ -2,6 +2,8 @@ package eu.jonahbauer.raytracing.render;
|
|
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
public record Color(double r, double g, double b) {
|
|
|
|
|
public static final @NotNull Color BLACK = new Color(0.0, 0.0, 0.0);
|
|
|
|
|
public static final @NotNull Color WHITE = new Color(1.0, 1.0, 1.0);
|
|
|
|
@ -24,16 +26,16 @@ public record Color(double r, double g, double b) {
|
|
|
|
|
return new Color(a.r() * b.r(), a.g() * b.g(), a.b() * b.b());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static @NotNull Color random() {
|
|
|
|
|
return new Color(Math.random(), Math.random(), Math.random());
|
|
|
|
|
public static @NotNull Color random(@NotNull Random random) {
|
|
|
|
|
return new Color(random.nextDouble(), random.nextDouble(), random.nextDouble());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static @NotNull Color random(double min, double max) {
|
|
|
|
|
public static @NotNull Color random(@NotNull Random random, double min, double max) {
|
|
|
|
|
var span = max - min;
|
|
|
|
|
return new Color(
|
|
|
|
|
Math.fma(Math.random(), span, min),
|
|
|
|
|
Math.fma(Math.random(), span, min),
|
|
|
|
|
Math.fma(Math.random(), span, min)
|
|
|
|
|
Math.fma(random.nextDouble(), span, min),
|
|
|
|
|
Math.fma(random.nextDouble(), span, min),
|
|
|
|
|
Math.fma(random.nextDouble(), span, min)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|