From 57044bd9cd247e658583fd758cd9f6d08146c924 Mon Sep 17 00:00:00 2001 From: annieversary Date: Thu, 30 Sep 2021 22:05:19 +0200 Subject: [PATCH] 19, 20, 21 --- Cargo.lock | 24 +++++++++ crates/subtitled19/Cargo.toml | 8 +++ crates/subtitled19/src/main.rs | 66 +++++++++++++++++++++++ crates/subtitled20/Cargo.toml | 8 +++ crates/subtitled20/src/main.rs | 60 +++++++++++++++++++++ crates/subtitled21/Cargo.toml | 8 +++ crates/subtitled21/src/main.rs | 97 ++++++++++++++++++++++++++++++++++ 7 files changed, 271 insertions(+) create mode 100644 crates/subtitled19/Cargo.toml create mode 100644 crates/subtitled19/src/main.rs create mode 100644 crates/subtitled20/Cargo.toml create mode 100644 crates/subtitled20/src/main.rs create mode 100644 crates/subtitled21/Cargo.toml create mode 100644 crates/subtitled21/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index e9269b2..0efea05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2438,6 +2438,14 @@ dependencies = [ "utils", ] +[[package]] +name = "subtitled19" +version = "0.1.0" +dependencies = [ + "nannou", + "utils", +] + [[package]] name = "subtitled2" version = "0.1.0" @@ -2446,6 +2454,22 @@ dependencies = [ "utils", ] +[[package]] +name = "subtitled20" +version = "0.1.0" +dependencies = [ + "nannou", + "utils", +] + +[[package]] +name = "subtitled21" +version = "0.1.0" +dependencies = [ + "nannou", + "utils", +] + [[package]] name = "subtitled3" version = "0.1.0" diff --git a/crates/subtitled19/Cargo.toml b/crates/subtitled19/Cargo.toml new file mode 100644 index 0000000..8f5eafb --- /dev/null +++ b/crates/subtitled19/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "subtitled19" +version = "0.1.0" +edition = "2018" + +[dependencies] +nannou = "0.17" +utils = { path = "../utils" } diff --git a/crates/subtitled19/src/main.rs b/crates/subtitled19/src/main.rs new file mode 100644 index 0000000..b8275fc --- /dev/null +++ b/crates/subtitled19/src/main.rs @@ -0,0 +1,66 @@ +use nannou::prelude::*; +use utils::{drawing::draw_soft_bg, *}; + +fn main() { + nannou::app(model).update(update).simple_window(view).run(); +} + +struct Walker { + pos: Vec2, + vel: Vec2, + color: f32, +} + +struct Model { + walkers: Vec, +} + +fn model(_app: &App) -> Model { + Model { + walkers: (0..100) + .map(|_| Walker { + pos: Vec2::ZERO, + vel: Vec2::ZERO, + color: random_range(0.0, 1.0), + }) + .collect(), + } +} + +fn update(app: &App, model: &mut Model, _update: Update) { + let _t = app.elapsed_frames() as f32 / 60.0; + + for walker in &mut model.walkers { + walker.vel += vec2_range(-2.0, 1.0); + walker.vel = walker.vel.normalize(); + + walker.pos += walker.vel; + + // wrap around the box + const SIZE: f32 = 100.0; + if walker.pos.x.abs() > SIZE { + walker.pos.x = -walker.pos.x; + } + if walker.pos.y.abs() > SIZE { + walker.pos.y = -walker.pos.y; + } + } +} + +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 walker in &model.walkers { + let h = (t * 10.0 + walker.color * 50.0) / 360.0; + draw.ellipse() + .xy(walker.pos) + .radius(1.0) + .color(hsl(h.fract(), 0.7, 0.5)); + } + + draw.to_frame(app, &frame).unwrap(); + utils::record::record(app, &frame); +} diff --git a/crates/subtitled20/Cargo.toml b/crates/subtitled20/Cargo.toml new file mode 100644 index 0000000..e9f5d4b --- /dev/null +++ b/crates/subtitled20/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "subtitled20" +version = "0.1.0" +edition = "2018" + +[dependencies] +nannou = "0.17" +utils = { path = "../utils" } diff --git a/crates/subtitled20/src/main.rs b/crates/subtitled20/src/main.rs new file mode 100644 index 0000000..b318bd2 --- /dev/null +++ b/crates/subtitled20/src/main.rs @@ -0,0 +1,60 @@ +use nannou::prelude::*; +use utils::*; + +// based on https://nbickford.wordpress.com/2011/04/03/the-minsky-circle-algorithm/ + +fn main() { + nannou::app(model).update(update).simple_window(view).run(); +} + +struct Model { + points: Vec, + base_hue: f32, +} + +fn model(_app: &App) -> Model { + Model { + points: (0..1000).map(|_| Vec2::ONE * 6.0).collect(), + base_hue: 0.0, + } +} + +fn advance(mut point: Vec2, t: f32) -> Vec2 { + let d = map_sin(t * 1.1, 0.01, 0.12); + let e = (t.sqrt() * 0.01 + 0.3).min(1.1); + point.x -= (point.y * d).floor(); + point.y += (point.x * e).floor(); + point +} + +fn update(app: &App, model: &mut Model, _update: Update) { + let t = app.elapsed_frames() as f32 / 60.0; + + // advance all points in list + let mut last = model.points.last().unwrap().clone(); + for v in &mut model.points { + last = advance(last, t); + *v = last; + } + + // move base_hue + model.base_hue += random::(); +} + +fn view(app: &App, model: &Model, frame: Frame) { + let t = frame.nth() as f32 / 60.0; + + let draw = app.draw(); + drawing::draw_soft_bg(&draw, app, BLACK, 0.01); + + for &p in &model.points { + let h = random_range(model.base_hue, model.base_hue + 60.0) / 360.0; + draw.ellipse() + .radius(map_sin(p.x.powi(3) + p.y.powi(7) + t * 0.1, 1.0, 3.0)) + .xy(p * 7.0) + .color(hsla(h.fract(), 1.0, 0.5, 0.1)); + } + + draw.to_frame(app, &frame).unwrap(); + utils::record::record(app, &frame); +} diff --git a/crates/subtitled21/Cargo.toml b/crates/subtitled21/Cargo.toml new file mode 100644 index 0000000..b65c09e --- /dev/null +++ b/crates/subtitled21/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "subtitled21" +version = "0.1.0" +edition = "2018" + +[dependencies] +nannou = "0.17" +utils = { path = "../utils" } diff --git a/crates/subtitled21/src/main.rs b/crates/subtitled21/src/main.rs new file mode 100644 index 0000000..ce99c6f --- /dev/null +++ b/crates/subtitled21/src/main.rs @@ -0,0 +1,97 @@ +use nannou::prelude::*; +// use utils::*; + +// from https://fabiensanglard.net/doom_fire_psx/ + +fn main() { + nannou::app(model) + .update(update) + .simple_window(view) + .size(800, 800) + .run(); +} + +struct Model {} + +const BALL_SIZE: f32 = 3.0; + +fn model(_app: &App) -> Model { + Model {} +} + +fn update(app: &App, _model: &mut Model, _update: Update) { + let _t = app.elapsed_frames() as f32 / 60.0; +} + +fn shader(i: usize, j: usize, w: usize, h: usize, t: f32) -> Rgb { + let x = i as f32 / w as f32; + let y = j as f32 / h as f32; + let pos = vec2(x, y); + + // srgb(pos.x, pos.y, 0.0) + + // let a = (pos - vec2(0.5, 0.5)).length(); + // srgb(a, a, a) + + creation(pos, t) +} + +fn creation(pos: Vec2, t: f32) -> Rgb { + let mut l = t; + let mut z = t; + let mut c = [0.0; 3]; + + for i in 0..3 { + let mut uv = pos; + let mut p = pos; + + p -= Vec2::splat(0.5); + z += 0.07; + l = p.length(); + uv += p / l * (z.sin() + 1.) * abs((l * 9. - z * 2.).sin()); + c[i] = 0.01 / ((vec2(uv.x.fract(), uv.y.fract()) - Vec2::splat(0.5)).abs()).length(); + } + + srgb(c[0] / l, c[1] / l, c[2] / l) +} + +fn view(app: &App, _model: &Model, frame: Frame) { + let t = frame.nth() as f32 / 120.0; + + let draw = app.draw(); + draw.background().color(BLACK); + + let (l, top, w, h) = app.window_rect().l_t_w_h(); + + let cols = (w / BALL_SIZE) as usize; + let rows = (h / BALL_SIZE) as usize; + + for i in 0..cols { + for j in 0..rows { + let x = l + j as f32 * BALL_SIZE; + let y = top - i as f32 * BALL_SIZE; + let p = vec2(x, y) + + (t * 0.4).min(5.0) + * 10.0 + * vec2( + (t * 0.7 + (i * j) as f32).sin(), + (t * 0.9 + (2 * i * j) as f32).cos(), + ); + + let color = shader(i, j, cols, rows, t); + + draw.quad() + .points( + p + BALL_SIZE * vec2(1., 1.), + p + BALL_SIZE * vec2(1., -1.), + p + BALL_SIZE * vec2(-1., -1.), + p + BALL_SIZE * vec2(-1., 1.), + ) + .xy(p) + .color(color); + } + } + + draw.to_frame(app, &frame).unwrap(); + utils::record::record(app, &frame); +}