import * as scrawl from '../source/scrawl.js';
import { reportSpeed, addImageDragAndDrop } from './utilities.js';import * as scrawl from '../source/scrawl.js';
import { reportSpeed, addImageDragAndDrop } from './utilities.js';const canvas = scrawl.library.canvas.mycanvas;
scrawl.importDomImage('.flowers');Create the filter
ranges attributeconst myFilter = scrawl.makeFilter({
name: 'chromakey',
method: 'chromakey',
red: 0,
green: 127,
blue: 0,
opaqueAt: 1,
transparentAt: 0,
});Create the target entity
const piccy = scrawl.makePicture({
name: 'base-piccy',
asset: 'iris',
width: '100%',
height: '100%',
copyWidth: '100%',
copyHeight: '100%',
method: 'fill',
filters: ['chromakey'],
});Function to display frames-per-second data, and other information relevant to the demo
const report = reportSpeed('#reportmessage', function () {@ts-expect-error
return ` Reference color: ${reference.value}\n Transparent at: ${transparentAt.value}, Opaque at: ${opaqueAt.value}\n Opacity: ${opacity.value}`;
});Create the Display cycle animation
const demoAnimation = scrawl.makeRender({
name: "demo-animation",
target: canvas,
afterShow: report,
});scrawl.observeAndUpdate({
event: ['input', 'change'],
origin: '.controlItem',
target: myFilter,
useNativeListener: true,
preventDefault: true,
updates: {
transparentAt: ['transparentAt', 'float'],
opaqueAt: ['opaqueAt', 'float'],
opacity: ['opacity', 'float'],
reference: ['reference', 'raw'],
},
});Setup form
const reference = document.querySelector('#reference'),
opaqueAt = document.querySelector('#opaqueAt'),
transparentAt = document.querySelector('#transparentAt'),
opacity = document.querySelector('#opacity');@ts-expect-error
reference.value = '#007700';@ts-expect-error
opaqueAt.value = 1;@ts-expect-error
transparentAt.value = 0;@ts-expect-error
opacity.value = 1;addImageDragAndDrop(canvas, '#my-image-store', piccy);console.log(scrawl.library);