public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken) { var r = new Random(); var center = EffectSettings.LocationCenter; var orderedLeftLayer = layer.OrderByDescending(x => x.LightLocation.Angle(center.X, center.Y)).GetLeft(); var ordereRightLayer = layer.OrderByDescending(x => x.LightLocation.Angle(center.X, center.Y)).GetRight(); var toDark = r.NextDouble() >= 0.5; while (!cancellationToken.IsCancellationRequested) { var randomLeftColor = RGBColor.Random(r); var randomRightColor = RGBColor.Random(r); foreach (var light in orderedLeftLayer) { Task.Run(async() => { var angle = light.LightLocation.Angle(center.X, center.Y).Move360(91); var timeSpan = waitTime() / 360 * angle; await Task.Delay(timeSpan); //Debug.WriteLine($"{light.Id} Angle {angle} and timespan {timeSpan.TotalMilliseconds}"); light.SetState(cancellationToken, randomLeftColor, 1, waitTime() / 2); if (toDark) { await Task.Delay(waitTime() * 1.1); await Task.Delay(timeSpan); light.SetBrightness(cancellationToken, 0, waitTime() / 2); } }); } await Task.Delay(waitTime() * 1.1); foreach (var light in ordereRightLayer) { Task.Run(async() => { var angle = Math.Abs(light.LightLocation.Angle(center.X, center.Y).Move360(271) - 180); var timeSpan = waitTime() / 360 * angle; await Task.Delay(timeSpan); //Debug.WriteLine($"{light.Id} Angle {angle} and timespan {timeSpan.TotalMilliseconds}"); light.SetState(cancellationToken, randomRightColor, 1, waitTime() / 2); if (toDark) { await Task.Delay(waitTime() * 1.1); await Task.Delay(timeSpan); light.SetBrightness(cancellationToken, 0, waitTime() / 2); } }); } await Task.Delay(waitTime() * 1.1); } }
public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken) { var r = new Random(); var center = EffectSettings.LocationCenter; var orderedLayer = layer.OrderByDescending(x => x.LightLocation.Angle(center.X, center.Y)); while (!cancellationToken.IsCancellationRequested) { var randomColor = RGBColor.Random(r); foreach (var light in orderedLayer) { Task.Run(async() => { var angle = light.LightLocation.Angle(center.X, center.Y).Move360(90); var timeSpan = waitTime() / 360 * angle; await Task.Delay(timeSpan); //Debug.WriteLine($"{light.Id} Angle {angle} and timespan {timeSpan.TotalMilliseconds}"); light.SetState(cancellationToken, randomColor, 1, waitTime() / 2); }); } await Task.Delay(waitTime() * 1.1); } }
public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken) { var r = new Random(); var center = EffectSettings.LocationCenter; var orderedLayer = layer.OrderByDescending(x => x.LightLocation.Angle(center.X, center.Y)); var hsb = r.Next(HSB.HueMaxValue); for (int i = 0; i < Chunks; i++) { var hsbColor = new HSB(hsb, 255, 255); _colors.Add(hsbColor.GetRGB()); hsb += (HSB.HueMaxValue / Chunks); } while (!cancellationToken.IsCancellationRequested) { foreach (var light in orderedLayer) { var angle = light.LightLocation.Angle(center.X, center.Y).Move360(StartRotation); double normalAngle = WrapValue(360, (int)angle); int arrayIndex = (int)(normalAngle / 361 * Chunks); light.SetState(cancellationToken, _colors[arrayIndex], 1); } StartRotation += AddRotation; StartRotation = WrapValue(360, StartRotation); await Task.Delay(waitTime() / 6); } }
public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken) { var r = new Random(); var center = EffectSettings.LocationCenter; var orderedLayer = layer.OrderByDescending(x => x.LightLocation.Angle(center.X, center.Y)); while (!cancellationToken.IsCancellationRequested) { color = RGBColor.Random(); foreach (var light in orderedLayer) { Task.Run(async() => { var distance = 1 + light.LightLocation.Y; var timeSpan = waitTime() / 2 * distance; await Task.Delay(timeSpan); //Debug.WriteLine($"{light.Id} Angle {angle} and timespan {timeSpan.TotalMilliseconds}"); light.SetState(cancellationToken, color, 1, TimeSpan.Zero); if (DipToBlack) { await Task.Delay(waitTime() * DipToBlackWait); light.SetBrightness(cancellationToken, 0, waitTime() * 0.1); } }); } await Task.Delay(waitTime() * 1.1); } }
public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken) { var r = new Random(); var center = EffectSettings.LocationCenter; var orderedLayer = layer.OrderByDescending(x => x.LightLocation.Angle(center.X, center.Y)); while (!cancellationToken.IsCancellationRequested) { foreach (var light in orderedLayer) { Task.Run(async() => { var angle = light.LightLocation.Angle(center.X, center.Y).Move360(90); var timeSpan = waitTime() / 360 * angle; var addHue = (int)(Steps / 360 * angle); await Task.Delay(timeSpan); //Debug.WriteLine($"{light.Id} Angle {angle} and timespan {timeSpan.TotalMilliseconds}"); var hsbColor = new HSB(StartStep + addHue, 255, 255); light.SetState(cancellationToken, hsbColor.GetRGB(), 1, waitTime() / 2); if (DipToBlack) { await Task.Delay(waitTime() * 0.8); light.SetBrightness(cancellationToken, 0, waitTime() * 0.1); } }); } StartStep += Steps; await Task.Delay(waitTime() * 1.1); } }