All pastes #754994 Raw Edit

Unbenannt

public text v1 · immutable
#754994 ·published 2007-10-30 11:33 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Mandelbrot
{
    public partial class frm_mandel : Form
    {
        public frm_mandel()
        {
            InitializeComponent();
        }

        private void cmd_zeichnen_Click(object sender, EventArgs e)
        {
            cmd_zeichnen.Enabled = false;
            pb.Minimum = 0;
            pb.Maximum = 300;
            int i, j, count;
            int N = 64;
            double RE_MIN = -2.0;
            double RE_MAX = 0.5;
            double IM_MIN = -1.25;
            //double IM_MAX = 1.25;
            double width = pic_mandel.Width;
            double height = pic_mandel.Height;
            Color farbe = new Color();
            double delta = (RE_MAX - RE_MIN) / width;

            Bitmap b = new Bitmap(this.Width, this.Height);
            complex z = new complex();

            for (i = 0, z.real = RE_MIN; i < width; i++, z.real += delta)
            {
                for (j = 0, z.imag = IM_MIN; j < height; j++, z.imag += delta)
                {
                    count = 0;
                    complex x = new complex();
                    x.imag = 0;
                    x.real = 0;
                    while (x.betragsquadr() <= 2.0 && count < N)
                    {
                        x = x * x + z;
                        count++;
                    }
                    if (x.betragsquadr() <= 2)
                    {
                        if(rb_1.Checked==true)
                            farbe = Color.FromArgb(0, 0, 0);
                        else
                            farbe = Color.FromArgb(0, 0, 255);
                    }
                    else
                    {
                        if(rb_1.Checked==true)
                            farbe = Color.FromArgb(1 + 254 * count / N, 1 + 254 * count / N, 1 + 254 * count / N);
                        else
                            farbe = Color.FromArgb(0, 1 + 254 * count / N, 255 -(1 + 254 * count / N));
                    }
                    b.SetPixel(i, j, farbe);
                }
                pb.PerformStep();
            }
            pic_mandel.BackgroundImage = (Image)b;
            cmd_zeichnen.Enabled = true;
            pb.Value = 0;
        }
    }

    public class complex
    {
        public double imag;
        public double real;

        public static complex operator +(complex rhs, complex lhs)
        {
            complex result = new complex();
            result.imag = rhs.imag + lhs.imag;
            result.real = rhs.real + lhs.real;
            return result;
        }

        public static complex operator *(complex rhs, complex lhs)
        {
            complex result = new complex();
            result.real = (rhs.real * lhs.real) - (rhs.imag * lhs.imag);
            result.imag = (rhs.real * lhs.imag) + (rhs.imag * lhs.real);
            return result;
        }

        public double betragsquadr()
        {
            return (this.imag * this.imag + this.real * this.real);
        }

    }
}