Function gen_points_fan

Source
pub fn gen_points_fan(
    radius: f32,
    n: usize,
    st_angle: f32,
    ed_angle: f32,
) -> Vec<Vec2>
Expand description

Generate random Vec2 within a fan-shape range

Examples found in repository?
examples/fountain.rs (lines 77-82)
74fn gen_fountain_firework(center: Vec2) -> Firework {
75    let colors = vec![(226, 196, 136), (255, 245, 253), (208, 58, 99)];
76    let mut particles = Vec::new();
77    for v in gen_points_fan(
78        300.,
79        45,
80        5 as f32 / 12 as f32 * PI,
81        7 as f32 / 12 as f32 * PI,
82    )
83    .iter()
84    {
85        particles.push(ParticleConfig::new(
86            center,
87            *v,
88            thread_rng().gen_range(28..38),
89            Duration::from_secs_f32(thread_rng().gen_range(2.5..3.8)),
90            *colors.iter().choose(&mut thread_rng()).unwrap(),
91        ));
92    }
93    let mut config = FireworkConfig::default()
94        .with_ar_scale(0.15)
95        .with_gravity_scale(0.5)
96        .with_gradient_scale(gradient);
97    config.set_enable_gradient(true);
98    Firework {
99        init_time: SystemTime::now(),
100        spawn_after: Duration::ZERO,
101        center,
102        particles,
103        config,
104        form: ExplosionForm::Sustained {
105            lasts: Duration::from_secs(5),
106            time_interval: Duration::from_secs_f32(0.08),
107            timer: Duration::ZERO,
108        },
109        ..Default::default()
110    }
111}
More examples
Hide additional examples
examples/heart.rs (line 85)
74fn gen_heart_firework(center: Vec2) -> Firework {
75    let colors = vec![
76        (233, 232, 237),
77        (254, 142, 130),
78        (200, 27, 72),
79        (86, 18, 31),
80    ];
81    let mut particles = Vec::new();
82    let trail_length = thread_rng().gen_range(100..105);
83    let life_time = Duration::from_secs_f32(thread_rng().gen_range(3.0..3.2));
84    let init_pos = center - Vec2::NEG_Y * 15.;
85    for v in gen_points_fan(300., 45, 0.2 * PI, 0.3 * PI).iter() {
86        particles.push(ParticleConfig::new(
87            init_pos,
88            *v,
89            trail_length,
90            life_time,
91            *colors.iter().choose(&mut thread_rng()).unwrap(),
92        ));
93    }
94    for v in gen_points_fan(300., 45, 0.7 * PI, 0.8 * PI).iter() {
95        particles.push(ParticleConfig::new(
96            init_pos,
97            *v,
98            trail_length,
99            life_time,
100            *colors.iter().choose(&mut thread_rng()).unwrap(),
101        ));
102    }
103    let mut config = FireworkConfig::default()
104        .with_ar_scale(0.1)
105        .with_gravity_scale(0.1)
106        .with_gradient_scale(gradient)
107        .with_additional_force(move |particle| (center - particle.pos) * 2.);
108    config.set_enable_gradient(true);
109    Firework {
110        init_time: SystemTime::now(),
111        spawn_after: Duration::ZERO,
112        center,
113        particles,
114        config,
115        form: ExplosionForm::Instant { used: false },
116        ..Default::default()
117    }
118}