Add project files.

This commit is contained in:
EinEtw4s 2022-11-30 21:36:50 +01:00
parent 8c39dcd0f2
commit 4856adf3d7
12 changed files with 337 additions and 0 deletions

View file

@ -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

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

16
Game_of_Life.sln Normal file
View file

@ -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

View file

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

61
Game_of_Life/MainForm1.Designer.cs generated Normal file
View file

@ -0,0 +1,61 @@
namespace Game_of_Life;
partial class MainForm1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}

48
Game_of_Life/MainForm1.cs Normal file
View file

@ -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);
}
};*/
}
}

View file

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -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);
}
}
}

70
Game_of_Life/Pixelmap.cs Normal file
View file

@ -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;
}
}

16
Game_of_Life/Program.cs Normal file
View file

@ -0,0 +1,16 @@
namespace Game_of_Life;
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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());
}
}

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="Pixelmap" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>Game_of_Life.Pixelmap, Game_of_Life, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>