marius
marius

Reputation: 1266

Mootools color instant morphing

what I'm searching is an fast way to instantly morph colors - (not by event / time). It would be nice if there is any function like morphColors(color1,color2,percent) - percent should give in a fractional value that says how much the morphing should go.

Maybe there is also a Javascript way?

Thx in advance!

Upvotes: 2

Views: 61

Answers (2)

marius
marius

Reputation: 1266

I 've found out a solution by myself

here i share the results:

if(percent<0) percent=0.0;
else if(percent>1) percent=1.0;
var r = Math.round(color1[0]*(1.0-percent) + color2[0]*percent);
var g = Math.round(color1[1]*(1.0-percent) + color2[1]*percent);
var b = Math.round(color1[2]*(1.0-percent) + color2[2]*percent);
return [r, g, b];

Upvotes: 1

Dimitar Christoff
Dimitar Christoff

Reputation: 26165

you could use Fx class to do stuff but it's not % based.

mootools also has an official plugin in more: http://mootools.net/docs/more/Utilities/Color - see .mix()

have a read of lessc's source here for ideas - https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js#L159-L177 - colour mix 2 colours with a weight.

Upvotes: 2

Related Questions