在PApplet中绘制相反的形状(Draw opposite of shape in PApplet)

编程入门 行业动态 更新时间:2024-10-28 05:13:35
在PApplet中绘制相反的形状(Draw opposite of shape in PApplet)

除了形状之外,有没有办法落下整个画布。 例如, 这个线程 ,但在Java的Processing PApplet中。

先谢谢你。

Is there a way to fall an entire canvas, except for a shape. For example, this thread, but in Java's Processing PApplet.

Thank you in advanced.

最满意答案

通过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); }

By the answer in HTML 5 linked, I assume you need something like this:

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(); }

second example

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); }

example using Unfold maps

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); }

更多推荐

Processing,PApplet,落下,画布,电脑培训,计算机培训,IT培训"/> <meta name="desc

本文发布于:2023-07-27 17:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:形状   PApplet   shape   Draw

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!