Exemplo n.º 1
0
        /// <summary>
        ///     Creates a metaball texture.
        ///     <p>
        ///         <b>Beware: Don't forget to dispose the texture at the end. Noone will take care of that for you.</b>
        ///     </p>
        /// </summary>
        /// <param name="radius">Determines the distance at which the metaball has influence.</param>
        /// <param name="textureFalloff">The texture falloff.</param>
        /// <param name="colorFalloff">The color falloff.</param>
        /// <param name="colorFunction">
        ///     A function that determines how to colour the metaball. Has no effect on their shape. It is purely
        ///     aesthetic.
        /// </param>
        /// <param name="graphicsDevice">The graphics device.</param>
        /// <returns>
        ///     The texture used for making metabalss
        /// </returns>
        public static Texture2D CreateMetaballTexture(int radius, FalloffFunction textureFalloff,
                                                      FalloffFunction colorFalloff, ColorFunction colorFunction, GraphicsDevice graphicsDevice)
        {
            int length = radius * 2;

            Color[] colors = new Color[length * length];

            for (int y = 0; y < length; y++)
            {
                for (int x = 0; x < length; x++)
                {
                    float distance = Vector2.Distance(Vector2.One, new Vector2(x, y) / radius);

                    // This is the falloff function used to make the metaballs.
                    float alpha = textureFalloff(distance, x, y);

                    // We'll use a smaller, inner gradient to colour the center of the metaballs a different colour. This is purely aesthetic.
                    float innerGradient = colorFalloff(distance, x, y);
                    colors[y * length + x]   = new Color(colorFunction(alpha, innerGradient));
                    colors[y * length + x].A = (byte)MathHelper.Clamp(alpha * 256f + 0.5f, 0f, 255f);
                }
            }

            Texture2D tex = new Texture2D(graphicsDevice, radius * 2, radius * 2);

            tex.SetData(colors);
            return(tex);
        }
Exemplo n.º 2
0
        //  ToolTip _tt; looks like tool-tips messes with mouse events.


        public ColorCursor(ColorFunction colorFunction, PictureBox bitmap, TextBox textbox, ColorCursorChangeCallBack callback, YColor initialColor)
        {
            _bitmap        = bitmap;
            _textbox       = textbox;
            _colorFunction = colorFunction;
            _callback      = callback;
            //_tt = new ToolTip();

            HueBackground = new Bitmap(255, 10);
            Graphics g = Graphics.FromImage(HueBackground);

            for (int i = 0; i < 256; i++)
            {
                YColor c = YColor.FromAhsl(255, (byte)i, 255, 127);
                Pen    p = new Pen(c.toColor(), 1);
                g.DrawLine(p, i, 0, i, 11);
                p.Dispose();
            }
            g.Dispose();



            _bitmap.MouseDown    += MouseAction;
            _bitmap.MouseMove    += MouseAction;
            _textbox.Text         = _value.ToString();
            _textbox.TextChanged += textBox_TextChanged;
            _textbox.MaxLength    = 3;
            setNewColor(initialColor);
        }
Exemplo n.º 3
0
 public void SetColorFunction(ColorFunction function)
 {
     _colorFunction        = function;
     rbRed.ColorFunction   = function;
     rbGreen.ColorFunction = function;
     rbBlue.ColorFunction  = function;
 }
Exemplo n.º 4
0
 private void setTempColorFunction(ColorFunction newFunction)
 {
     if (_colorFunctionTemp != newFunction)
     {
         _colorFunctionTemp = newFunction;
         updateColorFunction();
     }
 }
Exemplo n.º 5
0
 private void setColorFunctionMode(ColorFunction newFunction)
 {
     if (_colorFunctionMode != newFunction)
     {
         _colorFunctionMode = newFunction;
         updateColorFunction();
     }
 }
Exemplo n.º 6
0
 public void DetachColorFunc(
     ColorFunction f
     )
 {
     if (g_modFunctions.Contains(f))
     {
         g_modFunctions.Remove(f);
     }
 }
Exemplo n.º 7
0
 public void AttachColorFunc(
     ColorFunction f
     )
 {
     if (!g_modFunctions.Contains(f))
     {
         g_modFunctions.Add(f);
     }
 }
Exemplo n.º 8
0
        private void DrawProvinces()
        {
            AddLogEntry("Began drawing provinces.bmp...");
            ColorFunction colorFunction = delegate(int x, int y)
            {
                return(ProvinceGrid[x, y].Color);
            };

            GenerateBitmap(ProvincesMap, colorFunction);
            AddLogEntry("Finished drawing provinces.bmp.");
        }
Exemplo n.º 9
0
        private void DrawTopology()
        {
            AddLogEntry("Began drawing topology.bmp...");
            ColorFunction colorFunction = delegate(int x, int y)
            {
                byte altitude = (byte)MapGenerator.GetAltitude(x, y);
                return(Color.FromArgb(altitude, altitude, altitude));
            };

            GenerateBitmap(TopologyMap, colorFunction);
            AddLogEntry("Finished drawing topology.bmp.");
        }
Exemplo n.º 10
0
        private void DrawTerrain()
        {
            AddLogEntry("Began drawing terrain.bmp...");
            int           sealevel      = Settings.SeaLevel;
            ColorFunction colorFunction = delegate(int x, int y)
            {
                byte   altitude    = (byte)MapGenerator.GetAltitude(x, y);
                double temperature = MapGenerator.GetTemperature(x, y);
                return(GetTerrain(altitude, temperature));
            };

            GenerateBitmap(TerrainMap, colorFunction);
            AddLogEntry("Finished drawing terrain.bmp.");
        }
Exemplo n.º 11
0
        public static ColorFunction GetColorFunction(Keys keys)
        {
            ColorFunction function = ColorFunction.NotSet;

            if (keys == Keys.Control)
            {
                function = ColorFunction.AddToColor;
            }
            else if (keys == (Keys.Shift | Keys.Control))
            {
                function = ColorFunction.RemoveFromColor;
            }
            return(function);
        }
Exemplo n.º 12
0
        private void DrawCulturesPreview()
        {
            AddLogEntry("Began drawing cultures preview...");
            ColorFunction colorFunction = delegate(int x, int y)
            {
                Province province = ProvinceGrid[x, y];
                if (province.Culture != null)
                {
                    return(province.Culture.Color);
                }
                return(Color.Black);
            };

            GenerateBitmap(CulturesMap, colorFunction);
            AddLogEntry("Finished drawing cultures preview.");
        }
Exemplo n.º 13
0
        private void DrawRivers()
        {
            AddLogEntry("Began drawing rivers.bmp...");
            int           sealevel      = Settings.SeaLevel;
            ColorFunction colorFunction = delegate(int x, int y)
            {
                byte  altitude = (byte)MapGenerator.GetAltitude(x, y);
                Color color    = RiversWater;
                if (altitude >= sealevel)
                {
                    color = RiversLand;
                }
                return(color);
            };

            GenerateBitmap(RiversMap, colorFunction);
            AddLogEntry("Finished drawing rivers.bmp.");
        }
Exemplo n.º 14
0
 /// <summary>
 /// Returns the color of a field in the matrix.
 /// </summary>
 /// <param name="isOne">
 /// Is the field set to 1.
 /// </param>
 /// <param name="toggle">
 /// Is the value of the field changed?
 /// </param>
 /// <param name="EditStatus">
 /// The edit status of this field, i.e. of this row or column.
 /// </param>
 /// <param name="function">
 /// What will be drawn with this color.
 /// </param>
 /// <returns></returns>
 public Color this[bool isOne, bool toggle, EditStatus status, ColorFunction function]
 {
     get
     {
         return(fieldColorSet[
                    isOne ? 1 : 0,
                    toggle ? 1 : 0,
                    (int)status,
                    (int)function
                ]);
     }
     set
     {
         fieldColorSet[
             isOne ? 1 : 0,
             toggle ? 1 : 0,
             (int)status,
             (int)function
         ] = value;
     }
 }
Exemplo n.º 15
0
        private void GenerateBitmap(Bitmap bitmap, ColorFunction colorFunction)
        {
            BitmapData data   = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
            int        stride = data.Stride;

            unsafe
            {
                byte *pointer = (byte *)data.Scan0;
                for (int x = 0; x < bitmap.Width; x++)
                {
                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        Color color = colorFunction(x, y);
                        pointer[x * 3 + y * stride]     = color.B;
                        pointer[x * 3 + y * stride + 1] = color.G;
                        pointer[x * 3 + y * stride + 2] = color.R;
                    }
                }
            }
            bitmap.UnlockBits(data);
        }
Exemplo n.º 16
0
        public void setNewColor(YColor color)
        {
            _color = color;

            if ((_colorFunction == ColorFunction.COLOR_H) || (_colorFunction == ColorFunction.COLOR_R))
            {
                _colorFunction = _color.isHSL ? ColorFunction.COLOR_H : ColorFunction.COLOR_R;
            }

            if ((_colorFunction == ColorFunction.COLOR_S) || (_colorFunction == ColorFunction.COLOR_G))
            {
                _colorFunction = _color.isHSL ? ColorFunction.COLOR_S : ColorFunction.COLOR_G;
            }

            if ((_colorFunction == ColorFunction.COLOR_L) || (_colorFunction == ColorFunction.COLOR_B))
            {
                _colorFunction = _color.isHSL ? ColorFunction.COLOR_L : ColorFunction.COLOR_B;
            }

            switch (_colorFunction)
            {
            case ColorFunction.COLOR_H: /*_tt.SetToolTip(_bitmap, "Hue");*/ _value = _color.H; updateTextBox(); break;

            case ColorFunction.COLOR_R: /*_tt.SetToolTip(_bitmap, "Red"); */ _value = _color.R; updateTextBox(); break;

            case ColorFunction.COLOR_G: /*_tt.SetToolTip(_bitmap, "Green");*/ _value = _color.G; updateTextBox(); break;

            case ColorFunction.COLOR_B: /*_tt.SetToolTip(_bitmap, "Blue"); */ _value = _color.B; updateTextBox(); break;

            case ColorFunction.COLOR_S: /*_tt.SetToolTip(_bitmap, "Saturation");*/ _value = _color.S; updateTextBox(); break;

            case ColorFunction.COLOR_L: /*_tt.SetToolTip(_bitmap, "Luminosity"); */ _value = _color.L; updateTextBox(); break;

            case ColorFunction.COLOR_A: /*_tt.SetToolTip(_bitmap, "Alpha-transparency"); */ _value = _color.A; updateTextBox(); break;
            }
            redraw();
        }
Exemplo n.º 17
0
 /// <summary>
 /// Constructor for Stucki dithering
 /// </summary>
 /// <param name="colorfunc">Color function</param>
 public StuckiDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Stucki", "_STU")
 {
 }
Exemplo n.º 18
0
 /// <summary>
 /// Constructor for Burkes dithering
 /// </summary>
 /// <param name="colorfunc">Color function</param>
 public BurkesDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Burkes", "_BUR")
 {
 }
Exemplo n.º 19
0
        public void ApplyColorFunction(ColorFunction colorFunction)
        {
            foreach (var edgeCoord in edgeCoordinates)
            {
                var colors      = new List <Color>();
                var edge        = edgeCoord.Key;
                var edgeCoords  = edgeCoord.Value;
                var startCoords = edgeCoords.Item1;
                var endCoords   = edgeCoords.Item2;

                var reverseList = false;

                var x1 = Math.Min(startCoords.Item1, endCoords.Item1);
                var y1 = Math.Min(startCoords.Item2, endCoords.Item2);
                var z1 = Math.Min(startCoords.Item3, endCoords.Item3);
                var x2 = Math.Max(startCoords.Item1, endCoords.Item1);
                var y2 = Math.Max(startCoords.Item2, endCoords.Item2);
                var z2 = Math.Max(startCoords.Item3, endCoords.Item3);

                int  i1;
                int  i2;
                bool ix = false;
                bool iy = false;
                bool iz = false;

                if (x1 != x2)
                {
                    i1 = x1;
                    i2 = x2;
                    ix = true;
                }
                else if (y1 != y2)
                {
                    i1 = y1;
                    i2 = y2;
                    iy = true;
                }
                else
                {
                    i1 = z1;
                    i2 = z2;
                    iz = true;
                }

                if (x1 < startCoords.Item1)
                {
                    reverseList = true;
                }
                if (y1 < startCoords.Item2)
                {
                    reverseList = true;
                }
                if (z1 < startCoords.Item3)
                {
                    reverseList = true;
                }

                for (var i = i1; i <= i2; i++)
                {
                    Color color;
                    if (ix)
                    {
                        color = colorFunction.Invoke(i, y1, z1);
                    }
                    else if (iy)
                    {
                        color = colorFunction.Invoke(x1, i, z1);
                    }
                    else
                    {
                        color = colorFunction.Invoke(x1, y1, i);
                    }
                    colors.Add(color);
                }

                if (reverseList)
                {
                    colors.Reverse();
                }

                //edge.ledColors = colors;
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Constructor for fake dithering (no dither, just color reduction)
 /// </summary>
 /// <param name="colorfunc"></param>
 /// <returns></returns>
 public FakeDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "No dithering", "_NONE")
 {
 }
 /// <summary>
 /// Constructor for Atkinson dithering
 /// </summary>
 /// <param name="colorfunc">Color function</param>
 public AtkinsonDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Atkinson", "_ATK")
 {
 }
Exemplo n.º 22
0
 public void SwitchToRainbow()
 {
     CF = new ColorFunction(ColorMaps.rainbowScheme);
     RecreateImage();
     OnNewGridLoad();
 }
 /// <summary>
 /// Constructor for Sierra two row dithering
 /// </summary>
 /// <param name="colorfunc">Color function</param>
 public SierraTwoRowDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "SierraTwoRow", "_SIE2R")
 {
 }
Exemplo n.º 24
0
 /// <summary>
 /// Constructor for Floyd-Steinberg dithering
 /// </summary>
 /// <param name="colorfunc">Color function</param>
 public FloydSteinbergDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Floyd-Steinberg", "_FS")
 {
 }
 /// <summary>
 /// Constructor for Sierra lite dithering
 /// </summary>
 /// <param name="colorfunc">Color function</param>
 public SierraLiteDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "SierraLite", "_SIEL")
 {
 }
Exemplo n.º 26
0
 public SetColorFunctionModeStripCommand(IAppState appState, ColorForm form, ColorFunction colorFunction) : base(appState)
 {
     _form          = form;
     _colorFunction = colorFunction;
 }
Exemplo n.º 27
0
 private void setupColorFunction()
 {
     _colorFunctionTemp = ColorFunction.NotSet;
     _colorFunctionMode = ColorFunction.SetColor;
     updateColorFunction();
 }
Exemplo n.º 28
0
 /// <summary>
 /// Constructor for Jarvis-Judice-Ninke dithering
 /// </summary>
 /// <param name="colorfunc">Color function</param>
 public JarvisJudiceNinkeDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Jarvis-Judice-Ninke", "_JJN")
 {
 }
Exemplo n.º 29
0
 /// <summary>
 /// Constructor for Sierra dithering
 /// </summary>
 /// <param name="colorfunc">Color function</param>
 public SierraDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Sierra", "_SIE")
 {
 }