Skip to content

Commit

Permalink
Merge pull request #27 from DavJCosby/master
Browse files Browse the repository at this point in the history
catch new-api up to master
  • Loading branch information
DavJCosby authored Dec 13, 2023
2 parents be87e4e + a5ad88b commit fadaca4
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 33 deletions.
24 changes: 10 additions & 14 deletions sandbox/cfg/config1.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
center_point = [1.5, 1.05]
center_point = [0.0, 0.5]
density = 30.0

[[line_segment]]
start = [-1.0, 0.0]
start = [-3.0, 0.0]
end = [0.5, -1.0]

[[line_segment]]
start = [0.5, -1.0]
end = [3.5, 0.0]

[[line_segment]]
start = [3.5, 0.0]
end = [2, 2]

[[line_segment]]
start = [2, 2]
end = [0.0, 2]

[[line_segment]]
start = [0.0, 2]
end = [-1.0, 0.0]

[[line_segment]]
start = [0.25, 1.75]
end = [2.5, 0.75]
start = [2.0, 2]
end = [-2.0, 2]

[[line_segment]]
start = [0.125, 0.25]
end = [2.75, 0.25]
start = [-2.0, 2]
end = [-3.0, 0.0]
42 changes: 28 additions & 14 deletions sandbox/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::f32::consts::TAU;

use sled::{Rgb, Sled, SledError};

use bevy::{
Expand Down Expand Up @@ -36,26 +38,38 @@ fn main() -> Result<(), SledError> {
Ok(())
}

const NUM_FAIRIES: usize = 12;
const GREEN_RADIUS: f32 = 35.0;
const GREEN_COUNT: usize = 64;

const BLUE_RADIUS: f32 = 45.0;
const BLUE_COUNT: usize = 96;

const TRAIL_RADIUS: f32 = 18.0;

fn step(sled: &mut Sled, elapsed: f32) -> Result<(), SledError> {
sled.for_each(|led| {
led.color *= Rgb::new(0.9, 0.94, 0.99);
});
let inner_color = Rgb::new(0.6, 0.93, 0.762);
let outer_delta = Rgb::new(0.4, 0.51, 0.93);

let center = sled.center_point();
let dist = (elapsed / 30.0) % 4.0;
let inner_time_scale = elapsed / GREEN_RADIUS;
let outer_time_scale = elapsed / BLUE_RADIUS;

sled.set_at_dist(dist, Rgb::new(1.0, 1.0, 1.0));
for i in 0..GREEN_COUNT {
let angle = inner_time_scale + (TAU / GREEN_COUNT as f32) * i as f32;
sled.get_at_angle_mut(angle).unwrap().color += inner_color;
}

// for i in 0..NUM_FAIRIES {
// let c = sled::color::Oklch::new(1.0, 0.9, elapsed + 20.0 * i as f32).adapt_into();
for i in 0..BLUE_COUNT {
let angle = outer_time_scale + (TAU / BLUE_COUNT as f32) * i as f32 % TAU;
sled.get_at_angle_mut(angle).unwrap().color += outer_delta;
}

// sled.set_at_angle(
// (elapsed + (360.0 / NUM_FAIRIES as f32) * i as f32 % 360.0).to_radians(),
// c,
// )?;
// }
let radar_time_scale = elapsed / TRAIL_RADIUS;
let angle = radar_time_scale % TAU;
sled.map(|led| {
let da = (led.angle() + angle) % TAU;
let fac = 1.0 - (da / (TAU)).powf(1.25);
led.color * fac
});

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion sled/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ path = "examples/basic.rs"
doc-scrape-examples = true

[[bench]]
name = "my_benchmark"
name = "quirky_trail"
harness = false

[lib]
Expand Down
66 changes: 66 additions & 0 deletions sled/benches/quirky_trail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use std::{f32::consts::TAU, time::Duration};

use criterion::{criterion_group, criterion_main, Criterion};
use sled::{Rgb, Sled};

const GREEN_RADIUS: f32 = 35.0;
const GREEN_COUNT: usize = 64;

const BLUE_RADIUS: f32 = 45.0;
const BLUE_COUNT: usize = 96;

const TRAIL_RADIUS: f32 = 18.0;

fn step(sled: &mut Sled, elapsed: f32) {
let inner_color = Rgb::new(0.6, 0.93, 0.762);
let outer_delta = Rgb::new(0.4, 0.51, 0.93);

let inner_time_scale = elapsed / GREEN_RADIUS;
let outer_time_scale = elapsed / BLUE_RADIUS;

for i in 0..GREEN_COUNT {
let angle = inner_time_scale + (TAU / GREEN_COUNT as f32) * i as f32;
sled.get_at_angle_mut(angle).unwrap().color += inner_color;
}

for i in 0..BLUE_COUNT {
let angle = outer_time_scale + (TAU / BLUE_COUNT as f32) * i as f32 % TAU;
sled.get_at_angle_mut(angle).unwrap().color += outer_delta;
}

let radar_time_scale = elapsed / TRAIL_RADIUS;
let angle = radar_time_scale % TAU;
sled.map(|led| {
let da = (led.angle() + angle) % TAU;
let fac = 1.0 - (da / (TAU)).powf(1.25);
led.color * fac
});
}

fn trail(c: &mut Criterion) {
let mut sled = Sled::new("./benches/config1.toml").unwrap();

let simulated_duration = 30.0;
let simulated_hz = 144.0;
let timestep = 1.0 / simulated_hz;
let total_steps = (simulated_duration * simulated_hz) as usize;

c.bench_function("quirky_trail", |b| {
b.iter(|| {
for i in 0..total_steps {
step(&mut sled, timestep * i as f32);
}
})
});
}

criterion_group! {
name = benches;
config = Criterion::default()
.significance_level(0.05)
.sample_size(500)
.warm_up_time(Duration::from_secs_f32(10.0))
.measurement_time(Duration::from_secs_f32(45.0));
targets = trail
}
criterion_main!(benches);
8 changes: 4 additions & 4 deletions sled/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use sled::{Rgb, Sled, SledError};


// fn display

fn main() {
fn main() -> Result<(), SledError> {
let mut sled = Sled::new("./benches/config1.toml").unwrap();
let white = Rgb::new(1.0, 1.0, 1.0);

sled.set_range(20..50, white);
}
sled.set_range(20..50, white)?;
Ok(())
}

0 comments on commit fadaca4

Please sign in to comment.