Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use nannou::color::Gradient;
- use nannou::noise::NoiseFn;
- use nannou::noise::SuperSimplex;
- use nannou::prelude::*;
- fn main() {
- nannou::sketch(view).size(1024, 1024).run();
- }
- fn view(app: &App, frame: Frame) {
- let noise = SuperSimplex::new();
- let draw = app.draw();
- let draw = draw.scale(0.95).translate(Vec3::new(-475.0, -475.0, 0.0));
- draw.background().color(BLACK);
- let gradient = Gradient::new([
- hsl((app.time / 3.0), 1.0, 0.8),
- hsl((app.time / 3.0 + 0.3), 1.0, 0.8),
- ]);
- for i in 0..100 {
- let mut base_r = 102.4;
- let n_circles = 50;
- let decay_r = base_r / (n_circles as f32);
- let time = app.time / 2.0;
- let row = i / 10;
- let column = i % 10;
- let row_offset = row as f32 * base_r;
- let column_offset = column as f32 * base_r;
- let gradient_id_col = if column > 4 {
- 1.0 - ((column as f32 - 5.0) / 4.0)
- } else {
- column as f32 / 4.0
- };
- let gradient_id_row = if row > 4 {
- 1.0 - ((row as f32 - 5.0) / 4.0)
- } else {
- row as f32 / 4.0
- };
- let gradient_id = if gradient_id_row > gradient_id_col {
- gradient_id_col
- } else {
- gradient_id_row
- };
- let hue = gradient.get(gradient_id).hue;
- for i in 0..n_circles {
- let id_frac = i as f32 / n_circles as f32;
- let frac_sin = ((id_frac.sin() + 1.0) / 2.0);
- let lum_range =
- (((app.time * 10.0 + id_frac / 0.02).sin() + 1.0) / 2.0).clamp(0.1, 0.9);
- let lum = lum_range;
- let sample = i as f64 / (n_circles as f64);
- let color = hsl(hue.to_degrees() / 360.0, 0.7, (id_frac + 0.1) * lum);
- let offset_x =
- 1.2 * (noise.get([time as f64 + sample + column as f64, 0.0f64]) as f32) * i as f32
- + column_offset;
- let offset_y =
- 1.2 * (noise.get([0.0f64, time as f64 + sample + row as f64]) as f32) * i as f32
- + row_offset;
- // let offset_x = app.time.sin() * i as f32 / 2.0;
- // let offset_y = app.time.cos() * i as f32 / 2.0;
- draw.ellipse()
- .w_h(base_r, base_r)
- .color(color)
- .x_y(offset_x * decay_r / 2.0, offset_y * decay_r / 2.0)
- .rotate(sample as f32);
- base_r -= decay_r;
- }
- }
- draw.to_frame(app, &frame).unwrap();
- // Capture the frame!
- // let file_path = captured_frame_path(app, &frame);
- // app.main_window().capture_frame(file_path);
- }
- fn captured_frame_path(app: &App, frame: &Frame) -> std::path::PathBuf {
- // Create a path that we want to save this frame to.
- app.project_path()
- .expect("failed to locate `project_path`")
- // Capture all frames to a directory called `/<path_to_nannou>/nannou/simple_capture`.
- .join(app.exe_name().unwrap())
- // Name each file after the number of the frame.
- .join(format!("pic{:04}", frame.nth()))
- // The extension will be PNG. We also support tiff, bmp, gif, jpeg, webp and some others.
- .with_extension("png")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement