#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# How can I get blendMode to blend everything?

edited October 2014

I've been using blendMode for and I realised then when you combine more than 2 color areas parts stop getting blended.

I was trying to do this in a more complicated sketch so I put a really simple one together to demonstrate the problem.

In this image (http://i.imgur.com/2i2ZRzg.png) you can see that there is a section that is not getting blended at all.

Why is this? Can it be fixed?

Demonstration Code:

``````void setup()
{
size(600,600);
background(0);
noStroke();
fill(random(0,255),random(0,255),random(0,255));
rect(100,100,100,100);
fill(random(0,255),random(0,255),random(0,255));
rect(150,150,100,100);
fill(random(0,255),random(0,255),random(0,255));
rect(175,175,100,100);
}
``````

More complicated code where I discovered the problem:

``````ArrayList sq;

float momentum;
boolean pressed;

void setup()
{
size(600,600);
sq = new ArrayList();
for(int i = 0; i < 3; i++)
{
float size = random(75.0f,150.0f);
}
}

void draw()
{
background(0);
rectMode(CENTER);
noStroke();
for(int i = 0; i < sq.size(); i++)
{
squareRect s = (squareRect) sq.get(i);
s.update();

{
if(s.removal)
{
sq.remove(i);
}
else
{
fill(s.c);
rect(s.x,s.y,s.w,s.h);
}
}
else
{
}
}
if(pressed)
{
momentum= momentum*1.05f;
}
else
{
momentum=0;
}

}

void mousePressed()
{
pressed=true;
momentum=1.0f;
}

void mouseReleased()
{

boolean stop = false;
pressed=false;
for(int i = 0; i < sq.size(); i++)
{
squareRect s = (squareRect) sq.get(i);
s.clickCheck(i, sq, stop, momentum);
if(s.removal)
{
break;
}
}
}

class squareRect
{
float tarX, tarY;
float x, y, w, h;
boolean removal;
int removalTimer = 0;
color c;

public squareRect(float nx, float ny, float nw, float nh)
{
x=nx;
y=ny;
w=nw;
h=nh;
tarX=nx;
tarY=ny;
c = color(random(0,255),random(0,255),random(0,255));
}

public squareRect(float nx, float ny, float nw, float nh, float nTarX, float nTarY, color nc)
{
x=nx;
y=ny;
w=nw;
h=nh;
tarX=nTarX;
tarY=nTarY;
c=nc;
}

public void split(int dex, ArrayList list, float mom)
{
float cx = x+(w/2);
float cy = y+(h/2);

color newColor = color(random(0,255),random(0,255),random(0,255));

}

public void update()
{
x = lerp(x,tarX,.1f);
y = lerp(y,tarY,.1f);
}

public void clickCheck(int dex, ArrayList list, boolean stopper, float mom)
{
if(mouseX >= x-(w/2) && mouseX < x+(w/2))
{
if(mouseY >= y-(h/2) && mouseY < y+(h/2))
{
split(dex,list, mom);
removal=true;
}
}
}
}
``````
Tagged: