Hello. I am making a game and inside the game I have a script which takes the height of each part and applies a gradient from white to black.
This is my code:
function mapValue(value, low1, high1, low2, high2)
local Fraction = (value - low1) / (high1 - low1)
return math.floor((low2 + high2 - 1) * Fraction)
end
function colour()
local high = math.huge * -1
local low = math.huge
for x=1, gridSize do -- determine highest and lowest points
for y=1, gridSize do
if workspace.map.points:FindFirstChild(x .. " " .. y).Position.Y > high then
high = workspace.map.points:FindFirstChild(x .. " " .. y).Position.Y
end
if workspace.map.points:FindFirstChild(x .. " " .. y).Position.Y < low then
low = workspace.map.points:FindFirstChild(x .. " " .. y).Position.Y
end
end
end
for k,v in pairs(workspace.map.fill:GetChildren()) do -- colour points relative to highest and lowest points
local height = v.Position.Y
local brightness = mapValue(height, low, high, 0, 255)
v.Color = Color3.fromRGB(brightness, brightness, brightness)
end
end
this gives me this:
is there any way I can choose any two colours and make the gradient go from one to the other rather than black to white? For example, make the lowest points orange and the highest points purple and everything in between.