private static void RunSelfTest(IPixelRenderer renderer) { Log.InfoFormat("Running self-test on {0}: {1} pixels", renderer, renderer.PixelCount); Log.InfoFormat("Red"); for (int i = 0; i < renderer.PixelCount; i++) { renderer.SetPixels(n => n == i ? 0xff0000 : 0x000000); renderer.Show(); Thread.Sleep(50); } Log.InfoFormat("Green"); for (int i = 0; i < renderer.PixelCount; i++) { renderer.SetPixels(n => n == i ? 0x00ff00 : 0x000000); renderer.Show(); Thread.Sleep(50); } Log.InfoFormat("Blue"); for (int i = 0; i < renderer.PixelCount; i++) { renderer.SetPixels(n => n == i ? 0x0000ff : 0x000000); renderer.Show(); Thread.Sleep(50); } }
/// <summary> /// Applies a transform function over the current state of all pixels /// </summary> /// <param name="map">A Func of the form (inputPixel,index) => outputPixel</param> public static void Apply(this IPixelRenderer renderer, Func <uint, int, uint> map) { var pixels = renderer.GetPixels(); var output = pixels.Select(map).ToArray(); renderer.SetPixels(output); }
public void SetPixels(uint[] pixels, int offset = 0) { Contract.Requires(pixels != null); var mapped = Transpose(pixels, offset); _renderer.SetPixels(mapped, offset); }
/// <summary> /// Sets all pixels based on a map function over pixel index /// </summary> /// <remarks>For convenience this overload maps to int, not uint</remarks> public static void SetPixels(this IPixelRenderer renderer, Func <int, int> map) { var rgbs = Enumerable.Range(0, renderer.PixelCount) .Select(map) .Cast <uint>() .ToArray() ; renderer.SetPixels(rgbs); }
public static void SetPixels(this IPixelRenderer renderer, IEnumerable <Color> pixels) { var rgbs = pixels .Take(renderer.PixelCount) .Select(ToRgb) .ToArray() ; renderer.SetPixels(rgbs); }