diff --git a/Cargo.lock b/Cargo.lock index 53c77b4..5c548bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2356,6 +2356,14 @@ dependencies = [ "utils", ] +[[package]] +name = "subtitled3" +version = "0.1.0" +dependencies = [ + "nannou", + "utils", +] + [[package]] name = "syn" version = "1.0.74" diff --git a/README.md b/README.md index a247295..237aff3 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,4 @@ this is a bunch of nannou projects - subtitled #1: some spinning circles - subtitled #2: idk spinning colors or something +- subtitled #3: small flashing circles diff --git a/crates/subtitled3/Cargo.toml b/crates/subtitled3/Cargo.toml new file mode 100644 index 0000000..43e7fe2 --- /dev/null +++ b/crates/subtitled3/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "subtitled3" +version = "0.1.0" +edition = "2018" + +[dependencies] +nannou = "0.17" +utils = { path = "../utils" } diff --git a/crates/subtitled3/src/main.rs b/crates/subtitled3/src/main.rs new file mode 100644 index 0000000..197a5e7 --- /dev/null +++ b/crates/subtitled3/src/main.rs @@ -0,0 +1,77 @@ +use nannou::prelude::*; + +use utils::color::color; + +fn main() { + nannou::app(model).update(update).simple_window(view).run(); +} + +const COLORS: &[Rgb] = &[ + color(125, 22, 22), + color(107, 19, 16), + color(69, 15, 16), + color(72, 0, 50), + color(223, 0, 84), + color(255, 139, 106), + color(255, 214, 194), +]; +fn rand_col() -> Rgb { + COLORS[random_range(0, COLORS.len())] +} + +struct Model {} + +fn model(_app: &App) -> Model { + Model {} +} + +fn update(_app: &App, _model: &mut Model, _update: Update) {} + +const BG: Rgb = color(250, 235, 215); + +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(BG); + } else { + let win = app.window_rect(); + draw.rect() + .wh(win.wh()) + .color(srgba(1., 250.0 / 255.0, 250.0 / 255.0, 0.01)); + } + + let win = app.window_rect(); + let xs = win.x.start; + let xe = win.x.end; + let ys = win.y.start; + let ye = win.y.end; + + let points: Vec<_> = (0..200) + .map(|_| vec2(random_range(xs, xe), random_range(ys, ye))) + .collect(); + + for p in points { + draw.ellipse().xy(p).radius(10.0).color(rand_col()); + } + + macro_rules! big_circ { + ($draw:ident, $axis:ident, $from:expr) => { + let mut r = $from; + while r.abs() > 1. { + $draw.ellipse().$axis(r).radius(r / 2.0).color(BG); + r /= 2.0; + } + }; + } + big_circ!(draw, x, 800.0); + big_circ!(draw, x, -800.0); + big_circ!(draw, y, 800.0); + big_circ!(draw, y, -800.0); + + draw.to_frame(app, &frame).unwrap(); + + utils::record::record(app, &frame); +}