public void RepeatSingleAnimation() { if (time < duration) { time += Time.deltaTime; } else { time = 0f; } time = Mathf.Clamp(time, 0f, duration); value = MathW.Remap(time, 0f, duration, 0f, 1f); }
//private float low = 0f, high = 1f; public void Visualize(List <float> _numbers, float _low = 0f, float _high = 1f) { //copy List numbers = new List <float>(_numbers); int width = resolution; int height = resolution;//Mathf.Max(numbers); Texture2D tex = new Texture2D(width, height); //clear texture for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { tex.SetPixel(x, y, backgroundColor); } } //draw samples foreach (var number in numbers) { var xPosition = MathW.Remap(number, _low, _high, 1f, width - 2f); int xPositionInt = Mathf.RoundToInt(xPosition); for (int i = -sampleHeight / 2; i < sampleHeight / 2; i++) { var currentPixelAlpha = tex.GetPixel(xPositionInt, height / 2 + i).a; tex.SetPixel(xPositionInt, height / 2 + i, sampleColor.With(a: currentPixelAlpha + sampleColor.a)); } } //draw border for (int i = -sampleHeight; i < sampleHeight; i++) { tex.SetPixel(0, height / 2 + i, borderColor); tex.SetPixel(width - 1, height / 2 + i, borderColor); } // apply some settings to make tex look better tex.Apply(); tex.filterMode = FilterMode.Point; tex.wrapMode = TextureWrapMode.Clamp; rawImage.texture = tex; }
private void Visualize() { samples.Clear(); samplesMapped.Clear(); for (int i = 0; i < sampleCount; i++) { var nextFloat = (sampleFloatOrInt == FloatOrInt.Float) ? randomW.NextFloat() : randomW.NextInt(); samples.Add(nextFloat); nextFloat = MathW.Remap(nextFloat, randomW.min, randomW.max, 0f, 1f); samplesMapped.Add(nextFloat); } visualizer.Visualize(samplesMapped); var minValue = samples.Min(t => t); var maxValue = samples.Max(t => t); Debug.Log("min value is: " + minValue + ", max value is: " + maxValue); }
public void BounceAnimation() { if (time < duration && up) { time += Time.deltaTime; } else if (time > 0 && !up) { time -= Time.deltaTime; } if (up && time >= duration) { up = false; } else if (!up && time <= 0f) { up = true; } time = Mathf.Clamp(time, 0f, duration); value = MathW.Remap(time, 0f, duration, 0f, 1f); }
void Update() { var relativeSpeed = MathW.Remap(characterRigidbody.velocity.magnitude, 0f, maxSpeed, 0f, 1f); animator.SetFloat("WalkingSpeed", relativeSpeed); }