-
Notifications
You must be signed in to change notification settings - Fork 2
/
curves.rs
78 lines (68 loc) · 1.74 KB
/
curves.rs
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// this module contains a series of SDFs
use math::prelude::*;
use crate::prelude::*;
use math::curves::{InterpolationMode, Op};
pub fn cie_e(power: f32) -> Curve {
Curve::Linear {
signal: vec![power],
bounds: EXTENDED_VISIBLE_RANGE,
mode: InterpolationMode::Linear,
}
}
pub fn blackbody_curve(temperature: f32, boost: f32) -> Curve {
Curve::Blackbody { temperature, boost }
}
pub fn cauchy(a: f32, b: f32) -> Curve {
Curve::Cauchy { a, b }
}
pub fn red(power: f32) -> Curve {
Curve::Exponential {
signal: vec![(640.0, 240.0, 240.0, 20.0 * 1.7 * power)],
}
}
pub fn green(power: f32) -> Curve {
Curve::Exponential {
signal: vec![(540.0, 240.0, 240.0, 20.0 * 1.7 * power)],
}
}
pub fn blue(power: f32) -> Curve {
Curve::Exponential {
signal: vec![(420.0, 240.0, 240.0, 20.0 * 1.7 * power)],
}
}
pub fn mauve(power: f32) -> Curve {
Curve::Exponential {
signal: vec![
(650.0, 300.0, 300.0, power),
(460.0, 200.0, 400.0, 0.75 * power),
],
}
}
pub fn add_pigment(
spd: Curve,
wavelength: f32,
std_dev1: f32,
std_dev2: f32,
strength: f32,
) -> Curve {
let pigment = Curve::InverseExponential {
signal: vec![(wavelength, std_dev1, std_dev2, strength)],
};
match spd {
Curve::Machine { seed, mut list } => {
list.push((Op::Mul, pigment));
Curve::Machine { seed, list }
}
_ => Curve::Machine {
seed: 1.0,
list: vec![(Op::Mul, spd), (Op::Mul, pigment)],
},
}
}
pub fn void() -> Curve {
Curve::Linear {
signal: vec![0.0],
bounds: EXTENDED_VISIBLE_RANGE,
mode: InterpolationMode::Linear,
}
}