diff --git a/.idea/.idea.Game_of_Life/.idea/.gitignore b/.idea/.idea.Game_of_Life/.idea/.gitignore new file mode 100644 index 0000000..a852fa9 --- /dev/null +++ b/.idea/.idea.Game_of_Life/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/projectSettingsUpdater.xml +/.idea.Game_of_Life.iml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.Game_of_Life/.idea/encodings.xml b/.idea/.idea.Game_of_Life/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.Game_of_Life/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.Game_of_Life/.idea/indexLayout.xml b/.idea/.idea.Game_of_Life/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.Game_of_Life/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Game_of_Life.sln b/Game_of_Life.sln new file mode 100644 index 0000000..5dee386 --- /dev/null +++ b/Game_of_Life.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game_of_Life", "Game_of_Life\Game_of_Life.csproj", "{AA4A9F5C-2787-4709-8889-0FC3479F490E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AA4A9F5C-2787-4709-8889-0FC3479F490E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA4A9F5C-2787-4709-8889-0FC3479F490E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA4A9F5C-2787-4709-8889-0FC3479F490E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA4A9F5C-2787-4709-8889-0FC3479F490E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Game_of_Life/Game_of_Life.csproj b/Game_of_Life/Game_of_Life.csproj new file mode 100644 index 0000000..638e474 --- /dev/null +++ b/Game_of_Life/Game_of_Life.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net7.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/Game_of_Life/MainForm1.Designer.cs b/Game_of_Life/MainForm1.Designer.cs new file mode 100644 index 0000000..f42c19b --- /dev/null +++ b/Game_of_Life/MainForm1.Designer.cs @@ -0,0 +1,61 @@ +namespace Game_of_Life; + +partial class MainForm1 +{ + /// + /// 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.pictureBox1 = new PictureBoxWithInterpolationMode(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Location = new System.Drawing.Point(0, 0); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(800, 450); + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // MainForm1 + // + 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.pictureBox1); + this.Name = "MainForm1"; + this.Text = "MainForm1"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private PictureBoxWithInterpolationMode pictureBox1; +} \ No newline at end of file diff --git a/Game_of_Life/MainForm1.cs b/Game_of_Life/MainForm1.cs new file mode 100644 index 0000000..ab8147a --- /dev/null +++ b/Game_of_Life/MainForm1.cs @@ -0,0 +1,48 @@ +using System.Drawing.Drawing2D; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; + +namespace Game_of_Life; + +public partial class MainForm1 : Form +{ + public MainForm1() + { + Pixelmap pixelmap; + int scalingFactor = 10; + + InitializeComponent(); + + int height = pictureBox1.Size.Height; + int width = pictureBox1.Size.Width; + + Graphics graphics = pictureBox1.CreateGraphics(); + + + pixelmap = new Pixelmap(height, width, scalingFactor); + Random rand = new Random(); + + for (int i = 0; i < 20; i++) + { + pixelmap.setPixel(rand.Next(width), rand.Next(height), rand.Next(3)); + } + + pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; + pictureBox1.InterpolationMode = InterpolationMode.NearestNeighbor; + pixelmap.paintOnGraphics(graphics); + + /* this.Shown += (s, e) => + { + while (true) + { + for (int i = 0; i < 20; i++) + { + pixelmap.setPixel(rand.Next(50), rand.Next(20), rand.Next(3)); + } + + pictureBox1.Image = pixelmap.ToBitmap(); + Thread.Sleep(120); + } + };*/ + } +} \ No newline at end of file diff --git a/Game_of_Life/MainForm1.resx b/Game_of_Life/MainForm1.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Game_of_Life/MainForm1.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/Game_of_Life/PictureBoxWithInterpolationMode.cs b/Game_of_Life/PictureBoxWithInterpolationMode.cs new file mode 100644 index 0000000..339d507 --- /dev/null +++ b/Game_of_Life/PictureBoxWithInterpolationMode.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Game_of_Life +{ + internal class PictureBoxWithInterpolationMode : PictureBox + { + public InterpolationMode InterpolationMode { get; set; } + + protected override void OnPaint(PaintEventArgs paintEventArgs) + { + paintEventArgs.Graphics.InterpolationMode = InterpolationMode; + base.OnPaint(paintEventArgs); + } + } +} diff --git a/Game_of_Life/Pixelmap.cs b/Game_of_Life/Pixelmap.cs new file mode 100644 index 0000000..ea23588 --- /dev/null +++ b/Game_of_Life/Pixelmap.cs @@ -0,0 +1,70 @@ +namespace Game_of_Life; + +public class Pixelmap +{ + private int height; + private int width; + private Color[,] map; + private int scalingFactor; + + public Pixelmap(int height, int width, int scalingFactor) + { + this.height = height; + this.width = width; + map = new Color[width, height]; + for (int w = 0; w < width; w++) + { + for (int h = 0; h < height; h++) + { + map[w, h] = Color.Black; + } + } + + this.scalingFactor = scalingFactor; + } + + public void setPixel(int x, int y, int val) + { + Color col = Color.Black;; + if (val == 1) + { + col = Color.White; + } else if (val == 2) + { + col = Color.Chocolate; + } + map[x, y] = col; + } + + public Bitmap ToBitmap() + { + Bitmap b = new Bitmap(width, height); + + for (int w = 0; w < width; w++) + { + for (int h = 0; h < height; h++) + { + b.SetPixel(w, h, map[w,h]); + } + } + + return b; + } + + public Graphics paintOnGraphics(Graphics g) + { + for (int w = 0; w < width; w++) + { + for (int h = 0; h < height; h++) + { + Color pixelColor = map[w, h]; + if (!pixelColor.Equals(Color.Black)) + { + Pen pixelBrush = new Pen(pixelColor); + g.DrawRectangle(pixelBrush, new Rectangle((w/scalingFactor), (h/scalingFactor), scalingFactor, scalingFactor)); + } + } + } + return g; + } +} \ No newline at end of file diff --git a/Game_of_Life/Program.cs b/Game_of_Life/Program.cs new file mode 100644 index 0000000..86cf05e --- /dev/null +++ b/Game_of_Life/Program.cs @@ -0,0 +1,16 @@ +namespace Game_of_Life; + +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 MainForm1()); + } +} \ No newline at end of file diff --git a/Game_of_Life/Properties/DataSources/Pixelmap.datasource b/Game_of_Life/Properties/DataSources/Pixelmap.datasource new file mode 100644 index 0000000..182a239 --- /dev/null +++ b/Game_of_Life/Properties/DataSources/Pixelmap.datasource @@ -0,0 +1,10 @@ + + + + Game_of_Life.Pixelmap, Game_of_Life, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file