Color Wheel Hue Problems

  1. What do you want to achieve? Proper hue coloration for a color wheel!

  2. What is the issue? The color wheel’s hue is not accurate.

  3. What solutions have you tried so far? I’ve tried to change values, and use different types of math, and I’ve also tried to use division and then addition to normalize the hue. None of it has worked.

Here is the color wheel’s script:

local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

local ColorWheelFrame = script.Parent
local WheelImage = ColorWheelFrame:WaitForChild("WheelImage")
local CursorImage = WheelImage:WaitForChild("CursorImage")
local DarknessPicker = ColorWheelFrame:WaitForChild("DarknessPicker")
local SliderFrame = DarknessPicker:WaitForChild("SliderFrame")
local ColorDisplay = ColorWheelFrame:WaitForChild("ColorDisplay")

local isDown = false
local movingSlider = false

local function UpdateColor(Center)
	local WheelCenterVector = Vector2.new(
		CursorImage.AbsolutePosition.X + (CursorImage.AbsoluteSize.X / 2),
		CursorImage.AbsolutePosition.Y + (CursorImage.AbsoluteSize.Y / 2)
	)

	local DeltaX = WheelCenterVector.X - Center.X
	local DeltaY = WheelCenterVector.Y - Center.Y

	local Angle = math.atan2(DeltaY, DeltaX)
	local Distance = math.sqrt(DeltaX^2 + DeltaY^2)

	local HueValue = (Angle + math.pi) % (2 * math.pi)
	local SaturationValue = Distance / (WheelImage.AbsoluteSize.X / 2)
	local ValueValue = math.abs((SliderFrame.AbsolutePosition.Y - DarknessPicker.AbsolutePosition.Y) / DarknessPicker.AbsoluteSize.Y - 1)

	local HSV = Color3.fromHSV(math.clamp(HueValue, 0, 1), math.clamp(SaturationValue, 0, 1), math.clamp(ValueValue, 0, 1))

	ColorDisplay.BackgroundColor3 = HSV
	DarknessPicker.UIGradient.Color = ColorSequence.new{
		ColorSequenceKeypoint.new(0, HSV),
		ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0))
	}
end

WheelImage.MouseButton1Down:Connect(function()
	isDown = true
	
	local MousePosition = UserInputService:GetMouseLocation() - Vector2.new(0, GuiService:GetGuiInset().Y)
	local WheelCenterVector = Vector2.new(WheelImage.AbsolutePosition.X + (WheelImage.AbsoluteSize.X / 2), WheelImage.AbsolutePosition.Y + (WheelImage.AbsoluteSize.Y / 2))
	local MouseDistFromWheel = (MousePosition - WheelCenterVector).Magnitude

	if MouseDistFromWheel <= WheelImage.AbsoluteSize.X / 2 then
		CursorImage.Position = UDim2.new(0, MousePosition.X - WheelImage.AbsolutePosition.X, 0, MousePosition.Y - WheelImage.AbsolutePosition.Y)
	end

	UpdateColor(WheelCenterVector)
end)

DarknessPicker.MouseButton1Down:Connect(function()
	movingSlider = true
end)

WheelImage.MouseButton1Up:Connect(function()
	isDown = false
end)

DarknessPicker.MouseButton1Up:Connect(function()
	movingSlider = false
end)

UserInputService.InputEnded:Connect(function(InputObject)
	if InputObject.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
	
	isDown = false
	movingSlider = false
end)

UserInputService.InputChanged:Connect(function(InputObject)
	if InputObject.UserInputType ~= Enum.UserInputType.MouseMovement then
		return
	end

	local MousePosition = UserInputService:GetMouseLocation() - Vector2.new(0, GuiService:GetGuiInset().Y)

	if isDown then
		local WheelCenterVector = Vector2.new(WheelImage.AbsolutePosition.X + (WheelImage.AbsoluteSize.X / 2), WheelImage.AbsolutePosition.Y + (WheelImage.AbsoluteSize.Y / 2))
		local MouseDistFromWheel = (MousePosition - WheelCenterVector).Magnitude

		if MouseDistFromWheel <= WheelImage.AbsoluteSize.X / 2 then
			CursorImage.Position = UDim2.new(0, MousePosition.X - WheelImage.AbsolutePosition.X, 0, MousePosition.Y - WheelImage.AbsolutePosition.Y)
		end

		UpdateColor(WheelCenterVector)
	elseif movingSlider then
		SliderFrame.Position = UDim2.new(SliderFrame.Position.X.Scale, 0, 0, math.clamp(MousePosition.Y - DarknessPicker.AbsolutePosition.Y, 0, DarknessPicker.AbsoluteSize.Y))
		UpdateColor(Vector2.new(WheelImage.AbsolutePosition.X + (WheelImage.AbsoluteSize.X / 2), WheelImage.AbsolutePosition.Y + (WheelImage.AbsoluteSize.Y / 2)))
	end
end)

Here’s a screenshot of the color wheel:

Can you try clicking on yellow and see what color it switches to? It may be inversed.

It is, and I can’t understand how to fix it.

Sorry I forgot about this post. Can you try just reversing the values you use?