Shapes as a Mask
in
Programming Questions
•
2 months ago
Hey Folks -
SUPER new to the processing scene, so I'm sorry if this is a bit of a 'noob' question.
I'm in the very early stages of a collaborative project with another individual and we're trying to dive into processing to see if it can help us create an interactive / data responsive piece down the line. At the moment we're just figuring out the language and the pieces - and we're already stuck.
Basically - we know how to mask using alpha colors; but is it possible to make a shape a mask based on it's color? So, perhaps a rectangle placed in a workspace would reveal an image?
Currently we've got a very SIMPLE set up that draws a rectangle grid and randomly assigns each rectangle as black or white / transparent.
I'd like to be able to take this grid and only show an image in the spaces created by black rectangles. Is something like this possible? Is blend() the better option to explore?
Just wondering if someone could point me in the right direction. ;)
Current code:
- PImage img;
- float y = 1;
- float x = 1;
- float r = random(1, 30);
- void setup() {
- size(640, 480);
- img = loadImage("test.jpg");
- imageMode(CENTER);
- frameRate(30);
- background(0);
- image(img, width/2, height/2);
- }
- void draw() {
- r = random(1, 55);
- x = x + 16;
- if (x > 640) {
- y = y + 6;
- x = 1;
- x = x + 16;}
- noStroke();
- if (r > 30) {
- fill(0);
- } else {
- fill(255, 255, 255, 40);
- }
- rect(x, y, 15, 5);
- }
Any advice?
1