diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | src/config.zig | 3 | ||||
| -rw-r--r-- | src/particle.zig | 27 |
3 files changed, 27 insertions, 5 deletions
@@ -1,3 +1,3 @@ zig-out/ -zig-cache/ +.zig-cache/ imgui.ini diff --git a/src/config.zig b/src/config.zig index 162f71c..06d60bb 100644 --- a/src/config.zig +++ b/src/config.zig @@ -5,6 +5,8 @@ pub const screenWidth = 2560; pub const screenHeight = 1440; pub const particleMax = 4000; pub const initialParticles = 3000; +pub const colorAmnt = colors.len; + pub var particleCount: i32 = initialParticles; pub var radius: f32 = 100.0; pub var minDistance: f32 = 20.0; @@ -18,5 +20,4 @@ pub const colors = [_]rl.Color{ rl.Color.orange, rl.Color.gray, }; -pub const colorAmnt = colors.len; pub var rules: [colorAmnt][colorAmnt]f32 = undefined; diff --git a/src/particle.zig b/src/particle.zig index bf36cfb..7b16182 100644 --- a/src/particle.zig +++ b/src/particle.zig @@ -23,9 +23,28 @@ pub fn updateVelocities(particles: std.MultiArrayList(particle), rules: [cfg.col for (particles.items(.x), particles.items(.y), 0..) |x2, y2, j| { if (i == j) continue; - const rx: f32 = @floatFromInt(x - x2); - const ry: f32 = @floatFromInt(y - y2); - var r = @sqrt(rx * rx + ry * ry); + var check2x = x - cfg.screenWidth; + var check2y = y - cfg.screenWidth; + if (x < cfg.screenWidth / 2) + check2x = x + cfg.screenWidth; + if (y < cfg.screenHeight / 2) + check2y = y + cfg.screenHeight; + + var rx: f32 = @floatFromInt(x - x2); + var ry: f32 = @floatFromInt(y - y2); + const check2rx: f32 = @floatFromInt(check2x - x2); + const check2ry: f32 = @floatFromInt(check2y - y2); + + const r1 = @sqrt(rx * rx + ry * ry); + const r2 = @sqrt(rx * rx + check2ry * check2ry); + const r3 = @sqrt(check2rx * check2rx + check2ry * check2ry); + const r4 = @sqrt(check2rx * check2rx + ry * ry); + + var r = @min(@min(r1, r2), @min(r3, r4)); + + if (@abs(rx) > @abs(check2rx)) rx = check2rx; + if (@abs(ry) > @abs(check2ry)) ry = check2ry; + if (r == 0) { r = 0.0001; } @@ -91,3 +110,5 @@ pub fn createParticle() particle { .yvel = 0, }; } + +//TODO: Create tests |
