A game framework written with osu! in mind.
at master 104 lines 4.3 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System.Linq; 5using NUnit.Framework; 6using osu.Framework.Allocation; 7using osu.Framework.Graphics; 8using osu.Framework.Graphics.Colour; 9using osu.Framework.Graphics.Containers; 10using osu.Framework.Graphics.Shapes; 11using osu.Framework.Graphics.Sprites; 12using osu.Framework.Graphics.Textures; 13using osu.Framework.Utils; 14using osuTK; 15using osuTK.Graphics; 16 17namespace osu.Framework.Tests.Visual.Drawables 18{ 19 public class TestSceneColourInterpolation : FrameworkTestScene 20 { 21 [Test] 22 public void TestColourInterpolatesInLinearSpace() 23 { 24 FillFlowContainer interpolatingLines = null; 25 26 AddStep("load interpolated colours", () => 27 { 28 Child = new FillFlowContainer 29 { 30 Anchor = Anchor.CentreLeft, 31 Origin = Anchor.CentreLeft, 32 AutoSizeAxes = Axes.Both, 33 Direction = FillDirection.Vertical, 34 Margin = new MarginPadding(20), 35 Children = new Drawable[] 36 { 37 new SpriteText 38 { 39 Anchor = Anchor.CentreLeft, 40 Origin = Anchor.CentreLeft, 41 Text = "d3.interpolateRgb.gamma(2.2)(\"red\", \"blue\")" 42 }, 43 new SampleSpriteD3 44 { 45 Anchor = Anchor.CentreLeft, 46 Origin = Anchor.CentreLeft, 47 Size = new Vector2(750f, 50f), 48 }, 49 new SpriteText 50 { 51 Margin = new MarginPadding { Top = 20f }, 52 Anchor = Anchor.CentreLeft, 53 Origin = Anchor.CentreLeft, 54 Text = $"{nameof(ColourInfo)}.{nameof(ColourInfo.GradientHorizontal)}(Blue, Red)" 55 }, 56 new Box 57 { 58 Anchor = Anchor.CentreLeft, 59 Origin = Anchor.CentreLeft, 60 Size = new Vector2(750f, 50f), 61 Colour = ColourInfo.GradientHorizontal(Color4.Red, Color4.Blue), 62 }, 63 new SpriteText 64 { 65 Margin = new MarginPadding { Top = 20f }, 66 Anchor = Anchor.CentreLeft, 67 Origin = Anchor.CentreLeft, 68 Text = $"{nameof(Interpolation)}.{nameof(Interpolation.ValueAt)}(Red, Red) with 1px boxes", 69 }, 70 interpolatingLines = new FillFlowContainer 71 { 72 Anchor = Anchor.CentreLeft, 73 Origin = Anchor.CentreLeft, 74 AutoSizeAxes = Axes.X, 75 Height = 50f, 76 ChildrenEnumerable = Enumerable.Range(0, 750).Select(i => new Box 77 { 78 Width = 1f, 79 RelativeSizeAxes = Axes.Y, 80 Colour = Interpolation.ValueAt(i, Color4.Red, Color4.Blue, 0, 750), 81 }), 82 }, 83 } 84 }; 85 }); 86 87 AddAssert("interpolation in linear space", () => 88 { 89 var middle = interpolatingLines.Children[interpolatingLines.Children.Count / 2]; 90 return middle.Colour.AverageColour.Linear == new Color4(0.5f, 0f, 0.5f, 1f); 91 }); 92 } 93 94 public class SampleSpriteD3 : Sprite 95 { 96 [BackgroundDependencyLoader] 97 private void load(TextureStore textures) 98 { 99 // Taken from https://observablehq.com/@d3/working-with-color 100 Texture = textures.Get("colour-interpolation"); 101 } 102 } 103 } 104}