Last active
September 18, 2016 12:29
-
-
Save ale2x72/f5d83fd013d791400769431f324bde63 to your computer and use it in GitHub Desktop.
improved fading using blendMode()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
an improvement upon the fading rectangle technique | |
using blendMode() to get rid of the 'streaks' that | |
usually remained | |
code for Processing 3 | |
*/ | |
float ang, inc; | |
boolean inv; | |
int blendMode; | |
color bg, str, fi; | |
void setup() { | |
size(600, 600, P2D); | |
smooth(8); | |
ang = 0; | |
inc = 0.022; | |
inv = false; | |
bg = color(0); | |
fi = color(1); | |
blendMode = SUBTRACT; | |
str = color(255); | |
background(bg); | |
//stroke(str); | |
strokeWeight(20); | |
} | |
void draw() { | |
stroke(str); | |
pushMatrix(); | |
translate(width*.5, height*.5); | |
rotate(ang); | |
point(100, 0); | |
point(150, 0); | |
point(200, 0); | |
popMatrix(); | |
ang-=inc; | |
blendMode(blendMode); // trick for better fading | |
fill(fi); | |
rect(0, 0, width, height); | |
blendMode(BLEND); | |
} | |
void keyPressed() { | |
if (key == ' ') { | |
inv = !inv; | |
if (inv) { | |
blendMode = ADD; | |
fi = color(254, 1); | |
str = color(0); | |
bg = color(255); | |
} else { | |
blendMode = SUBTRACT; | |
fi = color(1); | |
str = color(255); | |
bg = color(0); | |
} | |
background(bg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment