aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/examples/fireworks/modules/objects/vector.v
blob: 0e29283fb76010b8f3ca54e7e782113fcbe1ebad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module objects

import math
import rand

pub struct Vector {
pub mut:
	x f32
	y f32
}

pub fn (a Vector) + (b Vector) Vector {
	return Vector{a.x + b.x, a.y + b.y}
}

pub fn (vector Vector) mult(scalar f32) Vector {
	return Vector{vector.x * scalar, vector.y * scalar}
}

pub fn random_vector_in_circle() Vector {
	theta := rand.f32n(2 * math.pi)
	y := rand.f32()

	return Vector{
		x: f32(y * math.sin(theta))
		y: f32(y * math.cos(theta))
	}
}