From f5c4671bfbad96bf346bd7e9a21fc4317b4959df Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sat, 3 Dec 2022 17:00:20 +0530 Subject: Adds most of the tools --- .../v/examples/fireworks/modules/objects/vector.v | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 v_windows/v/examples/fireworks/modules/objects/vector.v (limited to 'v_windows/v/examples/fireworks/modules/objects/vector.v') diff --git a/v_windows/v/examples/fireworks/modules/objects/vector.v b/v_windows/v/examples/fireworks/modules/objects/vector.v new file mode 100644 index 0000000..0e29283 --- /dev/null +++ b/v_windows/v/examples/fireworks/modules/objects/vector.v @@ -0,0 +1,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)) + } +} -- cgit v1.2.3