【发布时间】:2014-02-12 09:29:04
【问题描述】:
有没有办法让整个画布掉下来,除了一个形状。比如this thread,但是在Java的Processing PApplet中。
谢谢你。
【问题讨论】:
标签: java drawing processing
有没有办法让整个画布掉下来,除了一个形状。比如this thread,但是在Java的Processing PApplet中。
谢谢你。
【问题讨论】:
标签: java drawing processing
根据HTML 5 链接中的答案,我认为您需要这样的东西:
PGraphics mask, filler;
int x;
void setup(){
size(400,400);
// initial bg color, the white circle...
background(255);
//init both PGraphics
mask = createGraphics(width, height);
filler = createGraphics(width, height);
// draw a circle as a mask
mask.beginDraw();
mask.background(255);
mask.noStroke();
mask.fill(0);
mask.ellipse(width/2, height/2, 200, 200);
mask.endDraw();
}
void draw(){
// a changing bg
x = (x+1)%255;
background(x);
//dinamiaclly draw random rects
filler.beginDraw();
filler.noStroke();
filler.fill(random(255), random(255), random(255));
filler.rect(random(width), random(height), random(5,40), random(5,40));
filler.endDraw();
// get an imge out ofthis...
PImage temp = filler.get();
//mask image
temp.mask(mask);
//dispay it
image(temp, 0, 0);
}
void mousePressed(){
mask.beginDraw();
mask.background(0);
mask.noStroke();
mask.fill(255);
mask.ellipse(width/2, height/2, 200, 200);
mask.endDraw();
}
void mouseReleased(){
mask.beginDraw();
mask.background(255);
mask.noStroke();
mask.fill(0);
mask.ellipse(width/2, height/2, 200, 200);
mask.endDraw();
}
第二个例子
PGraphics mask, front, back;
int x;
void setup(){
size(400,400);
background(0);
//init both PGraphics
mask = createGraphics(width, height);
front = createGraphics(width, height);
back = createGraphics(width, height);
}
void draw(){
float x = random(width);
float y = random(height);
float sx = random(5, 40);
// draw a circle as a mask
mask.beginDraw();
mask.background(255);
mask.noStroke();
mask.fill(100);
mask.ellipse(mouseX, mouseY, 200, 200);
mask.endDraw();
//dinamiaclly draw random colored rects to PG
front.beginDraw();
front.noStroke();
front.fill(random(255), random(255), random(255));
front.rect(x, y, sx, sx);
front.endDraw();
//dinamiaclly draw random gray rects to display
back.beginDraw();
back.stroke(200);
back.fill(0, 100);
back.rect(x, y, sx, sx);
back.endDraw();
// get an imge out ofthis...
PImage temp = front.get();
//mask image
temp.mask(mask);
//dispay it
image(back,0,0);
image(temp, 0, 0);
}
使用展开地图的示例
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.geo.*;
import de.fhpotsdam.unfolding.utils.*;
PGraphics mask, red;
color transparent = color(0);
color opaque = color(255);
UnfoldingMap map;
void setup() {
size(800, 600, P2D);
mask = createGraphics(width, height);
red = createGraphics(width, height);
map = new UnfoldingMap(this);
map.zoomAndPanTo(new Location(52.5f, 13.4f), 10);
MapUtils.createDefaultEventDispatcher(this, map);
}
void draw() {
map.draw();
PImage temp = get();
//red
red.beginDraw();
red.tint(200,20,20);
red.image(temp, 0, 0);
red.endDraw();
//mask
mask.beginDraw();
mask.noStroke();
mask.background(opaque);
mask.fill(transparent);
mask.ellipseMode(CENTER);
mask.ellipse(mouseX, mouseY, 200,200);
mask.endDraw();
// without this i'm not getting to call mask in red...
// don't really know why, this is a workaround
PImage redCasted = red.get();
redCasted.mask(mask);
image(redCasted, 0, 0);
}
【讨论】:
您的问题没有说明您是否想要比该链接显示的更多内容,所以也许这个答案不是您想要的(但它是您所要求的)。首先,用你想要的任何颜色填充整个屏幕,然后在上面绘制你的形状。示例:
background(0);
fill(255);
ellipse(50,50,50,50);
【讨论】: