From 0a186bbe3017a94361c09c887a11b96c8588996b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Thu, 25 Mar 2021 22:24:49 +0100 Subject: [PATCH] Add project files. --- TestWinFormsDataVis.sln | 31 +++ TestWinFormsDataVis/Form1.Designer.cs | 69 +++++++ TestWinFormsDataVis/Form1.cs | 193 ++++++++++++++++++ TestWinFormsDataVis/Form1.resx | 60 ++++++ TestWinFormsDataVis/Program.cs | 25 +++ TestWinFormsDataVis/StraightLine.cs | 16 ++ .../TestWinFormsDataVis.csproj | 9 + TestWinFormsDataVis/TwoPoints.cs | 26 +++ Testthings/Program.cs | 75 +++++++ Testthings/Testthings.csproj | 8 + 10 files changed, 512 insertions(+) create mode 100644 TestWinFormsDataVis.sln create mode 100644 TestWinFormsDataVis/Form1.Designer.cs create mode 100644 TestWinFormsDataVis/Form1.cs create mode 100644 TestWinFormsDataVis/Form1.resx create mode 100644 TestWinFormsDataVis/Program.cs create mode 100644 TestWinFormsDataVis/StraightLine.cs create mode 100644 TestWinFormsDataVis/TestWinFormsDataVis.csproj create mode 100644 TestWinFormsDataVis/TwoPoints.cs create mode 100644 Testthings/Program.cs create mode 100644 Testthings/Testthings.csproj diff --git a/TestWinFormsDataVis.sln b/TestWinFormsDataVis.sln new file mode 100644 index 0000000..8810ecd --- /dev/null +++ b/TestWinFormsDataVis.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31005.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestWinFormsDataVis", "TestWinFormsDataVis\TestWinFormsDataVis.csproj", "{E863ED95-AF3C-4F67-BF82-3C9A57A38274}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testthings", "Testthings\Testthings.csproj", "{521D3DAA-F6A8-44F1-85CF-7E0AAC405BBB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E863ED95-AF3C-4F67-BF82-3C9A57A38274}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E863ED95-AF3C-4F67-BF82-3C9A57A38274}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E863ED95-AF3C-4F67-BF82-3C9A57A38274}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E863ED95-AF3C-4F67-BF82-3C9A57A38274}.Release|Any CPU.Build.0 = Release|Any CPU + {521D3DAA-F6A8-44F1-85CF-7E0AAC405BBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {521D3DAA-F6A8-44F1-85CF-7E0AAC405BBB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {521D3DAA-F6A8-44F1-85CF-7E0AAC405BBB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {521D3DAA-F6A8-44F1-85CF-7E0AAC405BBB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D06D1593-FCB9-4A09-94CF-1C68304F2495} + EndGlobalSection +EndGlobal diff --git a/TestWinFormsDataVis/Form1.Designer.cs b/TestWinFormsDataVis/Form1.Designer.cs new file mode 100644 index 0000000..8a7ca21 --- /dev/null +++ b/TestWinFormsDataVis/Form1.Designer.cs @@ -0,0 +1,69 @@ + +namespace TestWinFormsDataVis +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.pnlCanvas = new System.Windows.Forms.Panel(); + this.paintTimer = new System.Windows.Forms.Timer(this.components); + this.SuspendLayout(); + // + // pnlCanvas + // + this.pnlCanvas.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192))))); + this.pnlCanvas.Location = new System.Drawing.Point(269, 297); + this.pnlCanvas.Name = "pnlCanvas"; + this.pnlCanvas.Size = new System.Drawing.Size(487, 123); + this.pnlCanvas.TabIndex = 0; + this.pnlCanvas.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlCanvas_Paint); + // + // paintTimer + // + this.paintTimer.Enabled = true; + this.paintTimer.Tick += new System.EventHandler(this.paintTimer_Tick); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.pnlCanvas); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel pnlCanvas; + private System.Windows.Forms.Timer paintTimer; + } +} + diff --git a/TestWinFormsDataVis/Form1.cs b/TestWinFormsDataVis/Form1.cs new file mode 100644 index 0000000..0165529 --- /dev/null +++ b/TestWinFormsDataVis/Form1.cs @@ -0,0 +1,193 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TestWinFormsDataVis +{ + + + public partial class Form1 : Form + { + + Pen myPen = new Pen(Color.Black); + Graphics g = null; + + List koordCross = new(); + List CurveSin = new(); + List CurveCos = new(); + public bool CrossDrawn { get; set; } = false; + + static int _yMid = 0; + static int _yxPos = 3; + static int _yTop = 0; + static int _yStep = 0; + static long _yScaleStep = 0; + static int _yBottom = 0; + static int _xRight = 0; + static int countNum = 0; + static double _timeX = 0; + static int _timeXPosOld = 0; + static int _timeXPos = 0; + static int _timeYSin = 0; + static int _timeYCos = 0; + + + public Form1() + { + InitializeComponent(); + _yMid = pnlCanvas.Height / 2; + _yTop = pnlCanvas.Height; + _yBottom = 0; + _xRight = pnlCanvas.Width; + createKoordCross(koordCross, 3000, -3000); + pnlCanvas.Refresh(); + _timeYCos = _yMid; + _timeYSin = _yMid; + } + + private static void createKoordCross(List koordCross, decimal maxVal, decimal minVal) + { + // Y-axel + koordCross.Add(new StraightLine { start_x = _yxPos, start_y = _yTop, end_x = _yxPos, end_y = _yBottom }); + // X-axel + koordCross.Add(new StraightLine { start_x = _yxPos - 2, start_y = _yMid, end_x = _xRight, end_y = _yMid }); + + + _yScaleStep = scaleStep(maxVal, 8); + _yStep = (int)_yScaleStep * _yMid / (int)maxVal; + var _yVal = _yMid; + while (_yVal < _yTop) + { + koordCross.Add(new StraightLine { start_x = _yxPos - 2, start_y = _yVal, end_x = _yxPos + 2, end_y = _yVal }); + _yVal += _yStep; + } + + _yVal = _yMid; + while (_yVal > 0) + { + koordCross.Add(new StraightLine { start_x = _yxPos - 2, start_y = _yVal, end_x = _yxPos + 2, end_y = _yVal }); + _yVal -= _yStep; + } + + } + + private static long scaleStep(decimal maxValue, int maxSteps) + { + long stepValue = nextValue(true); + long tmpValue = stepValue; + int _maxSteps = (int)((int)maxValue / stepValue); + while (_maxSteps > maxSteps) + { + stepValue = tmpValue * nextValue(); + _maxSteps = (int)((int)maxValue / stepValue); + tmpValue = stepValue == tmpValue * 10 ? stepValue : tmpValue; + } + return stepValue; + } + + private static int nextValue(bool first = false) + { + if (first) + { + countNum = 1; + } + else + { + switch (countNum) + { + case 1: + { + countNum = 2; + break; + } + case 2: + { + countNum = 5; + break; + } + case 5: + { + countNum = 10; + break; + } + case 10: + { + countNum = 2; + break; + } + } + } + return countNum; + } + + + + private void drawKoordCrossLines() + { + foreach (var x in koordCross) + { + Point[] points = + { + new Point(x.start_x,x.start_y), + new Point(x.end_x,x.end_y) + }; + g.DrawLines(myPen, points); + } + CrossDrawn = true; + } + + private void drawCurves() + { + var _prevYSin = _timeYSin; + var _prevYCos = _timeYCos; + + _timeX = _timeX + .017453292519; + _timeYSin = _yMid + (int)(Math.Sin(_timeX) * -1 * _yMid); + CurveSin.Add(new TwoPoints { X1 = _timeXPosOld, Y1 = _prevYSin, X2 = _timeXPos, Y2 = _timeYSin }); + + foreach (var tp in CurveSin) + { + g.DrawLines(myPen, tp.drwPoints()); + } + //Debug.WriteLine($"p1 (x1,y1,x2,y2) -> {points[0].X},{points[0].Y},{points[1].X},{points[1].Y} "); + + _timeYCos = _yMid + (int)(Math.Cos(_timeX) * _yMid); + CurveSin.Add(new TwoPoints { X1 = _timeXPosOld, Y1 = _prevYCos, X2 = _timeXPos, Y2 = _timeYCos }); + + foreach (var tp in CurveCos) + { + g.DrawLines(myPen, tp.drwPoints()); + } + //Debug.WriteLine($"p2 (x1,y1,x2,y2) -> {xpoints[0].X},{xpoints[0].Y},{xpoints[1].X},{xpoints[1].Y} "); + _timeXPosOld = _timeXPos; + } + + + private void pnlCanvas_Paint(object sender, PaintEventArgs e) + { + if (!CrossDrawn) + { + myPen.Width = 1; + g = pnlCanvas.CreateGraphics(); + drawKoordCrossLines(); + } + + //drawCurves(); + + } + + private void paintTimer_Tick(object sender, EventArgs e) + { + _timeXPos += 1; + drawCurves(); + //pnlCanvas.Refresh(); + } + } +} diff --git a/TestWinFormsDataVis/Form1.resx b/TestWinFormsDataVis/Form1.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/TestWinFormsDataVis/Form1.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestWinFormsDataVis/Program.cs b/TestWinFormsDataVis/Program.cs new file mode 100644 index 0000000..e5234bd --- /dev/null +++ b/TestWinFormsDataVis/Program.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TestWinFormsDataVis +{ + static class Program + { + + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/TestWinFormsDataVis/StraightLine.cs b/TestWinFormsDataVis/StraightLine.cs new file mode 100644 index 0000000..7fc533a --- /dev/null +++ b/TestWinFormsDataVis/StraightLine.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TestWinFormsDataVis +{ + public class StraightLine + { + public int start_x { get; set; } + public int start_y { get; set; } + public int end_x { get; set; } + public int end_y { get; set; } + } +} diff --git a/TestWinFormsDataVis/TestWinFormsDataVis.csproj b/TestWinFormsDataVis/TestWinFormsDataVis.csproj new file mode 100644 index 0000000..4ea815e --- /dev/null +++ b/TestWinFormsDataVis/TestWinFormsDataVis.csproj @@ -0,0 +1,9 @@ + + + + WinExe + net5.0-windows + true + + + diff --git a/TestWinFormsDataVis/TwoPoints.cs b/TestWinFormsDataVis/TwoPoints.cs new file mode 100644 index 0000000..65c515c --- /dev/null +++ b/TestWinFormsDataVis/TwoPoints.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TestWinFormsDataVis +{ + public class TwoPoints + { + public int X1 { get; set; } + public int Y1 { get; set; } + public int X2 { get; set; } + public int Y2 { get; set; } + + public Point[] drwPoints(int posShift = 0) + { + return new Point[] { + new Point(X1+posShift,Y1), + new Point(X2+posShift,Y2) + }; + } + + } +} diff --git a/Testthings/Program.cs b/Testthings/Program.cs new file mode 100644 index 0000000..0c4b8f9 --- /dev/null +++ b/Testthings/Program.cs @@ -0,0 +1,75 @@ +using System; +using System.Diagnostics; + +namespace Testthings +{ + class Program + { + + static int countNum = 0; + + static void Main(string[] args) + { + var x = 0.0001; + for (int i = 0; i < 360; i++) + { + x = x + .017453292519; + var y = Math.Sin(x) * 250; + Debug.WriteLine($"pos [{i}] x={x}, y={y}"); + } + + //Console.WriteLine($"testar scaling {445} -> {scaleStep(445, 8)}"); + } + + + + private static long scaleStep(decimal maxValue, int maxSteps) + { + long stepValue = nextValue(true); + long tmpValue = stepValue; + int _maxSteps = (int)((int) maxValue/stepValue); + while (_maxSteps > maxSteps) + { + stepValue = tmpValue * nextValue(); + _maxSteps = (int)((int)maxValue / stepValue); + tmpValue = stepValue == tmpValue * 10 ? stepValue : tmpValue; + } + return stepValue; + } + + private static int nextValue(bool first=false) + { + if (first) + { + countNum = 1; + } + else + { + switch (countNum) + { + case 1: + { + countNum = 2; + break; + } + case 2: + { + countNum = 5; + break; + } + case 5: + { + countNum = 10; + break; + } + case 10: + { + countNum = 2; + break; + } + } + } + return countNum; + } + } +} diff --git a/Testthings/Testthings.csproj b/Testthings/Testthings.csproj new file mode 100644 index 0000000..2082704 --- /dev/null +++ b/Testthings/Testthings.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + +