Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of Gradient.
        /// </summary>
        static GradientPresets()
        {
            // Grayscale gradient color keys
            var grayscaleColorKeys = new List<GradientKey>
            {
                new GradientKey(new Color(1, 0, 0, 0), 0),
                new GradientKey(new Color(1,1,1,1), 1)
            };

            // RGB gradient color keys
            var rgbColorKeys = new List<GradientKey>
            {
                new GradientKey(new Color(1, 255, 0, 0), 0),
                new GradientKey(new Color(1, 0, 255, 0), 0.5f),
                new GradientKey(new Color(1, 0, 0, 255), 1)
            };

            // RGBA gradient color keys
            var rgbaColorKeys = new List<GradientKey>
            {
                new GradientKey(new Color(1, 255, 0, 0), 0),
                new GradientKey(new Color(1, 0, 255, 0), 1 / 3f),
                new GradientKey(new Color(1, 0, 0, 255), 2 / 3f),
                new GradientKey(new Color(1, 0, 0, 0), 1)
            };

            // RGBA gradient alpha keys
            var rgbaAlphaKeys = new List<GradientAlphaKey> {new GradientAlphaKey(0, 2 / 3f), new GradientAlphaKey(1, 1)};

            // Terrain gradient color keys
            var terrainColorKeys = new List<GradientKey>
            {
                new GradientKey(new Color(255, 0, 0, 128), 0),
                new GradientKey(new Color(255, 32, 64, 128), 0.4f),
                new GradientKey(new Color(255, 64, 96, 191), 0.48f),
                new GradientKey(new Color(255, 0, 191, 0), 0.5f),
                new GradientKey(new Color(255, 191, 191, 0), 0.625f),
                new GradientKey(new Color(255, 159, 96, 64), 0.85f),
                new GradientKey(new Color(255, 128, 255, 255), 0.98f),
                new GradientKey(new Color(255, 240, 240, 250), 1)
            };

            // Generic gradient alpha keys
            var alphaKeys = new List<GradientAlphaKey> {new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1)};

            _empty = new Gradient();

            _rgb = new Gradient();
            _rgb.SetKeys(rgbColorKeys.ToArray());

            _rgba = new Gradient();
            _rgba.SetKeys(rgbaColorKeys.ToArray());

            _grayscale = new Gradient();
            _grayscale.SetKeys(grayscaleColorKeys.ToArray());

            _terrain = new Gradient();
            _terrain.SetKeys(terrainColorKeys.ToArray());
        }
Exemplo n.º 2
0
		/// <summary>
		/// Creates a texture map for the current content of the noise map.
		/// </summary>
		/// <param name="gradient">The gradient to color the texture map with.</param>
		/// <returns>The created texture map.</returns>
		public Color[] GetTexture(Gradient gradient)
		{
			//Bitmap map = new Bitmap (_width, _height, System.Drawing.Imaging.PixelFormat.DontCare);
			Color[] pixels = new Color[_width * _height];
			for (int x = 0, locX = 0; x < _width; x++, locX++) {
				for (int y = 0, locY = 0; y < _height; y++, locY++){
					float sample;
					if (!float.IsNaN(_borderValue) &&
					    (x == 0 || x== _width - _ucBorder | y == 0 || y == _height - _ucBorder))
					{
						sample = _borderValue;
					}
					else
					{
						sample = _data[x, y];
					}
					//map.SetPixel(x, y, gradient.Evaluate((sample + 1) / 2));
					pixels[x + y * _width] = gradient.Evaluate(locX, locY, (sample + 1) / 2);
					if (locY >= 9)
						locY = 0;
				}
				if (locX >= 9)
					locX = 0;
			}
			return pixels;

			/*var texture = new Texture2D(_width, _height);
			var pixels = new Color[_width * _height];
			for (var x = 0; x < _width; x++)
			{
				for (var y = 0; y < _height; y++)
				{
					float sample;
					if (!float.IsNaN(_borderValue) &&
					    (x == 0 || x == _width - _ucBorder || y == 0 || y == _height - _ucBorder))
					{
						sample = _borderValue;
					}
					else
					{
						sample = _data[x, y];
					}
					pixels[x + y * _width] = gradient.Evaluate((sample + 1) / 2);
				}
			}
			texture.SetPixels(pixels);
			texture.wrapMode = TextureWrapMode.Clamp;
			texture.Apply();
			return texture;*/
		}
Exemplo n.º 3
0
 public static Gradient CreateGradient(List<GradientKey> keys)
 {
     Gradient grad = new Gradient ();
     grad.SetKeys (keys.ToArray ());
     return grad;
 }