public static bool PaintFill(Color[,] colors, int r, int c, Color ncolor) { if (r < 0 || r >= colors.GetLength (0) || c < 0 || c >= colors.GetLength (1)) return false; if (ncolor == colors [r, c]) return false; return PaintFill (colors, r, c, colors [r, c], ncolor); }
private static void Print(Color[,] colors) { for (int r = 0; r < colors.GetLength (0); ++r) { for (int c = 0; c < colors.GetLength (1); ++c) { Console.Write (colors [r, c].ToString()[0] + " "); } Console.WriteLine (); } Console.WriteLine (); }
private static bool PaintFill(Color[,] colors, int r, int c, Color ocolor, Color ncolor) { if (r < 0 || r >= colors.GetLength (0) || c < 0 || c >= colors.GetLength (1)) return false; bool result = false; if (colors [r, c] == ocolor) { colors [r, c] = ncolor; result = true; result |= PaintFill(colors, r - 1, c, ocolor, ncolor); result |= PaintFill(colors, r + 1, c, ocolor, ncolor); result |= PaintFill(colors, r, c - 1, ocolor, ncolor); result |= PaintFill(colors, r, c + 1, ocolor, ncolor); } return result; }
//////////////////////////////////////////////////////////// /// <summary> /// Construct the image directly from an array of pixels /// </summary> /// <param name="pixels">2 dimensions array containing the pixels</param> /// <exception cref="LoadingFailedException" /> //////////////////////////////////////////////////////////// public Image(Color[,] pixels) : base(IntPtr.Zero) { unsafe { fixed (Color* PixelsPtr = pixels) { uint Width = (uint)pixels.GetLength(0); uint Height = (uint)pixels.GetLength(1); SetThis(sfImage_CreateFromPixels(Width, Height, (byte*)PixelsPtr)); } } if (This == IntPtr.Zero) throw new LoadingFailedException("image"); }
//////////////////////////////////////////////////////////// /// <summary> /// Update the pixels of the image /// </summary> /// <param name="pixels">2 dimensions array containing the pixels</param> /// <param name="x">X position of the rectangle to update</param> /// <param name="y">Y position of the rectangle to update</param> //////////////////////////////////////////////////////////// public void UpdatePixels(Color[,] pixels, uint x, uint y) { unsafe { fixed (Color* PixelsPtr = pixels) { int Width = pixels.GetLength(0); int Height = pixels.GetLength(1); sfImage_UpdatePixels(This, PixelsPtr, new IntRect((int)x, (int)y, Width, Height)); } } }
//////////////////////////////////////////////////////////// /// <summary> /// Construct the image directly from an array of pixels /// </summary> /// <param name="pixels">2 dimensions array containing the pixels</param> /// <exception cref="LoadingFailedException" /> //////////////////////////////////////////////////////////// public Image(Color[,] pixels) : base(IntPtr.Zero) { uint Width = (uint)pixels.GetLength(0); uint Height = (uint)pixels.GetLength(1); // Transpose the array (.Net gives dimensions in reverse order of what SFML expects) Color[,] transposed = new Color[Height, Width]; for (int x = 0; x < Width; ++x) for (int y = 0; y < Height; ++y) transposed[y, x] = pixels[x, y]; unsafe { fixed (Color* PixelsPtr = transposed) { SetThis(sfImage_createFromPixels(Width, Height, (byte*)PixelsPtr)); } } if (CPointer == IntPtr.Zero) throw new LoadingFailedException("image"); }
public static Color[,] recolor(int[,] geo) { Color[,] geolocal = new Color[geo.GetLength(0), geo.GetLength(1)]; Random rn = new Random(); for (int t1 = 0; t1 < geolocal.GetLength(0) / 20; t1++) { for (int t2 = 0; t2 < geolocal.GetLength(1) / 20; t2++) { // int currTheme = (rn.Next(3) * 11) + (rn.Next(2) * 38); // if (currTheme == 2 * 11 || currTheme == 11 + 38) // break; double hue = rn.Next(60) - 15; hue = (Math.Abs(hue * 360) + hue) % 360; for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { if (geo[i + (t1 * 20), j + (t2 * 20)] == gr) { geolocal[i + (t1 * 20), j + (t2 * 20)] = Chroma.RandomBlend(Color.White, Color.FromHsv(hue, rn.NextDouble() / 2.5 + 0.2, 0.8), 0.05, 0.2); } else if (geo[i + (t1 * 20), j + (t2 * 20)] != da)// && geo[i + (t1 * 20), j + (t2 * 20)] != 1187) { geolocal[i + (t1 * 20), j + (t2 * 20)] = Chroma.RandomBlend(Color.White, Color.FromHsv(hue, rn.NextDouble() / 2.5 + 0.2, 0.8), 0.15, 0.3); } } } } } return geolocal; }
public Sprite(Color[,] layout) { _size = new Size(layout.GetLength(0), layout.GetLength(1)); _layout = layout; }