| 1 | module objects |
| 2 | |
| 3 | import math |
| 4 | import rand |
| 5 | |
| 6 | pub struct Vector { |
| 7 | pub mut: |
| 8 | x f32 |
| 9 | y f32 |
| 10 | } |
| 11 | |
| 12 | pub fn (a Vector) + (b Vector) Vector { |
| 13 | return Vector{a.x + b.x, a.y + b.y} |
| 14 | } |
| 15 | |
| 16 | pub fn (vector Vector) mult(scalar f32) Vector { |
| 17 | return Vector{vector.x * scalar, vector.y * scalar} |
| 18 | } |
| 19 | |
| 20 | pub fn random_vector_in_circle() Vector { |
| 21 | theta := rand.f32n(2 * math.pi) or { 0 } |
| 22 | y := rand.f32() |
| 23 | |
| 24 | return Vector{ |
| 25 | x: f32(y * math.sin(theta)) |
| 26 | y: f32(y * math.cos(theta)) |
| 27 | } |
| 28 | } |
| 29 | |