I’ve refactored @hamoid’s Java Mode sketch just a little:
// Discourse.Processing.org/t/blendmode-difference-in-p2d-p3d/17541/5
// Forum.OpenFrameworks.cc/t/blend-mode-invertcolor/34415/8
// Hamoid (2020/Feb/05)
import com.jogamp.opengl.GLContext;
import com.jogamp.opengl.GL3;
//static final float[] FS = { .527, 3e-4, .729, 1e-4 };
static final String RENDER = P2D;
static final color C = #00FFFF; // cyan
static final int
SMOOTH = 8, BLENDER = DIFFERENCE,
BALLS = 20, DIAM = 50,
SFACTOR = GL3.GL_ONE_MINUS_DST_COLOR,
DFACTOR = GL3.GL_ZERO;
void setup() {
size(600, 600, RENDER);
smooth(SMOOTH);
fill(C);
noStroke();
blendMode(BLENDER); // DIFFERENCE isn't supported by OPENGL
GLContext.getCurrentGL().getGL3().glBlendFunc(SFACTOR, DFACTOR);
}
void draw() {
background(C);
final int w = width, h = height, m = millis();
for (int i = 0; i < BALLS; ++i) {
final float
x = noise(.527 * i + 3e-4 * m) * w,
y = noise(.729 * i + 1e-4 * m) * h,
d = i % 4 * DIAM + DIAM;
circle(x, y, d);
}
}
And then made a Python Mode version out of it:
# Discourse.Processing.org/t/blendmode-difference-in-p2d-p3d/17541/5
# Forum.OpenFrameworks.cc/t/blend-mode-invertcolor/34415/8
# Hamoid (2020/Feb/05)
from com.jogamp.opengl import GLContext, GL3
FS = .527, 3e-4, .729, 1e-4
RENDER, SMOOTH, BLENDER = P2D, 8, DIFFERENCE
BALLS, DIAM, C = 20, 50, 0xffFFFF00 # yellow
BALLS_RANGE = tuple(range(BALLS))
SFACTOR, DFACTOR = GL3.GL_ONE_MINUS_DST_COLOR, GL3.GL_ZERO
def setup():
size(600, 600, RENDER)
smooth(SMOOTH)
fill(C), noStroke()
blendMode(BLENDER) # DIFFERENCE isn't supported by OPENGL
GLContext.getCurrentGL().getGL3().glBlendFunc(SFACTOR, DFACTOR)
def draw():
background(C)
w = width
h = height
m = millis()
for i in BALLS_RANGE:
x = noise(FS[0] * i + FS[1] * m) * w
y = noise(FS[2] * i + FS[3] * m) * h
d = i % 4 * DIAM + DIAM
circle(x, y, d)