我的项目第三次出现故障。本身没有故障,但是绝对没有做我需要做的事情。因此,基本上,我需要绘制一个曼德布罗分形。它需要接受用户的数据,例如最大迭代次数,颜色,比例,中间x和中间y。这些中间坐标给我带来了问题。我不知道该怎么做,所以曼德尔布罗特分形将中间的x和中间的y作为其图像的中点。你们能帮我吗?
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 practicum_2_poging_2_officieel
{
public partial class Form1 : Form
{
int hoogte = 400, breedte = 400;
double xInput, yInput, scaleNum;
TextBox xInputBox;
TextBox yInputBox;
TextBox scaleInputBox;
TextBox maxInputBox;
Button okButton;
PictureBox pictureBox;
Bitmap bitmap;
ComboBox comboBox;
Label middleX;
Label middleY;
Label schaal;
Label max;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//form aanpassen mooie kleurtjes en naam.
this.Text = "Mandelbrot Bjorn Jonathan:";
this.ClientSize = new Size(500, 600);
this.BackColor = Color.LightBlue;
//Labels plaats + sizes e.d.
middleX = new Label();
middleX.Location = new Point(20, 10);
middleX.Size = new Size(55, 20);
middleX.Text = "Midden X:";
middleY = new Label();
middleY.Location = new Point(20, 40);
middleY.Size = new Size(55, 20);
middleY.Text = "Midden Y:";
schaal = new Label();
schaal.Location = new Point(180, 10);
schaal.Size = new Size(55, 20);
schaal.Text = "Schaal:";
max = new Label();
max.Location = new Point(180, 40);
max.Size = new Size(90, 20);
max.Text = "Max herhalingen:";
//Textbox
this.xInputBox = new TextBox();
this.xInputBox.Location = new Point(80, 10);
this.xInputBox.Size = new Size(80, 20);
xInputBox.Text = "-2";
this.yInputBox = new TextBox();
this.yInputBox.Location = new Point(80, 40);
this.yInputBox.Size = new Size(80, 20);
yInputBox.Text = "2";
this.scaleInputBox = new TextBox();
this.scaleInputBox.Location = new Point(270, 10);
this.scaleInputBox.Size = new Size(80, 20);
scaleInputBox.Text = "0.01";
this.maxInputBox = new TextBox();
this.maxInputBox.Location = new Point(270, 40);
this.maxInputBox.Size = new Size(80, 20);
maxInputBox.Text = "100";
//OK okButton
okButton = new Button();
okButton.Location = new Point(390, 10);
okButton.Size = new Size(80, 30);
okButton.Text = "OK";
//Box
pictureBox = new PictureBox();
pictureBox.Location = new Point(20, 75);
pictureBox.Size = new Size(400, 400);
//bitmap
//Midden bitmap = (252 + 20, 280 +75) = (272, 355)
bitmap = new Bitmap(breedte, hoogte);
//Combobox
comboBox = new ComboBox();
comboBox.Location = new Point(390, 40);
comboBox.Size = new Size(80, 20);
comboBox.Text = "W";
comboBox.Items.Add("W");
comboBox.Items.Add("R");
comboBox.Items.Add("G");
comboBox.Items.Add("B");
//Alle Controls.Add
//Controls voor labels
this.Controls.Add(middleX);
this.Controls.Add(middleY);
this.Controls.Add(max);
this.Controls.Add(schaal);
//Controls.Add voor textboxen
this.Controls.Add(this.xInputBox);
this.Controls.Add(this.yInputBox);
this.Controls.Add(this.scaleInputBox);
this.Controls.Add(this.maxInputBox);
//Controls voor Box
this.Controls.Add(pictureBox);
//okButton
this.Controls.Add(okButton);
//Ok en Enter zorgt voor startbereken
okButton.Click += Invoer;
okButton.Click += StartBerekening;
//okButton.Click += Kleuren;
this.AcceptButton = okButton; //voor enterokButton
//Controls voor combobox
this.Controls.Add(comboBox);
//this.Paint += StartBerekening;
}
private void Invoer(object sender, EventArgs e)
{
scaleNum = Convert.ToDouble(scaleInputBox.Text);
}
//private void StartBerekening(object sender, PaintEventArgs e)
private void StartBerekening(object sender, EventArgs e)
{
double yInput = Convert.ToDouble(yInputBox.Text);
double xInput = Convert.ToDouble(xInputBox.Text);
//ComboBox doubleRead = (ComboBox)comboBox.SelectedItem;
string combVal = (string)comboBox.SelectedItem;
char combChar = combVal[0];
for (double x = 0; x < breedte; x++)
{
for (double y = 0; y < hoogte; y++)
{
int MandelGetal;
double a, b, Distance, a2;
xInput = (x - 200) * scaleNum;
yInput = (y - 200) * scaleNum;
MandelGetal = 0;
// a en b op 0
a = 0;
b = 0;
a2 = a;
//Afstand berekenen tussen O(0,0) en punt P(x,y) mbv Pythagoras
//Begin distance
Distance = Math.Pow((Math.Pow(xInput, 2) + Math.Pow(yInput, 2)), 0.5);
while (Distance < 2 && MandelGetal < Convert.ToInt32(maxInputBox.Text))
{
//verandering van a en b door f(a,b) = (a*a-b*b+x, 2*a*b+y)
//a = gebruikt voorgaande a en b
a = (a * a) - (b * b) + xInput;
//b = gebruikt voorgaande a en b, gebruikt nu nieuwe a
b = (2 * a2 * b) + yInput;
a2 = a;
Distance = Math.Pow((Math.Pow(a, 2) + Math.Pow(b, 2)), 0.5);
MandelGetal++;
}
if ((MandelGetal % 2) != 0)
{
switch (combChar)
{
case 'W':
bitmap.SetPixel(Convert.ToInt32(x), Convert.ToInt32(y), Color.White);
break;
case 'R':
bitmap.SetPixel(Convert.ToInt32(x), Convert.ToInt32(y), Color.Red);
break;
case 'G':
bitmap.SetPixel(Convert.ToInt32(x), Convert.ToInt32(y), Color.Green);
break;
case 'B':
bitmap.SetPixel(Convert.ToInt32(x), Convert.ToInt32(y), Color.Blue);
break;
}
}
else
{
bitmap.SetPixel(Convert.ToInt32(x), Convert.ToInt32(y), Color.Black);
}
}
}
pictureBox.Image = bitmap;
}
}
}