Hi,
I whipped up a little proof of concept sketch in Processing. It's a drawing program that uses Processing's mask() function.
Works fine in Java mode, not fine in Javascript mode. I can see one of the images, but not the one effected by the mask functionality. Is it possible that I can't use that filter? Or any filter, for that matter? I've been having trouble running many different examples in Processing.js, so I'm not really sure what the limitations are.
Tested on newest version of Processing, 2.0.3, on Win8 in Chrome and IE.
- /* @pjs preload="leaves.jpg, moonwalk.jpg";
- */
- PGraphics maskPattern;
- PGraphics savedImg;
- PImage img;
- PImage img2;
- int displayImageX;
- int displayImageY;
- float scaleFactor;
- float centerScaledAdjustedXpos;
- float centerScaledAdjustedYpos;
- void setup() {
- img = loadImage("moonwalk.jpg");
- size(800,800,JAVA2D);
- //640,260
- maskPattern = createGraphics(img.width,img.height);
- savedImg = createGraphics(img.width,img.height);
- img2 = loadImage("leaves.jpg");
- scaleFactor=1;
- displayImageX = width/2;
- displayImageY = height/2;
- centerScaledAdjustedXpos=0;
- centerScaledAdjustedYpos=0;
- }
- void draw() {
- pushMatrix();
- scale(scaleFactor);
- background(0);
- imageMode(CENTER);
- image(img2,displayImageX/scaleFactor,displayImageY/scaleFactor);
- if (mousePressed == true) {
- maskPaint();
- }
- img.mask(maskPattern);
- image(img,displayImageX/scaleFactor,displayImageY/scaleFactor);
- popMatrix();
- }
- void maskPaint(){
- centerScaledAdjustedXpos = ((mouseX-displayImageX)/scaleFactor+(maskPattern.width/2));
- centerScaledAdjustedYpos = ((mouseY-displayImageY)/scaleFactor+(maskPattern.height/2));
- maskPattern.beginDraw();
- maskPattern.stroke(255);
- maskPattern.fill(255);
- //maskPattern.ellipse(mouseX,mouseY,50,50);
- //maskPattern.ellipse(((mouseX-(displayImageX))+(maskPattern.width/2)), ((mouseY-(displayImageY))+(maskPattern.height/2)), 50, 50);
- maskPattern.ellipse(centerScaledAdjustedXpos, centerScaledAdjustedYpos, 50, 50);
- maskPattern.endDraw();
- println(centerScaledAdjustedXpos + ", " + centerScaledAdjustedYpos);
- }
- void keyPressed() {
- if(key == 's')
- {
- savedImg.beginDraw();
- savedImg.image(img2,0,0);
- img.mask(maskPattern);
- savedImg.image(img,0,0);
- savedImg.endDraw();
- savedImg.save("final_image.jpg");
- }
- if(key == ' '){
- maskPattern.clear();
- }
- if (key == '-') {
- println("minus ");
- // srcImage.width--;
- // //maskImage.width--;
- // bgImage.width--;
- // srcImage.height--;
- // //maskImage.height--;
- // bgImage.height--;
- //background(0);
- scaleFactor=scaleFactor-.01;
- }
- if (key == '=') {
- println(img.width/2);
- scaleFactor=scaleFactor+.01;
- }
- }
1