use cosmol_viewer::shapes::Sphere;
use cosmol_viewer::{Animation, Scene, Viewer};
use std::f32::consts::PI;
fn main() {
let ids = ["a", "b", "c", "d", "e", "f"];
let interval: f32 = 0.05; let duration: f32 = 10.0; let num_frames = (duration / interval) as usize;
let mut animation = Animation::new(interval, -1, true);
for frame_idx in 0..num_frames {
let t = frame_idx as f32 * interval / duration * PI * 4.0;
let mut scene = Scene::new();
scene.set_scale(2.0);
for (i, id) in ids.iter().enumerate() {
let phase = i as f32 * PI / 3.0;
let theta = t + phase;
let x = 1.5 * f32::cos(theta);
let y = 0.8 * f32::sin(theta);
let z = 0.5 * f32::sin(theta * 1.5);
let radius = 0.3 + 0.15 * f32::sin(theta * 1.5);
let r = 0.5 + 0.5 * f32::sin(theta);
let g = 0.5 + 0.5 * f32::cos(theta);
let b = 1.0 - r;
let sphere = Sphere::new([x, y, z], radius).color([
(r * 256.0) as u8,
(g * 256.0) as u8,
(b * 256.0) as u8,
]);
scene.add_shape_with_id(*id, sphere);
}
animation.add_frame(scene);
}
let _ = Viewer::play(animation, 800.0, 500.0);
}