Skip to content

Instantly share code, notes, and snippets.

@jaycody
Last active May 13, 2016 18:50
Show Gist options
  • Save jaycody/ad773a632706d6eac9f964f0cbbba77e to your computer and use it in GitHub Desktop.
Save jaycody/ad773a632706d6eac9f964f0cbbba77e to your computer and use it in GitHub Desktop.
trails with alpha rectangle - UPDATED with blendMode(SUBSTRACT);
/*trails with alpha rectangle - UPDATED with blendMode(SUBSTRACT);
There’s the quite well-known technique of painting a more or less transparent rectangle each frame (instead of a full background)
in order to get objects to create more or less long trails,
but if you set the alpha below a certain value, like 25, then you start getting smudgy ‘leftovers'
//shiffman's quick hack
fill(0,1);
rect(0,0,width, height);
//updated with blendMode
blendMode(SUBTRACT);
fill(1);
rect(0,0,width, height);
blendMode(BLEND);
example:
*/
float x, y, theta;
int frms = 280, num = 3;
void setup() {
size(540, 540);
background(0);
}
void draw() {
blendMode(SUBTRACT);
fill(1);
noStroke();
rect(0, 0, width, height);
blendMode(BLEND);
fill(255);
for (int i=0; i<num; i++) {
x = width/2 + sin(theta)*60*(i+1);
y = height/2 + cos(theta)*60*(i+1);
ellipse(x, y, 25, 25);
}
theta += TWO_PI/frms;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment