::BASIC_29_jagged_circle

BamgasiJM·2025년 10월 24일

Nannou <BASIC>

목록 보기
38/41
post-thumbnail

📝 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);

    // 🔹 1️⃣ Fill (채움)
    draw.path()
        .fill()
        .color(hsla(0.9, 0.9, 0.9, 0.1)) // 반투명한 면 색
        .points_closed(model.points.clone());

    // 🔹 2️⃣ Stroke (윤곽선)
    draw.path()
        .stroke()
        .weight(1.5)
        .color(WHITE)
        .points_closed(model.points.clone());

    draw.to_frame(app, &frame).unwrap();
}

profile
Coding Art with Blender / oF / Processing / p5.js / nannou

0개의 댓글