📝 Rust Code
use nannou::prelude::*;
use nannou::noise::{NoiseFn, Perlin};
struct Model {
points: Vec<Vec2>,
}
fn main() {
nannou::app(model).update(update).run();
}
fn model(app: &App) -> Model {
app.new_window()
.size(1080, 1080)
.view(view)
.build()
.unwrap();
let num_points = 300;
let perlin = Perlin::new();
let mut points = Vec::with_capacity(num_points);
for i in 0..num_points {
let theta = i as f32 * TAU / num_points as f32;
let r = random_range(400.0, 450.0);
let base_x = theta.cos() * r;
let base_y = theta.sin() * r;
let noise_scale = 0.05;
let noise_amp = 30.0;
let noise_x = perlin.get([i as f64 * noise_scale, 0.0]) as f32 * noise_amp;
let noise_y = perlin.get([i as f64 * noise_scale, 1.0]) as f32 * noise_amp;
points.push(pt2(base_x + noise_x, base_y + noise_y));
}
Model { points }
}
fn update(_app: &App, _model: &mut Model, _update: Update) {}
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
draw.background().color(BLACK);
draw.path()
.fill()
.color(hsla(0.9, 0.9, 0.9, 0.1))
.points_closed(model.points.clone());
draw.path()
.stroke()
.weight(1.5)
.color(WHITE)
.points_closed(model.points.clone());
draw.to_frame(app, &frame).unwrap();
}