1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Implement new difficulty rating colour spectrum sampling

This commit is contained in:
Salman Ahmed 2021-07-12 19:35:03 +03:00
parent 8dd72a9dc6
commit d9686332a1
2 changed files with 57 additions and 0 deletions

View File

@ -69,6 +69,26 @@ namespace osu.Game.Graphics
}
}
public Color4 ForStarDifficulty(double starDifficulty)
{
var spectrumPoint = (float)(starDifficulty / 8.00);
if (spectrumPoint > 1f)
return Color4.Black;
return ColourUtils.SampleFromLinearGradient(new[]
{
(0.2159f, Color4Extensions.FromHex("4fc0ff")),
(0.2693f, Color4Extensions.FromHex("4fffd5")),
(0.3217f, Color4Extensions.FromHex("7cff4f")),
(0.4111f, Color4Extensions.FromHex("f6f05c")),
(0.5767f, Color4Extensions.FromHex("ff8068")),
(0.7307f, Color4Extensions.FromHex("ff3c71")),
(0.8667f, Color4Extensions.FromHex("6563de")),
(0.9996f, Color4Extensions.FromHex("18158e")),
}, spectrumPoint);
}
/// <summary>
/// Retrieves the colour for a <see cref="ScoreRank"/>.
/// </summary>

View File

@ -0,0 +1,37 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Utils;
using osuTK.Graphics;
namespace osu.Game.Utils
{
public static class ColourUtils
{
/// <summary>
/// Samples from a given linear gradient at a certain specified point.
/// </summary>
/// <param name="gradient">The gradient, defining the colour stops and their positions (in [0-1] range) in the gradient.</param>
/// <param name="point">The point to sample the colour at.</param>
/// <returns>A <see cref="Color4"/> sampled from the linear gradient.</returns>
public static Color4 SampleFromLinearGradient(IReadOnlyList<(float position, Color4 colour)> gradient, float point)
{
if (point < gradient[0].position)
return gradient[0].colour;
for (int i = 0; i < gradient.Count - 1; i++)
{
var startStop = gradient[i];
var endStop = gradient[i + 1];
if (point >= endStop.position)
continue;
return Interpolation.ValueAt(point, startStop.colour, endStop.colour, startStop.position, endStop.position);
}
return gradient[^1].colour;
}
}
}