subtitled #17: chaikin

main
annieversary 2021-09-18 13:49:26 +02:00
parent 658093b77f
commit e89291202c
3 changed files with 70 additions and 0 deletions

8
Cargo.lock generated
View File

@ -2422,6 +2422,14 @@ dependencies = [
"utils", "utils",
] ]
[[package]]
name = "subtitled17"
version = "0.1.0"
dependencies = [
"nannou",
"utils",
]
[[package]] [[package]]
name = "subtitled2" name = "subtitled2"
version = "0.1.0" version = "0.1.0"

View File

@ -0,0 +1,8 @@
[package]
name = "subtitled17"
version = "0.1.0"
edition = "2018"
[dependencies]
nannou = "0.17"
utils = { path = "../utils" }

View File

@ -0,0 +1,54 @@
use nannou::prelude::*;
use utils::{curves::*, drawing::draw_soft_bg, *};
const POINTS: usize = 10;
const SIZE: f32 = 300.0;
fn main() {
nannou::app(model).update(update).simple_window(view).run();
}
struct Model {
curves: Vec<Chaikin>,
}
fn model(_app: &App) -> Model {
let curves = (0..10)
.map(|_| {
Chaikin::new(
(0..POINTS)
.map(|_| vec2_range(-1., 1.) * SIZE)
.collect::<Vec<_>>(),
)
})
.collect();
Model { curves }
}
fn update(app: &App, _model: &mut Model, _update: Update) {
let _t = app.elapsed_frames() as f32 / 60.0;
}
fn view(app: &App, model: &Model, frame: Frame) {
let t = frame.nth() as f32 / 60.0;
let draw = app.draw();
draw_soft_bg(&draw, app, SNOW, 0.01);
for (i, curve) in model.curves.iter().enumerate() {
let div = map_sin(t * 0.7 + (2 * i) as f32, 0.15, 0.35);
let h = map_sin(t * 0.3 + i as f32, 0., 1.);
draw.polyline().stroke_weight(1.5).points_colored(
curve
.points(div, 10)
.into_iter()
.enumerate()
.map(|(i, p)| (p, hsla((h + i as f32 / 10000.0).fract(), 0.5, 0.5, 0.5))),
);
}
draw.to_frame(app, &frame).unwrap();
utils::record::record(app, &frame);
}