Skip to content

Instantly share code, notes, and snippets.

@Vercidium
Last active May 4, 2019 02:20
Show Gist options
  • Save Vercidium/e3690ae75d8d5699e0522a9a7a38b183 to your computer and use it in GitHub Desktop.
Save Vercidium/e3690ae75d8d5699e0522a9a7a38b183 to your computer and use it in GitHub Desktop.
Colour Interpolation
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