mirror of
https://github.com/eliasstepanik/FluidSimulation.git
synced 2026-01-11 21:48:28 +00:00
Added Holes to the mix
This commit is contained in:
parent
2a742b170b
commit
0b7fa3e99f
20
PixelEngine/BlackHole.cs
Normal file
20
PixelEngine/BlackHole.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
@ -112,11 +112,11 @@ public class Fluid
|
|||||||
this.density[index] += amount;
|
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);
|
int index = IX(x + i, y + j);
|
||||||
|
|
||||||
|
|||||||
15
PixelEngine/Hole.cs
Normal file
15
PixelEngine/Hole.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
@ -15,6 +15,8 @@ var N = 64;
|
|||||||
var Scale = 10;
|
var Scale = 10;
|
||||||
var Iter = 10;
|
var Iter = 10;
|
||||||
float t = 0;
|
float t = 0;
|
||||||
|
int whiteholes = 4;
|
||||||
|
int blackholes = 1;
|
||||||
|
|
||||||
Fluid fluid;
|
Fluid fluid;
|
||||||
|
|
||||||
@ -23,10 +25,32 @@ InitWindow(N * Scale, N * Scale, "Raylib_CsLo");
|
|||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
Random rd = new Random();
|
Random rd = new Random();
|
||||||
|
|
||||||
|
|
||||||
var pMouseX = GetMouseX();
|
var pMouseX = GetMouseX();
|
||||||
var pMouseY = GetMouseY();
|
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())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
@ -58,7 +82,7 @@ while (!WindowShouldClose())
|
|||||||
fluid.addDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100);
|
fluid.addDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100);
|
||||||
else if (IsMouseButtonDown(MouseButton.MOUSE_BUTTON_RIGHT))
|
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
|
//TODO: Suction for Density Reduction
|
||||||
@ -70,8 +94,22 @@ while (!WindowShouldClose())
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
fluid.addDensity(N - 3, 3, 200);
|
|
||||||
fluid.addVelocity(N - 3 , 3, -10f, -10f);
|
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);*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*if (GetMouseX() != pMouseX || GetMouseY() != pMouseY)
|
/*if (GetMouseX() != pMouseX || GetMouseY() != pMouseY)
|
||||||
|
|||||||
23
PixelEngine/WhiteHole.cs
Normal file
23
PixelEngine/WhiteHole.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user