![]() The update function calculates the relative mouse position inside the frame based on the InputObject's Position and Button's AbsolutePosition and AbsoluteSize. This allows the user to click either the square or the hue wheel and drag anywhere, even outside the color wheel, potentially improving the user experience. The initial click determines which part of the color wheel should change whenever the mouse moves. Whenever the user clicks the color wheel, WheelMain starts handling mouse movement. Button is an ImageButton with the second image and a dynamic ImageColor3.H and SV are Frames indicating the current selection.WheelMain handles mouse input and ColorWheel's Color attribute ( ColorWheel:GetAttribute("Color") and ColorWheel:SetAttribute("Color", Color3.new(1, 1, 1))).The attached place file is just an example. It can be anywhere, with any size (for obvious reasons, it should be a square), and any AnchorPoint. ColorWheel is an ImageLabel with the first image.My sleep-deprived brain decided to turn the color wheel into a standalone UI component because apparently writing code for 2 hours is better than sleep. This recreation made debugging (without the full code) a lot easier at the cost of potentially making all of your effort absolutely pointless. Most of that effort went into a complete recreation of the color wheel. It took a concerning amount of effort to fix the hue issue. This is in a input changed, first makes sure that the inFrame is equal to true, which is set by a mouse.enter and mouse.leave, it checks for mouse down and mouse movement to where to move the color picker icon toĪssuming one of an unknown number of issues with your code is the hue calculation, one way to (hopefully) fix that would be the following: local h = (math.atan2(colourPickerCentre.Y - centreOfWheel.Y, colourPickerCentre.X - centreOfWheel.X) + math.pi / 2) / (math.pi * 2) % 1Ĭould you upload a video of your color wheel misbehaving? Local s = (centreOfWheel - colourPickerCentre).Magnitude / (/2) Local h = (math.pi - math.atan2(colourPickerCentre.Y - centreOfWheel.Y, colourPickerCentre.X - centreOfWheel.X)) / (math.pi * 2) My get color function: local colourPickerCentre = Vector2.new( + (/2), + (/2)) I’ll do my best to attempt to answer them as soon as I return from being dead If it was, that’s great! If not, please ask as many questions as you can. More if you also count comments.Īll of this information may or may not be useful for solving your problem. ![]() 2 if you count the assignment of ImageColor3. assuming btn is the ImageButton previously defined in "The boring part"ītn.ImageColor3 = omHSV(hue, 1, 1) as long as you get a number from 0 to 1 conversion to degrees could be skipped, but it doesn't really matter How many lines of code do we need to find the selected hue based on the mouse position? - see "The fun part" for definition of x and y It’s almost like magic (and even I don’t fully understand it). HellĮnter math.atan2(y: number, x: number): number. The outer ring starts at a radius of 0.8 and ends at 1, leaving the corners of the image transparent.ĭo you like trigonometry? Read this if you don't know how to get the hue.V depends on y and can be calculated using -y + 0.5.Left is no saturation, right is full saturation. S depends on x and can be calculated using x + 0.5.For mouse events, you might want to use the entire inner circle, but clamp the values of x and y to -0.5… 0.5.The inner square’s top left and bottom right corners are at -0.5, -0.5 and 0.5, 0.5 respectively.The arguments x and y could be the relative position of the mouse, with -1, -1 being the top left corner of the image and 1, 1 being the bottom right corner. ![]() UserInputService to handle edge cases of Roblox not firing signals. It could be something with that ImageButton. How that function is called is left as an exercise for the reader. Suppose you have a function click(x: number, y: number). To make this color wheel interactive, you’ll want to listen to mouse inputs. To achieve the effect I assume you want, you could change its ImageColor3 based on the selected hue, possibly using the Color3 HSV functions. ![]() This could be an ImageButton parented to the static ImageLabel. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |