Function firework_rs::utils::gen_points_circle

source ·
pub fn gen_points_circle(radius: isize, n: usize) -> Vec<Vec2>
Expand description

Generate random Vec2 within a circle range

Examples found in repository?
examples/vortex.rs (line 82)
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
fn gen_vortex_firework(center: Vec2) -> Firework {
    let colors = vec![
        (6, 55, 63),
        (24, 90, 96),
        (47, 123, 119),
        (92, 174, 166),
        (200, 255, 255),
    ];
    let mut particles = Vec::new();
    for p in gen_points_circle(30, 45).iter() {
        particles.push(ParticleConfig::new(
            center + *p,
            Vec2::new((*p).y, -(*p).x).normalize() * 15.,
            thread_rng().gen_range(28..40),
            Duration::from_secs_f32(thread_rng().gen_range(4.5..7.0)),
            *colors.iter().choose(&mut thread_rng()).unwrap(),
        ));
    }
    let mut config = FireworkConfig::default()
        .with_ar_scale(0.05)
        .with_gravity_scale(0.)
        .with_gradient_scale(gradient)
        .with_additional_force(move |particle| {
            (center - particle.pos).normalize() * (1. / center.distance(particle.pos)) * 150.
        });
    config.set_enable_gradient(true);
    Firework {
        init_time: SystemTime::now(),
        spawn_after: Duration::ZERO,
        center,
        particles,
        config,
        form: ExplosionForm::Sustained {
            lasts: Duration::from_secs(10),
            time_interval: Duration::from_secs_f32(0.01),
            timer: Duration::ZERO,
        },
        ..Default::default()
    }
}