From d7d0301116c988c1bdd12f69f80cdf078e7f34a0 Mon Sep 17 00:00:00 2001 From: annieversary Date: Tue, 17 Aug 2021 16:26:05 +0200 Subject: [PATCH] subtitled2 --- Cargo.lock | 8 +++++ README.md | 1 + crates/subtitled2/Cargo.toml | 8 +++++ crates/subtitled2/src/main.rs | 61 +++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 crates/subtitled2/Cargo.toml create mode 100644 crates/subtitled2/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 9d19b0b..53c77b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2348,6 +2348,14 @@ dependencies = [ "utils", ] +[[package]] +name = "subtitled2" +version = "0.1.0" +dependencies = [ + "nannou", + "utils", +] + [[package]] name = "syn" version = "1.0.74" diff --git a/README.md b/README.md index af5ba70..a247295 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,4 @@ this is a bunch of nannou projects ## list - subtitled #1: some spinning circles +- subtitled #2: idk spinning colors or something diff --git a/crates/subtitled2/Cargo.toml b/crates/subtitled2/Cargo.toml new file mode 100644 index 0000000..eae2675 --- /dev/null +++ b/crates/subtitled2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "subtitled2" +version = "0.1.0" +edition = "2018" + +[dependencies] +nannou = "0.17" +utils = { path = "../utils" } diff --git a/crates/subtitled2/src/main.rs b/crates/subtitled2/src/main.rs new file mode 100644 index 0000000..74993b4 --- /dev/null +++ b/crates/subtitled2/src/main.rs @@ -0,0 +1,61 @@ +use nannou::prelude::*; + +use utils::*; + +fn main() { + nannou::app(model).update(update).simple_window(view).run(); +} + +struct Model { + points: Vec, +} + +const PNUM: i32 = 500; + +fn model(_app: &App) -> Model { + let points = (0..PNUM) + .map(|i| (i as f32 * TAU / PNUM as f32).sin_cos().into()) + .map(|v: Vec2| v * 100.0) + .collect(); + Model { points } +} + +fn update(_app: &App, _model: &mut Model, _update: Update) {} + +fn view(app: &App, model: &Model, frame: Frame) { + let t = frame.nth() as f32 / 60.0; + + let draw = app.draw(); + + if frame.nth() == 1 { + draw.background().color(BLACK); + } else { + let win = app.window_rect(); + draw.rect().wh(win.wh()).color(srgba(0., 0., 0., 0.03)); + } + + let big_r = map_sin(t * 2.0, 1.0, 2.0); + + let points: Vec = model + .points + .clone() + .into_iter() + .enumerate() + .map(|(i, p)| { + let o = map_sin(t * 10.0 + 10.0 * TAU * (i as f32 / PNUM as f32), 0.8, 1.2); + p * o * big_r + }) + .collect(); + + for p in points { + let h = ((p.atan2() - t * 0.2) % TAU) / TAU; + let s = 0.7; + let l = map_range(p.length(), 100.0 * 0.8, 200.0 * 1.2, 0.1, 0.5); + + draw.ellipse().color(hsl(h, s, l)).xy(p).w_h(10.0, 10.0); + } + + draw.to_frame(app, &frame).unwrap(); + + utils::record::record(app, &frame); +}