/// <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); }
// 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); }
public void SetColorFunction(ColorFunction function) { _colorFunction = function; rbRed.ColorFunction = function; rbGreen.ColorFunction = function; rbBlue.ColorFunction = function; }
private void setTempColorFunction(ColorFunction newFunction) { if (_colorFunctionTemp != newFunction) { _colorFunctionTemp = newFunction; updateColorFunction(); } }
private void setColorFunctionMode(ColorFunction newFunction) { if (_colorFunctionMode != newFunction) { _colorFunctionMode = newFunction; updateColorFunction(); } }
public void DetachColorFunc( ColorFunction f ) { if (g_modFunctions.Contains(f)) { g_modFunctions.Remove(f); } }
public void AttachColorFunc( ColorFunction f ) { if (!g_modFunctions.Contains(f)) { g_modFunctions.Add(f); } }
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."); }
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."); }
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."); }
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); }
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."); }
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."); }
/// <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; } }
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); }
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(); }
/// <summary> /// Constructor for Stucki dithering /// </summary> /// <param name="colorfunc">Color function</param> public StuckiDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Stucki", "_STU") { }
/// <summary> /// Constructor for Burkes dithering /// </summary> /// <param name="colorfunc">Color function</param> public BurkesDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Burkes", "_BUR") { }
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; } }
/// <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") { }
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") { }
/// <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") { }
public SetColorFunctionModeStripCommand(IAppState appState, ColorForm form, ColorFunction colorFunction) : base(appState) { _form = form; _colorFunction = colorFunction; }
private void setupColorFunction() { _colorFunctionTemp = ColorFunction.NotSet; _colorFunctionMode = ColorFunction.SetColor; updateColorFunction(); }
/// <summary> /// Constructor for Jarvis-Judice-Ninke dithering /// </summary> /// <param name="colorfunc">Color function</param> public JarvisJudiceNinkeDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Jarvis-Judice-Ninke", "_JJN") { }
/// <summary> /// Constructor for Sierra dithering /// </summary> /// <param name="colorfunc">Color function</param> public SierraDitheringRGBByte(ColorFunction colorfunc) : base(colorfunc, "Sierra", "_SIE") { }