mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 18:52:55 +08:00
Implement new difficulty rating colour spectrum sampling
This commit is contained in:
parent
8dd72a9dc6
commit
d9686332a1
@ -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>
|
||||
|
37
osu.Game/Utils/ColourUtils.cs
Normal file
37
osu.Game/Utils/ColourUtils.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user