I am designing a 2D drawing library (it is its very early stages) and I was wondering what to do with Alpha (transparency).

I have two trains of thought:

A. Implement Alpha in the Color class since it affects the eventual color. The color red (255, 0, 0, 255) looks totally different from the color (255, 0, 0, 127) both on a white background.

B. Implement the Alpha value in the Shape class containing all base properties for a shape like position, color (in this case color would only contain r, g, b values), stroke weight etc. This could also work since Alpha would affect the entire object.

What do you guys think makes more sense?

Side notes:
If Alpha would be part of Shape it would be harder to quickly change colors and reassign them. But this would make it easier to implement functions like color mixing etc in the color class.

(let me know if this is the place to ask this, I was also thinking about software engineering stack exchange. But this seemed to make more sense)

  • $\begingroup$ What is wrong with using one integer to store ARGB? You can extract the values from the int if required using bit shifting and masking. $\endgroup$
    – clankill3r
    Apr 1, 2020 at 8:35


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.