You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I would like to create a math function that correlates the darkness value to the RGB values.
What is the issue? Include screenshots/videos if possible!
I have a color picker that works correctly and gives the correct RGB color and darkness values, but I am unable to correlate the darkness values to the RGB color values, as it starts getting weird and creating colors that are obviously not correlated with the darkness and RGB value, with reference to the color sliders.
Code Snippet:
print("R: " .. colorR)
print("G: " .. colorG)
print("B: " .. colorB)
print("V: " .. darknessR) -- Doesn't matter what RGB darkness because all darknesses are the same
local resultColor = Color3.fromRGB(colorR - darknessR, colorG - darknessG, colorB - darknessB)
colorPreview.BackgroundColor3 = resultColor
Red is the (darkness) value and I would like that to correlate that to the RGB value, in which Roblox does.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried looking online for math operations for RGB and darkness values, but they are in another code. I have also tried looking on the DevForum, but what they are experiencing is only RGB conversion issues, not correlation issues with darkness and RGB color values.
function UpdateColorPreview()
--Get the percentage of the slider position, as divided by the color gradient size
local colorMaxXSize = colorGradientButton.AbsoluteSize.X
local colorXPos = colorSlider.Position.X.Offset / colorMaxXSize
--Get the percentage of the slider position, as divided by the darkness gradient size
local darknessMaxXSize = darknessGradientButton.AbsoluteSize.X
local darknessXPos = darknessSlider.Position.X.Offset / darknessMaxXSize
--Multiplying the color (percentage) by the RGB range in order to find the (color) RGB format
local color = ReturnColor(colorXPos, colorGradientButton.UIGradient.Color.Keypoints)
local colorR, colorG, colorB = math.floor(color.R * 255), math.floor(color.G * 255), math.floor(color.B * 255)
--Multiplying the darkness (percentage) by the RGB range, and subtracting RGB(255) the product in order to get the (darkness) value in RGB format [Note: All the darknessRGBs will be the same]
local darkness = ReturnColor(darknessXPos, darknessGradientButton.UIGradient.Color.Keypoints)
local darknessR, darknessG, darknessB = 255 - math.floor(darkness.R * 255), 255 - math.floor(darkness.G * 255), 255 - math.floor(darkness.B * 255)
--Subtracting the darkness values from the color values in order to get the final RGB color that pertains the darkness value and color values, each taken from the slider percentages
--CHANGE IT TO WHERE THE COLOR CORRELATES TO THE DARKNESS VALUE (PROBABLY BY AN EQUATION FOUND ONLINE)
print("R: " .. colorR)
print("G: " .. colorG)
print("B: " .. colorB)
print("V: " .. darknessR) -- Doesn't matter what RGB darkness because all darknesses are the same
local resultColor = Color3.fromRGB(colorR - darknessR, colorG - darknessG, colorB - darknessB)
print(resultColor)
colorPreview.BackgroundColor3 = resultColor
end
I am questioning now, is it a mistake in the darknessRGB and colorRGB calculations? It is showing large floats for the final output when the darknessRGB and colorRGB values have been floored and made into integers, as shown in the print() functions that print the RGB and Darkness values.
I would like it to be in RGB format as my what I want the color picker to be used for is applying RGB to a multiple GuiFrames that will be using the RGB format.
There is no other way of darkening a color, what you could do is convert the rgb value to hsv for the calculations and then turn it back to rgb
For example :
function darkerColor(color)
local h, s, v = color:ToHSV()
return h, s, v-10 -- put whatever number you like
end)
frameorwhatever.BackgroundColor3 = darkerColor(frame.BackgroundColor3):ToRGB()