Loading...
Logo
Processing Forum
Hi all,

I'm helping a friend with a project. Right now, she has an image that is masked and made visible by the mouse position.

What we want is a fading trail (of masks?). I pulled in some code kindly put on openprocessing to create a trail of ellipses, but am having trouble figuring out how to make the basic logic work.

Here is the code, if you think you could help, it will be greatly and eternally appreciated!!!
Cheers!

Copy code

  1. PImage bgImage;
  2. PImage maskImage;
  3. PGraphics graphicalMask;
  4. int iw, ih;
  5. int dw, dh;
  6. int angle = 0;

  7. //here we are creating an array of x and y positions. 
  8. float [] x = new float [50];   //create an empty array of 50 x positions
  9. float [] y = new float [50];   // do the same for y 

  10. //thanks to Emily Burgess for trail help


  11. void setup()
  12. {
  13.   
  14.   size(500, 500);
  15.   bgImage = loadImage("paris_nightstreet.jpg");
  16.   iw = bgImage.width;
  17.   ih = bgImage.height;
  18. //  dw = width - iw;
  19. //  dh = height - ih;
  20.   graphicalMask = createGraphics(iw, ih, JAVA2D);

  21. //ok, here you are creating a loop that says to set the *initial* value of 
  22. // each item in your array to 0. It's basically initializing the array (I think)
  23.   for (int i = 0; i<50; i++){     //here, i is an iterator we create temporarily
  24.     x[i] = 0;  
  25.     y[i] = 0;   
  26.   } 
  27. //end for loop  

  28. }

  29. void draw()
  30. {
  31.   background(0,0,0);

  32.   graphicalMask.beginDraw();
  33.   // Erase graphics
  34.   graphicalMask.background(0);
  35.   // Draw the mask

  36.   angle += 10;
  37.     float val = cos(radians(angle)) * 6.0;
  38.     for (int a = 0; a < 360; a += 50) {
  39.       float xoff = cos(radians(a)) * val;
  40.       float yoff = sin(radians(a)) * val;
  41.     graphicalMask.fill(255);
  42.     graphicalMask.noStroke();
  43.     graphicalMask.ellipse(mouseX + xoff, mouseY + yoff, 100,100);
  44.     }
  45.   graphicalMask.endDraw();
  46.   // Copy the original image (kept as reference)
  47.   maskImage = bgImage.get();
  48.   // Apply the mask
  49.   maskImage.mask(graphicalMask);
  50.   // Display the result
  51.   image(maskImage, dw/2, dh/2);

  52.   
  53. /////Ok, here is another for-loop. What we're doing is cycling through the array
  54. // and setting the value of each item in the array to the one before it
  55.   for (int i=0; i<49; i++) {  
  56.     x[i] = x [i + 1];  
  57.     y[i] = y [i + 1];
  58.     
  59.     fill (i*2); //set the fill color by i
  60.     ellipse (x[i], y[i], i, i);
  61.   }
  62. //so each time the draw loop happens, we start this loop and go and reset the x and y values to the previous value
  63.   x[49] = mouseX;
  64.   y[49] = mouseY;
  65.    

  66. }
 

Replies(2)

you're pretty close. you've already got the logic for the diminishing ellipses working, so (if I understand you correctly) what you want to do is draw the trail of ellipses into the image mask with a fading color value. Try adding in this for loop at line 46:

graphicalMask.noStroke();
for(int i = 0; i < x.length; i++){
  graphicalMask.fill(i * (255 / x.length) );
  graphicalMask.ellipse(x[i], y[i], i*3, i*3);
}
graphicalMask.endDraw();

This draws your collection of ellipses with receding transparency.
Thanks, we'll give this a try!
Cheers!