# Quickly mix two colours

**URL:** https://community.aseprite.org/t/quickly-mix-two-colours/8427
**Category:** Scripts & Extensions
**Created:** [March 14, 2021, 10:51pm UTC](https://community.aseprite.org/t/quickly-mix-two-colours/8427 "2021-03-14T22:51:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Olga\_Galvanova](https://community.aseprite.org/user_avatar/community.aseprite.org/olga_galvanova/32/3294_2.png) [@Olga\_Galvanova](https://community.aseprite.org/u/Olga_Galvanova)
#### Post date: [March 14, 2021, 10:51pm UTC](https://community.aseprite.org/t/quickly-mix-two-colours/8427/1 "2021-03-14T22:51:37Z")

</div>

this is a very simple script which will create 1:1 blend of selected foreground and background colours.  
the best way to use it is to assign a keyboard shortcut.  
useful for building palettes, blending and antialiasing.

```
-- ***QUICK MIX 0.1*** --- 
-- based on aquova's hue generator 
-- https://github.com/aquova/aseprite-scripts 
-- 
-- blends foreground and background colours 

local c1 = app.fgColor 
local c2 = app.bgColor 

local mix = {
	red = (c1.red - c2.red),
	green = (c1.green - c2.green),
	blue = (c1.blue - c2.blue),
}

local newRed = c1.red - math.floor(mix.red * 0.5) 
local newGreen = c1.green - math.floor(mix.green * 0.5) 
local newBlue = c1.blue - math.floor(mix.blue * 0.5) 

local c3 = Color{
	r = newRed, 
	g = newGreen, 
	b = newBlue, 
	a = 255 --newAlpha
}

app.fgColor = c3
```

---

<div class="post-metadata">

### Author: ![Olga\_Galvanova](https://community.aseprite.org/user_avatar/community.aseprite.org/olga_galvanova/32/3294_2.png) [@Olga\_Galvanova](https://community.aseprite.org/u/Olga_Galvanova)
#### Post date: [July 15, 2021, 12:01pm UTC](https://community.aseprite.org/t/quickly-mix-two-colours/8427/2 "2021-07-15T12:01:02Z")

</div>

update:  
now works with alpha channels.  
if one of colours is fully transparent, only alpha channels get mixed.

```auto
-- ***QUICK MIX 0.2*** --- 
-- b236, based on aquova's hue generator 
-- https://github.com/aquova/aseprite-scripts 
-- 
-- blends foreground and background colours 
-- if one of colours is fully transparent, 
-- the script will mix alpha channels only 

local c1 = app.fgColor 
local c2 = app.bgColor 
local newRed
local newGreen
local newBlue
local newAlpha

if (c1.alpha == 0) then 
	local mix = {
		red = c2.red,
		green = c2.green,
		blue = c2.blue,
		alpha = (c1.alpha - c2.alpha)
	}
	newRed = c2.red 
	newGreen = c2.green 
	newBlue = c2.blue 
	newAlpha = c1.alpha - math.floor(mix.alpha * 0.5) 
	
elseif (c2.alpha == 0) then 
	local mix = {
		red = c1.red,
		green = c1.green,
		blue = c1.blue,
		alpha = (c1.alpha - c2.alpha)
	}
	newRed = c1.red 
	newGreen = c1.green 
	newBlue = c1.blue 
	newAlpha = c1.alpha - math.floor(mix.alpha * 0.5) 
	
else 
	local mix = {
		red = (c1.red - c2.red),
		green = (c1.green - c2.green),
		blue = (c1.blue - c2.blue),
		alpha = (c1.alpha - c2.alpha)
	}
	
	newRed = c1.red - math.floor(mix.red * 0.5) 
	newGreen = c1.green - math.floor(mix.green * 0.5) 
	newBlue = c1.blue - math.floor(mix.blue * 0.5) 
	newAlpha = c1.alpha - math.floor(mix.alpha * 0.5) 
	
end 

local c3 = Color{
	r = newRed, 
	g = newGreen, 
	b = newBlue, 
	a = newAlpha 
}

app.fgColor = c3 

```
