The image of the dinosaur is greyscale. The SVG then uses a,
feFlood
&
feComposite
to combine the
SourceGraphic
with the
flood-color
using an
arithmetic
operator. This operator is kind of a lot to get your head around (because
MATHS
), but it has 4 additional attributes:
k1, k2, k3
&
k4
that work like this:
result = k1*in*in2 + k2*in + k3*in2 + k4
In this example, we can ignore
k2 - k4
because
k1
does everything for us: the results of
in * in2
(the dino image and the flood-color) multiplied by the value of
k1
- in this instance,
1
. Note that this only works so well because we're using a pure greyscale image as a base - full-colour images can still be colourised, but not in the same way, as the flood-color is multiplied by the original colours in the image itself.
Then we're just using GSAP to loop through an array of colours and append a change of the filter's
feFlood flood-color
to the timeline. Nice! ✨