diff --git a/PixelEngine/BlackHole.cs b/PixelEngine/BlackHole.cs new file mode 100644 index 0000000..d32d096 --- /dev/null +++ b/PixelEngine/BlackHole.cs @@ -0,0 +1,20 @@ +using System.Numerics; + +namespace PixelEngine; + +public class BlackHole : Hole +{ + public BlackHole(Vector2 position, int radius, float mass) : base(position, mass) + { + this.radius = radius; + } + + public override void Spawn(Fluid fluid) + { + fluid.reduceDensity((int)position.X, (int)position.Y, mass, radius); + } + + public override Vector2 position { get; set; } + public int radius { get; set; } + public override float mass { get; set; } +} \ No newline at end of file diff --git a/PixelEngine/Fluid.cs b/PixelEngine/Fluid.cs index 91e3a62..b8adff8 100644 --- a/PixelEngine/Fluid.cs +++ b/PixelEngine/Fluid.cs @@ -112,11 +112,11 @@ public class Fluid this.density[index] += amount; } - public void reduceDensity(int x, int y, float amount) { + public void reduceDensity(int x, int y, float amount, int rSize) { - for (int i = -10; i < 10; i++) + for (int i = -rSize; i < rSize; i++) { - for (int j = -10; j < 10; j++) + for (int j = -rSize; j < rSize; j++) { int index = IX(x + i, y + j); diff --git a/PixelEngine/Hole.cs b/PixelEngine/Hole.cs new file mode 100644 index 0000000..bb6cf6b --- /dev/null +++ b/PixelEngine/Hole.cs @@ -0,0 +1,15 @@ +using System.Numerics; + +namespace PixelEngine; + +public abstract class Hole +{ + public Hole(Vector2 position, float mass) + { + this.position = position; + this.mass = mass; + } + public abstract void Spawn(Fluid fluid); + public abstract Vector2 position { get; set; } + public abstract float mass { get; set; } +} \ No newline at end of file diff --git a/PixelEngine/Program.cs b/PixelEngine/Program.cs index 8a9ee31..48e034e 100644 --- a/PixelEngine/Program.cs +++ b/PixelEngine/Program.cs @@ -15,6 +15,8 @@ var N = 64; var Scale = 10; var Iter = 10; float t = 0; +int whiteholes = 4; +int blackholes = 1; Fluid fluid; @@ -23,10 +25,32 @@ InitWindow(N * Scale, N * Scale, "Raylib_CsLo"); SetTargetFPS(60); Random rd = new Random(); - var pMouseX = GetMouseX(); var pMouseY = GetMouseY(); +var whiteholesA = new WhiteHole[whiteholes]; +var blackholesA = new BlackHole[blackholes]; + +for (int i = 0; i < whiteholes; i++) +{ + whiteholesA[i] = new WhiteHole( + new Vector2(rd.Next(3, N - 3), rd.Next(3, N - 3)), + new Vector2(rd.Next(50, 100), rd.Next(50, 100)), + rd.Next(0, 100), + rd.Next(0, 100) + ); +} + +for (int i = 0; i < blackholes; i++) +{ + blackholesA[i] = new BlackHole( + new Vector2(rd.Next(3, N - 3), rd.Next(3, N - 3)), + rd.Next(0, 3), + rd.Next(0,200) + ); +} + + while (!WindowShouldClose()) { @@ -58,7 +82,7 @@ while (!WindowShouldClose()) fluid.addDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100); else if (IsMouseButtonDown(MouseButton.MOUSE_BUTTON_RIGHT)) { - fluid.reduceDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100); + fluid.reduceDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100, 5); //TODO: Suction for Density Reduction @@ -67,11 +91,25 @@ while (!WindowShouldClose()) fluid.addVelocity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, amtX, amtY);*/ } + + + + + foreach (var hole in blackholesA) + { + hole.Spawn(fluid); + } + + foreach (var hole in whiteholesA) + { + hole.Spawn(fluid); + } + /*fluid.addDensity(N - 3 , 3, 100); + fluid.addVelocity(N - 3 , 3, -10f, 0);*/ + - fluid.addDensity(N - 3, 3, 200); - fluid.addVelocity(N - 3 , 3, -10f, -10f); /*if (GetMouseX() != pMouseX || GetMouseY() != pMouseY) diff --git a/PixelEngine/WhiteHole.cs b/PixelEngine/WhiteHole.cs new file mode 100644 index 0000000..84089a2 --- /dev/null +++ b/PixelEngine/WhiteHole.cs @@ -0,0 +1,23 @@ +using System.Numerics; + +namespace PixelEngine; + +public class WhiteHole : Hole +{ + public override void Spawn(Fluid fluid) + { + fluid.addDensity((int) position.X, (int) position.Y, mass); + fluid.addVelocity((int) position.X, (int) position.Y, direction.X * speed, direction.Y * speed); + } + + public override Vector2 position { get; set; } + public Vector2 direction { get; set; } + public override float mass { get; set; } + public float speed { get; set; } + + public WhiteHole(Vector2 position, Vector2 direction, float mass, float speed) : base(position, mass) + { + this.direction = direction; + this.speed = speed; + } +} \ No newline at end of file