Initial commit

This commit is contained in:
2018-07-12 10:13:00 +02:00
commit 1ec7b51479
10 changed files with 912 additions and 0 deletions

6
MandelbrotSet/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -0,0 +1,62 @@
namespace MandelbrotSet
{
partial class MandelbrotDisplay
{
/// <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.pbxDisplay = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pbxDisplay)).BeginInit();
this.SuspendLayout();
//
// pbxDisplay
//
this.pbxDisplay.Dock = System.Windows.Forms.DockStyle.Fill;
this.pbxDisplay.Location = new System.Drawing.Point(0, 0);
this.pbxDisplay.Name = "pbxDisplay";
this.pbxDisplay.Size = new System.Drawing.Size(666, 504);
this.pbxDisplay.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pbxDisplay.TabIndex = 0;
this.pbxDisplay.TabStop = false;
//
// MandelbrotDisplay
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(666, 504);
this.Controls.Add(this.pbxDisplay);
this.Name = "MandelbrotDisplay";
this.Text = "Mandelbrot Set";
((System.ComponentModel.ISupportInitialize)(this.pbxDisplay)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pbxDisplay;
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MandelbrotSet
{
public partial class MandelbrotDisplay : Form
{
public MandelbrotDisplay(Image image)
{
InitializeComponent();
pbxDisplay.Image = image;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FD750A95-E7F5-4FF5-9572-8AD93F2BAFE5}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MandelbrotSet</RootNamespace>
<AssemblyName>MandelbrotSet</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MandelbrotDisplay.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MandelbrotDisplay.Designer.cs">
<DependentUpon>MandelbrotDisplay.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MandelbrotDisplay.resx">
<DependentUpon>MandelbrotDisplay.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

173
MandelbrotSet/Program.cs Normal file
View File

@ -0,0 +1,173 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Numerics;
using System.Windows.Forms;
namespace MandelbrotSet
{
class Program
{
#region Params
private static int MaxIterations = 96; // int: Höhe des Ausgabebilds in Pixeln. Nicht größer als 20000 setzen!
private static int Height = 1000; // int: Höhe des Ausgabebilds in Pixeln. Nicht größer als 20000 setzen!
private static int Width;// int: Breite des Ausgabebilds in Pixeln. Nicht größer als 20000 setzen!
private static string Filename = "plot"; // Dateiname
private const double Xmin = -2.0; // double: Untere Grenze des Definitionsbereichs des Plots
private const double Xmax = 1.0; // double: Obere Grenze des Definitionsbereichs des Plots
private const double Ymin = -1.0; // double: Untere Grenze des Wertebereichs des Plots
private const double Ymax = 1.0; // double: Obere Grenze des Wertebereichs des Plots
private const double HueFactor = 360.0;
private const double Mathwidth = Xmax - Xmin;
private const double Mathheight = Ymax - Ymin;
private static Color Corecolor { get; } = Color.Black;
#endregion
private static BigInteger _pixelsDrawn;
private static Bitmap _map;
static Program()
{
_pixelsDrawn = 0;
}
static void Main(string[] args)
{
if (args.Length >= 1)
{
Filename = args[0];
if (args.Length >= 2)
{
if (int.TryParse(args[1], out var newHeight))
{
Height = newHeight;
Console.WriteLine($"Parameter Höhe wurde auf {Height} gesetzt!.");
}
else
{
Console.WriteLine($"\"{args[1]}\" ist keine gültige Höhenangabe!");
Console.WriteLine($"Parameter Höhe wurde auf Standardwert ({Height}) zurückgesetzt!.");
}
if (args.Length >= 3)
{
if (int.TryParse(args[2], out var newMaxIterations))
{
MaxIterations = newMaxIterations;
Console.WriteLine($"Parameter Iterationen wurde auf {MaxIterations} gesetzt!.");
}
else
{
Console.WriteLine($"\"{args[2]}\" ist keine gültige Iterationsangabe!");
Console.WriteLine($"Parameter Iterationen wurde auf Standardwert ({MaxIterations}) zurückgesetzt!.");
}
}
}
}
Filename = $"{Filename}-{Height}px-{MaxIterations}it.bmp";
Console.WriteLine($"Parameter Dateiname wurde auf \"{Filename}\" gesetzt!.");
Width = Height * 3 / 2;
try
{
_map = new Bitmap(Width, Height);
}
catch (Exception e)
{
Console.WriteLine("Bitmap kann nicht erstellt werden: " + e.Message);
return;
}
Stopwatch watch;
Console.WriteLine("Beginning Task...\n├─── Drawing Mandelbrot...");
watch = Stopwatch.StartNew();
DrawMandelbrot();
Console.WriteLine($"│ └─── Mandelbrot drawn!\nDEBUG: { _pixelsDrawn.ToString()} pixels were drawn.\nSuccessfully rendered in {((double)watch.ElapsedMilliseconds / 1000.0).ToString()} seconds!\n├─── Saving bitmap...");
watch = Stopwatch.StartNew();
_map.Save(Filename);
Console.WriteLine($"│ ├─── Saved as \"{Filename}\"!\n│ Successfully saved in {((double)watch.ElapsedMilliseconds / 1000.0).ToString()} seconds!\nFinished Task!");
Process.Start(Filename);
}
private static int Constrain(int value, int min, int max) => value < min ? min : (value > max ? max : value);
private static Color ColorFromHue(double hue)
{
double r, g, b, x;
int R, G, B;
hue %= 360.0;
x = 1.0 - Math.Abs(hue / 60.0 % 2.0 - 1);
#region COLOR MODE
if (hue < 60.0)
{
r = 1.0; g = x; b = 0.0;
}
else if (hue < 120.0)
{
r = x; g = 1.0; b = 0.0;
}
else if (hue < 180.0)
{
r = 0.0; g = 1.0; b = x;
}
else if (hue < 240.0)
{
r = 0.0; g = x; b = 1.0;
}
else if (hue < 300.0)
{
r = x; g = 0.0; b = 1.0;
}
else
{
r = 1.0; g = 0.0; b = x;
}
#endregion
R = Constrain((int)Math.Round(r * 255), 0, 255);
G = Constrain((int)Math.Round(g * 255), 0, 255);
B = Constrain((int)Math.Round(b * 255), 0, 255);
return Color.FromArgb(R, G, B);
}
static double XtoMath(int xb) => Xmin + xb * Mathwidth / Width;
static double YtoMath(int yb) => Ymax - yb * Mathheight / Height;
private static void DrawMandelbrot()
{
int y, x, iterations;
double xd, yd;
for (y = 0; y < Height; y++)
{
if (y % 100 == 99) Console.WriteLine($"│ ├─── Progress: {(double)(y + 1) * 100.0 / (double)Height}%");
yd = YtoMath(y);
for (x = 0; x < Width; x++)
{
xd = XtoMath(x);
iterations = MandelbrotIterations(new Complex(xd, yd), Complex.Zero);
if (iterations == -1)
{
_map.SetPixel(x, y, Corecolor);
_pixelsDrawn++;
continue;
}
_map.SetPixel(x, y, ColorFromHue(((double)iterations / (double)MaxIterations) * HueFactor));
_pixelsDrawn++;
}
}
}
private static Complex NextItem(Complex point, Complex z) => new Complex(z.Real * z.Real - z.Imaginary * z.Imaginary + point.Real, 2.0 * z.Real * z.Imaginary + point.Imaginary);
private static int MandelbrotIterations(Complex point, Complex z, int depth = 0)
{
if (depth > MaxIterations) return -1;
if (z.Magnitude >= 2.0) return depth;
return MandelbrotIterations(point, NextItem(point, z), depth + 1);
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("MandelbrotSet")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MandelbrotSet")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("fd750a95-e7f5-4ff5-9572-8ad93f2bafe5")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" />
</packages>