It looks like you're new here. If you want to get involved, click one of these buttons!
function SlideColorPicker:setHue(xhexcolor) --self.colors = {0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF, 0xFF0000} self.e = Event.new("COLOR_CHANGED") local r, g, b = self:hex2rgb(xhexcolor) self.currColor = r*65536 + g*256 + b local hpr = (1 - (r / 255)) * 51 -- 51 is image width 306 / 6 (#self.colors{} - 1) local hpg = (1 - (g / 255)) * 51 local hpb = (1 - (b / 255)) * 51 local hueposition = hpr + hpg + hpb self.hueArrows:setX(hueposition) self.e.color = self.currColor self:dispatchEvent(self.e) end |
Comments
Likes: MoKaLux
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
see
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Colors/Color_picker_tool
so you need only to convert the rgb of the pixel to hsl first
e.g.
https://www.rapidtables.com/convert/color/rgb-to-hsl.html
and then you can easily get the right place on the color slider. of course only if the color is present there, i.e., has S50 and L50. otherwise you can get the closest color by caring only about the H value.
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
One problem is left I cannot figure out how to transform this h value to translate to my image (306 pixel wide).
edit: I think I get it: local hueposition = h * (306 / 360)
Wonderful thank you very much guys.
local hueposition = h * (305 / 359)
is even more correct (assuming your colorslider has width 306)
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: keszegh
Likes: Apollo14, oleg