コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            zoom             = 1;
            zoomText.Text    = "1";
            currentZoom.Text = "Current Zoom = " + zoom + "x";
            offset           = new Complex(0, 0);
            Bitmap bm = new Bitmap(picCanvas.Width, picCanvas.Height);

            for (int x = 0; x < picCanvas.Width; x++)
            {
                for (int y = 0; y < picCanvas.Height; y++)
                {
                    double  a  = (double)(x - (picCanvas.Width / 2)) / (double)(picCanvas.Width / 4);
                    double  b  = (double)(y - (picCanvas.Height / 2)) / (double)(picCanvas.Height / 4);
                    Complex c0 = new Complex(a, b);
                    Complex z  = new Complex(0, 0);
                    int     it = 0;
                    do
                    {
                        it++;
                        z.Square();
                        z.Add(c0);
                        if (z.Magnitude() > 2.0)
                        {
                            break;
                        }
                    }while (it < 129);
                    bm.SetPixel(x, y, Color.FromArgb(it % 128 * 2, it % 64 * 4, it % 32 * 8));
                }

                picCanvas.Image = bm;
            }
        }
コード例 #2
0
        private void picCanvas_MouseClick(object sender, MouseEventArgs e)
        {
            double Mouse_X = e.X;
            double Mouse_Y = e.Y;
            double c;
            double d;

            c = (double)(Mouse_X - (picCanvas.Width / 2)) / (double)(picCanvas.Width / 4 * zoom);
            d = (double)(Mouse_Y - (picCanvas.Height / 2)) / (double)(picCanvas.Height / 4 * zoom);



            zoom             = zoom + zoomAdd;
            currentZoom.Text = "Current Zoom = " + zoom + "x";
            Complex offset1 = new Complex(c, d);

            offset.Add(offset1);
            System.Diagnostics.Debug.WriteLine(c);
            System.Diagnostics.Debug.WriteLine(d);
            //newCX = (float)Mouse_X;
            //newCY = (float)Mouse_Y;

            // picCanvas.Refresh();


            Bitmap bm = new Bitmap(picCanvas.Width, picCanvas.Height);

            for (int x = 0; x < picCanvas.Width; x++)
            {
                for (int y = 0; y < picCanvas.Height; y++)
                {
                    double  a  = (double)(x - ((picCanvas.Width) / 2)) / (double)((picCanvas.Width) / 4 * zoom);
                    double  b  = (double)(y - ((picCanvas.Width) / 2)) / (double)((picCanvas.Width) / 4 * zoom);
                    Complex c0 = new Complex(a, b);
                    c0.Add(offset);
                    Complex z  = new Complex(0, 0);
                    int     it = 0;
                    do
                    {
                        it++;
                        z.Square();
                        z.Add(c0);
                        if (z.Magnitude() > 2.0)
                        {
                            break;
                        }
                    }while (it < 129);
                    bm.SetPixel(x, y, Color.FromArgb(it % 128 * 2, it % 64 * 4, it % 32 * 8));
                }

                picCanvas.Image = bm;
            }
        }