Esempio n. 1
0
        private void DrawJapaneseColorNames(DrawSet ds)
        {
            FontFamily[] ffs  = ds.ffs;
            Random       rand = ds.rand;

            FontStyle[] styles = ds.styles, jstyles = ds.jstyles;
            Rectangle   rect   = ds.rect;
            KeyValuePair <string, NamedSolidColorBrush> kvp = ds.kvp;
            NamedSolidColorBrush Nscb = ds.Nscb;
            Brush      hsurb          = ds.hsurb;
            Pen        pen            = ds.pen;
            FontFamily ff             = ffs[rand.Next(0, ffs.Length)];
            FontStyle  fs             = styles[rand.Next(0, jstyles.Length)];
            float      jsize          = Convert.ToSingle(rect.Height) / 2.5f;
            Font       jont           = new Font(ff, jsize, fs);
            PointF     joint          = new PointF(rect.Left + pen.Width, rect.Top + pen.Width);
            string     jtext          = String.Format("{0}({1})", kvp.Key, Nscb.Name);

            switch (rand.Next(1, 6))
            {
            case 1:
                jtext = String.Format("{0}", kvp.Key);
                break;

            case 2:
                jtext = String.Format("{0}", Nscb.Name);
                break;

            default:
                break;
            }
            for (int i = 0; i < 10; ++i)
            {
                if (AvoidBlankCharacter(jont))
                {
                    ff   = ffs[rand.Next(0, ffs.Length)];
                    fs   = styles[rand.Next(0, jstyles.Length)];
                    jont = new Font(ff, jsize, fs);
                }
                else
                {
                    break;
                }
            }
            RectangleF ject = new RectangleF {
                X      = Convert.ToSingle(rect.X),
                Y      = Convert.ToSingle(rect.Y),
                Width  = Convert.ToSingle(rect.Width),
                Height = Convert.ToSingle(rect.Height)
            };

            g.DrawString(jtext, jont, hsurb, ject);
        }
Esempio n. 2
0
        protected void DoDraw(PaintEventArgs e)
        {
            KeyValuePair <string, NamedSolidColorBrush>[] kvps = jc.Cores.ToArray();
            g = e.Graphics;
            Rectangle bounds = Screen.GetBounds(new Point());
            Random    rand   = new Random();

            SmoothingMode[] smodes = new SmoothingMode[] { SmoothingMode.AntiAlias, SmoothingMode.Default, SmoothingMode.HighQuality, SmoothingMode.HighSpeed, /*SmoothingMode.Invalid,*/ SmoothingMode.None };
            LineCap[]       lcaps  = new LineCap[] { LineCap.Triangle, LineCap.SquareAnchor, LineCap.Square, LineCap.RoundAnchor, LineCap.Round, LineCap.NoAnchor, LineCap.Flat, LineCap.DiamondAnchor, LineCap.Custom, LineCap.ArrowAnchor, LineCap.AnchorMask };
            DashCap[]       dcaps  = new DashCap[] { DashCap.Triangle, DashCap.Round, DashCap.Flat };
            g.SmoothingMode = smodes[rand.Next(0, smodes.Length)];
            FontFamily[] ffs = FontFamily.Families;
            string       ss  = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@#$%^&*()_-+={[}\\]|\"':;?//>.<,";

            FontStyle[] styles  = new FontStyle[] { FontStyle.Bold, FontStyle.Italic, FontStyle.Regular, FontStyle.Strikeout, FontStyle.Underline };
            FontStyle[] jstyles = new FontStyle[] { FontStyle.Bold, FontStyle.Italic, FontStyle.Regular, FontStyle.Underline };
            for (;;)
            {
                int    top  = rand.Next(0, bounds.Height);
                int    left = rand.Next(0, bounds.Right);
                Point  loc  = new Point(left, top);
                int    wide = rand.Next(miniWide, bounds.Width);
                int    high = rand.Next(miniHigh, bounds.Height);
                Size   size = new Size(wide, high);
                byte[] rgb  = { 0, 0, 0, 0 };
                rand.NextBytes(rgb);
                if (!UseAlpha)
                {
                    rgb[0] = (byte)0xff;
                }
                KeyValuePair <string, NamedSolidColorBrush> kvp = kvps[rand.Next(0, kvps.Length)];
                NamedSolidColorBrush Nscb = kvp.Value;
                Color fore;
                if (UseJapaneseColor)
                {
                    Color jcc = Nscb.GetColor();
                    fore = Color.FromArgb((int)rgb[0], jcc.R, jcc.G, jcc.B);
                }
                else
                {
                    fore = Color.FromArgb((int)rgb[0], (int)rgb[1], (int)rgb[2], (int)rgb[3]);
                }
                Color back  = invert(fore);
                Brush brush = new SolidBrush(fore);
                Brush hsurb = new SolidBrush(back);
                Pen   pen   = new Pen(hsurb, Convert.ToSingle(rand.Next(ofPen.from, ofPen.upto)));
                pen.SetLineCap(lcaps[rand.Next(0, lcaps.Length)], lcaps[rand.Next(0, lcaps.Length)], dcaps[rand.Next(0, dcaps.Length)]);
                Rectangle rect   = new Rectangle(loc, size);
                Point[]   points = GeneratePoints(rand, bounds);
                try {
                    switch (what)
                    {
                    case WhatToDraw.Rectangular:
                        g.DrawRectangle(pen, rect);
                        g.FillRectangle(brush, rect);
                        if (UseJapaneseColor && !UseAlpha)
                        {
                            DrawSet ds = new DrawSet {
                                ffs     = ffs,
                                rand    = rand,
                                styles  = styles,
                                jstyles = jstyles,
                                rect    = rect,
                                kvp     = kvp,
                                Nscb    = Nscb,
                                hsurb   = hsurb,
                                pen     = pen
                            };
                            DrawJapaneseColorNames(ds);
                        }
                        break;

                    case WhatToDraw.Circle:
                        g.DrawEllipse(pen, rect);
                        g.FillEllipse(brush, rect);
                        if (UseJapaneseColor && !UseAlpha)
                        {
                            DrawSet ds = new DrawSet {
                                ffs     = ffs,
                                rand    = rand,
                                styles  = styles,
                                jstyles = jstyles,
                                rect    = rect,
                                kvp     = kvp,
                                Nscb    = Nscb,
                                hsurb   = hsurb,
                                pen     = pen
                            };
                            DrawJapaneseColorNames(ds);
                        }
                        break;

                    case WhatToDraw.Text:
                        float  fsize = Convert.ToSingle(rand.Next(ofFont.from, ofFont.upto));
                        Font   font  = new Font(ffs[rand.Next(0, ffs.Length)], fsize, styles[rand.Next(0, styles.Length)]);
                        PointF point = new PointF(left, top);
                        g.DrawString(ss.Substring(rand.Next(0, ss.Length), 1), font, brush, point);
                        g.RotateTransform(Convert.ToSingle(rand.Next(-360, 361)));
                        break;

                    case WhatToDraw.Line:
                        g.DrawLine(pen, loc, new Point(size));
                        break;

                    case WhatToDraw.Arc:
                        float a1 = Convert.ToSingle(rand.Next(-360, 361));
                        float a2 = Convert.ToSingle(rand.Next(-360, 361));
                        g.DrawArc(pen, rect, a1, a2);
                        break;

                    case WhatToDraw.Bezier:
                        int   x1 = rand.Next(0, bounds.Right);
                        int   x2 = rand.Next(0, bounds.Right);
                        int   y1 = rand.Next(0, bounds.Height);
                        int   y2 = rand.Next(0, bounds.Height);
                        Point p1 = loc;
                        Point p2 = new Point(size);
                        Point p3 = new Point(x1, y1);
                        Point p4 = new Point(x2, y2);
                        g.DrawBezier(pen, p1, p2, p3, p4);
                        break;

                    case WhatToDraw.Polygon:
                        g.DrawPolygon(pen, points);
                        g.FillPolygon(brush, points);
                        break;

                    case WhatToDraw.ClosedCurve:
                        g.DrawClosedCurve(pen, points);
                        g.FillClosedCurve(brush, points);
                        break;

                    case WhatToDraw.OfColorCode:
                        float  jfsize = Convert.ToSingle(rand.Next(miniSizej, UseJapaneseColor ? maxSizej : maxSize_));
                        Font   jfont  = new Font(ffs[rand.Next(0, ffs.Length)], jfsize, styles[rand.Next(0, jstyles.Length)]);
                        PointF jpoint = new PointF(left, top);
                        string text   = null;
                        for (int i = 0; i < 10; ++i)
                        {
                            if (AvoidBlankCharacter(jfont))
                            {
                                jfont = new Font(ffs[rand.Next(0, ffs.Length)], jfsize, styles[rand.Next(0, jstyles.Length)]);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (UseJapaneseColor)
                        {
                            text = String.Format("{0}({1})", kvp.Key, Nscb.Name);
                        }
                        else
                        {
                            string fore_Code = String.Format(UseAlpha ? "{0},{1},{2},{3}" : "{1},{2},{3}", fore.A, fore.R, fore.G, fore.B);
                            text = fore.IsNamedColor ? fore.Name : fore_Code;
                        }
                        g.DrawString(text, jfont, brush, jpoint);
                        g.RotateTransform(Convert.ToSingle(rand.Next(-360, 361)));
                        break;

#if false
                    case WhatToDraw.Background:
                        //This lets freeze for sure...I don't know why... as of July 17, 2019
                        this.BackColor = back;
                        this.ForeColor = fore;
                        break;
#endif
                    }
                } catch { }
                base.OnPaint(e);
                Application.DoEvents();
                if (isScreenSaver)
                {
                    System.Threading.Thread.Sleep(0);
                }
                if (!running)
                {
                    break;
                }
            }
        }