hammerspoon2-docs
    Preparing search index...

    Function animate

    • Animate changes to one or more canvases

      Calls changes straight away, and animates every change it makes to a canvas from its current value to the new one, over options.duration seconds. The changes can be to any number of elements, on any number of canvases, and all animate together.

      Inside changes, these animate:

      • element attributes set with setElementAttribute(), assignElement() (each attribute that differs), rotateElement(), rotateElementAroundPoint() and setElementTransformation(): frame, center, radius, coordinates (with the same number of points), rotation, rotationPoint, transformation, strokeWidth, startAngle, endAngle, roundedRectRadii, textSize, imageAlpha, canvasAlpha, fillColor, strokeColor, textColor, fillGradientColors (with the same number of colors), fillGradientAngle and fillGradientCenter
      • setTransformation() and clearTransformation()
      • the window, with setFrame(), setTopLeft(), setSize() and setAlpha(), while the canvas is showing

      Everything else (e.g. text, type, action, or adding and removing elements) changes immediately, as it does outside animate(). A number and a percentage animate between each other (e.g. a frame width of "100%" to 50).

      Getters return the new values as soon as changes returns, not the values being drawn part way through the animation. Mouse tracking follows what's drawn.

      Changing an attribute that's already animating (inside or outside another animate()) replaces that animation, starting from where it had got to on screen. Calls can be nested: changes inside a nested call use its options.

      If changes throws, the error propagates to the caller, and the changes made before the error still animate.

      Parameters

      • options: {
            curve?:
                | [number, number, number, number]
                | "linear"
                | "easeIn"
                | "easeOut"
                | "easeInOut";
            duration?: number;
        }

        {duration, curve}. duration is in seconds (default 0.25; 0 makes the changes without animating them). curve is "linear", "easeIn", "easeOut", "easeInOut" (the default), or a cubic bezier [x1, y1, x2, y2] like CSS's cubic-bezier(), with x1 and x2 between 0 and 1

      • changes: () => void

        A function that changes canvases

      Returns Promise<boolean>

      A Promise that resolves once the animation has finished: true if every change ran to completion, or false if any was interrupted (by another change to the same attribute, its element or attribute being removed, or its canvas being destroyed)

      Throws an Error on failure; wrap calls in try/catch to handle it.