-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Color from hex code, updated examples #222
base: master
Are you sure you want to change the base?
Conversation
I have added a function |
The test suite is failing at "Run webfactory/[email protected]" with error |
Wouldn't it be easier to have an hex : Int -> Color
hex n =
rgb255 (n // 0x10000) (n // 0x100 |> modBy 0x100) (modBy 0x100 n)
-- example
white : Color
white = hex 0xffffff |
Do you mean easier in use or easier in implementation? I'm not saying you're wrong just outlining my thought process and arguments :) . |
I was also thinking a little bit about performance. I haven't benchmarked any of it but I'm assuming all that string parsing can't do very well. Maybe it doesn't matter. FWIW, here are hex versions long and short without and with alpha channel. I haven't tested these extensively but I believe they are correct. The names may be argued about. :D -- regular 0xRRGGBB
hex6 : Int -> Css.Color
hex6 n =
rgb (n // 0x10000) (n // 0x100 |> modBy 0x100) (modBy 0x100 n)
-- short 0xRGB
hex3 : Int -> Css.Color
hex3 n =
rgb
(n // 0x100 * 0x11)
((n // 0x10 |> modBy 0x10) * 0x11)
(modBy 0x10 n * 0x11)
-- with alpha 0xRRGGBBAA
hex8 : Int -> Css.Color
hex8 n =
rgba
(n // 0x1000000)
(n // 0x10000 |> modBy 0x100)
(n // 0x100 |> modBy 0x100)
(toFloat (modBy 0x100 n) / 0xff)
-- short with alpha 0xRGBA
hex4 : Int -> Css.Color
hex4 n =
rgba
(n // 0x1000 * 0x11)
((n // 0x100 |> modBy 0x10) * 0x11)
((n // 0x10 |> modBy 0x10) * 0x11)
(toFloat (modBy 0x10 n) / 0xf) |
I have converted the PR to a draft now so it does not get merged in it's current state. I suggest we let @mdgriffith decide on the use of Ints or Strings or perhaps both. |
Any updates on this? |
Having hex colors functionality will be great - @mdgriffith @Anton-4 any updates? |
@jaladh-singhal everything is ready for @mdgriffith to decide whether he wants to use hex functions that accept |
Would be great to have hex functionality, @mdgriffith @Anton-4 |
I think I am still going to clean up the code a bit.
Let me know if you have any suggestions @mdgriffith !