Transforms (Scaling, Rotating, and Translating)

The transform key affects the rotation, scaling, and translation of a clip's asset. Hypno script provides built-in options for simple fit and fill algorithms, as well as the ability to rotate in common increments.

hypno.transform.fit scales the longer side of the image to the script dimensions (like css contain) and hypno.transform.fill scales the shorter side (like css cover). And, you can add CW , CCW, and Flip to any of these parameters to include a rotation clockwise, counter-clockwise, and flipped, respectively. For example, transform: hypno.transform.fillCW fills and rotates the image counter clockwise. Here's what it looks like in the code:

// Transform Demo 1

import * as hypno from './stl.js'

const mainTrack = composition.track("main")

hypno.buildTimeline({

    fps: 30,
    resolution: new Vector(960, 1280),
    clips: [
        {
            asset: new Asset("./air-camera-input-1")
            start: 0,
            duration: 120,
            track: mainTrack,
            transform: hypno.transform.fillCW
        },
    ]
})

Check out the visual examples below, where the figure on the left shows the input dimensions, and the figure on the right shows the image after the transform.

You can also use the more advanced option of specifying values manually for the transform, in which case you pass in an object with the translate, scale, and rotate keys. See example below.

// Transform Demo 2

import * as hypno from './stl.js'

const mainTrack = composition.track("main")

hypno.buildTimeline({

    fps: 30,
    resolution: new Vector(960, 1280),
    clips: [
        {
            asset: new Asset("./air-camera-input-1")
            start: 0,
            duration: 120,
            track: mainTrack,
            transform: {
                translate: new Vector(0, 1620)
                scale: new Vector(960/1080, 960/1080)
                rotate: -0.5
            }
        },
    ]
})

Last updated

Was this helpful?