Skip to content
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

Tutorial implementing own color type #217

Open
marsupialsoup opened this issue Sep 7, 2020 · 2 comments
Open

Tutorial implementing own color type #217

marsupialsoup opened this issue Sep 7, 2020 · 2 comments
Labels

Comments

@marsupialsoup
Copy link

I am not sure if this belongs in the issues section, but it would be nice if there was a tutorial for implementing your own color type in Julia. There is some suggestions in the readme.md but it seems too intimidating to do so, at least to me. This is more of a general question for implementing own types in Julia in general, and understanding the mechanics of Julia's type system.

@kimikage
Copy link
Collaborator

kimikage commented Sep 7, 2020

In fact, if you don't have to think about interactions with other color types, implementing own color types is exactly the same as Julia's general struct definition.

# dummy type for testing 2-component color
struct AnaglyphColor{T} <: Color{T,2} # not `TransparentGray`
left::T; right::T
end
# dummy type for testing 4-component color
struct CMYK{T} <: Color{T,4} # not `Transparent3`
c::T; m::T; y::T; k::T
end
# dummy type for testing 5-component color
struct ACMYK{T} <: AlphaColor{CMYK{T},T,5}
alpha::T; c::T; m::T; y::T; k::T
ACMYK{T}(c, m, y, k, alpha=1) where T = new{T}(alpha, c, m, y, k)
end

The @make_constructors mentioned in the README, as the name implies, adds convenient constructors, but I'm thinking of modifying this mechanism. (PR #197)

IMO, it might be more useful to create a separate package as an add-on, rather than adding new types into ColorTypes.jl. I am thinking of creating a new package CMYKColorTypes.jl, which does not include color management features. Perhaps it should be a living tutorial.

@kimikage
Copy link
Collaborator

I'm also interested in the HWB colors, which will be part of CSS Color Module Level 4.
(cf. https://drafts.csswg.org/css-color/#the-hwb-notation)
I'm skeptical that the HWB will remain in the Recommendation or that it will actually catch on, but I think it's more suitable for the tutorial than the CMYK.

One simple color model which is "actually used" is YCoCg. I think YCoCg qualifies as a member of ColorTypes.jl, but I'm not even going to actively introduce it because it's too simple. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants