subtitled #4
parent
ad4be3db13
commit
31f496d2ba
|
@ -2364,6 +2364,14 @@ dependencies = [
|
|||
"utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "subtitled4"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"nannou",
|
||||
"utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.74"
|
||||
|
|
|
@ -7,3 +7,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
|
||||
- subtitled #4: more spinning circles wow what a surprise
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "subtitled4"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
nannou = "0.17"
|
||||
utils = { path = "../utils" }
|
|
@ -0,0 +1,59 @@
|
|||
use nannou::{color::Mix, prelude::*};
|
||||
|
||||
use utils::*;
|
||||
|
||||
fn main() {
|
||||
nannou::app(model).update(update).simple_window(view).run();
|
||||
}
|
||||
|
||||
struct Model {
|
||||
points: Vec<Vec2>,
|
||||
}
|
||||
|
||||
fn model(_app: &App) -> Model {
|
||||
let r = 300.0;
|
||||
|
||||
Model {
|
||||
points: (0..100)
|
||||
.map(|_| {
|
||||
let r = r * random::<f32>().sqrt();
|
||||
let theta = random::<f32>() * TAU;
|
||||
let x = r * theta.cos();
|
||||
let y = r * theta.sin();
|
||||
vec2(x, y)
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn update(_app: &App, model: &mut Model, _update: Update) {
|
||||
for p in &mut model.points {
|
||||
*p += vec2(p.y, -p.x) * 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
fn view(app: &App, model: &Model, frame: Frame) {
|
||||
let t = frame.nth() as f32 / 60.0;
|
||||
|
||||
let draw = app.draw();
|
||||
let bg_color = srgb(1.0f32, 250.0 / 255.0, 250.0 / 255.0);
|
||||
let fg_color = srgb(189.0 / 255.0, 178.0 / 255.0, 1.0);
|
||||
|
||||
if frame.nth() == 1 {
|
||||
draw.background().color(bg_color);
|
||||
} else {
|
||||
let win = app.window_rect();
|
||||
draw.rect()
|
||||
.wh(win.wh())
|
||||
.color(srgba(1., 250.0 / 255.0, 250.0 / 255.0, 0.001));
|
||||
}
|
||||
|
||||
for p in &model.points {
|
||||
let m = map_sin(t * 1.2 + p.length() / 100.0, 0.0, 1.0).powi(3);
|
||||
|
||||
let color = fg_color.into_linear().mix(&bg_color.into_linear(), m);
|
||||
draw.ellipse().xy(*p).radius(10.0).color(color);
|
||||
}
|
||||
|
||||
draw.to_frame(app, &frame).unwrap();
|
||||
}
|
Loading…
Reference in New Issue