processing / p5.js-website-OLD

The website for p5.js.
http://p5js.org
Other
61 stars 75 forks source link

use graphic as mask. why does this not work? #191

Closed soundreactor closed 8 years ago

soundreactor commented 8 years ago

i edited the masking example http://p5js.org/examples/examples/Image_Alpha_Mask.php

using a graphic as mask does not work like expected why so? and is there a fix for that?

var img; var imgMask; var pg;

function preload() { img = loadImage("assets/moonwalk.jpg"); imgMask = loadImage("assets/mask.png"); } function setup() { createCanvas(720, 400); pg = createGraphics(720, 400); pg.background(0); pg.noStroke(); pg.fill(255); pg.ellipse(300, 200, 50, 50); img.mask(pg); } function draw(){ background(0, 102, 153); //this should work but does not image(img, 0,0); }

lmccart commented 8 years ago

mask() only works with an image file, not with graphics. From the reference: "Masks part of an image from displaying by loading another image and using it's alpha channel as an alpha channel for this image."