public void Set() { var fillPercentage = target.CurrentHealth / (float)target.MaxHealth; healthSlider.localPosition = Vector3.Lerp(emptyPosition, Vector3.zero, fillPercentage); barGraphic.color = HSVColor.Lerp(emptyColor, fullColor, fillPercentage); }
private IEnumerator WhileTimerTicking() { // Update the interface while the timer is going. while (true) { clockText.text = string.Format(secondsFormat, drivingTimer.RemainingSeconds); radialFillImage.fillAmount = 1 - drivingTimer.Interpolant; radialFillImage.color = HSVColor.Lerp(filledColor, emptyColor, drivingTimer.Interpolant).AsRGB; yield return(null); } }
// Set duration to -1 for indefinite private async Task FadeBetweenTwoColors(float rate, HSVColor col1, HSVColor col2, float duration, CancellationToken cancelToken) { int msCounter = 0; while ((duration >= 0 && msCounter < duration) || duration < 0) { float sin = (float)Math.Sin((msCounter / 1000f) * rate); this.leds.SetAllToColor(HSVColor.Lerp(col1, col2, sin)); if (cancelToken.IsCancellationRequested) { throw new TaskCanceledException(); } NewFrameReady.Invoke(this, this.leds, LightingMode.Line); await Task.Delay(30); msCounter += 30; } }
public void FadeBetweenTwoColors(LightZone zones, HSVColor col1, HSVColor col2, float rate = 0.15f, float duration = 2) { // TODO: Broken int frames = (int)Math.Round(duration * FPS); for (int i = 0; i < frames; i++) { float currentTime = i / FPS; float sin = (float)Math.Sin(currentTime * rate); HSVColor color = HSVColor.Lerp(col1, col2, sin); LEDData newFrame = LEDData.Empty; List <Led[]> newFrameLightArrays = newFrame.GetArraysForZones(zones); foreach (Led[] arr in newFrameLightArrays) { foreach (Led l in arr) { l.Color(color); } } SendFrame(newFrame, zones); } }