Jump to content

tiscavalcanti

Members
  • Posts

    46
  • Joined

  • Last visited

Posts posted by tiscavalcanti

  1. 7 hours ago, Ingolme said:

    You need to learn two things:

    1. Linear interpolation
    2. Timing in Javascript

    Linear interpolation is described here with some examples of function implementations: https://en.wikipedia.org/wiki/Linear_interpolation#Programming_language_support

    The time t in linear interpolation is a value from 0 to 1. To get this value, you just divide the amount of time that has passed since the animation started by the total duration of the animation. In pseudo-code, something like this:

    
    t = (currentTime - startTime) / (endTime - startTime)

    When the animation starts, you need to store the current time in a variable startTime to use it in the formula described above.

    In Javascript, when using setTimeout or setInterval, you get the startTime and currentTime values from the Date object's getTime() method. If you're using requestAnimationFrame, see Mozilla's documentation, the current time is given as a parameter in the callback function. When using requestAnimationFrame you can get the startTime value using performance.now() right before the animation begins.

     

    Your information is quite useful, I will delve into the links, and in fact, I use video program that uses expressions based on JS ...

    Look, I just figured out a way to sort this out ... maybe it'll work ...

    Do you know how I can make a variable go from 0 to 22, and when it reaches 22, return to 0?

    Type a slide inside the number 22, that is, from 0 to 22, it results in 22, and from 22 to 44 it also results in 22, as if the variable was reset every time it was 22, then 23 would be 1 , and 45, 1 also, and so on.

  2. I need to make a code like this:

    Initial value 11

    Final value 33

    I want to insert the code on the property time (that changes) of the program I use

    So I want the code to interpolate through the time between numbers 11 and 33, meaning this code will move 22 seconds in time

    I want that when the code results in the final value, that is, arrive at the value 33
    It is reinitiated, thus causing an infinite loop. Going from 11 to 33 in 22 seconds and then repeating on and on.

    There is a codebase that may allow time to be used in a dynamic way:

    linear (t, tMin, tMax, value1, value2)

    There it is (time, start time, end time, initial value, final value)

    Maybe this code is useful ... I do not know. It is an interpolation code

  3.  

    Again, your question is oddly worded. Are you saying that you want to supply three values to a function and receive the "middle" value back?

    function middle(a,b,c){
    if ((a > b && a < c)||(a > c && a < ){
    return a;
    }else if ((b > a && b < c)||(b > c && b < a)){
    return b;
    }else if ((c > a && c < ||(c > b && c < a)){
    return c;
    }else{
     return -999; // if a = b or a = c or b = c
    }
    
    }//end of function
    

    Thanks for your time, my friend. This forum like ever, very efficient. Work very well. :)

  4. Again, your question is oddly worded. Are you saying that you want to supply three values to a function and receive the "middle" value back?

    I want the value of a property of my program, to which this code is entered, is defined by the value of another property that is between two other properties, ie three properties, I do not even want Math.max or Math. min, but the value is between these two.

  5. You can either write your own function to return the median of an array, or you can use a library that includes one.

     

    http://mathjs.org/docs/reference/functions/median.html

    Thanks, but I believe which Math.median() don't work in After Effects Software by expression. I get a error ("Math.median is not a function").

     

     

    Three given values? Why not use an exhaustive if-then-else construct?

     

    Your question is oddly worded because you might also be implying the arithmetic average which is 45.45.

    I could use if/else but, in my case, the values are not fixed, this value that I show is just example.

    How i can do this between if/else?

  6. I want to get the value that is in the center between three values.

     

    For example: Math."middle"(34.78, 56.12, 45.54)

    Result in: 45.54

     

    How I can do this?

  7.  

    Huh? Maybe...

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8"/>
    <title>title</title>
    <style>
    </style>
    <script>
    window.onerror = function(a,b,c){
    alert('Javascript Error: '+a+'\nURL: '+b+'\nLine Number: '+c);
    return true;
    }
    </script>
    </head>
    <body>
    
    <input type="checkbox" id="chk01"/>
    
    <br/>
    <input type="button" id="btn1" value="Toggle"/>
    
    <script>
    'use strict';
    
    function togglechk(id){
     var chk = document.getElementById(id);
     chk.checked = (chk.checked == true)? false : true;
    }//end of func
    
    document.getElementById('btn1').onclick = function(){ togglechk('chk01');};
    
    </script>
    
    </body>    
    </html>
    

    Perfect, friend;

    Work very cool! ;)
    Exactly! :)
  8.  

    Huh? Maybe...

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8"/>
    <title>title</title>
    <style>
    </style>
    <script>
    window.onerror = function(a,b,c){
    alert('Javascript Error: '+a+'\nURL: '+b+'\nLine Number: '+c);
    return true;
    }
    </script>
    </head>
    <body>
    
    <input type="checkbox" id="chk01"/>
    
    <br/>
    <input type="button" id="btn1" value="Toggle"/>
    
    <script>
    'use strict';
    
    function togglechk(id){
     var chk = document.getElementById(id);
     chk.checked = (chk.checked == true)? false : true;
    }//end of func
    
    document.getElementById('btn1').onclick = function(){ togglechk('chk01');};
    
    </script>
    
    </body>    
    </html>
    

     

    Okay! I will make some tests.

    Thank you very, very much!

  9. You need to carefully describe what you want, because it isn't perfectly clear.

    I want a code which switch a property, that is, toggle between two fixed values; (Checkbox - 1 or 0)

     

    If a determined condition is true.

     

    For example:

    a = 1;
    b = 2;
    
    if (a >  "CheckBox switch for 1 (if was at 0) or switch for 0 (if was at 1)"; else 0;

    If "ELSE" is satisfied, and get back to "IF" satisfied;

    The Checkbox will be with the inverse value of what was before "ELSE".

     

    That's what I want.

     

    In another example. I will create a situation, step by step:

    1. Checkbox is at 0.
    2. "IF" is satisfied.
    3. Checkbox is at 1.
    4. "ELSE" is satisfied.
    5. Checkbox is at 0 ("ELSE" always is 0).
    6. "IF" is satisfied again.
    7. Checkbox is at 0 again.
  10. I want to know, if is there any way to javascript change (switch) between two values (1 and 0) in a Checkbox,

     

    A code without resulting in a fixed value, its function becomes only toggle value.

     

    For example, I need put this in a Property:

     

    if (thisComp.layer("Logo").transform.opacity==100) "My Checkbox" (switch) else 0;

     

     

     

    After Effects Expression

  11. Yes, you can, but since we're talking about optimizing and efficiency, what does this do for you:

     

    switch (true) {
      case yB < xA:
        return [yB, yB];
      default:
        return [xA, xA];
    }
    that is better than this:

     

    if (yB < xA) {
      return [yB, yB];
    }
    else {
      return [xA, xA];
    }
    or this:

     

    return (yB < xA) ? [yB, yB] : [xA, xA];
    This way is interesting:
    return (yB <xA)? [yB, yB]: [xA, xA];
    Could you explain a little more how it works.
    The use of interrogation, is something new to me.
  12. It would, but if you're doing a switch on a boolean it usually makes more sense to use an if/else structure. If your goal is optimization, you don't see big performance increases by using a switch over an if/else structure.

    I can do this:

     

    function getValue() {
    switch (true) {
    case yB < xA:
    return [yB, yB];
    default:
    return [xA, xA];
    }
    }
    
    
    E = getValue();
    
    
    if (w > maxWidth || h > textHeight){
    x = E[0]; y = E[1];
    }
    
    
    [x, y];
  13. The switch statement is not the optimal structure to use in this situation. Why do you want to use it?

    And something like "switch(true)" work? If not, could edit this code for me, in If/Else same, of a better way?

     

    Thanks!

  14. Hello,

     

    I have created this code:

     

    if (w > maxWidth || h > textHeight) {
    if (y < x) {
    [y, y]
    } else {
    [x, x]
    }
    } else {
    [value[0], value[1]]
    }

     

    It is a piece, but it gives to understand what I want to optimize without the rest.

     

    How to modify this code to work with: Switch Statement instead If/Else mode?

     

    This is a expression of After Effects.

     

    Thanks.

  15.  

    Like this:

    switch( {  case 1:  case 4:    // Do something  break;}

    Ok. Good. I needed use a Array in final of code, because After Effects require it.

     

    My code was practically perfect. I'm going to change only a few details.
    Thank you very much!
  16. That's not a question, that's code.

     

    Is the code doing what you want it to? If it isn't, then what is it actually doing and what did you want it to do?

     

    Since you're treating the elements of array p like numbers, you shouldn't put them in quotation marks:

    p = [.95, .90, .85, .05, .10, .15];

    Be sure to declare all your variables with the var keyword like this

    var w = 1920;var h = 1080;

    The indentation in your code is confusing. The else if statement should be nested at the same level as the if that preceded it. This also looks like a good place for a switch statement instead of all those if conditions.

    switch( {  case 1: return [x*p[3],y*p[0]];  case 2: return [x*p[4],y*p[1]];  case 3: return [x*p[5],y*p[2]];}

    I've changed the indentation of your current code to make it more readable:

    function xyFinal(){  function variable(x,y){    if(b==1){      return [x*p[3],y*p[0]];    }else if(b==2){      return [x*p[4],y*p[1]];    }else if(b==3){      return [x*p[5],y*p[2]];    }  }  var o = variable(w,h);  if(c==1){    return o;  }else if(c==2){    return [w/2,o[1]];  }else if(c==3){    return [w-o[0],o[1]];  }}    v=xyFinal();x=v[0];y=v[1];[x,y];

    That [x,y] at the end of your code isn't really doing anything because you're not returning it or printing it.

    Oh, yeah! Thank you very much, help me a lot! This code is my result after many tries, and finally I got it. And with your instructions, will stay very best.

  17. I'm not sure what your question is. Did you post a conversation between you and someone else or something?

    This is it. I'm able, finally. Thanks for your time!

    w=1920;h=1080;p = [".95", ".90", ".85",".05", ".10",".15"];x=0;y=0;b=3;c=3;function xyFinal(){    function variable(x,y){        if(b==1){            return [x*p[3],y*p[0]];            }else if(b==2){                return [x*p[4],y*p[1]];                }else if(b==3){                    return [x*p[5],y*p[2]];                    }                }                var o=variable(w,h);            if(c==1){                return o;                }else if(c==2){                    return [w/2,o[1]];                    }else if(c==3){                        return [w-o[0],o[1]];                        }                    }                    v=xyFinal();                x=v[0];                y=v[1];[x,y];
×
×
  • Create New...