Advertisement
HowToRoblox

ColourWheelHandler

Nov 30th, 2020 (edited)
4,798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 KB | None | 0 0
  1. local colourWheel = script.Parent:WaitForChild("ColourWheel")
  2. local wheelPicker = colourWheel:WaitForChild("Picker")
  3.  
  4. local darknessPicker = script.Parent:WaitForChild("DarknessPicker")
  5. local darknessSlider = darknessPicker:WaitForChild("Slider")
  6.  
  7. local colourDisplay = script.Parent:WaitForChild("ColourDisplay")
  8.  
  9.  
  10. local uis = game:GetService("UserInputService")
  11.  
  12.  
  13. local buttonDown = false
  14. local movingSlider = false
  15.  
  16.  
  17. local function updateColour(centreOfWheel)
  18.    
  19.    
  20.     local colourPickerCentre = Vector2.new(
  21.         colourWheel.Picker.AbsolutePosition.X + (colourWheel.Picker.AbsoluteSize.X/2),
  22.         colourWheel.Picker.AbsolutePosition.Y + (colourWheel.Picker.AbsoluteSize.Y/2)
  23.     )
  24.     local h = (math.pi - math.atan2(colourPickerCentre.Y - centreOfWheel.Y, colourPickerCentre.X - centreOfWheel.X)) / (math.pi * 2)
  25.    
  26.     local s = (centreOfWheel - colourPickerCentre).Magnitude / (colourWheel.AbsoluteSize.X/2)
  27.    
  28.     local v = math.abs((darknessSlider.AbsolutePosition.Y - darknessPicker.AbsolutePosition.Y) / darknessPicker.AbsoluteSize.Y - 1)
  29.    
  30.    
  31.     local hsv = Color3.fromHSV(math.clamp(h, 0, 1), math.clamp(s, 0, 1), math.clamp(v, 0, 1))
  32.    
  33.    
  34.     colourDisplay.ImageColor3 = hsv
  35.     darknessPicker.UIGradient.Color = ColorSequence.new{
  36.         ColorSequenceKeypoint.new(0, hsv),
  37.         ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0))
  38.     }
  39. end
  40.  
  41.  
  42. colourWheel.MouseButton1Down:Connect(function()
  43.     buttonDown = true
  44. end)
  45.  
  46. darknessPicker.MouseButton1Down:Connect(function()
  47.     movingSlider = true
  48. end)
  49.  
  50.  
  51. uis.InputEnded:Connect(function(input)
  52.    
  53.     if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
  54.    
  55.     buttonDown = false
  56.     movingSlider = false
  57. end)
  58.  
  59.  
  60. uis.InputChanged:Connect(function(input)
  61.    
  62.     if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end
  63.    
  64.    
  65.     local mousePos = uis:GetMouseLocation() - Vector2.new(0, game:GetService("GuiService"):GetGuiInset().Y)
  66.    
  67.     local centreOfWheel = Vector2.new(colourWheel.AbsolutePosition.X + (colourWheel.AbsoluteSize.X/2), colourWheel.AbsolutePosition.Y + (colourWheel.AbsoluteSize.Y/2))
  68.    
  69.     local distanceFromWheel = (mousePos - centreOfWheel).Magnitude
  70.    
  71.    
  72.     if distanceFromWheel <= colourWheel.AbsoluteSize.X/2 and buttonDown then
  73.        
  74.         wheelPicker.Position = UDim2.new(0, mousePos.X - colourWheel.AbsolutePosition.X, 0, mousePos.Y - colourWheel.AbsolutePosition.Y)
  75.  
  76.        
  77.     elseif movingSlider then
  78.        
  79.         darknessSlider.Position = UDim2.new(darknessSlider.Position.X.Scale, 0, 0,
  80.             math.clamp(
  81.             mousePos.Y - darknessPicker.AbsolutePosition.Y,
  82.             0,
  83.             darknessPicker.AbsoluteSize.Y)
  84.         )  
  85.     end
  86.    
  87.    
  88.     updateColour(centreOfWheel)
  89. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement