50% between 2 colors button

A script would be perfect for this since you can put it on a hotkey. Here’s a script that blends your background and foreground colours, and sets your foreground colour to the result.

do
    local bg = app.bgColor
	local fg = app.fgColor
	local newColor
	
	newColor = fg
	
	local fg_alpha = 0.5
	local fg_r = fg.red/255 * fg_alpha
	local fg_g = fg.green/255 * fg_alpha
	local fg_b = fg.blue/255 * fg_alpha
	
	local bg_alpha = 1.0
	local bg_r = bg.red/255 * bg_alpha
	local bg_g = bg.green/255 * bg_alpha
	local bg_b = bg.blue/255 * bg_alpha
	
	newColor.alpha = 255
	newColor.red = 		255 * (fg_r + bg_r*(1-fg_alpha))
	newColor.green = 	255 * (fg_g + bg_g*(1-fg_alpha))
	newColor.blue = 	255 * (fg_b + bg_b*(1-fg_alpha))
		
	app.fgColor = newColor
end

Note that it completely disregards the alpha of your BG/FG colours. If you want the average of their opacities as well, then change newColor.alpha = 255 to newColor.alpha = (fg.alpha + bg.alpha)/2.

This script doesn’t give quite the same results as Aseprite because I had to reimplement the colour math since Aseprite doesn’t provide any blending functions in the scripting API, and the script rounds differently from Aseprite. This should not be a significant difference, it’s at most 1 in every channel.

2 Likes