I need to fill an ellipse with a .jpg image. Is that even possible? because I can't find any example of that.
Thanks ^^
Thanks ^^
1
// http://forum.processing.org/topic/image-into-shapes final static String URL = "http://reesephoto.files.wordpress.com/2012/07/"; final static String FILE = "swallowtail-on-red-flowers.jpg"; final static String PATH = URL + FILE; //final static String PATH = FILE; final static color BG = #80A020; final static float SCALING = .9; PImage img; void setup() { size(600, 400); noLoop(); smooth(); noStroke(); fill(-1); background(0); ellipse(width >> 1, height >> 1, width*SCALING, height*SCALING); img = loadImage(PATH); img.resize(width, height); img.mask(g); //img.mask( get() ); // alternative to g. background(BG); } void draw() { background(img); }
// http://forum.processing.org/topic/image-into-shapes
final static String URL = "http://reesephoto.files.wordpress.com/2012/07/";
final static String FILE = "swallowtail-on-red-flowers.jpg";
//final static String PATH = URL + FILE;
final static String PATH = FILE;
final static color BG = #80A020;
final static float SCALING = .9;
PImage imgEllipse, imgRect;
boolean toggle;
void setup() {
size(600, 400);
noLoop();
final PImage img = loadImage(PATH);
img.resize(width, height);
imgEllipse = img.get();
imgRect = img.get();
final PGraphics pg = initSurface();
pg.ellipse(width >> 1, height >> 1, width*SCALING, height*SCALING);
imgEllipse.mask( pg.get() );
pg.background(0);
pg.rect(width >> 1, height >> 1, width*.5, height*.5);
imgRect.mask( pg.get() );
}
void draw() {
background(BG);
image(toggle? imgEllipse:imgRect, 0, 0);
}
void mousePressed() {
redraw();
toggle = !toggle;
println(toggle);
}
void keyPressed() {
mousePressed();
}
PGraphics initSurface() {
final PGraphics pg = createGraphics(width, height, JAVA2D);
pg.beginDraw();
pg.smooth();
pg.noStroke();
pg.fill(-1);
pg.background(0);
pg.ellipseMode(CENTER);
pg.rectMode(CENTER);
pg.endDraw();
return pg;
}