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
use crate::{color::Color, quaternion::Quaternion, scene_object::SceneObject, vec3::Vec3};
const MAX_ITERS: i32 = 20;
pub struct Julia<C> {
pub c: Quaternion,
pub color: C,
}
impl<C: Color> SceneObject<C> for Julia<C> {
fn distance_to(&self, point: Vec3, t: f64) -> f64 {
let mut z = Quaternion::new(point.x, point.y, point.z, t);
let mut dz = Quaternion::new(1.0, 0.0, 0.0, 0.0);
let mut count = 0;
while count < MAX_ITERS {
let z_new = z * z + self.c;
dz = 2.0 * z * dz;
z = z_new;
if z.magnitude() > 4.0 {
break;
}
count += 1;
}
let dist: f64 = z.magnitude() * z.magnitude().ln() / dz.magnitude();
dist * 0.2
}
fn get_color(&self, t: f64) -> C {
self.color
}
}