예제 #1
0
        private void mandelbrot() // calculate all points // djm
        {
            int   x, y;
            float h, b, alt = 0.0f;

            action = false;

            this.Cursor = Cursors.WaitCursor;

            //this.Cursor = this.c1;
            // setCursor(c1); // djm
            this.Text = "Mandelbrot-Set will be produced - please wait...";
            // showStatus("mandelbrot-Set will be produced - please wait..."); // djm
            for (x = 0; x < x1; x += 2)
            {
                for (y = 0; y < y1; y++)
                {
                    h = this.pointcolour(xstart + xzoom * (double)x, ystart + yzoom * (double)y); // color value
                    if (h != alt)
                    {
                        b = 1.0f - h * h;                                            // brightness

                        var customColour    = new HSB(h * 255, 0.8f * 255, b * 255); // hsb colour
                        var convertedColour = HSB.FromHSB(customColour);             // convert hsb to rgb

                        this.pen = new Pen(convertedColour);
                        alt      = h;
                    }
                    this.g1.DrawLine(this.pen, x, y, x + 1, y);
                }
            }
            this.Text = "Mandelbrot-Set ready - please select zoom area with pressed mouse.";
            // showStatus("mandelbrot-Set ready - please select zoom area with pressed mouse."); // djm

            this.Cursor = Cursors.Cross;
            //this.Cursor = this.c2;
            action = true;
        }
예제 #2
0
        public static Color FromHSB(HSB hsbColor)
        {
            float r = hsbColor.b;
            float g = hsbColor.b;
            float b = hsbColor.b;

            if (hsbColor.s != 0)
            {
                float max = hsbColor.b;
                float dif = hsbColor.b * hsbColor.s / 255f;
                float min = hsbColor.b - dif;

                float h = hsbColor.h * 360f / 255f;

                if (h < 60f)
                {
                    r = max;
                    g = h * dif / 60f + min;
                    b = min;
                }
                else if (h < 120f)
                {
                    r = -(h - 120f) * dif / 60f + min;
                    g = max;
                    b = min;
                }
                else if (h < 180f)
                {
                    r = min;
                    g = max;
                    b = (h - 120f) * dif / 60f + min;
                }
                else if (h < 240f)
                {
                    r = min;
                    g = -(h - 240f) * dif / 60f + min;
                    b = max;
                }
                else if (h < 300f)
                {
                    r = (h - 240f) * dif / 60f + min;
                    g = min;
                    b = max;
                }
                else if (h <= 360f)
                {
                    r = max;
                    g = min;
                    b = -(h - 360f) * dif / 60 + min;
                }
                else
                {
                    r = 0;
                    g = 0;
                    b = 0;
                }
            }

            return(Color.FromArgb
                   (
                       hsbColor.a,
                       (int)Math.Round(Math.Min(Math.Max(r, 0), 255)),
                       (int)Math.Round(Math.Min(Math.Max(g, 0), 255)),
                       (int)Math.Round(Math.Min(Math.Max(b, 0), 255))
                   ));
        }