public static void Between(float start, float end, float step, AnimationSpeed speed, Action<float> run) { Action callback = null; if (start < end) { callback = () => { run(start); if (start >= end) { run(end); return; } start += step; Window.SetTimeout(callback, (int)speed); }; } else { callback = () => { run(start); if (start <= end) { run(end); return; } start -= step; Window.SetTimeout(callback, (int)speed); }; } Window.SetTimeout(callback, (int)speed); }
public Sprite(string name, int spriteWidth, AnimationSpeed speed = AnimationSpeed.Normal, AnimationType type = AnimationType.AnimateOnce) { BitmapImage spriteSheet = new BitmapImage(UriFromImageName(name)) { BaseUri = BaseUriHelper.GetBaseUri(this) }; numSprites = (int)((spriteSheet.Width / spriteWidth) - 1); int spriteHeight = (int)spriteSheet.Height; croppedImages = new CroppedBitmap[numSprites]; for (int i = 0; i < numSprites; i++) { Int32Rect cropWindow = new Int32Rect(spriteWidth * i, 0, spriteWidth, spriteHeight); croppedImages[i] = new CroppedBitmap(spriteSheet, cropWindow); } animationType = type; this.Source = croppedImages[0]; animationTimer.Interval = (int)speed; animationTimer.Tick += animationTimer_Tick; animationTimer.Start(); }
private void ExecuteAudioAlgorithm() { Complex averageBassVolume = GetAverageBassVolume(); _averageAnimationSpeed = GetAverageAnimationSpeed(); AnimationSpeed currentSpeed = GetAnimationSpeedByFftData(averageBassVolume); _previousAnimationSpeeds.Add(currentSpeed); if (_previousAnimationSpeeds.Count > 10) { _previousAnimationSpeeds.RemoveRange(0, _previousAnimationSpeeds.Count - 3); } Console.WriteLine(averageBassVolume.Y); Console.WriteLine(currentSpeed); if (!MusicIsPlaying()) { return; } if (_averageAnimationSpeed != AnimationSpeed.Off) { _laserAnimationStatus.AnimationSpeed = _averageAnimationSpeed; } PlayAnimation(GetRandomPattern(), new PatternOptions { AnimationSpeed = AnimationSpeed.NotSet, DurationMilliseconds = 0, Total = new Random(Guid.NewGuid().GetHashCode()).Next(2, 5) }); }
private void slowToolStripMenuItem_Click(object sender, EventArgs e) { this.animationSpeed = AnimationSpeed.SLOW; this.slowToolStripMenuItem.Checked = true; this.fastToolStripMenuItem.Checked = false; this.mediumToolStripMenuItem.Checked = false; }
/// <summary> /// Handles a change to the animation speed. /// </summary> /// <param name="dependencyObject">The object that owns the property.</param> /// <param name="dependencyPropertyChangedEventArgs">A description of the changed property.</param> private static void OnAnimationSpeedChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { // Set the speed for animation. ReportDebtNegotiatorPaymentSummary reportPrototype = dependencyObject as ReportDebtNegotiatorPaymentSummary; AnimationSpeed animationSpeed = (AnimationSpeed)dependencyPropertyChangedEventArgs.NewValue; reportPrototype.Duration = ReportDebtNegotiatorPaymentSummary.animationDurations[(Int32)animationSpeed]; }
public LightSetting(ColorMode mode, AnimationSpeed speed, bool moving, bool forward, int ledSize, params int[] colors) : this(mode) { Speed = speed; Moving = moving; Forward = forward; LedSize = ledSize; ColorOptions = colors.ToList(); }
/// <summary> /// Handles a change to the animation speed. /// </summary> /// <param name="dependencyObject">The object that owns the property.</param> /// <param name="dependencyPropertyChangedEventArgs">A description of the changed property.</param> private static void OnAnimationSpeedChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { // Set the speed for animation. ReportCreditCard reportPrototype = dependencyObject as ReportCreditCard; AnimationSpeed animationSpeed = (AnimationSpeed)dependencyPropertyChangedEventArgs.NewValue; reportPrototype.Duration = ReportCreditCard.animationDurations[(Int32)animationSpeed]; }
public void ClearDelegates() { CombatInfoCall = null; AnimationSpeedCall = null; BeatTrackNoteCall = null; AdvanceIndexCall = null; NoMoreBeatsCall = null; CombatOverCall = null; }
public LightningManager(LightChannel observedChannel) { lightChannel = observedChannel; availableModes = new List <LightSetting>(); BuildLightOptions(); menuItems = MenuFactory(availableModes); animationSpeed = AnimationSpeed.Normal; selectedSetting = availableModes[0]; }
void Start() { sr = GetComponent <SpriteRenderer>(); sr.sprite = sprites[level - 1]; anim = GetComponent <Animation>(); AnimationSpeed speed = GetComponentInChildren <AnimationSpeed>(); speed.speed = Random.Range(0.4f, 0.8f); speed.offset = Random.Range(0f, 1f); }
public Animation(Sprite[] sprites, bool cycled, int loopStartFrame = 0, int loopEndFrame = int.MaxValue, AnimationSpeed speed = AnimationSpeed.Average) { Frames = sprites; Looping = cycled; Speed = speed; if (cycled) { LoopStart = loopStartFrame; LoopEnd = loopEndFrame; } }
public void Project(PatternOptions options) { int totalLines = 4; if (totalLines < 2) { totalLines = 2; } var stopwatch = new Stopwatch(); stopwatch.Start(); var colors = new List <LaserColors>(); for (int i = 0; i < totalLines; i++) { colors.Add(_laserPatternHelper.GetRandomLaserColors()); } AnimationSpeed animationSpeed = options.AnimationSpeed; double iterations = 0; while (stopwatch.ElapsedMilliseconds < options.DurationMilliseconds || iterations / 6.3 < options.Total) { iterations += (double)animationSpeed / 700; if (stopwatch.ElapsedMilliseconds > options.DurationMilliseconds && options.DurationMilliseconds != 0 || _laserAnimationStatus.AnimationCanceled) { break; } if (options.AnimationSpeed == AnimationSpeed.NotSet) { animationSpeed = _laserAnimationStatus.AnimationSpeed; } for (int line = 0; line < totalLines; line++) { int x = Convert.ToInt32(Math.Cos(iterations + line) * Math.Abs(_settings.maxLeft)); int y = Convert.ToInt32(Math.Sin(iterations) * Math.Abs(2000)); _laser.SendTo(x, y); System.Threading.Thread.SpinWait(40000); _laser.On(colors[line]); System.Threading.Thread.SpinWait(6000); _laser.Off(); } } }
public static int GetNextInterval(AnimationSpeed speed = AnimationSpeed.Normal) { switch (speed) { case AnimationSpeed.Low: return random.Next(1500, 1000 * 1000); case AnimationSpeed.Normal: return random.Next(1500, 1000 * 100); case AnimationSpeed.Fast: return random.Next(1500, 1000 * 10); } return random.Next(1500, 1000 * 60 * 10); }
public static int GetSpeed(AnimationSpeed s) { switch (s) { case AnimationSpeed.VeryFast: return(5); case AnimationSpeed.Fast: return(20); case AnimationSpeed.Medium: return(50); } return(250); }
/// <summary> /// Handles a change to the AnimationSpeed property. /// </summary> /// <param name="dependencyObject">The object that owns the property.</param> /// <param name="dependencyPropertyChangedEventArgs">A description of the changed property.</param> private static void OnAnimationSpeedChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { // Extract the strongly typed variables from the generic parameters. ViewerDebtBlotter viewerPrototype = dependencyObject as ViewerDebtBlotter; AnimationSpeed animationSpeed = (AnimationSpeed)dependencyPropertyChangedEventArgs.NewValue; // Set the animation speed on the report. ViewerDebtBlotter.reportWorkingOrder.AnimationSpeed = animationSpeed; // Adjust the menu items for the new animation setting. viewerPrototype.menuItemSetAnimationFast.IsChecked = animationSpeed == AnimationSpeed.Fast; viewerPrototype.menuItemSetAnimationMedium.IsChecked = animationSpeed == AnimationSpeed.Medium; viewerPrototype.menuItemSetAnimationOff.IsChecked = animationSpeed == AnimationSpeed.Off; viewerPrototype.menuItemSetAnimationSlow.IsChecked = animationSpeed == AnimationSpeed.Slow; }
private void Animate(AnimationSpeed speed, MovementDirection direction) { _isAnimating = true; var interval = SpeedMap.GetSpeed(speed); if (direction == MovementDirection.Right) { AutoAnimationSpeed = -AutoAnimationSpeed; } _timer = new System.Windows.Forms.Timer { Interval = interval }; VarZ = AutoAnimationSpeed; _timer.Tick += (s, a) => ResetZ(0); _timer.Start(); }
public static int GetNextInterval(AnimationSpeed speed = AnimationSpeed.Normal) { switch (speed) { case AnimationSpeed.Low: return(random.Next(1500, 1000 * 1000)); case AnimationSpeed.Normal: return(random.Next(1500, 1000 * 100)); case AnimationSpeed.Fast: return(random.Next(1500, 1000 * 10)); } return(random.Next(1500, 1000 * 60 * 10)); }
/// <summary> /// Creates a new <see cref="AnimationSpeedDefinition"/> instance /// for a given <see cref="AnimationSpeed"/> enum value. /// </summary> /// <param name="value"> /// The <see cref="AnimationSpeed"/>, for which an /// <see cref="AnimationSpeedDefinition"/> should be generated /// </param> /// <returns> /// A new instance of the <see cref="AnimationSpeedDefinition"/> /// struct. /// </returns> /// <exception cref="ArgumentException"> /// Is thrown when an invalid/unsupported <see cref="AnimationSpeed"/> /// enum value is specified. /// </exception> public static AnimationSpeedDefinition FromEnum(AnimationSpeed value) { switch (value) { case AnimationSpeed.None: return(None); case AnimationSpeed.Fast: return(Fast); case AnimationSpeed.Medium: return(Medium); case AnimationSpeed.Slow: return(Slow); default: throw new ArgumentException("The specified " + "animation speed was not supported!"); } }
public Preloader(Control control, AnimationStyle style, AnimationSpeed speed, Position position = Position.MiddleCenter) { this.control = control; if (control == null) { throw new NullReferenceException("control reference not set to an instance of Control"); } //Make sure control is double buffered typeof(Control).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, control, new object[] { true }); control.BackgroundImageLayout = ImageLayout.Stretch; this.style = style; this.speed = speed; this.position = position; double timerInterval; switch (speed) { case AnimationSpeed.VerySlow: timerInterval = 500; break; case AnimationSpeed.Slow: timerInterval = 250; break; case AnimationSpeed.Fast: timerInterval = 50; break; case AnimationSpeed.VeryFast: timerInterval = 25; break; case AnimationSpeed.Medium: default: timerInterval = 100; break; } CreateFrames(); this.originalBackgroundImage = control.BackgroundImage; timer = new System.Timers.Timer(timerInterval); timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); }
public void Project(PatternOptions options) { LaserColors colors = _laserPatternHelper.GetRandomLaserColors(); int xCenter = (_settings.maxLeft + _settings.maxRight) / 2; var stopwatch = new Stopwatch(); stopwatch.Start(); AnimationSpeed animationSpeed = options.AnimationSpeed; int iterations = 0; while (stopwatch.ElapsedMilliseconds < options.DurationMilliseconds || iterations < options.Total) { iterations++; if (options.AnimationSpeed == AnimationSpeed.NotSet) { animationSpeed = _laserAnimationStatus.AnimationSpeed; } int left = xCenter - 100; int right = xCenter + 100; int y = new Random(Guid.NewGuid().GetHashCode()).Next(_settings.minHeight, _settings.maxHeight); while (left > _settings.maxLeft || right < _settings.maxRight) { if (stopwatch.ElapsedMilliseconds > options.DurationMilliseconds && options.DurationMilliseconds != 0 || _laserAnimationStatus.AnimationCanceled) { break; } _laser.SendTo(left -= (int)animationSpeed / 2, y); System.Threading.Thread.SpinWait(30000); _laser.On(colors); _laser.SendTo(right += (int)animationSpeed / 2, y); System.Threading.Thread.SpinWait(30000); _laser.Off(); System.Threading.Thread.SpinWait(100); } } _laser.Off(); }
public string ToStruct(bool decomp = false) { StringBuilder result = new StringBuilder("{ "); result.Append("0"); // Animation frame is only used internally result.Append(", "); result.Append(AnimationSpeed.ToC()); result.Append(", "); result.Append(MaxFrame.ToC()); result.Append(", "); result.Append(Model != null ? ((decomp ? "" : "&") + Model.Name) : "NULL"); result.Append(", "); result.Append(Animation != null ? ((decomp ? "" : "&") + Animation.ActionName) : "NULL"); result.Append(", (NJS_TEXLIST *)"); result.Append(TexlistPointer.ToCHex()); result.Append(" }"); return(result.ToString()); }
public void Project(PatternOptions options) { var stopwatch = new Stopwatch(); stopwatch.Start(); var color = _laserPatternHelper.GetRandomLaserColors(); AnimationSpeed animationSpeed = options.AnimationSpeed; double sin = 0; int iterations = 0; while (stopwatch.ElapsedMilliseconds < options.DurationMilliseconds || iterations < options.Total * 2000) { if (stopwatch.ElapsedMilliseconds > options.DurationMilliseconds && options.DurationMilliseconds != 0 || _laserAnimationStatus.AnimationCanceled) { break; } if (options.AnimationSpeed == AnimationSpeed.NotSet) { animationSpeed = _laserAnimationStatus.AnimationSpeed; } for (int i = _settings.maxLeft; i < _settings.maxRight; i += 15) { iterations++; sin += 0.026; int y = Convert.ToInt32(Math.Sin(sin) * Math.Abs(_settings.maxHeight)); _laser.SendTo(i, y); if (i == _settings.maxLeft) { System.Threading.Thread.SpinWait(22000); } _laser.On(color); } _laser.Off(); } }
public void Project(PatternOptions options) { LaserColors colors = _laserPatternHelper.GetRandomLaserColors(); var stopwatch = new Stopwatch(); stopwatch.Start(); AnimationSpeed animationSpeed = options.AnimationSpeed; var xPos = new List <int> { _settings.maxLeft, _settings.maxRight }; double iterations = 0; while (stopwatch.ElapsedMilliseconds < options.DurationMilliseconds || iterations / 6.3 < options.Total) { iterations += (double)animationSpeed / 1400; if (options.AnimationSpeed == AnimationSpeed.NotSet) { animationSpeed = _laserAnimationStatus.AnimationSpeed; } for (int line = 0; line < 2; line++) { if (stopwatch.ElapsedMilliseconds > options.DurationMilliseconds && options.DurationMilliseconds != 0 || _laserAnimationStatus.AnimationCanceled) { break; } for (int j = 0; j < 3; j++) { int y = Convert.ToInt32(Math.Sin(iterations + line) * Math.Abs(2000)); _laser.SendTo(xPos[line], y); System.Threading.Thread.SpinWait(15000); _laser.On(colors); } } } _laser.Off(); }
public void Project(PatternOptions options) { LaserColors colors = _laserPatternHelper.GetRandomLaserColors(); var stopwatch = new Stopwatch(); stopwatch.Start(); AnimationSpeed animationSpeed = options.AnimationSpeed; int iterations = 0; while (stopwatch.ElapsedMilliseconds < options.DurationMilliseconds || iterations < options.Total) { iterations++; for (int i = _settings.maxHeight; i > _settings.minHeight; i -= (int)animationSpeed) { if (stopwatch.ElapsedMilliseconds > options.DurationMilliseconds && options.DurationMilliseconds != 0 || _laserAnimationStatus.AnimationCanceled) { break; } if (options.AnimationSpeed == AnimationSpeed.NotSet) { animationSpeed = _laserAnimationStatus.AnimationSpeed; } _laser.SendTo(_settings.maxLeft, i); System.Threading.Thread.SpinWait(30000); _laser.On(colors); _laser.SendTo(_settings.maxRight, i); System.Threading.Thread.SpinWait(30000); } } _laser.Off(); }
public void SetAnimationSpeed(AnimationSpeed speedSetting, MenuItem sender) { if (previousSpeedBox != null) { previousSpeedBox.IsChecked = false; } sender.IsChecked = true; previousSpeedBox = sender; logoManager.animationSpeed = speedSetting; rimManager.animationSpeed = speedSetting; commander.AddCommand(KrakenDevice.GenerateLightMessage(logoManager.selectedSetting.mode, new ControlBlock(false, false, logoManager.lightChannel), new LEDConfiguration(0, 0, speedSetting), new[] { 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF })); commander.AddCommand(KrakenDevice.GenerateLightMessage(rimManager.selectedSetting.mode, new ControlBlock(false, false, rimManager.lightChannel), new LEDConfiguration(0, 0, speedSetting), new[] { 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF })); }
public string SetAnimationSpeed(AnimationSpeed animationSpeed) { return($"(set-animationspeed,{(int)animationSpeed})"); }
public void Project(PatternOptions options) { int xCenter = (_settings.maxLeft + _settings.maxRight) / 2; var stopwatch = new Stopwatch(); stopwatch.Start(); AnimationSpeed animationSpeed = options.AnimationSpeed; int iterations = 0; List <LaserColors> colors = GetRandomColors(); int totalLines = colors.Count; int lineDistance = (Math.Abs(_settings.maxLeft) + Math.Abs(_settings.maxRight)) / totalLines; int previousColorChange = 0; int y = _settings.maxHeight; while (stopwatch.ElapsedMilliseconds < options.DurationMilliseconds || iterations < options.Total) { if (y > _settings.minHeight) { y -= (int)animationSpeed / 5 + 2; } else { iterations++; y = _settings.maxHeight; } if (options.AnimationSpeed == AnimationSpeed.NotSet) { animationSpeed = _laserAnimationStatus.AnimationSpeed; } int iterationThreshold = 0; try { iterationThreshold = 600 / (int)animationSpeed; } catch (Exception e) { } if (iterations - previousColorChange > iterationThreshold) { previousColorChange = iterations; colors = GetRandomColors(); } for (int i = 0; i < totalLines; i++) { _laser.SendTo(_settings.maxLeft + lineDistance * i, y); System.Threading.Thread.SpinWait(16000); _laser.On(colors[i]); } _laser.Off(); } _laser.Off(); }
public LEDConfiguration(byte lightIndex, byte ledGroupSize, AnimationSpeed animationSpeed) { this.lightIndex = lightIndex; this.ledGroupSize = ledGroupSize; this.animationSpeed = animationSpeed; }
public void Project(PatternOptions options) { var stopwatch = new Stopwatch(); stopwatch.Start(); AnimationSpeed animationSpeed = options.AnimationSpeed; int iterations = 0; var random = new Random(Guid.NewGuid().GetHashCode()); List <LaserPositionAndColors> laserPosAndColors = GetPredifinedLaserPositionAndColors(); int previousColorChange = 0; bool xToLeft = false; bool yUp = false; while (stopwatch.ElapsedMilliseconds < options.DurationMilliseconds || iterations < options.Total * 100) { iterations++; LaserPositionAndColors lastLaserPositionAndColors = laserPosAndColors.Last(); int x = lastLaserPositionAndColors.X; int y = lastLaserPositionAndColors.Y; if (xToLeft) { x -= random.Next(-10 / (int)animationSpeed, (int)animationSpeed * 3 + 15); } else { x += random.Next(-10 / (int)animationSpeed, (int)animationSpeed * 3 + 15); } if (yUp) { y += random.Next(-10 / (int)animationSpeed, (int)animationSpeed * 3 + 15); } else { y -= random.Next(-10 / (int)animationSpeed, (int)animationSpeed * 3 + 15); } if (x >= _settings.maxRight && !xToLeft) { xToLeft = true; } else if (x <= _settings.maxLeft && xToLeft) { xToLeft = false; } if (y >= _settings.maxHeight && yUp) { yUp = false; } else if (y <= _settings.minHeight && !yUp) { yUp = true; } var color = lastLaserPositionAndColors.LaserColors; if (iterations - previousColorChange > 25) { previousColorChange = iterations; color = _laserPatternHelper.GetRandomLaserColors(); } laserPosAndColors.Add(new LaserPositionAndColors { LaserColors = color, Y = y, X = x }); foreach (var laserposAndColor in laserPosAndColors) { _laser.SendTo(laserposAndColor.X, laserposAndColor.Y); _laser.On(laserposAndColor.LaserColors); } if (laserPosAndColors.Count > 100 - (int)animationSpeed) { laserPosAndColors.RemoveRange(0, 1); } } _laser.Off(); }