Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(demos): blend #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions demo/blend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Kampos, effects } from '../index.js';

const media1 = document.querySelector('#video3');
const media2 = document.querySelector('#video4');
const target = document.querySelector('#target');

// create the effects/transitions we need
const blend = effects.blend({
mode: 'screen',
});

// make sure videos are loaded and playing
prepareVideos([media1, media2]).then(() => {
const width = media1.videoWidth;
const height = media1.videoHeight;

blend.image = media2;
// it's a video so update on every frame
blend.textures[0].update = true;

// init kampos
const instance = new Kampos({ target, effects: [blend] });

// set media source
instance.setSource({ media: media1, width, height });
// start kampos
instance.play();
});
10 changes: 9 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function startDemo(script, ids) {
updatePreview(
preview,
doc.getValue(),
video ? video.innerHTML : '',
video ? video.innerHTML : ''
);

refresh.addEventListener('click', update);
Expand Down Expand Up @@ -154,6 +154,14 @@ const sectionScripts = {
refresh: 'refresh9',
});
},
section10() {
startDemo('./blend.js', {
code: 'code10',
preview: 'preview',
video: 'videos2',
refresh: 'refresh10',
});
},
};

insertSection('section7');
16 changes: 15 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down Expand Up @@ -313,6 +313,17 @@
</section>
</template>

<template id="section10">
<section id="blend">
<div class="code-container">
<button class="refresh-button" id="refresh10">
Refresh
</button>
<textarea id="code10"></textarea>
</div>
</section>
</template>

<nav>
<ul>
<li>
Expand Down Expand Up @@ -360,6 +371,9 @@
>Luminance Mask</a
>
</li>
<li>
<a href="#section10" data-section-id="section10">Blend</a>
</li>
</ul>
</nav>
<main>
Expand Down
77 changes: 44 additions & 33 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(function () {
'use strict';

function updatePreview (iframe, example, videos) {
iframe.setAttribute('srcdoc', getIFrameHTML({example, videos}));
function updatePreview(iframe, example, videos) {
iframe.setAttribute('srcdoc', getIFrameHTML({ example, videos }));
}

function getIFrameHTML ({example, videos}) {
function getIFrameHTML({ example, videos }) {
return `<!DOCTYPE html>
<html>
<head>
Expand All @@ -30,7 +30,7 @@

window.updatePreview = updatePreview;

function insertSection (id) {
function insertSection(id) {
const section = document.querySelector(`#${id}`);
const main = document.querySelector('main');

Expand All @@ -39,34 +39,37 @@
sectionScripts[id]();
}

document.querySelector('nav')
.addEventListener('click', e => {
const id = e.target.dataset.sectionId;
insertSection(id);
});
document.querySelector('nav').addEventListener('click', (e) => {
const id = e.target.dataset.sectionId;
insertSection(id);
});

document.querySelector('#open-code')
.addEventListener('click', () => {
document.querySelector('#section-wrapper').classList.toggle('open');
});
document.querySelector('#open-code').addEventListener('click', () => {
document.querySelector('#section-wrapper').classList.toggle('open');
});

function startDemo (script, ids) {
function startDemo(script, ids) {
const code = document.querySelector(`#${ids.code}`);
const preview = document.querySelector(`#${ids.preview}`);
const video = document.querySelector(`#${ids.video}`);
const refresh = document.querySelector(`#${ids.refresh}`);

fetch(script)
.then(resp => resp.text())
.then(text => {
.then((resp) => resp.text())
.then((text) => {
code.value = text;
const doc = CodeMirror.fromTextArea(code, {
value: text,
lineNumbers: true,
theme: 'dracula'
theme: 'dracula',
});

const update = () => updatePreview(preview, doc.getValue(), video ? video.innerHTML : '');
const update = () =>
updatePreview(
preview,
doc.getValue(),
video ? video.innerHTML : ''
);

refresh.addEventListener('click', update);

Expand All @@ -75,47 +78,47 @@
}

const sectionScripts = {
section1 () {
section1() {
startDemo('./turbulence.js', {
code: 'code1',
preview: 'preview',
video: 'videos1',
refresh: 'refresh1'
refresh: 'refresh1',
});
},

section2 () {
section2() {
startDemo('./hue-fade.js', {
code: 'code2',
preview: 'preview',
video: 'videos2',
refresh: 'refresh2'
refresh: 'refresh2',
});
},

section3 () {
section3() {
startDemo('./disp.js', {
code: 'code3',
preview: 'preview',
video: 'videos3',
refresh: 'refresh3'
refresh: 'refresh3',
});
},

section4 () {
section4() {
startDemo('./duotone.js', {
code: 'code4',
preview: 'preview',
video: 'videos4',
refresh: 'refresh4'
refresh: 'refresh4',
});
},

section5 () {
section5() {
startDemo('./cellular-noise.js', {
code: 'code5',
preview: 'preview',
refresh: 'refresh5'
refresh: 'refresh5',
});
},

Expand All @@ -124,7 +127,7 @@
code: 'code6',
preview: 'preview',
video: 'videos2',
refresh: 'refresh6'
refresh: 'refresh6',
});
},

Expand All @@ -133,7 +136,7 @@
code: 'code7',
preview: 'preview',
video: 'none',
refresh: 'refresh7'
refresh: 'refresh7',
});
},

Expand All @@ -142,7 +145,7 @@
code: 'code8',
preview: 'preview',
video: 'videos5',
refresh: 'refresh8'
refresh: 'refresh8',
});
},

Expand All @@ -151,9 +154,17 @@
code: 'code9',
preview: 'preview',
video: 'videos2',
refresh: 'refresh9'
refresh: 'refresh9',
});
}
},
section10() {
startDemo('./blend.js', {
code: 'code10',
preview: 'preview',
video: 'videos2',
refresh: 'refresh10',
});
},
};

insertSection('section7');
Expand Down
Loading