19, 20, 21

main
annieversary 2021-09-30 22:05:19 +02:00
parent f20a328784
commit 57044bd9cd
7 changed files with 271 additions and 0 deletions

24
Cargo.lock generated
View File

@ -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"

View File

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

View File

@ -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<Walker>,
}
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);
}

View File

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

View File

@ -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<Vec2>,
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::<f32>();
}
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);
}

View File

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

View File

@ -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);
}