GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2017-06-06 17:50:17

DragonCoke
Member
Registered: 2017-06-06
Posts: 1

merge_color_squared

Expand/// merge_color_squared(col1,col2,amount);
//
// Returns a color merged from two colors by the specified amount. The values
// are squared to make a more natural blend.
//
//		col1 		the first color
//		col2 		the second color
//		amount	amount of blend, 0 - 1
//
//
/// GMLscripts.com/license
{
	var _col1 = argument0;
	var _col2 = argument1;
	var _amount = argument2;

	var _col;
	_col[1,2] = colour_get_blue(_col2);
	_col[1,1] = colour_get_green(_col2);
	_col[1,0] = colour_get_red(_col2);

	_col[0,2] = colour_get_blue(_col1);
	_col[0,1] = colour_get_green(_col1);
	_col[0,0] = colour_get_red(_col1);


	for (var i=0;i<3;i++) {
		_col[0,i] = sqrt(
			lerp(
				sqr(_col[0,i]),
				sqr(_col[1,i]),
				_amount
			)
		);
	}


	return make_colour_rgb(_col[0,0],_col[0,1],_col[0,2]);
}

Offline

#2 2017-06-06 17:55:13

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: merge_color_squared

Welcome to the forums, DragonCoke, and thank you for the submission.

This is a cool variation of merge_color() that fixes some of the aesthetic drawbacks of lerping through the RGB color cube. I'll be sure to add it to the site.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB