Hallo leute,
Ich habe in meinem Project die OnPaint Methode überschrieben.
Das problem ist nur, dass der dabei nie zum ende kommt, da er immer wieder von forne beginnt.
MFG 01
Ich habe in meinem Project die OnPaint Methode überschrieben.
Das problem ist nur, dass der dabei nie zum ende kommt, da er immer wieder von forne beginnt.
MFG 01
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Mandelbrot
{
public partial class Form1 : Form
{
private bool painted = false;
private const int MaxIterations = 50;
//Region
private const float Min_X = -2.2F;
private const float Max_X = 1F;
private const float Min_Y = -1.2F;
private const float Max_Y = 1.2F;
//Startpunkt
private float X_Min = Min_X;
private float X_Max = Max_X;
private float Y_Min = Min_Y;
private float Y_Max = Max_Y;
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
if (!painted)
{
base.OnPaint(e);
painted = true;
const float Max_Squared = 2.0F;
GetProportion();
int count;
float XC, YC, dXC, dYC, XZ, YZ, XZ2, YZ2;
int wi = this.Width;
int hi = this.Height;
dXC = (X_Max - X_Min) / (wi - 1);
dYC = (Y_Max - Y_Min) / (hi - 1);
XC = X_Min;
for (float i = 0F; i <= wi - 1; i++)
{
YC = Y_Min;
for (float j = 0F; j <= hi - 1; j++)
{
XZ = 0;
YZ = 0;
XZ2 = 0;
YZ2 = 0;
count = 0;
while (count < MaxIterations && XZ < Max_Squared && YZ < Max_Squared)
{
XZ2 = XZ * XZ;
YZ2 = YZ * YZ;
YZ = 2 * YZ * XZ + YC;
XZ = XZ2 - YZ2 + XC;
count++;
}
//Color C = Color.FromArgb(count, count, count);
//Pen P=new Pen(C);
Pen P = new Pen(Color.Black);
if (!(count < MaxIterations))
{
e.Graphics.DrawLine(P, i, j, i + 0.1F, j + 0.1F);
}
YC = YC + dYC;
}
XC = XC + dXC;
}
painted = false;
}
}
private void GetProportion()
{
float Proportion, FormProportion;
float hi, wi, mid;
Proportion = (Y_Max - Y_Min) / (X_Max - X_Min);
FormProportion = float.Parse(this.Height.ToString()) / float.Parse(this.Width.ToString());
if (Proportion > FormProportion)
{
wi = (Y_Max - Y_Min) / FormProportion;
mid = (X_Min + X_Max) / 2F;
X_Min = mid - wi / 2F;
X_Max = mid + wi / 2F;
}
else
{
hi = (X_Max - X_Min) * FormProportion;
mid = (Y_Min + Y_Max) / 2F;
Y_Min = mid - hi / 2F;
Y_Max = mid + hi / 2F;
}
}
private void Form1_Resize(object sender, EventArgs e)
{
this.Invalidate();
}
}
}