From fd5c7fa77db6c0a1bde65f37d96ce2323ff5dea6 Mon Sep 17 00:00:00 2001 From: annieversary Date: Tue, 24 Aug 2021 23:03:09 +0200 Subject: [PATCH] subtitled #9 --- Cargo.lock | 8 +++ crates/subtitled9/Cargo.toml | 8 +++ crates/subtitled9/src/main.rs | 117 ++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 crates/subtitled9/Cargo.toml create mode 100644 crates/subtitled9/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 8df08da..2c51002 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2404,6 +2404,14 @@ dependencies = [ "utils", ] +[[package]] +name = "subtitled9" +version = "0.1.0" +dependencies = [ + "nannou", + "utils", +] + [[package]] name = "syn" version = "1.0.74" diff --git a/crates/subtitled9/Cargo.toml b/crates/subtitled9/Cargo.toml new file mode 100644 index 0000000..3824e02 --- /dev/null +++ b/crates/subtitled9/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "subtitled9" +version = "0.1.0" +edition = "2018" + +[dependencies] +nannou = "0.17" +utils = { path = "../utils" } diff --git a/crates/subtitled9/src/main.rs b/crates/subtitled9/src/main.rs new file mode 100644 index 0000000..ba28aba --- /dev/null +++ b/crates/subtitled9/src/main.rs @@ -0,0 +1,117 @@ +use nannou::prelude::*; +use utils::*; + +fn main() { + nannou::app(model).update(update).simple_window(view).run(); +} + +struct Model {} + +fn model(_app: &App) -> Model { + Model {} +} + +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() == 0 { + draw.background().color(SNOW); + } else { + // we only want fading on the inner box, + // outside of it we want a hard reset + + let win = app.window_rect(); + draw.rect() + .wh(win.wh()) + .color(srgba(1.0, 250.0 / 255.0, 250.0 / 255.0, 0.01)); + } + + // okay so this is a bit of a hack + // we draw the ones inside and outside the box in two separate passes + // on the first one, we draw the ones inside the box, with a box of size 220 + // then we draw the blank stuff outside of a 200 box + // then we draw the points outside the 200 box + + // this is cause otherwise either the colored lines go outside the box, + // or the colored lines finish too early + // this works and it's still real time so + // don't judge me uwu + + // inner draw + for i in 0..50 { + let r = 1.5; + let r2 = r * (50 + i) as f32 / 50.0; + let v = vec2((t * r + i as f32).sin(), (t * r2 + (2 * i) as f32).sin()) * 300.0; + + // while inside the box, draw a line to the last point + if v.x.abs() < 220.0 && v.y.abs() < 220.0 { + let t = t - 1.0 / 60.0; + let v_prev = vec2((t * r + i as f32).sin(), (t * r2 + (2 * i) as f32).sin()) * 300.0; + + let h_prev = map_sin((v_prev.x + v_prev.y) / 400.0 + i as f32, 0.0, 1.0); + + draw.line() + .stroke_weight(4.0) + .points(v, v_prev) + .color(hsl(h_prev, 0.5, 0.5)); + + let h = map_sin((v.x + v.y) / 400.0 + i as f32, 0.0, 1.0); + draw.ellipse().radius(2.0).xy(v).color(hsl(h, 0.5, 0.5)); + } + } + + // draw exteriors + draw_exterior(&draw); + + // outer draw + for i in 0..50 { + let r = 1.5; + let r2 = r * (50 + i) as f32 / 50.0; + let v = vec2((t * r + i as f32).sin(), (t * r2 + (2 * i) as f32).sin()) * 300.0; + + if v.x.abs() > 201.0 || v.y.abs() > 201.0 { + draw.ellipse().radius(2.0).xy(v).color(BLACK); + } + } + + draw.to_frame(app, &frame).unwrap(); + utils::record::record(app, &frame); +} + +fn draw_exterior(draw: &Draw) { + draw.quad() + .points( + vec2(200.0, -1000.0), + vec2(200.0, 1000.0), + vec2(1000.0, 1000.0), + vec2(1000.0, -1000.0), + ) + .color(SNOW); + draw.quad() + .points( + vec2(-200.0, -1000.0), + vec2(-200.0, 1000.0), + vec2(-1000.0, 1000.0), + vec2(-1000.0, -1000.0), + ) + .color(SNOW); + draw.quad() + .points( + vec2(-1000.0, 200.0), + vec2(-1000.0, 1000.0), + vec2(1000.0, 1000.0), + vec2(1000.0, 200.0), + ) + .color(SNOW); + draw.quad() + .points( + vec2(-1000.0, -200.0), + vec2(-1000.0, -1000.0), + vec2(1000.0, -1000.0), + vec2(1000.0, -200.0), + ) + .color(SNOW); +}