import * as scrawl from '../source/scrawl.js';
import { reportSpeed, addImageDragAndDrop, addCheckerboardBackground } from './utilities.js';import * as scrawl from '../source/scrawl.js';
import { reportSpeed, addImageDragAndDrop, addCheckerboardBackground } from './utilities.js';const canvas = scrawl.findCanvas('mycanvas');Namespacing boilerplate
const namespace = canvas.name;
const name = (n) => `${namespace}-${n}`;Import the initial image used by the Picture entity
scrawl.importDomImage('.flowers');Create the background
addCheckerboardBackground(scrawl, canvas, namespace);Create the filter
const myFilter = scrawl.makeFilter({
name: name('chroma-key'),
method: 'chromakey',
red: 190,
green: 129,
blue: 223,
opaqueAt: 0.39,
transparentAt: 0.32,
});Create the target entity
const piccy = scrawl.makePicture({
name: name('image'),
asset: 'iris',
copyDimensions: ['100%', '100%'],
dimensions: ['95%', '95%'],
handle: ['center', 'center'],
start: ['center', 'center'],
filters: [name('chroma-key')],
});Function to display frames-per-second data, and other information relevant to the demo
const report = reportSpeed('#reportmessage', function () {
return `
Reference color: ${dom.reference.value}
Transparent at: ${dom.transparentAt.value}
Opaque at: ${dom.opaqueAt.value}
Opacity: ${dom.opacity.value}`;
});Create the Display cycle animation
scrawl.makeRender({
name: name('animation'),
target: canvas,
afterShow: report,
});const dom = scrawl.initializeDomInputs([
['input', 'reference', '#be81df'],
['input', 'opaqueAt', '0.39'],
['input', 'transparentAt', '0.32'],
['input', 'opacity', '1'],
]);Setup form observer functionality
scrawl.makeUpdater({
event: ['input', 'change'],
origin: '.controlItem',
target: myFilter,
useNativeListener: true,
preventDefault: true,
updates: {
transparentAt: ['transparentAt', 'float'],
opaqueAt: ['opaqueAt', 'float'],
opacity: ['opacity', 'float'],
reference: ['reference', 'raw'],
},
});addImageDragAndDrop(scrawl, canvas, `#${namespace} .assets`, piccy);console.log(scrawl.library);