objective c - Can you mix views of different colours to create new colours? -
i hoping having yellow view on top of blue view create smaller green view. :d
uiview *blueview = [uiview new]; blueview.frame = cgrectmake(0.0, 0.0, 100.0, 100.0); blueview.alpha = 0.5; blueview.backgroundcolor = [uicolor bluecolor]; [self.view addsubview:blueview]; uiview *yellowview = [uiview new]; yellowview.frame = cgrectmake(40.0, 40.0, 100.0, 100.0); yellowview.alpha = 0.5; yellowview.backgroundcolor = [uicolor yellowcolor]; [self.view addsubview: yellowview]; didn't work though... ideas on this?
i'd use circles too.
because computer color blending additive, mixing blue , yellow never make green.
colors represented rgb value (usually 0-255 each component occupies single byte, i'll representing them here 0-1 simplicity).
when blending other colors, these rgb values interpolated according alphas of respective colors (how opaque are). larger alpha value means larger weighting towards given color.
therefore when first blending white background, yellow end up:
(1, 1, 0) * 0.5 + (1, 1, 1) * 0.5 = (0.5, 0.5, 0) + (0.5, 0.5, 0.5) = (1, 1, 0.5) now when blue gets blended white background, you'll get:
(0, 0, 1) * 0.5 + (1, 1, 1) * 0.5 = (0, 0, 0.5) + (0.5, 0.5, 0.5) = (0.5, 0.5, 1) finally, resulting color when blending them depends 1 draw first. if draw blue first (like you've done), you'll blended blue un-blended yellow together:
(0.5, 0.5, 1) * 0.5 + (1, 1, 0) * 0.5 = (0.25, 0.25, 0.5) + (0.5, 0.5, 0) = (0.75, 0.75, 0.5) ew.
i think best way approximate green try , aim light green
you can achieve mixing cyan (0, 1, 1) , yellow (1, 1, 0) alphas of 0.5.
that way you'll end (0.75, 1, 0.5) if add cyan before yellow:
and (0.5, 1, 0.75) if mix yellow before cyan:
however you'll never able end color of (0, 1, 0) mixing 2 colors (unless colors (0, 1, 0) begin with).
imagine picking 2 colors on it, , drawing straight line between them.
this line represents different colors can achieve additively blending these 2 colors @ varying alphas.
this shows how no 2 colors have green along line, besides green & green. true red , blue, extremes of color gamut.
however, may able achieve desired result using different blend-mode normal additive one. can in core graphics using cgcontextsetblendmode(). have @ core graphics blend-mode docs.









Comments
Post a Comment