From c7ae204dc1fbefcf10e25bf2dda8f215f3a6ce65 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Wed, 27 Apr 2022 15:24:43 +0300 Subject: [PATCH 1/5] Clock is drawn --- Clock/Clock/Clock.sln | 25 +++++++++ Clock/Clock/Clock/Clock.csproj | 11 ++++ Clock/Clock/Clock/Form1.Designer.cs | 72 +++++++++++++++++++++++++ Clock/Clock/Clock/Form1.cs | 65 +++++++++++++++++++++++ Clock/Clock/Clock/Form1.resx | 82 +++++++++++++++++++++++++++++ Clock/Clock/Clock/Program.cs | 17 ++++++ 6 files changed, 272 insertions(+) create mode 100644 Clock/Clock/Clock.sln create mode 100644 Clock/Clock/Clock/Clock.csproj create mode 100644 Clock/Clock/Clock/Form1.Designer.cs create mode 100644 Clock/Clock/Clock/Form1.cs create mode 100644 Clock/Clock/Clock/Form1.resx create mode 100644 Clock/Clock/Clock/Program.cs diff --git a/Clock/Clock/Clock.sln b/Clock/Clock/Clock.sln new file mode 100644 index 0000000..472f1f9 --- /dev/null +++ b/Clock/Clock/Clock.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32414.318 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clock", "Clock\Clock.csproj", "{F80D3B91-059D-4932-B6F9-68EDC93303DE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F80D3B91-059D-4932-B6F9-68EDC93303DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F80D3B91-059D-4932-B6F9-68EDC93303DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F80D3B91-059D-4932-B6F9-68EDC93303DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F80D3B91-059D-4932-B6F9-68EDC93303DE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B5180CCA-4140-42E2-9B3E-012D1D8F3759} + EndGlobalSection +EndGlobal diff --git a/Clock/Clock/Clock/Clock.csproj b/Clock/Clock/Clock/Clock.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/Clock/Clock/Clock/Clock.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/Clock/Clock/Clock/Form1.Designer.cs b/Clock/Clock/Clock/Form1.Designer.cs new file mode 100644 index 0000000..f26bb39 --- /dev/null +++ b/Clock/Clock/Clock/Form1.Designer.cs @@ -0,0 +1,72 @@ +namespace Clock +{ + 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(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); + this.pictureBox1.Location = new System.Drawing.Point(0, 0); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(800, 450); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.PictureBoxPaint); + // + // timer1 + // + this.timer1.Enabled = true; + this.timer1.Tick += new System.EventHandler(this.TimerTick); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.pictureBox1); + this.Name = "Form1"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + private PictureBox pictureBox1; + private System.Windows.Forms.Timer timer1; + } +} \ No newline at end of file diff --git a/Clock/Clock/Clock/Form1.cs b/Clock/Clock/Clock/Form1.cs new file mode 100644 index 0000000..406c4bb --- /dev/null +++ b/Clock/Clock/Clock/Form1.cs @@ -0,0 +1,65 @@ +namespace Clock; +using System.Drawing.Drawing2D; + +public partial class Form1 : Form +{ + public Form1() + { + InitializeComponent(); + } + + private void DrawClock(Graphics graph) + { + PointF clockCenter = new PointF(pictureBox1.Width / 2, pictureBox1.Height / 2); + var radius = Math.Min(pictureBox1.Width, pictureBox1.Height) * 4/5 * 1/2; + graph.DrawEllipse(new(Brushes.Black, 5), pictureBox1.Width / 2 - radius, pictureBox1.Height / 2 - radius, radius * 2, radius * 2); + int fontSize = (int)Math.Floor((decimal)radius / 9); + Matrix matrix = new(); + + for (int i = 60; i > 0; i--) + { + if (i % 5 == 0) + { + graph.DrawString($"{i / 5}", new Font("Arial", fontSize), Brushes.Black, clockCenter.X - fontSize, clockCenter.Y - radius); + graph.DrawLine(new(Brushes.Black, 5), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius * 1.94 / 2), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius)); + } + else + { + graph.DrawLine(new(Brushes.Black, 2), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius * 1.94 / 2), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius)); + + } + + matrix.RotateAt(-6.0F, clockCenter); + graph.Transform = matrix; + } + } + + + private void DrawHand(Graphics graph, Color color, float angleRelativeStartingPoint, float length, float width) + { + PointF clockCenter = new(pictureBox1.Width / 2, pictureBox1.Height / 2); + var radius = Math.Min(pictureBox1.Width, pictureBox1.Height) * 4 / 5 * 1 / 2; + Matrix matrix = new(); + matrix.RotateAt(angleRelativeStartingPoint, clockCenter); + graph.Transform = matrix; + graph.DrawLine(new(color, radius * width), clockCenter, new(clockCenter.X, radius * (1 - length))); + } + + private void DrawAllHands(Graphics e) + { + DrawHand(e, Color.Red, DateTime.Now.Second * 6F, 0.6F, 0.01F); + DrawHand(e, Color.Black, (DateTime.Now.Minute + DateTime.Now.Second / 60f) * 6F, 0.3F, 0.012F); + DrawHand(e, Color.Black, (DateTime.Now.Hour + DateTime.Now.Minute / 60f + DateTime.Now.Second / 3600f) * 30F, 0.2F, 0.015F); + } + + private void PictureBoxPaint(object sender, PaintEventArgs e) + { + DrawClock(e.Graphics); + DrawAllHands(e.Graphics); + } + + private void TimerTick(object sender, EventArgs e) + { + pictureBox1.Invalidate(); + } +} \ No newline at end of file diff --git a/Clock/Clock/Clock/Form1.resx b/Clock/Clock/Clock/Form1.resx new file mode 100644 index 0000000..c576ffc --- /dev/null +++ b/Clock/Clock/Clock/Form1.resx @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + iVBORw0KGgoAAAANSUhE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+ AAAAftQA18UAAbbfLIIAAAAASUVORK5CYII= + + + + 17, 17 + + \ No newline at end of file diff --git a/Clock/Clock/Clock/Program.cs b/Clock/Clock/Clock/Program.cs new file mode 100644 index 0000000..dfde0b7 --- /dev/null +++ b/Clock/Clock/Clock/Program.cs @@ -0,0 +1,17 @@ +namespace Clock +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file From 5288e911b16f34798ae3da40b096f4e76a9b78c8 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Wed, 27 Apr 2022 15:48:06 +0300 Subject: [PATCH 2/5] add comments --- Clock/Clock/Clock/Form1.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Clock/Clock/Clock/Form1.cs b/Clock/Clock/Clock/Form1.cs index 406c4bb..53814a8 100644 --- a/Clock/Clock/Clock/Form1.cs +++ b/Clock/Clock/Clock/Form1.cs @@ -10,14 +10,22 @@ public Form1() private void DrawClock(Graphics graph) { - PointF clockCenter = new PointF(pictureBox1.Width / 2, pictureBox1.Height / 2); + // The center of the clock will be in the center of the shape + PointF clockCenter = new(pictureBox1.Width / 2, pictureBox1.Height / 2); + + // Multiply by 4/5 so that the clock does not go beyond the form, but at the same time occupies most of the form var radius = Math.Min(pictureBox1.Width, pictureBox1.Height) * 4/5 * 1/2; + + // Draw clock graph.DrawEllipse(new(Brushes.Black, 5), pictureBox1.Width / 2 - radius, pictureBox1.Height / 2 - radius, radius * 2, radius * 2); + + // If the counter is divided by 5, then draw a thick hour mark and a number int fontSize = (int)Math.Floor((decimal)radius / 9); Matrix matrix = new(); for (int i = 60; i > 0; i--) { + // if the counter is divided by 5, then draw a thick hour mark and a number if (i % 5 == 0) { graph.DrawString($"{i / 5}", new Font("Arial", fontSize), Brushes.Black, clockCenter.X - fontSize, clockCenter.Y - radius); @@ -25,10 +33,12 @@ private void DrawClock(Graphics graph) } else { + // Draw a minute mark graph.DrawLine(new(Brushes.Black, 2), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius * 1.94 / 2), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius)); } + // We change the angle by -6 (that is, we reduce the minute) matrix.RotateAt(-6.0F, clockCenter); graph.Transform = matrix; } @@ -47,8 +57,13 @@ private void DrawHand(Graphics graph, Color color, float angleRelativeStartingPo private void DrawAllHands(Graphics e) { + // draw the second hand DrawHand(e, Color.Red, DateTime.Now.Second * 6F, 0.6F, 0.01F); + + // draw the minute hand DrawHand(e, Color.Black, (DateTime.Now.Minute + DateTime.Now.Second / 60f) * 6F, 0.3F, 0.012F); + + // draw the hour hand DrawHand(e, Color.Black, (DateTime.Now.Hour + DateTime.Now.Minute / 60f + DateTime.Now.Second / 3600f) * 30F, 0.2F, 0.015F); } From 9cb09c28a442754f130a733f4df79810e6b4e44a Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 24 May 2022 22:50:20 +0300 Subject: [PATCH 3/5] formatted --- Clock/Clock/Clock/Form1.Designer.cs | 126 ++++++++++++++-------------- Clock/Clock/Clock/Program.cs | 25 +++--- 2 files changed, 74 insertions(+), 77 deletions(-) diff --git a/Clock/Clock/Clock/Form1.Designer.cs b/Clock/Clock/Clock/Form1.Designer.cs index f26bb39..06dd574 100644 --- a/Clock/Clock/Clock/Form1.Designer.cs +++ b/Clock/Clock/Clock/Form1.Designer.cs @@ -1,72 +1,70 @@ -namespace Clock +namespace Clock; + +partial class Form1 { - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + /// + /// 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) + /// + /// 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)) { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); + 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(); - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.timer1 = new System.Windows.Forms.Timer(this.components); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - this.SuspendLayout(); - // - // pictureBox1 - // - this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); - this.pictureBox1.Location = new System.Drawing.Point(0, 0); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(800, 450); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox1.TabIndex = 0; - this.pictureBox1.TabStop = false; - this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.PictureBoxPaint); - // - // timer1 - // - this.timer1.Enabled = true; - this.timer1.Tick += new System.EventHandler(this.TimerTick); - // - // Form1 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.pictureBox1); - this.Name = "Form1"; - this.Text = "Form1"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - this.ResumeLayout(false); - - } + #region Windows Form Designer generated code - #endregion - private PictureBox pictureBox1; - private System.Windows.Forms.Timer timer1; + /// + /// 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(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); + this.pictureBox1.Location = new System.Drawing.Point(0, 0); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(800, 450); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.PictureBoxPaint); + // + // timer1 + // + this.timer1.Enabled = true; + this.timer1.Tick += new System.EventHandler(this.TimerTick); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.pictureBox1); + this.Name = "Form1"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); } + + #endregion + private PictureBox pictureBox1; + private System.Windows.Forms.Timer timer1; } \ No newline at end of file diff --git a/Clock/Clock/Clock/Program.cs b/Clock/Clock/Clock/Program.cs index dfde0b7..cfde7b6 100644 --- a/Clock/Clock/Clock/Program.cs +++ b/Clock/Clock/Clock/Program.cs @@ -1,17 +1,16 @@ -namespace Clock +namespace Clock; + +internal static class Program { - internal static class Program + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); - } + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); } } \ No newline at end of file From 767431f524e771a4c202d5ae18ab9633d5c1309d Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 1 Jun 2022 23:57:55 +0300 Subject: [PATCH 4/5] rename yml --- .github/workflows/{dotnet.yml => Clock.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{dotnet.yml => Clock.yml} (100%) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/Clock.yml similarity index 100% rename from .github/workflows/dotnet.yml rename to .github/workflows/Clock.yml From 6e2c2b71db564bb0594828d6f45d4e8b85ae02a9 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 2 Jun 2022 01:24:21 +0300 Subject: [PATCH 5/5] rename yml --- .github/workflows/{Clock.yml => dotnet.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{Clock.yml => dotnet.yml} (100%) diff --git a/.github/workflows/Clock.yml b/.github/workflows/dotnet.yml similarity index 100% rename from .github/workflows/Clock.yml rename to .github/workflows/dotnet.yml