Ejemplo n.º 1
0
        void UpdateBitmap0(GThread thread)
        {
            // update progress bar
            if (pb.Value + 1 <= pb.Maximum)
            {
                pb.Value++;
            }

            // update status bar
            sb.Text = (DateTime.Now - startTime).ToString();

            MandelThread mandel = (MandelThread)thread;
            int          startX = mandel.MapNumX * mandel.Width;
            int          startY = mandel.MapNumY * mandel.Height;

            for (int x = 0; x < mandel.Width; x++)
            {
                for (int y = 0; y < mandel.Height; y++)
                {
                    map.SetPixel(x + startX, y + startY, mandel.Map.GetPixel(x, y));
                }
            }
            pictureBox1.Refresh();
        }
Ejemplo n.º 2
0
        private void Generate()
        {
            try
            {
                totalHorzMaps = int.Parse(txHorz.Text);
                totalVertMaps = int.Parse(txVert.Text);
            }
            catch
            {
                MessageBox.Show("Invalid value(s) for 'No. Cells'.");
                return;
            }

            if (!initted)
            {
                GConnectionDialog gcd = new GConnectionDialog();
                if (gcd.ShowDialog() == DialogResult.OK)
                {
                    // initialise application
                    ga = new GApplication(true);
                    ga.ApplicationName = "Alchemi Fractal Generator - Alchemi sample";

                    ga.Connection = gcd.Connection;
                }
                else
                {
                    return;
                }

                // set dependencies
                ga.Manifest.Add(new ModuleDependency(typeof(KarlsTools.Complex).Module));
                ga.Manifest.Add(new ModuleDependency(typeof(MandelThread).Module));

                // subscribe to events
                ga.ThreadFinish      += new GThreadFinish(UpdateBitmap);
                ga.ApplicationFinish += new GApplicationFinish(AppDone);

                try
                {
                    ga.Start();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }

                initted = true;
            }

            startTime = DateTime.Now;

            for (int mapNumX = 0; mapNumX < totalHorzMaps; mapNumX++)
            {
                for (int mapNumY = 0; mapNumY < totalVertMaps; mapNumY++)
                {
                    MandelThread mandel = new MandelThread(
                        mapNumX,
                        mapNumY,
                        width / totalHorzMaps,
                        height / totalVertMaps,
                        xOffset + mapNumX * width / totalHorzMaps,
                        yOffset + mapNumY * height / totalVertMaps,
                        zoom,
                        pbColorOne.BackColor,
                        pbColorTwo.BackColor
                        );
                    //ga.Threads.Add(mandel);
                    ga.StartThread(mandel);
                }
            }

            pb.Minimum = 0;
            pb.Value   = 0;
            pb.Maximum = totalHorzMaps * totalVertMaps;
        }