Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Windows.Forms;
- using System.Drawing;
- using System;
- namespace Mandelbrot
- {
- static class Program
- {
- static void Main()
- {
- Application.Run(new Scherm());
- }
- class Scherm : Form
- {
- // Declaraties
- public TextBox midxtext;
- public TextBox midytext;
- public TextBox maxtext;
- public TextBox schaaltext;
- public Label middenx;
- public Label middeny;
- public Label schaal;
- public Label max;
- public Button okbutton;
- public Button resetbutton;
- public Label check;
- public bool getekend = false;
- public Bitmap bitmapscherm;
- public Scherm()
- {
- // Nieuwe objecten aanmaken (soort van)
- this.midxtext = new TextBox();
- this.midytext = new TextBox();
- this.maxtext = new TextBox();
- this.schaaltext = new TextBox();
- this.middenx = new Label();
- this.middeny = new Label();
- this.schaal = new Label();
- this.max = new Label();
- this.okbutton = new Button();
- this.resetbutton = new Button();
- this.check = new Label();
- this.bitmapscherm = new Bitmap(400, 400);
- this.BackColor = Color.Black;
- /***************/
- //Eigenschappen//
- /***************/
- // Textbox: midxtext
- this.midxtext.Location = new Point(72, 6);
- this.midxtext.Name = "midxtext";
- this.midxtext.Size = new Size(90, 20);
- this.midxtext.Text = "0"; ;
- // Textbox: midytext
- this.midytext.Location = new Point(72, 32);
- this.midytext.Name = "midytext";
- this.midytext.Size = new Size(90, 20);
- this.midytext.TabIndex = 1;
- this.midytext.Text = "0";
- // Textbox: maxtext
- this.maxtext.Location = new Point(293, 32);
- this.maxtext.Name = "maxtext";
- this.maxtext.Size = new Size(52, 20);
- this.maxtext.TabIndex = 2;
- this.maxtext.Text = "100";
- // Textbox: schaaltext
- this.schaaltext.Location = new Point(293, 6);
- this.schaaltext.Name = "schaaltext";
- this.schaaltext.Size = new Size(120, 20);
- this.schaaltext.TabIndex = 3;
- this.schaaltext.Text = "0,01";
- // Label: middenx
- this.middenx.AutoSize = true;
- this.middenx.Location = new Point(12, 9);
- this.middenx.Name = "middenx";
- this.middenx.Size = new Size(55, 13);
- this.middenx.TabIndex = 4;
- this.middenx.Text = "Midden X:";
- this.middenx.ForeColor = Color.White;
- this.middenx.BackColor = Color.Black;
- // Label: middeny
- this.middeny.AutoSize = true;
- this.middeny.Location = new Point(12, 35);
- this.middeny.Name = "middeny";
- this.middeny.Size = new Size(55, 13);
- this.middeny.TabIndex = 5;
- this.middeny.Text = "Midden Y:";
- this.middeny.ForeColor = Color.White;
- this.middeny.BackColor = Color.Black;
- // Label: schaal
- this.schaal.AutoSize = true;
- this.schaal.Location = new Point(244, 9);
- this.schaal.Name = "schaal";
- this.schaal.Size = new Size(43, 13);
- this.schaal.TabIndex = 6;
- this.schaal.Text = "Schaal:";
- this.schaal.ForeColor = Color.White;
- this.schaal.BackColor = Color.Black;
- // Label: max
- this.max.AutoSize = true;
- this.max.Location = new Point(244, 32);
- this.max.Name = "max";
- this.max.Size = new Size(30, 13);
- this.max.TabIndex = 7;
- this.max.Text = "Max:";
- this.max.ForeColor = Color.White;
- this.max.BackColor = Color.Black;
- // Button: OK
- this.okbutton.Location = new Point(351, 29);
- this.okbutton.Name = "okbutton";
- this.okbutton.Size = new Size(62, 23);
- this.okbutton.TabIndex = 8;
- this.okbutton.Text = "OK";
- this.okbutton.UseVisualStyleBackColor = true;
- this.okbutton.BackColor = Color.White;
- // Button: Reset
- this.resetbutton.Location = new Point(13, 480);
- this.resetbutton.Name = "resetbutton";
- this.resetbutton.Size = new Size(62, 23);
- this.resetbutton.TabIndex = 9;
- this.resetbutton.Text = "Reset";
- this.resetbutton.UseVisualStyleBackColor = true;
- this.resetbutton.BackColor = Color.White;
- /***********************/
- // Einde eigenschappen //
- /***********************/
- this.ClientSize = new Size(425, 530);
- this.Text = "Mandelbrot";
- // Events
- this.Paint += this.bouwScherm;
- this.okbutton.Click += this.okklik;
- this.resetbutton.Click += this.resetklik;
- this.MouseClick += this.zoomin;
- // Controls.Add
- this.Controls.Add(this.okbutton);
- this.Controls.Add(this.resetbutton);
- this.Controls.Add(this.max);
- this.Controls.Add(this.schaal);
- this.Controls.Add(this.middeny);
- this.Controls.Add(this.middenx);
- this.Controls.Add(this.schaaltext);
- this.Controls.Add(this.maxtext);
- this.Controls.Add(this.midytext);
- this.Controls.Add(this.midxtext);
- this.Controls.Add(this.check);
- //Enter = knop indrukken
- this.AcceptButton = okbutton;
- Invalidate();
- }
- public void okklik(object o, EventArgs e)
- {
- Invalidate();
- }
- public void resetklik(object o, EventArgs e)
- {
- midxtext.Text = "0";
- midytext.Text = "0";
- schaaltext.Text = "0,01";
- maxtext.Text = "100";
- Invalidate();
- }
- public void zoomin(object o, MouseEventArgs e)
- {
- if (e.X >= 13 && e.Y >= 69 && e.X <= 413 && e.Y <= 469)
- {
- double midx = double.Parse(midxtext.Text);
- double midy = double.Parse(midytext.Text);
- double schaal = double.Parse(schaaltext.Text);
- midx = (midx - 213 * schaal) + (e.X * schaal);
- midy = (midy + 269 * schaal) - (e.Y * schaal);
- schaal = schaal / 2;
- this.schaaltext.Text = schaal.ToString();
- this.midxtext.Text = midx.ToString();
- this.midytext.Text = midy.ToString();
- Invalidate();
- }
- }
- public void bouwScherm(object o, PaintEventArgs pea)
- {
- double xxx = double.Parse(midxtext.Text);
- double yyy = double.Parse(midytext.Text);
- int x = 0;
- int y = 0;
- double schaal = double.Parse(schaaltext.Text);
- pea.Graphics.DrawImage(bitmapscherm, 13, 69, 400, 400);
- while (y <= 399)
- {
- double y2 = (yyy + 200 * schaal) - y * schaal;
- while (x <= 399)
- {
- double x2 = (xxx - 200 * schaal) + x * schaal;
- int mandelgetal = mandelFormule(x2, y2);
- bitmapscherm.SetPixel(x, y, Color.FromArgb(2 * mandelgetal % 255, 3 * mandelgetal % 255, mandelgetal % 255));
- x++;
- }
- x = 0;
- y++;
- pea.Graphics.DrawImage(bitmapscherm, 13, 69, 400, 400);
- }
- }
- private int mandelFormule(double x, double y)
- {
- double a1 = 0.0;
- double a = 0.0;
- double b = 0.0;
- double pyth = 0.0;
- int teller = 0;
- double max = int.Parse(maxtext.Text);
- while (pyth <= 2 && teller < max)
- {
- a1 = a * a - b * b + x;
- b = 2 * a * b + y;
- a = a1;
- pyth = Math.Sqrt(a * a + b * b);
- teller++;
- }
- return teller;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement