main
annieversary 2021-08-24 23:54:06 +02:00
parent fd5c7fa77d
commit c39dec8f61
4 changed files with 108 additions and 0 deletions

8
Cargo.lock generated
View File

@ -2348,6 +2348,14 @@ dependencies = [
"utils",
]
[[package]]
name = "subtitled10"
version = "0.1.0"
dependencies = [
"nannou",
"utils",
]
[[package]]
name = "subtitled2"
version = "0.1.0"

View File

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

View File

@ -0,0 +1,89 @@
use nannou::prelude::*;
fn main() {
nannou::app(model).update(update).simple_window(view).run();
}
#[derive(Clone, Copy, Debug)]
struct Params {
a: f32,
b: f32,
c: f32,
d: f32,
}
impl Params {
fn new() -> Self {
// magic numbers from here:
// http://paulbourke.net/fractals/clifford/paul_richards/main.cpp
let min_a = f32::acos(1.6 / 2.0);
let max_a = f32::acos(1.3 / 2.0);
let min_b = f32::acos(-0.6 / 2.0);
let max_b = f32::acos(1.7 / 2.0);
let min_c = f32::acos(-1.2 / 2.0);
let max_c = f32::acos(0.5 / 2.0);
let min_d = f32::acos(1.6 / 2.0);
let max_d = f32::acos(1.4 / 2.0);
Self {
a: random_range(min_a, max_a),
b: random_range(min_b, max_b),
c: random_range(min_c, max_c),
d: random_range(min_d, max_d),
}
}
}
struct Model {
params: Params,
points: Vec<Vec2>,
base_hue: f32,
}
fn model(_app: &App) -> Model {
let params = Params::new();
dbg!(params);
Model {
params,
base_hue: random_range(0., 360.0),
points: vec![Vec2::ZERO; 10000],
}
}
fn advance(params: Params, point: Vec2) -> Vec2 {
// xn+1 = sin(a yn) + c cos(a xn)
// yn+1 = sin(b xn) + d cos(b yn)
vec2(
(params.a * point.y).sin() + (params.a * point.x).cos() * params.c,
(params.b * point.x).sin() + (params.b * point.y).cos() * params.d,
)
}
fn update(_app: &App, model: &mut Model, _update: Update) {
let mut last = model.points.last().unwrap().clone();
for v in &mut model.points {
last = advance(model.params, last);
*v = last;
}
}
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(BLACK);
}
for &p in &model.points {
let h = random_range(model.base_hue, model.base_hue + 60.0) / 360.0;
draw.ellipse()
.radius(0.1)
.xy(150.0 * p)
.color(hsla(h.fract(), 1.0, 0.5, 0.1));
}
draw.to_frame(app, &frame).unwrap();
utils::record::record(app, &frame);
}

View File

@ -17,6 +17,9 @@ fn view(app: &App, _model: &Model, frame: Frame) {
let draw = app.draw();
draw.background().color(PLUM);
draw.ellipse().color(STEELBLUE);
draw.to_frame(app, &frame).unwrap();
utils::record::record(app, &frame);
}