Skip to content

Instantly share code, notes, and snippets.

@Fabax
Created October 19, 2014 13:47
Show Gist options
  • Save Fabax/54901e9206f70fd38e2c to your computer and use it in GitHub Desktop.
Save Fabax/54901e9206f70fd38e2c to your computer and use it in GitHub Desktop.
Processing : mask pgraphic
PGraphics s, m;
void setup(){
size(220,220);
// Create a cookie cutter.
// White areas are kept. Black areas are not.
m = createGraphics( width, height, P2D );
m.beginDraw();
m.background(0);
m.fill(255);
m.stroke(255);
m.ellipse(100, 100, 60, 60);
m.endDraw();
// Create a pattern.
s = createGraphics( width, height, P2D );
s.beginDraw();
s.smooth();
s.translate(s.width/2, s.height/2);
s.rotate( radians(35) );
s.background(0,0,255);
s.noStroke();
s.fill( 0,255,0);
for( int i = -300; i < 300; i+=10 ){
s.rect( i, -300, 5, 600);
}
// This line uses the cookie cutter.
s.mask( m.get() );
s.endDraw();
}
void draw(){
background(128,0,0);
image( s.get(), 0, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment