# [Pharo-dev] Color arithmetical operations are broken

Nicolai Hess nicolaihess at web.de
Sun Mar 22 16:44:17 EDT 2015

```2015-03-22 21:26 GMT+01:00 Aliaksei Syrel <alex.syrel at gmail.com>:

>
> On Sun, Mar 22, 2015 at 8:17 PM, Nicolai Hess <nicolaihess at web.de> wrote:
>
>> Yes, but I think the operation were defined as the Color class did not
>> contain the alpha value
>
>
> Exactly
>
> Ah, Ok. In that case I would not use the arithmetic operations at all.
>> never :)
>
>
> I wanted to solve the problem without actually solving it :)
>
> In the image there is a general animation class that supports linear
> interpolation defined as:
>
>> (to - from) * delta + from
>
> So it can theoretically work with all objects polymorphic with numbers in
> sense of math operations. I browsed Color class and surprisingly found that
> it is polymorphic with Number! What a lucky moment :) However when I tried
> I failed. Then I realized that color's value can't be negative, so
> general solution will not work, since (to - from) can't be negative
> Color.
>

In that case you may be interested on this issue:
15138 <https://pharo.fogbugz.com/default.asp?15138>
inprecise interpolateTo:at: for floats

>
> That is why I had to interpolate each channel separately:
>
> |r g b a|
>> r := (to red - from red) * delta + from red.
>> g := (to green - from green) * delta + from green.
>> b := (to blue - from blue) * delta + from blue.
>> a := (to alpha - from alpha) * delta + from alpha.
>> ^ Color r: r g: g b: b alpha: a
>
>
> I don't need math operations with colors anymore :) But having that
> feature doesn't work we should do something before release ;) That's why
> issue was opened. Feel free to make slice requests
>
> Cheers,
> Alex
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20150322/a7a09707/attachment-0002.html>
```