Skip to main content

vec2

Function vec2 

Source
pub const fn vec2(x: f32, y: f32) -> Vec2
Expand description

Shorthand: vec2(x, y)

Examples found in repository?
examples/basics.rs (line 18)
16    fn new() -> Self {
17        Self {
18            position: vec2(400.0, 300.0),
19            velocity: vec2(250.0, -180.0),
20            radius: 30.0,
21            color: Color::GOLD,
22            trail: Vec::with_capacity(60),
23        }
24    }
More examples
Hide additional examples
examples/particles.rs (line 14)
12    fn on_enter(&mut self, _ctx: &mut Context) {
13        // Fire emitter at bottom center
14        let mut fire = ParticleEmitter::new(vec2(400.0, 500.0));
15        fire.configure(|cfg| {
16            cfg
17                .rate(80.0)
18                .shape(EmitterShape::Line { x1: 370.0, y1: 500.0, x2: 430.0, y2: 500.0 })
19                .speed(80.0, 200.0)
20                .angle(std::f32::consts::PI * 1.1, std::f32::consts::PI * 1.9)
21                .size(3.0, 10.0)
22                .lifetime(0.3, 1.0)
23                .gravity(0.0, -80.0)
24                .color_start(Color::from_hex("#FF6600").unwrap())
25                .color_end(Color::from_hex("#FFFF00").unwrap())
26                .size_end(0.0)
27                .drag(1.5);
28        });
29        self.emitters.push(fire);
30
31        // Sparkle emitter
32        let mut sparkles = ParticleEmitter::new(vec2(400.0, 300.0));
33        sparkles.configure(|cfg| {
34            cfg
35                .rate(30.0)
36                .shape(EmitterShape::Circle { cx: 400.0, cy: 300.0, radius: 150.0 })
37                .speed(10.0, 50.0)
38                .angle(0.0, std::f32::consts::TAU)
39                .size(2.0, 6.0)
40                .lifetime(0.5, 1.5)
41                .gravity(0.0, 20.0)
42                .color_start(Color::from_hex("#FFFFFF").unwrap())
43                .color_end(Color::TRANSPARENT)
44                .size_end(0.0);
45        });
46        self.emitters.push(sparkles);
47    }