main
annieversary 2021-09-18 13:49:13 +02:00
parent 8fe1852e55
commit 658093b77f
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,31 @@
use nannou::prelude::*;
pub struct Chaikin {
pub points: Vec<Vec2>,
}
impl Chaikin {
pub fn new(points: Vec<Vec2>) -> Self {
Self { points }
}
pub fn points(&self, div: f32, n: usize) -> Vec<Vec2> {
let mut points = self.points.clone();
for _ in 0..n {
let first = *points.first().unwrap();
let last = *points.last().unwrap();
points = points
.windows(2)
.flat_map(|p| {
let a = p[0];
let b = p[1];
[a + div * (b - a), a + (1.0 - div) * (b - a)]
})
.collect();
points.insert(0, first);
points.push(last);
}
points
}
}

View File

@ -1,4 +1,5 @@
pub mod color; pub mod color;
pub mod curves;
pub mod drawing; pub mod drawing;
pub mod record; pub mod record;
pub mod sequences; pub mod sequences;
@ -49,3 +50,7 @@ pub fn vec2_range(min: f32, max: f32) -> Vec2 {
pub fn ivec2_range(min: i32, max: i32) -> IVec2 { pub fn ivec2_range(min: i32, max: i32) -> IVec2 {
ivec2(random_range(min, max), random_range(min, max)) ivec2(random_range(min, max), random_range(min, max))
} }
/// returns a random vector in the unit circle
pub fn vec2_circ() -> Vec2 {
random_range(0., TAU).sin_cos().into()
}

View File

@ -8,6 +8,7 @@ if [[ -z $1 ]]; then
echo -e "\t$0 packagename" echo -e "\t$0 packagename"
else else
rm -rf "recordings/$1/frames" rm -rf "recordings/$1/frames"
mkdir -p "recordings/$1/videos"
cargo run --release --package $1 -- -record cargo run --release --package $1 -- -record
filename="video$(( $(find recordings/$1/videos -type f -exec basename -s .mp4 {} \; | sed 's/^video//' | sort -n | tail -n1) + 1)).mp4" filename="video$(( $(find recordings/$1/videos -type f -exec basename -s .mp4 {} \; | sed 's/^video//' | sort -n | tail -n1) + 1)).mp4"
ffmpeg -framerate 60 -i "recordings/$1/frames/%03d.png" -pix_fmt yuv420p "recordings/$1/videos/$filename" ffmpeg -framerate 60 -i "recordings/$1/frames/%03d.png" -pix_fmt yuv420p "recordings/$1/videos/$filename"