Skip to content

Instantly share code, notes, and snippets.

@jacobsologub
Last active November 6, 2019 20:39
Show Gist options
  • Select an option

  • Save jacobsologub/23853fd06c53c3a506c3bbe76c77dabd to your computer and use it in GitHub Desktop.

Select an option

Save jacobsologub/23853fd06c53c3a506c3bbe76c77dabd to your computer and use it in GitHub Desktop.

Revisions

  1. jacobsologub revised this gist Nov 6, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion crossfade-images.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,8 @@
    // Created by Jacob Sologub on 29 Oct 2019 9:22:41pm
    // Copyright © 2019 Jacob Sologub. All rights reserved.

    import { Asset, Time, TimeRange, Clip, Vector, Image, Filter, coreimage } from 'hypno';
    import { Asset, Time, TimeRange, Clip, Vector, coreimage } from 'hypno';
    import { Image, Filter } from 'hypno/coreimage';

    Time.timescale = 30;
    let emptyClip = new Clip (new Time (30 * 3));
  2. jacobsologub created this gist Oct 30, 2019.
    38 changes: 38 additions & 0 deletions crossfade-images.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    //
    // crossfade-images.js
    // libhypno
    //
    // Created by Jacob Sologub on 29 Oct 2019 9:22:41pm
    // Copyright © 2019 Jacob Sologub. All rights reserved.

    import { Asset, Time, TimeRange, Clip, Vector, Image, Filter, coreimage } from 'hypno';

    Time.timescale = 30;
    let emptyClip = new Clip (new Time (30 * 3));

    const TrackIDs = {
    Image: "image"
    };

    const track = composition.track (TrackIDs.Image);
    track.add (emptyClip);

    const image1 = new Image ("./T0YRgsZ11jr6.jpg");
    const image2 = new Image ("./T0YRgsZ11jr6-swapped.png");

    composition.renderSize = image1.size;

    composition.render = function (context) {
    const instruction = context.instruction;
    const instructionProgress = (instruction.time.value / instruction.timeRange.duration.value);

    const colorMatrixFilter = new Filter (coreimage.CIColorMatrix, {
    inputAVector: new Vector (0.0, 0.0, 0.0, instructionProgress),
    inputImage: image2
    });

    const sourceOverFilter = new Filter (coreimage.CISourceOverCompositing);
    sourceOverFilter.set ({ inputBackgroundImage: image1, inputImage: colorMatrixFilter.apply() });

    context.setFrame (TrackIDs.Image, sourceOverFilter.apply());
    };