public override void Animate(IViewPublisher publisher, CancellationToken token) { for (int loopi = 0; loopi < 1000; loopi++) { DispatcherInvocker(() => { var colors = new List <Brush>(); for (int i = 0; i < TOTAL_LED; i++) { var green = BrushHelper.BuildBrush(0, 255, 0); colors.Add(green); } for (int i = 0; i < 5; i++) { var ind = rd.Next(0, TOTAL_LED); colors[ind] = BrushHelper.BuildBrush(255, 255, 255); } publisher.UpdateAllLeds(colors); }); token.ThrowIfCancellationRequested(); WaitAction(); } }
public override void Animate(IViewPublisher publisher, CancellationToken token) { string path = string.Empty; MainWindow.MainDispatcher.Invoke(() => { FolderBrowserDialog openFileDialog = new FolderBrowserDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { path = openFileDialog.SelectedPath; } }); if (!string.IsNullOrEmpty(path)) { var files = Directory.GetFiles(path); do { foreach (var file in files) { var rows = File.ReadAllLines(file); foreach (string row in rows) { if (row.Length >= (TOTAL_LED * 3 * 3)) // because 3 colors RGB , each color encoded on 3 char { DispatcherInvocker(() => { var colors = new List <Brush>(); for (int id = 0; id < TOTAL_LED; id++) { var red = Convert.ToInt32(row.Substring(id * 9, 3)); var green = Convert.ToInt32(row.Substring(id * 9 + 3, 3)); var blue = Convert.ToInt32(row.Substring(id * 9 + 6, 3)); var b = BrushHelper.BuildBrush(red, green, blue); colors.Add(b); } publisher.UpdateAllLeds(colors); }); token.ThrowIfCancellationRequested(); WaitAction(); } } } } while (!token.IsCancellationRequested); } }
public override void Animate(IViewPublisher publisher, CancellationToken token) { int head = 0; bool running = true; int loop = 0; while (loop < 1000) { DispatcherInvocker(() => { var colors = new List <Brush>(); for (int i = 0; i < TOTAL_LED; i++) { int blue = 0; if (i == head) { blue = 50; } if ((i - 1) == head) { blue = 150; } if ((i - 2) == head) { blue = 255; } colors.Add(BrushHelper.BuildBrush(0, 0, blue)); } publisher.UpdateAllLeds(colors); }); token.ThrowIfCancellationRequested(); head++; if (head > TOTAL_LED) { head = 0; } WaitAction(); loop++; } }
public override void Animate(IViewPublisher publisher, CancellationToken token) { Brush colorRing1 = null; Brush colorRing2 = null; Brush colorRing3 = null; Brush colorRing4 = null; DispatcherInvocker(() => { colorRing1 = BrushHelper.BuildBrush(0, 0, 0); colorRing2 = BrushHelper.BuildBrush(0, 0, 0); colorRing3 = BrushHelper.BuildBrush(0, 0, 0); colorRing4 = BrushHelper.BuildBrush(0, 0, 0); }); while (true) { for (int loopi = 1; loopi <= 1530; loopi = loopi + 30) { DispatcherInvocker(() => { var colors = new List <Brush>(); colorRing4 = colorRing3; colorRing3 = colorRing2; colorRing2 = colorRing1; colorRing1 = BrushHelper.RGBRadiant(loopi); colors.AddRange(Enumerable.Repeat(colorRing4, 24).ToList()); colors.AddRange(Enumerable.Repeat(colorRing3, 16).ToList()); colors.AddRange(Enumerable.Repeat(colorRing2, 12).ToList()); colors.AddRange(Enumerable.Repeat(colorRing1, 8).ToList()); publisher.UpdateAllLeds(colors); }); token.ThrowIfCancellationRequested(); WaitActionCustom(100); } } }
public override void Animate(IViewPublisher publisher, CancellationToken token) { for (int loopi = 0; loopi < 1000; loopi++) { DispatcherInvocker(() => { var colors = new List <Brush>(); for (int i = 0; i < TOTAL_LED; i++) { var random = getRandomBrush(); colors.Add(random); } publisher.UpdateAllLeds(colors); }); token.ThrowIfCancellationRequested(); WaitAction(); } }
public override void Animate(IViewPublisher publisher, CancellationToken token) { int step = 100; var colorsKey = Enumerable.Range(0, step).Select(x => x * (1530 / step)).OrderByDescending(x => x).ToList(); int i = 0; while (true) { DispatcherInvocker(() => { var colors = new List <Brush>(); for (int led_i = 0; led_i < TOTAL_LED; led_i++) { int indice = i + led_i; if (indice >= step) { indice = indice - step; } colors.Add(BrushHelper.RGBRadiant(colorsKey[indice])); } publisher.UpdateAllLeds(colors); }); token.ThrowIfCancellationRequested(); WaitActionCustom(50); i++; if (i > step) { i = 0; } } }
public override void Animate(IViewPublisher publisher, CancellationToken token) { do { for (int i = 0; i < 24; i++) { DispatcherInvocker(() => { //ring 1; int a1 = i; int b1 = i - 1; if (b1 < 0) { b1 = b1 + 24; } int c1 = i - 2; if (c1 < 0) { c1 = c1 + 24; } int d1 = i - 3; if (d1 < 0) { d1 = d1 + 24; } //ring2 int a2 = secondRing[a1] + 24; int b2 = a2 - 1; if (b2 < 24) { b2 = b2 + 16; } int c2 = a2 - 2; if (c2 < 24) { c2 = c2 + 16; } //ring3 int a3 = thirdRing[a1] + 24 + 16; int b3 = a3 - 1; if (b3 < (24 + 16)) { b3 = b3 + 12; } //ring4 int a4 = fourthRing[a1] + 24 + 16 + 12; var brushes = Enumerable.Repeat(0, 60).Select(x => BrushHelper.BuildBrush(0, 0, 0)).ToList(); brushes[d1] = BrushHelper.BuildBrush(0, 0, 40); brushes[c1] = BrushHelper.BuildBrush(0, 0, 105); brushes[b1] = BrushHelper.BuildBrush(0, 0, 175); brushes[a1] = BrushHelper.BuildBrush(0, 0, 255); //if(a1 != 0 && a1 != 6 && a1 != 12 && a1 != 18) if (a1 != 4 && a1 != 10 && a1 != 16 && a1 != 22) { brushes[c2] = BrushHelper.BuildBrush(0, 0, 55); } brushes[b2] = BrushHelper.BuildBrush(0, 0, 150); brushes[a2] = BrushHelper.BuildBrush(0, 0, 255); brushes[b3] = BrushHelper.BuildBrush(0, 0, 120); brushes[a3] = BrushHelper.BuildBrush(0, 0, 255); brushes[a4] = BrushHelper.BuildBrush(0, 0, 255); publisher.UpdateAllLeds(brushes); }); token.ThrowIfCancellationRequested(); WaitActionCustom(30); } } while (!token.IsCancellationRequested); }
public const int TOTAL_LED = 60; //24+16+12+8 abstract public void Animate(IViewPublisher publisher, CancellationToken token);
public void Animate(string scenario, IViewPublisher publisher, CancellationToken token) { var s = Get(scenario); s.Animate(publisher, token); }