Beispiel #1
0
        /// <summary>
        /// Gets the brush to be used for drawing a specific field for the given model
        /// </summary>
        /// <param name="m">the current model instance</param>
        /// <param name="i">the fields i position</param>
        /// <param name="j">the fields j position</param>
        /// <param name="fc">the specified field color</param>
        /// <param name="bgCol">the specified background color</param>
        /// <param name="fancy">flag whether to use color gradients</param>
        /// <param name="random">glag whether to use random coloring</param>
        /// <param name="showProfile">flag whether to show the profile information instead
        /// of whether cells are currently dead or animate</param>
        /// <returns></returns>
        private Brush GetBrush(GameOfLife m, int i, int j, Color fc, Color bgCol, bool fancy, bool random, bool showProfile)
        {
            Brush b;

            // should we display the profile?
            if (showProfile)
            {
                // we had one visit at least for the current cell
                if (m.Profile[i, j] > 0)
                {
                    int v = Math.Min(m.Profile[i, j], 255);
                    b = new SolidBrush(Color.FromArgb(v, 255 - v, 0));
                }
                else
                {
                    // no visit yet, draw bgColor
                    b = new SolidBrush(bgCol);
                }
            }
            else
            {
                // draw the currently living cells in the colors
                // specified by the options
                bool v = m.Envir[i, j];
                if (v)
                {
                    Color c = fc;
                    // if we use fancy/gradient coloring, use color depending on
                    // number of neighbouring living fields
                    if (fancy)
                    {
                        int[] n   = m.GetNeighbourhood(i, j);
                        int   sum = 0;
                        for (int z = 0; z < n.Length; z++)
                        {
                            sum += n[z];
                        }
                        c = ControlPaint.Light(fc, 1 - (sum * 1.0f) / n.Length);
                    }
                    // supercedes fancy/gradient coloring
                    if (random)
                    {
                        if (this.controller.StaticRandomColors)
                        {
                            c = this.controller.RandomFieldColors[i, j];
                        }
                        else
                        {
                            // create a random color
                            c = Color.FromArgb(Controller.RNG.Next(256),
                                               Controller.RNG.Next(256),
                                               Controller.RNG.Next(256));
                        }
                    }
                    b = new SolidBrush(c);
                }
                else
                {
                    b = new SolidBrush(bgCol);
                }
            }
            return(b);
        }