Images are now saved and you can have randomized values at the generation and a name can be chooen for the simulation

This commit is contained in:
2022-05-05 11:36:37 +02:00
parent beb4658c95
commit c8b38b5d6b
6 changed files with 331 additions and 184 deletions
@@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace PropagationRemasteredBeta
{
@@ -26,8 +27,11 @@ namespace PropagationRemasteredBeta
public int deathRate;
public int infectionRate;
public int cureTime;
public bool needToSave;
public string savesLocation;
public string simulationName;
public SimulationVue(Size terrainSize, int infectedProportion, int resistantProportion, int deathRate, int infectionRate, int cureTime)
public SimulationVue(Size terrainSize, int infectedProportion, int resistantProportion, int deathRate, int infectionRate, int cureTime, bool needToSave, string savesLocation, string simulationName)
{
InitializeComponent();
this.terrainSize = terrainSize;
@@ -36,9 +40,12 @@ namespace PropagationRemasteredBeta
this.deathRate = deathRate;
this.infectionRate = infectionRate;
this.cureTime = cureTime;
this.needToSave = needToSave;
this.savesLocation = savesLocation;
this.simulationName = simulationName;
frameCount = 0;
BufferImage = new Bitmap(terrainSize.Width,terrainSize.Height);
BufferImage = new Bitmap(terrainSize.Width, terrainSize.Height);
stopwatch = new Stopwatch();
totalTime = 0;
}
@@ -66,7 +73,7 @@ namespace PropagationRemasteredBeta
btnStartNormal.Text = "Stop";
btnStartOneForAll.Text = "Stop";
tmrTick.Start();
t = new Terrain(terrainSize,infectedProportion,resistantProportion,deathRate,infectionRate,cureTime);
t = new Terrain(terrainSize, infectedProportion, resistantProportion, deathRate, infectionRate, cureTime);
frameCount = 0;
switch (mode)
@@ -78,24 +85,12 @@ namespace PropagationRemasteredBeta
t.GenerateOneForAll();
break;
}
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
if (started)
{
/*
BufferImage = t.Display();
pbxTerrain.Image = BufferImage;
stopwatch.Stop();
totalTime = stopwatch.ElapsedMilliseconds;
frameCount++;
lblFrameCount.Text = frameCount.ToString();
lblTotalTime.Text = totalTime.ToString();
*/
}
}
private void tmrTick_Tick(object sender, EventArgs e)
@@ -128,7 +123,10 @@ namespace PropagationRemasteredBeta
BufferImage = t.Display();
tmrTick.Start();
if (needToSave)
{
Save(BufferImage, frameCount);
}
pbxTerrain.Image = BufferImage;
stopwatch.Stop();
totalTime = stopwatch.ElapsedMilliseconds;
@@ -145,7 +143,20 @@ namespace PropagationRemasteredBeta
//lblSain.Text = t.SainCount[t.SainCount.Count() - 1].ToString();
//lblDeaths.Text = t.DeadCount[t.DeadCount.Count() - 1].ToString();
}
private void Save(Bitmap imageToSave, int frameNumber)
{
string path = "./" + savesLocation + "/" + simulationName + "/";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//only save if the directory has been created successfully
imageToSave.Save(path + simulationName + "_" + frameNumber + ".png", System.Drawing.Imaging.ImageFormat.Png);
}
/// <summary>
/// Code found on Stack Overflow, dont quote me on it
/// </summary>
/// <returns></returns>
private double GetMemoryUsage()
{
var memory = 0.0;
@@ -173,5 +184,10 @@ namespace PropagationRemasteredBeta
{
this.Close();
}
private void SimulationVue_Load(object sender, EventArgs e)
{
lblSimulationName.Text = simulationName;
}
}
}