public static Color[] GetColorRamp(ColorRampEnum index) { if (index == ColorRampEnum.Default) return _default; else return null; }
public static Color[] GetColorRamp(ColorRampEnum index) { if (index == ColorRampEnum.Default) { return(_default); } else { return(null); } }
/// <summary> /// Init a new Voronoi engine /// </summary> /// <param name="nbOfPoints"></param> public VoronoiEngine(int nbOfPoints, ColorRampEnum colorRamp = ColorRampEnum.RAINBOW, ApplyColorDirectionEnum colorDirection = ApplyColorDirectionEnum.NONE) : this() { for (var i = 0; i < nbOfPoints; i++) { this._points.Add(new VoronoiPoint { Color = Color.Black, InitialCoordinates = new Vector2 { X = this._random.Next(0, 100) / 100.0f, Y = this._random.Next(0, 100) / 100.0f } }); } this.ApplyColorRamp(colorRamp, colorDirection); }
/// <summary> /// Generate a color ramp according to provided enum /// </summary> /// <param name="ramp"></param> /// <returns></returns> private Color[] GenerateColorRamp(ColorRampEnum ramp) { Color[] res = new Color[256]; if (ramp == ColorRampEnum.GRAY_SCALE) { for (int i = 0; i < 256; i++) { res[i] = new Color(i, i, i); } } else if (ramp == ColorRampEnum.RAINBOW) { for (int i = 0; i < 256; i++) { res[i] = Toolkit.FromHsl((float)i / 256f, 1f, 0.5f); var d = res[i]; } } return(res); }
/// <summary> /// Apply a color ramp according to provided enum /// </summary> /// <param name="ramp"></param> /// <returns></returns> private void ApplyColorRamp(ColorRampEnum ramp, ApplyColorDirectionEnum colorDirection = ApplyColorDirectionEnum.NONE) { var pointCount = this._points.Count; if (colorDirection == ApplyColorDirectionEnum.HORIZONTAL) { this._points.Sort((a, b) => a.RelativeCoordinates.X.CompareTo(b.RelativeCoordinates.X)); } else if (colorDirection == ApplyColorDirectionEnum.VERTICAL) { this._points.Sort((a, b) => a.RelativeCoordinates.Y.CompareTo(b.RelativeCoordinates.Y)); } if (ramp == ColorRampEnum.GRAY_SCALE) { for (int i = 0; i < pointCount; i++) { var comp = (int)(i * 256.0 / pointCount); this._points[i].Color = new Color(comp, comp, comp); } } else if (ramp == ColorRampEnum.RAINBOW) { for (int i = 0; i < pointCount; i++) { this._points[i].Color = Toolkit.FromHsl(i / 20.0f, 1f, 0.5f); } } else if (ramp == ColorRampEnum.OCEAN) { var colors = Toolkit.GenerateRampBetween(Color.Blue, Color.White, this._points.Count); for (int i = 0; i < this._points.Count; i++) { this._points[i].Color = colors[i]; } } else if (ramp == ColorRampEnum.DARK_LEAF) { var colors = Toolkit.GenerateRampBetween(Color.Green, Color.Black, this._points.Count); for (int i = 0; i < this._points.Count; i++) { this._points[i].Color = colors[i]; } } else if (ramp == ColorRampEnum.LAVA) { var colors = Toolkit.GenerateRampBetween(Color.Yellow, Color.Red, this._points.Count); for (int i = 0; i < this._points.Count; i++) { this._points[i].Color = colors[i]; } } else if (ramp == ColorRampEnum.RANDOM) { for (int i = 0; i < pointCount; i++) { this._points[i].Color = new Color( this._random.Next(0, 255), this._random.Next(0, 255), this._random.Next(0, 255) ); } } }
/// <summary> /// Init a new VoronoiEngine with a list of points /// </summary> /// <param name="points"></param> public VoronoiEngine(List <VoronoiPoint> points, ColorRampEnum colorRamp = ColorRampEnum.RAINBOW, ApplyColorDirectionEnum colorDirection = ApplyColorDirectionEnum.NONE) { this._points = points; this.ApplyColorRamp(colorRamp, colorDirection); }
/// <summary> /// Generate plasma effect on a device (as a Texture2D) with given width and height /// <returns></returns> public Texture2D GeneratePlasma(GraphicsDevice device, int width, int height, ColorRampEnum colorRamp = ColorRampEnum.GRAY_SCALE, int shiftX = 0, int shiftY = 0, int colorRampShift = 0, int ratio = 50) { Texture2D rect = new Texture2D(device, width, height); Color[] data = new Color[width * height]; /*for (int x = 0; x < width; x++) * { * for (int y = 0; y < height; y++) * { * var p = this.GetPlasmaPatternAt(x, y, width, height); * var color = this._colorRamp[colorRamp][(p + colorRampShift) % 256]; * data[((y) * width) + (x)] = color; * } * }*/ /*for (int i=0; i < data.Length; i++) * { * var p = this.GetPlasmaPatternAt(i%width, i/width, width, height); * var color = this._colorRamp[colorRamp][(p + colorRampShift) % 256]; * data[i] = color; * }*/ var stepX = ratio; var stepY = ratio; for (int x = 0; x < width; x += stepX) { for (int y = 0; y < height; y += stepY) { var p = this.GetPlasmaPatternAt(x + shiftX, y + shiftY, width, height); var color = this._colorRamp[colorRamp][(p + colorRampShift) % 256]; var topA = Math.Min(x + stepX, width); var topB = Math.Min(y + stepY, height); for (int a = x; a < topA; a++) { for (int b = y; b < topB; b++) { data[((b) * width) + (a)] = color; } } } } rect.SetData(data); return(rect); }