Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Dynamic Magnifying Glass

  • Dynamic Magnifying Glass

    Posted by Vitantonio D’ambrosio on October 25, 2007 at 11:46 am

    Hello Everyone,

    I already posted about this in the general AfterFX discussion group, and I’ve told I may have better chance in solving this here.
    Sorry if I copy and paste from there:

    Let me apologize for my bad english in advance, hopefully I will manage to make this as clear as possible.
    I’m trying to create a Dynamic magnifying glass.
    I have a big composition (w=5000px lh=1440px) that I will use both as the magnified part (masked of course) and as the part to be magnified.
    I’ve created an object that will be my “lens”, made of two circles, one that would be the highlighting part, and one that will contain the magnified version.
    I’ve linked everything to a null object, and by doing this I managed to move the mask around the big composition according to the movement of the little highlighting circle, but what I basically need to do is to dynamically move the composition too so that the highlighted part and the magnifyed part match.
    I cannot use the Magnyfing glass effect that is in the tutorial section as it’s important that the magnifyed part doesn’t loose quality and that the image is as clear as possible.
    And I need to separate have the highlighted part and the magnifyed part both visible.

    I think I should link the center of my highlighting circle to the position of the big composition somehow, but the position value have to go opposite of the movement I make with the highlighting circle (that is, if I move to the left, the composition need to move to the right, sort of like how the camera works when you move it around and you have 2 layers very distant one from the other)

    Help!
    How can I do this? Is this possible at all?

    Thanks
    V.

    Vitantonio D’ambrosio replied 18 years, 6 months ago 2 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    October 26, 2007 at 5:45 am

    The expression is probably pretty simple, but it depends so much on how you have things set up. For example, let’s say you have a magnified comp that consists of the magnifier in the center and the magnified map below and maybe a Track matte for the map the same shape as the magnifier and parented to the magnifier. That comp would be nested in a comp that has the unmagnified map.

    Back in the magnified comp, you have a expression for the map position that caclulates how far off center the magnifier comp is in the main comp and moves the magnified map that amount times the magification factor, in the opposite direction.

    So, for example, if your magnification was say, x4, the expression would look something like this:

    magnification = 4;
    C = comp(“main comp”);
    L = C.layer(“magnifier comp”);
    value – (L.position – [C.width,C.height]/2)*4;

    Something like that, anyway.

    Dan

  • Vitantonio D’ambrosio

    October 26, 2007 at 10:16 am

    Hi Dan,
    Thanks for your answer.
    This looks almost right, but I’m having a bit of a problem making it work as I want it to so I guess I’ll spare us some time if I describe you exactly how the composition is set up.

    Comp is 1550px X 620px
    layer 1 is a Null object with it’s position set to the center of the comp at 775, 310

    layer 2 is an alpha matte 300×300 px with it’s position set at 211, 85 and is parented with the null object

    layer 3 is the magnify composition wich is 3660px x 1440px and has it’s position set at 987,5 , 395 wich corresponds to the center of the matte layer

    layer 4 is a solid layer 48×48 pixels with a circle mask the same size and the position set in the middle of the comp at 775, 310 and is parented with the null object

    layer 5 is a solid with different mask to connect layer 4 to layer 6 and is parented with layer 4

    layer 6 is yet another solid layer 348×348 px, with a circle mask the same size wich is the frame for the magnify composition and it’s position is 251, 16 wich is yet again corresponding to the center of the magnify comp and the alpha matte layer and is parented to layer 4

    layer 7 is the composition to be magnifyed, wich is the same as the magnify comp but scaled down at 43% and positioned at 775, 310

    as things are now, the center of layer four is roughly the area that you see magnifyed and is the focal point of any movement I need to do.
    What I need to obtain is having the magnify comp (aka layer 3) move around when I move the null object and all it’s parented layer.

    If I apply your expression to the null object, it works only if I move the magnify comp.
    if I try to apply it to any other layer thing don’t work quite the way I need them to.

    Now, I understand I’m basically asking you to do the work for me, but please, help! 🙂

  • Dan Ebberts

    October 26, 2007 at 7:45 pm

    OK – I’d suggest moving layer 3 until it’s in the correct postiion relative to the starting setup. Then make it a child of the null. Then apply this position expression to layer 3:

    theNull = thisComp.layer(1);
    toBeMagnified = thisComp.layer(7);

    magnification = 1/(toBeMagnified.scale[0]/100);
    value – (theNull.position – [thisComp.width,thisComp.height]/2)*magnification;

    This all depends on the null being at the center of the comp when you make it the parent of layer 3. I haven’t tried it, but it should be close.

    Dan

  • Dan Ebberts

    October 26, 2007 at 8:00 pm

    Rats – that still didn’t work. OK – one more try:

    density = ” .’`,^:” + ‘”;~-_+<>i!lI?/\|()1{}[]rcvunxzjftLCJUYXZO0Qoahkbdpqwm*WMB8&%$#@’;
    target = thisComp.layer(“target”);
    cols = 80;
    rows = 60;
    w = thisComp.width/cols;
    h = thisComp.height/rows;

    s = “”

    for (var i = 0; i < rows; i++){ for(var j = 0; j < cols; j++){ center = [w/2 + j*w, h/2 + i*h]; sample = target.sampleImage(center,[(w-1)/2,(h-1)/2]); s += density[Math.round(linear(sample[0],0,1,0,density.length - 1))]; } s += "\\r"; } s Dan

  • Vitantonio D’ambrosio

    October 27, 2007 at 10:12 am

    Dan,
    thanks again for your help.
    I’ll try that on monday when I’m back at work and I’ll let you know!

  • Vitantonio D’ambrosio

    October 29, 2007 at 10:40 am

    So Dan,
    Thanks again for your great help.
    The first expression seems to work better than the second one to me.
    I’ll still have to make some adjustments when I move the null on the Z axis and if I rotate the objects, but it works great on the X and the Y

    The second expression won’t work.
    I can’t seem to make the target.sampleimage function to work, it says it’s undefined.
    I’m surely not doing something properly.

  • Dan Ebberts

    October 29, 2007 at 1:40 pm

    No, that was my fault. I posted that in the wrong thread – should have been in the “Video to ASCII effect” thread.

    Dan

  • Vitantonio D’ambrosio

    October 29, 2007 at 2:10 pm

    Oh!
    Ahaha…
    ok, sorry about that! 🙂

    Thanks again for your help!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy