Loading...
Logo
Processing Forum
Hello, 
what is the best way to make many magnifying glasses in one image in this example from Andres:
so it would look like this:


and would be used in multitouch application, for example.

Thanks.

Replies(2)

You can run the filter multiple times with different center coordinates.

Copy code
  1. import processing.opengl.*;
  2. import codeanticode.glgraphics.*;

  3. int lensDiam = 400;
  4. float magFactor = 5, scalef = .3f;
  5. GLTexture textImage, lensImage;
  6. GLTextureFilter lensFilter;

  7. void setup() {
  8.   size(450, 450, GLConstants.GLGRAPHICS);
  9.   noFill();
  10.   ellipseMode(CORNERS);
  11.   textureMode(NORMAL);
  12.   textImage = new GLTexture(this, "text.png");
  13.   lensImage = new GLTexture(this, textImage.width, textImage.height);   
  14.   lensFilter = new GLTextureFilter(this, "Mask.xml");
  15. }

  16. void draw() {
  17.   if (mouseX <= 0) mouseX = width/2;
  18.   if (mouseY <= 0) mouseY = height/2;
  19.   
  20.   float x0 = constrain(mouseX, 90, width - 90);
  21.   float y0 = constrain(mouseY, 90, height - 90);
  22.   
  23.   // display the original picture
  24.   image(textImage, 0, 0, width, height);

  25.   // Draw lenses.
  26.   createLensImage(x0, y0);
  27.   createLensImage(y0, x0);
  28. }

  29. void createLensImage(float x0, float y0) {
  30.   int radius = lensDiam/2;
  31.   float radiusAdj = radius/magFactor;
  32.   float lensDiamAdj = (int)(lensDiam/magFactor);
  33.   
  34.   float x = (x0 - radiusAdj);
  35.   float y = (y0 - radiusAdj); 
  36.   
  37.   // Converting magnified area to normalized texture coordinates:
  38.   float u0 = constrain(x / width, 0, 1);
  39.   float v0 = constrain(y / height, 0, 1);
  40.   float u1 = constrain(u0 + lensDiamAdj / width, 0, 1);
  41.   float v1 = constrain(v0 + lensDiamAdj / height, 0, 1);  
  42.   
  43.   // Making pixels transparent outside the lens area.
  44.   lensFilter.setParameterValue("center", new float[]{(u0 + u1)/2, (v0 + v1) / 2});
  45.   lensFilter.setParameterValue("radius", (float)radiusAdj/(width));
  46.   lensFilter.apply(textImage, lensImage);
  47.   
  48.   // display magnified image  
  49.   noStroke();
  50.   pushMatrix();
  51.   translate(x0 - (radius*scalef), y0 - (radius*scalef));
  52.   scale(scalef);
  53.   beginShape(QUADS);
  54.   texture(lensImage);
  55.   vertex(0, 0, u0, v0);
  56.   vertex(lensDiam, 0, u1, v0);
  57.   vertex(lensDiam, lensDiam, u1, v1);
  58.   vertex(0, lensDiam, u0, v1);
  59.   endShape();
  60.   
  61.   // drawing lens border.
  62.   stroke(0);
  63.   noFill();
  64.   ellipse(0, 0, lensDiam,lensDiam);  
  65.   popMatrix();  
  66. }