Last active
May 4, 2019 02:20
-
-
Save Vercidium/e3690ae75d8d5699e0522a9a7a38b183 to your computer and use it in GitHub Desktop.
Colour Interpolation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector3 position = GetPoint(); | |
position.Y -= heightMagnitude * Math.Sin(position.Magnitude * heightFrequency); | |
// Colour each point based on their global angle around the axis | |
Color blendedColour; | |
var angle = Math.Atan2(position.X, position.Z); | |
// c1, c2, c3 and c4 are random colours generated at the start of the program | |
// Blend the colours of adjacent quadrants together | |
if (angle < -Math.PI / 2) | |
blendedColour = Color.Interpolate(c1, c2, (angle + Math.PI) / (Math.PI / 2)); | |
else if (angle < 0) | |
blendedColour = Color.Interpolate(c2, c3, (Math.PI / 2 + angle) / (Math.PI / 2)); | |
else if (angle < Math.PI / 2) | |
blendedColour = Color.Interpolate(c3, c4, angle / (Math.PI / 2)); | |
else | |
blendedColour = Color.Interpolate(c4, c1, (angle - Math.PI / 2) / (Math.PI / 2)); | |
// maxMagnitude stores the distance of the furthest known point | |
if (position.Magnitude / maxMagnitude > 1) | |
maxMagnitude = position.Magnitude; | |
// Colours get brighter the closer they are to the center | |
uint pointColour = Color.Interpolate(Color.Black, Color.Interpolate(Color.White, blendedColour, position.Magnitude / maxMagnitude), 0.8).Value; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment