From f20a8236ef1d5528dbdd75d8af27ee43fcbac730 Mon Sep 17 00:00:00 2001 From: yassirfariz Date: Thu, 20 Jun 2024 11:35:22 +0100 Subject: [PATCH] v1.11 graphs and dataCollection --- Program.cs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Program.cs b/Program.cs index d12f300..956da64 100644 --- a/Program.cs +++ b/Program.cs @@ -197,12 +197,14 @@ class Graph{ Particle p; List val_vels; List val_accs; - - + int index; + List cache; public Graph(Particle particle){ p = particle; val_accs = []; val_vels = []; + cache = []; + index = 0; } private void Arrow(Vector2 posA,Vector2 posB,Color pcolor){ float angle = MathF.Atan2(posB.Y-posA.Y,posB.X-posA.X); @@ -219,8 +221,12 @@ public void Draw_UI(bool active){ Arrow(new Vector2(25,Raylib.GetScreenHeight()-15),new Vector2(425,Raylib.GetScreenHeight()-15),Color.White); Arrow(new Vector2(25,Raylib.GetScreenHeight()-15),new Vector2(25,Raylib.GetScreenHeight()-175),Color.White); if (active) { - val_vels.Add(p.vel.Length()); - val_accs.Add(p.acc.Length()); + float vl = p.vel.Length(); + float ac = p.acc.Length(); + val_vels.Add(vl); + val_accs.Add(ac); + cache.Add($"{index}:{vl},{ac}"); + index++; } if (active && val_vels.Count > 415) { val_vels.Remove(val_vels.First()); @@ -230,7 +236,7 @@ public void Draw_UI(bool active){ } if (val_accs.Count>1 || val_vels.Count>1){ if (p.vec_mode == "velocity"){ - float factor = val_vels.Max(); + float factor = val_vels.Max()+0.25f; for (int i=1;i< val_vels.Count; i++){ Raylib.DrawLineEx( new Vector2(25+i-1.15f,Raylib.GetScreenHeight()-15-150/factor*val_vels[i-1]), @@ -238,7 +244,7 @@ public void Draw_UI(bool active){ } } else{ - float factor = val_accs.Max(); + float factor = val_accs.Max()+0.25f; for (int i=1;i< val_accs.Count; i++){ Raylib.DrawLineEx( new Vector2(25+i-1.15f,Raylib.GetScreenHeight()-15-150/factor*val_accs[i-1]), @@ -248,9 +254,8 @@ public void Draw_UI(bool active){ } } - public void ExportData(string file){ - - + public void ExportData(string fileOutput){ + File.AppendAllLines(fileOutput,cache); } } partial class HelpMenu{ @@ -359,6 +364,12 @@ public static void Main() if (Raylib.IsKeyPressed(KeyboardKey.F11)){ Raylib.TakeScreenshot("./img.png"); } + if (Raylib.IsKeyPressed(KeyboardKey.S)){ + active = false; + gp.ExportData("proton.txt"); + ge1.ExportData("electron1.txt"); + ge2.ExportData("electron2.txt"); + } Raylib.BeginDrawing(); Raylib.ClearBackground(Color.Black); Raylib.SetMouseCursor(MouseCursor.Crosshair);