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