//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()); */ }
public MyPanelPixels(Size size) : base() { center = new ComplexDec(-0.75m, 0m); // dystance beteen pixels scale = 1m / (decimal)Math.Pow(2, 8); // white frame 6 pixels (set size and location size.Width = size.Width - 12 - (size.Width % 3); size.Height = size.Height - 12 - (size.Height % 3); Size = size; Location = new Point(6, 6); // complex value in point (0, 0), center(-0.75m, 0m) pointZero = new ComplexDec(-0.75m - scale * (size.Width / 2), scale * (size.Height / 2)); curent = new ComplexDec(0, 0); z = new ComplexDec(0, 0); // canvas to paint bitmap = new Bitmap(size.Width, size.Height); // control to display textBox = new TextBox(); textBox.Width = 30; textBox.Text = "Start"; this.Controls.Add(textBox); // counter to lines //line = 0; //Click += new EventHandler(MyClick); // old start //thread = new Thread(new ThreadStart(MyThreadFunction)); //Task.Delay(200).ContinueWith(t => thread.Start()); // new thread //t1 = new Thread(new ThreadStart(Thread1)); //Task.Delay(200).ContinueWith(t => t1.Start()); //thread.Start(); //drawLine(); // background worker draw picture in seperate thread backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; backgroundWorker.DoWork += BackgroundWorker_DoWork; backgroundWorker.ProgressChanged += BackgroundWorker_ProgressChanged; backgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted; backgroundWorker.RunWorkerAsync(); }
/* * 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(); }
public int?level(ComplexDec c) { int level = 0; decimal rSquare, iSquare; while (level < 110) { rSquare = real * real; iSquare = imag * imag; if (rSquare + iSquare >= 4) { return(level); } imag = imag * real * 2 + c.imag; real = rSquare - iSquare + c.real; level++; } return(null); }
public ComplexDec iteralizacja(ComplexDec c) { return(new ComplexDec(real * real - imag * imag + c.real, 2 * real * imag + c.imag)); }
public ComplexDec(ComplexDec model) { real = model.real; imag = model.imag; }