main
annieversary 2021-09-01 20:01:22 +02:00
parent 7506d4907f
commit 45fbe5a37f
3 changed files with 102 additions and 0 deletions

26
Cargo.lock generated
View File

@ -1188,6 +1188,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "libm"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a"
[[package]] [[package]]
name = "line_drawing" name = "line_drawing"
version = "0.7.0" version = "0.7.0"
@ -1649,6 +1655,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"libm",
] ]
[[package]] [[package]]
@ -2027,6 +2034,16 @@ dependencies = [
"getrandom 0.2.3", "getrandom 0.2.3",
] ]
[[package]]
name = "rand_distr"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "051b398806e42b9cd04ad9ec8f81e355d0a382c543ac6672c62f5a5b452ef142"
dependencies = [
"num-traits",
"rand 0.8.4",
]
[[package]] [[package]]
name = "rand_hc" name = "rand_hc"
version = "0.2.0" version = "0.2.0"
@ -2364,6 +2381,15 @@ dependencies = [
"utils", "utils",
] ]
[[package]]
name = "subtitled12"
version = "0.1.0"
dependencies = [
"nannou",
"rand_distr",
"utils",
]
[[package]] [[package]]
name = "subtitled2" name = "subtitled2"
version = "0.1.0" version = "0.1.0"

View File

@ -0,0 +1,9 @@
[package]
name = "subtitled12"
version = "0.1.0"
edition = "2018"
[dependencies]
nannou = "0.17"
rand_distr = "0.4.1"
utils = { path = "../utils" }

View File

@ -0,0 +1,67 @@
use nannou::prelude::*;
use nannou::rand::prelude::*;
use rand_distr::Normal;
use utils::*;
fn main() {
nannou::app(model).update(update).simple_window(view).run();
}
struct Model {
lines: Vec<Vec<Vec2>>,
}
fn lines(max_width: f32) -> Vec<Vec<Vec2>> {
let normal = Normal::new(0.0, 0.2).unwrap();
(0..20)
.map(|_| {
let mut line = vec![Vec2::Y];
// generate the y coordinates for all points
let n = random_range(4, 12);
let mut ys = (0..n).map(|_| random_range(-1.0, 1.0)).collect::<Vec<_>>();
ys.sort_by(|a, b| b.partial_cmp(a).unwrap());
// make the actual points and add them to the vec
for y in ys {
let w = map_range(1.0 - y.abs(), 0.0, 1.0, 0.01, max_width);
let x = nannou::rand::thread_rng().sample::<f32, _>(normal) * w;
line.push(vec2(x, y));
}
line.push(-Vec2::Y);
line
})
.collect()
}
fn model(_app: &App) -> Model {
Model { lines: lines(0.0) }
}
fn update(app: &App, model: &mut Model, _update: Update) {
let t = app.elapsed_frames() as f32 / 60.0;
if app.elapsed_frames() % 2 == 0 {
model.lines = lines(map_sin(t, 0.1, 1.0));
}
}
fn view(app: &App, model: &Model, frame: Frame) {
let _t = frame.nth() as f32 / 60.0;
let draw = app.draw();
draw.background().color(BLACK);
for line in &model.lines {
draw.polyline()
.stroke_weight(1.0)
.points(line.iter().map(|v| *v * 300.0))
.color(PINK);
}
draw.to_frame(app, &frame).unwrap();
utils::record::record(app, &frame);
}