UNPKG

scrawl-canvas

Version:
123 lines (85 loc) 2.78 kB
// # Demo Filters 023 // Filter parameters: randomNoise // [Run code](../../demo/filters-023.html) import * as scrawl from '../source/scrawl.js'; import { reportSpeed, addImageDragAndDrop } from './utilities.js'; // #### Scene setup const canvas = scrawl.library.canvas.mycanvas; scrawl.importDomImage('.flowers'); // Create the filter const myFilter = scrawl.makeFilter({ name: 'my-filter', method: 'randomNoise', width: 6, height: 6, level: 0.5, }); // Create the target entity const piccy = scrawl.makePicture({ name: 'base-piccy', asset: 'iris', width: '100%', height: '100%', copyWidth: '100%', copyHeight: '100%', method: 'fill', filters: ['my-filter'], }); // #### Scene animation // Function to display frames-per-second data, and other information relevant to the demo const report = reportSpeed('#reportmessage', function () { // @ts-expect-error return ` Width: ${width.value}, Height: ${height.value}\n Level: ${level.value}\n Opacity - ${opacity.value}`; }); // Create the Display cycle animation const demoAnimation = scrawl.makeRender({ name: "demo-animation", target: canvas, afterShow: report, }); // #### User interaction scrawl.observeAndUpdate({ event: ['input', 'change'], origin: '.controlItem', target: myFilter, useNativeListener: true, preventDefault: true, updates: { width: ['width', 'round'], height: ['height', 'round'], opacity: ['opacity', 'float'], level: ['level', 'float'], noWrap: ['noWrap', 'boolean'], includeRed: ['includeRed', 'boolean'], includeGreen: ['includeGreen', 'boolean'], includeBlue: ['includeBlue', 'boolean'], includeAlpha: ['includeAlpha', 'boolean'], }, }); // Setup form const width = document.querySelector('#width'), height = document.querySelector('#height'), level = document.querySelector('#level'), opacity = document.querySelector('#opacity'); // @ts-expect-error width.value = 6; // @ts-expect-error height.value = 6; // @ts-expect-error level.value = 0.5; // @ts-expect-error opacity.value = 1; // @ts-expect-error document.querySelector('#noWrap').options.selectedIndex = 0; // @ts-expect-error document.querySelector('#includeRed').options.selectedIndex = 1; // @ts-expect-error document.querySelector('#includeGreen').options.selectedIndex = 1; // @ts-expect-error document.querySelector('#includeBlue').options.selectedIndex = 1; // @ts-expect-error document.querySelector('#includeAlpha').options.selectedIndex = 1; // #### Drag-and-Drop image loading functionality addImageDragAndDrop(canvas, '#my-image-store', piccy); // #### Development and testing console.log(scrawl.library);