Here’s my exploration (with a few bits “borrowed” from @mpilgrem’s code!). The output is what I’ve just uploaded to Twitter (somehow I can never get those pictures to embed here). What it does is draw two squares one on top of the other with a specific blend mode. To avoid interaction with the background, it does this in a separate blank image. That image is then drawn in normal blending mode onto the background. The squares are gradients: block colour but with gradient alpha, and in different directions. Then all the different combinations (for the 2-element blendMode function) are displayed in a grid. Took me a while to spot NORMAL
amongst them!
--
-- Blend Modes Explorer
--
supportedOrientations(LANDSCAPE_ANY)
function setup()
print("This demonstrates blending modes. Blend modes determine "..
"how drawing operations blend together on-screen.")
mode = {
BLEND_ZERO, BLEND_ONE,
BLEND_SRC_COLOR, BLEND_ONE_MINUS_SRC_COLOR,
BLEND_DST_COLOR, BLEND_ONE_MINUS_DST_COLOR,
BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA,
BLEND_DST_ALPHA, BLEND_ONE_MINUS_DST_ALPHA,
BLEND_SRC_ALPHA_SATURATE}
modeName = {
"ZERO", "ONE",
"SRC_COLOR", "ONE_MINUS_SRC_COLOR",
"DST_COLOR", "ONE_MINUS_DST_COLOR",
"SRC_ALPHA", "ONE_MINUS_SRC_ALPHA",
"DST_ALPHA", "ONE_MINUS_DST_ALPHA",
"SRC_ALPHA_SATURATE"}
local n = #mode
local w = math.floor(math.min(WIDTH,HEIGHT)/n)
local src = mesh()
src:addRect(w/2,w/2,w,w)
src.colors = {
color(255, 0, 0, 0),
color(255, 0, 0, 255),
color(255, 0, 0, 255),
color(255, 0, 0, 0),
color(255, 0, 0, 255),
color(255, 0, 0, 0)
}
local dest = mesh()
dest:addRect(w/2,w/2,w,w)
dest.colors = {
color(0, 0, 255, 255),
color(0, 0, 255, 255),
color(0, 0, 255, 0),
color(0, 0, 255, 255),
color(0, 0, 255, 0),
color(0, 0, 255, 0),
}
im = image(WIDTH,HEIGHT)
spriteMode(CORNER)
local imw = image(w,w)
for i = 1, n do
print(modeName[n+1-i])
for j = 1,n do
setContext(imw)
dest:draw()
blendMode(mode[i],mode[j])
src:draw()
setContext()
blendMode(NORMAL)
setContext(im)
resetMatrix()
sprite(imw,(i-1)*w,(j-1)*w)
setContext()
end
end
end
function draw()
background(255, 255, 255, 255)
sprite(im,0,0)
end