Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Applications » Downloads
 
Add your own
alternative version

Tagged as

The beauty of fractals - A simple fractal rendering program done in C#

, 27 Jul 2009 CPOL
A fractal rendering application demonstrating many .NET programming techniques.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Reflection;
using System.IO;

using ComplexMath;

namespace FracMaster
{
    public partial class MDIForm : Form
    {
        public MDIForm()
        {
            InitializeComponent();
        }

        private void fractalSettingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
        }
         
        private void testFractalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FractalForm frmchild = new FractalForm();
            frmchild.MdiParent = this;
            frmchild.Fractal =  new TestFractal();       
            frmchild.Show();
            frmchild.Text = "Test Fractal";
        }

        private void mandelbrotFractalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FractalForm frmchild = new FractalForm();
            frmchild.MdiParent = this;
            frmchild.Fractal = new MandelbrotFractal();
            frmchild.Show();
            frmchild.Text = "Mandelbrot Fractal";
        }

        private void juliaFractalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FractalForm frmchild = new FractalForm();
            frmchild.MdiParent = this;
            frmchild.Fractal = new JuliaFractal();
            frmchild.Show();
            frmchild.Text = "Julia Fractal";
        }

        private void newtonFractalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FractalForm frmchild = new FractalForm();
            frmchild.MdiParent = this;
            frmchild.Fractal = new NewtonFractalByIterationsRequired();
            frmchild.Show();
            frmchild.Text = "Newton Fractal - Iterations Required";
        }

        
        private void loadFractalFromStream(Stream s)
        {
            // ToDo get type of fractal and load it!
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(s);
            XmlNodeList nodes = xmldoc.GetElementsByTagName("frac");
            if (nodes.Count == 1)
            {
                try
                {
                    s.Position = 0;
                    String type = nodes[0].Attributes["type"].Value;

                    if (type == "FracMaster.MandelbrotFractal")
                    {
                        FractalForm frmchild = new FractalForm();
                        frmchild.MdiParent = this;
                        frmchild.Fractal = new MandelbrotFractal();
                        frmchild.Fractal.ReadFromXml(s);
                        frmchild.Show();
                        frmchild.Text = "Mandelbrot Fractal";
                    }
                    else if (type == "FracMaster.JuliaFractal")
                    {
                        FractalForm frmchild = new FractalForm();
                        frmchild.MdiParent = this;
                        frmchild.Fractal = new JuliaFractal();
                        frmchild.Fractal.ReadFromXml(s);
                        frmchild.Show();
                        frmchild.Text = "Julia Fractal";
                    }
                    else if (type == "FracMaster.NewtonFractal" ||
                             type == "FracMaster.NewtonFractalByIterationsRequired")
                    {
                        FractalForm frmchild = new FractalForm();
                        frmchild.MdiParent = this;
                        frmchild.Fractal = new NewtonFractalByIterationsRequired();
                        frmchild.Fractal.ReadFromXml(s);
                        frmchild.Show();
                        frmchild.Text = "Newton Fractal - Iterations required";
                    }
                  
                    else
                    {
                        // ignore
                    }
                }
                catch { }
            }
        }

        private void loadFractalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // load fractal here
            OpenFileDialog dia = new OpenFileDialog();
            dia.Filter = "xml file (*.xml)|*.xml";

            if (dia.ShowDialog() == DialogResult.OK)
            {
                Stream s = new FileStream(dia.FileName,FileMode.Open);
                loadFractalFromStream(s);
                 
            }
        }

        private void aboutFracMasterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("FracMaster \n\r\n\r(C) 2009 Zimmermann Stephan");
        }

        

        private void cascadedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void tileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void tileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void newtonFractal01ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("FracMaster.BuildInFractals.frac_newton_01.xml");
            loadFractalFromStream(s);
        }

        private void mandelbrot01ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("FracMaster.BuildInFractals.frac_mandel_01.xml");
            loadFractalFromStream(s);
        }

        private void mandelbrot02ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("FracMaster.BuildInFractals.frac_mandel_02.xml");
            loadFractalFromStream(s);
        }

        private void mandelbrot03ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("FracMaster.BuildInFractals.frac_mandel_03.xml");
            loadFractalFromStream(s);
        }

        private void julia01ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("FracMaster.BuildInFractals.frac_julia_01.xml");
            loadFractalFromStream(s);
        }

        private void mandelbrot04ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("FracMaster.BuildInFractals.frac_mandel_04.xml");
            loadFractalFromStream(s);
        }

        private void mandelbrot05ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("FracMaster.BuildInFractals.frac_mandel_05.xml");
            loadFractalFromStream(s);
        }

       
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Zimmermann Stephan
Software Developer (Senior)
Austria Austria
I have started programming at the age of 13 on the commodore 64.
 
Ever since then I have been programming on many systems in many languages.
 
During the last 12 years I have been working as professional programmer in different companies and different areas.
 
Now I am working as freelancer programmer / consultant

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 27 Jul 2009
Article Copyright 2009 by Zimmermann Stephan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid