We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello there!
I am an artist and a quite new in processing :) I 'd like to achieve the following: I have two different images. I want to put them as layers and then find a way to reveal parts of the bottom image with some circles cut in the upper layer. The circles should be of different size and should be moving freely on the canvas.
It's like having a spotlight searching something into the dark. (This is why I have tried it with the brightness example, but I could not have the upper image since in this specific example is the black canvas.. so brightness doesn't work for me here.)
Any suggestions?
Thank you for your time :)
Answers
You are looking for PImage, mask() and PGraphics. Look in the reference, and/or search the forum for mask.
Here a simple example.
_vk thanks for your prompt answer!! I tried your code with my images and it works fine. the thing is that any attempt to write something different instead of mouseX, mouseY does not play anything..maybe the mask and the ellipse drawing produce a kind of conflict? I have a class named ball (from the example bouncing ball) and I put instead of mouseX, mouseY x and y. doesn't work :/
The idea was to help you understand how it's done... We can't help you much more without your code.
But it is pretty straightforward.You want to draw white (or gray) stuff in your mask layer. That's it. Try displaying the PGraphics
image(pg, 0, 0)
without masking anything, and check if you are drawing in it. once you get this working hide it back and use as a mask.Or post your code so we can try to go further.
;)
hi again! thank you so much for your tips. It is working now. The only thing is that I am trying to make a function that consists also the PGraphics so that I am able to create more of these "spotlights". I have tried several solutions but nothing is working so I am posting the code. If you have any advice it will be very helpful :) Although I create three balls only one is appearing on the screen. After some experiments it seems it is always the last one I put as extra. Thank you for your time :)
Hi, I can't run it right now, but I'd guess the issue is in line
83
. Each instance of ball is drawing an image covering the previous one. I think the image should be displayed in draw rather than inside the class. I'll run it later anyway to test.:)
Line 80 is also causing problems: you call background() for each circle thereby erasing the previous circles.
Also don't call createGraphics() in draw()! This causes a memory leak: it will create a new memory intensive PGraphics object each iteration. You need to move line 26 to setup().
Maybe you should call pg.beginDraw() and pg.endDraw() once per draw() but it might work fine if you call it more, not sure.
@_vk Hi again and happy new year! Although I moved line 83 inside draw() I still cannot display the other circles.. which it's weird... :-/
@_vk @colouredmirrorball I just figured it out with your help! I had also to remove line 80 and call background in draw(). Thank you both so much for your help!!! :)
Happy new year :)