Example #1
0
        public MainForm()
        {
            InitializeComponent();
            mMandelbrotGenerator        = new MandelbrotGenerator(Width, Height);
            mMandelbrotGenerator.Width  = panel1.Width;
            mMandelbrotGenerator.Height = panel1.Height;
            mMandelbrotGenerator.FixAspect();
            mMandelbrotGenerator.MandlebrotReady          += MMandelbrotGenerator_MandlebrotReady;
            mMandelbrotGenerator.MandlebrotPaletteChanged += MMandelbrotGenerator_MandlebrotPaletteChanged;
            MouseWheel += Form1_MouseWheel;
            UpdateMandelbrot();
            propertyGrid1.SelectedObject = mMandelbrotGenerator;
            //Load the presets from presets.xml (if it exists), and use the defaults otherwise
            string xmlpath = Path.GetDirectoryName(Application.ExecutablePath) + "\\presets.xml";

            if (File.Exists(xmlpath))
            {
                //try loading
                try
                {
                    mPresets = MandelbrotPresets.FromXml(File.ReadAllText(xmlpath));
                }
                catch
                {
                    mPresets = MandelbrotPresets.GenerateDefault();
                    SavePresets();
                }
            }
            else
            {
                mPresets = MandelbrotPresets.GenerateDefault();
                SavePresets();
            }
            UpdatePresets();
        }
Example #2
0
        private void exportButton_Click(object sender, EventArgs e)
        {
            //Generate it 4 times as big, to scale it down later and have nice anti-aliasing
            MandelbrotGenerator mg = new MandelbrotGenerator(mMandelbrotGeneratorTemplate, (int)widthUpDown.Value * 4, (int)heightUpDown.Value * 4);

            mg.FixAspect();
            mg.MandlebrotReady += delegate(Bitmap mandelbrot, bool is2Times)
            {
                mandelbrot = new Bitmap(mandelbrot, (int)widthUpDown.Value, (int)heightUpDown.Value);
                mandelbrot.Save(pathTextBox.Text, ImageFormat.Png);
                //Controls can't be changed from a different thread
                progressBar.Invoke((Action) delegate
                {
                    progressBar.Style = ProgressBarStyle.Blocks;
                    progressBar.Value = 100;
                });
                DialogResult = DialogResult.OK;
            };
            progressBar.Enabled  = true;
            progressBar.Style    = ProgressBarStyle.Marquee;
            cancelButton.Enabled = false;
            exportButton.Enabled = false;
            groupBox1.Enabled    = false;
            groupBox2.Enabled    = false;
            mg.StartGenerateMandelbrot();
        }
Example #3
0
 //Update the mandelbrot when the size of the panel changed
 private void panel1_SizeChanged(object sender, EventArgs e)
 {
     if (mMandelbrotGenerator != null)
     {
         mMandelbrotGenerator.Width  = panel1.Width;
         mMandelbrotGenerator.Height = panel1.Height;
         mMandelbrotGenerator.FixAspect();
         UpdateMandelbrot();
     }
 }
Example #4
0
 public void ApplyToGenerator(MandelbrotGenerator generator)
 {
     generator.MandelbrotX        = x;
     generator.MandelbrotY        = y;
     generator.MandelbrotWidth    = width;
     generator.MandelbrotHeight   = height;
     generator.MandelbrotStyle    = style;
     generator.MandlebrotMaxCount = maxCount;
     generator.BeginUpdatePalette();
     generator.MandelbrotPalette.Clear();
     foreach (int c in palette)
     {
         generator.MandelbrotPalette.Add(Color.FromArgb(c));
     }
     generator.EndUpdatePalette();
     generator.FixAspect();
 }