public List <Pixel> SingleColorFrame(Pixel pixel) { var frame = Enumerable.Range(0, OpcConstants.FadeCandy.MaxPixels).Select(i => pixel).ToList(); return(frame); }
public async Task BlinkRandomThenBright() { SetDitheringAndInterpolation(true); Pixel[] lightColors = { Pixel.RedPixel(), Pixel.YellowPixel(), Pixel.GreenPixel(), Pixel.BluePixel() }; var rng = new Random(); var basePixels = new Pixel[50]; for (var i = 0; i < basePixels.Length; i++) { var pixel = lightColors[rng.Next(4)]; basePixels[i] = pixel; } var allMax = new Pixel[50]; for (var i = 0; i < allMax.Length; i++) { var baseBright = 128; var red = baseBright; var green = baseBright; var blue = baseBright; if (basePixels[i].Red > red) { red = basePixels[i].Red; } if (basePixels[i].Green > green) { green = basePixels[i].Green; } if (basePixels[i].Blue > blue) { blue = basePixels[i].Blue; } allMax[i] = new Pixel(red, green, blue); } var fadeCount = 0; while (fadeCount < 20) { await Task.Delay(150); var pixels = new Pixel[50]; var fade = rng.NextDouble(); for (var i = 0; i < pixels.Length; i++) { var basePixel = basePixels[i]; var brightAdjustedPixel = new Pixel( (byte)(basePixel.Red * fade), (byte)(basePixel.Green * fade), (byte)(basePixel.Blue * fade) ); pixels[i] = brightAdjustedPixel; } WriteFrame(pixels.ToList()); fadeCount++; } await Task.Delay(500); WriteFrame(basePixels.ToList()); await Task.Delay(1000); WriteFrame(allMax.ToList()); await Task.Delay(1000); WriteFrame(SingleColorFrame(OpcConstants.DarkPixel)); await Task.Delay(200); WriteFrame(SingleColorFrame(OpcConstants.DarkPixel)); }