Example #1
0
        //Bitmap bitmap;
        public MyPanel(Size size) : base()
        {
            initColors();
            int wDiv = size.Width % 3;
            int hDiv = size.Height % 3;

            size.Width  -= 12 + wDiv;
            size.Height -= 12 + hDiv;
            Size         = size;
            Location     = new Point(6 + wDiv / 2, 6 + hDiv / 2);

            Console.WriteLine(size.ToString());

            bitmaps = new List <Bitmap>();
            for (int i = 0; i < size.Height / 3; i++)
            {
                bitmaps.Add(new Bitmap(size.Width, 3));
            }


            ComplexDec t;

            for (int y = 0; y < bitmaps.Count; y++)
            {
                for (int i = 0; i < size.Width / 3; i++)
                {
                    temp.real = start.real + (3m / (size.Width / 3)) * i;
                    temp.imag = start.imag - (2.5m / (size.Height / 3)) * y;
                    t         = new ComplexDec(temp);
                    int?  it    = t.level(temp);
                    Color color = ColorsTable.GetColor(it);

                    {
                        //Console.WriteLine(t.ToString());
                        bitmaps[y].SetPixel(i * 3, 0, color);
                        bitmaps[y].SetPixel(i * 3, 1, color);
                        bitmaps[y].SetPixel(i * 3, 2, color);
                        bitmaps[y].SetPixel(i * 3 + 1, 0, color);
                        bitmaps[y].SetPixel(i * 3 + 1, 1, color);
                        bitmaps[y].SetPixel(i * 3 + 1, 2, color);
                        bitmaps[y].SetPixel(i * 3 + 2, 0, color);
                        bitmaps[y].SetPixel(i * 3 + 2, 1, color);
                        bitmaps[y].SetPixel(i * 3 + 2, 2, color);
                    }
                    //bitmaps[1].SetPixel(i, 1, color);
                }
            }

            /*
             * bitmap = new Bitmap(size.Width, 3);
             *
             * using (Graphics gfx = Graphics.FromImage(bitmap))
             * using (SolidBrush brush = new SolidBrush(Color.Pink))
             * {
             *  gfx.FillRectangle(brush, 0, 0, 50, 3);
             * }
             * Console.WriteLine(size.ToString());
             */
        }
 private Color calculatePoint(int x, int y)
 {
     curent.imag = pointZero.imag - y * scale;
     curent.real = pointZero.real + x * scale;
     z.imag      = curent.imag;
     z.real      = curent.real;
     return(ColorsTable.GetColor(z.level(curent)));
 }
        /*
         * private void MyThreadIncrease()
         * {
         *  // increase 3x (9)
         *  ComplexDec complex = new ComplexDec(center.real - scale * (Width / 2 - mouseClick.X),
         *                                      center.imag + scale * (Height / 2 - mouseClick.Y));
         *  //Point startOrigin = new Point(mouseClick.X - Width / 6, mouseClick.Y - Height / 6);
         *  Bitmap copy = new Bitmap(Width / 3, Height / 3);
         *  using (Graphics gr = Graphics.FromImage(copy))
         *  {
         *      Point point = new Point(mouseClick.X - Width / 6, mouseClick.Y - Height / 6);
         *      Rectangle from = new Rectangle(point, copy.Size);
         *      Rectangle to = new Rectangle(new Point(0, 0), copy.Size);
         *      gr.DrawImage(bitmap, to, from, GraphicsUnit.Pixel);
         *  }
         *  Color color;
         *  for (int y = 0; y < copy.Height; y++)
         *  {
         *      for (int x = 0; x < copy.Width; x++)
         *      {
         *          color = copy.GetPixel(x, y);
         *          bitmap.SetPixel(x * 3, y * 3, color);
         *          bitmap.SetPixel(x * 3 + 1, y * 3, color);
         *          bitmap.SetPixel(x * 3 + 2, y * 3, color);
         *          bitmap.SetPixel(x * 3, y * 3 + 1, color);
         *          bitmap.SetPixel(x * 3 + 1, y * 3 + 1, color);
         *          bitmap.SetPixel(x * 3 + 2, y * 3 + 1, color);
         *          bitmap.SetPixel(x * 3, y * 3 + 2, color);
         *          bitmap.SetPixel(x * 3 + 1, y * 3 + 2, color);
         *          bitmap.SetPixel(x * 3 + 2, y * 3 + 2, color);
         *      }
         *  }
         *  Invalidate();
         *  // 2 step details (3,3,3)
         *  center = complex;
         *  scale /= 3;
         *  ComplexDec start = new ComplexDec(center.real - (bitmap.Width / 2) * scale, center.imag + (bitmap.Height / 2) * scale);
         *  ComplexDec z;
         *  for (int y = 0; y < Height; y += 3)
         *  {
         *      textBox.Text = y.ToString();
         *      complex.imag = start.imag - y * scale;
         *      for (int x = 0; x < Width; x += 3)
         *      {
         *          complex.real = start.real + x * scale;
         *          z = new ComplexDec(complex);
         *          color = ColorsTable.GetColor(z.level(complex));
         *          bitmap.SetPixel(x, y, color);
         *          bitmap.SetPixel(x + 1, y, color);
         *          bitmap.SetPixel(x, y + 1, color);
         *      }
         *      complex.imag = start.imag - (y + 2) * scale;
         *      for (int x = 0; x < Width; x += 3)
         *      {
         *          complex.real = start.real + (x + 2) * scale;
         *          z = new ComplexDec(complex);
         *          color = ColorsTable.GetColor(z.level(complex));
         *          bitmap.SetPixel(x + 2, y + 2, color);
         *          bitmap.SetPixel(x + 1, y + 2, color);
         *          bitmap.SetPixel(x + 2, y + 1, color);
         *      }
         *      Invalidate();
         *  }
         *
         *  Console.WriteLine("Thread increase!!! " + complex);
         *  Console.WriteLine("click  " + mouseClick);
         *  Console.WriteLine((mouseClick.X - Width / 6).ToString() + "  " + (mouseClick.Y - Height / 6).ToString());
         *
         * }
         */
        public void drawLine()
        {
            ComplexDec start   = new ComplexDec(center.real - (bitmap.Width / 2) * scale, center.imag + (bitmap.Height / 2) * scale);
            ComplexDec complex = new ComplexDec(center);
            ComplexDec z;
            int        y = 0; // line++;

            if (y < bitmap.Height)
            {
                complex.imag = start.imag - y * scale;
                for (int x = 0; x < bitmap.Width; x++)
                {
                    complex.real = start.real + x * scale;
                    z            = new ComplexDec(complex);
                    bitmap.SetPixel(x, y, ColorsTable.GetColor(z.level(complex)));
                    //if ( complex.real == 0 || complex.imag == 0 ) bitmap.SetPixel(x, y, Color.Black);
                }
            }
            //textBox.Text = y.ToString();
        }
        private void calculateLine(int line)
        {
            // ComplexDec start = new ComplexDec(center.real - (bitmap.Width / 2) * scale, center.imag + (bitmap.Height / 2) * scale);
            //ComplexDec complex = new ComplexDec(center);
            //ComplexDec z;
            int y = line; // line++;

            if (y < bitmap.Height)
            {
                curent.imag = pointZero.imag - y * scale;
                for (int x = 0; x < bitmap.Width; x++)
                {
                    curent.real = pointZero.real + x * scale;
                    z.imag      = curent.imag;
                    z.real      = curent.real;
                    bitmap.SetPixel(x, y, ColorsTable.GetColor(z.level(curent)));
                    //if ( complex.real == 0 || complex.imag == 0 ) bitmap.SetPixel(x, y, Color.Black);
                }
            }
        }