import * as scrawl from '../source/scrawl.js';
import { reportSpeed } from './utilities.js';import * as scrawl from '../source/scrawl.js';
import { reportSpeed } from './utilities.js';const canvas = scrawl.findCanvas('mycanvas');Namespacing boilerplate
const namespace = canvas.name;
const name = (n) => `${namespace}-${n}`;
const myMoon = scrawl.makeCrescent({
name: name('my-crescent'),
start: ['center', 'center'],
handle: ['center', 'center'],
outerRadius: 120,
innerRadius: 80,
displacement: 60,
fillStyle: 'orange',
strokeStyle: 'darkslategray',
lineWidth: 4,
lineJoin: 'round',
method: 'fillThenDraw',
});
scrawl.makeWheel({
name: name('pin'),
radius: 5,
fillStyle: 'red',
pivot: name('my-crescent'),
lockTo: 'pivot',
handle: ['center', 'center'],
});Function to display frames-per-second data, and other information relevant to the demo
const report = reportSpeed('#reportmessage', function () {
const {
roll,
scale,
outerRadius,
start,
handle,
offset,
innerRadius,
displacement,
} = myMoon;
const {
lineWidth,
shadowOffsetX,
shadowOffsetY,
shadowBlur
/** @ts-expect-error */
} = myMoon.state;
return ` Crescent - outerRadius: ${outerRadius}, innerRadius: ${innerRadius}, displacement: ${displacement}
Start - [${start}]; Handle - [${handle}]; Offset - [${offset}]
Roll: ${roll}; Scale: ${scale}; lineWidth: ${lineWidth}
Shadow - offsetX: ${shadowOffsetX}; offsetY: ${shadowOffsetY}; blur: ${shadowBlur}; `;
});Create the Display cycle animation
scrawl.makeRender({
name: name('animation'),
target: canvas,
afterShow: report,
});scrawl.makeUpdater({
event: ['input', 'change'],
origin: '.controlItem',
target: myMoon,
useNativeListener: true,
preventDefault: true,
updates: {
displacement: ['displacement', 'round'],
displayIntersect: ['displayIntersect', 'boolean'],
innerRadius: ['innerRadius', 'round'],
outerRadius: ['outerRadius', 'round'],
handle_xAbsolute: ['handleX', 'round'],
handle_xPercent: ['handleX', '%'],
handle_xString: ['handleX', 'raw'],
handle_yAbsolute: ['handleY', 'round'],
handle_yPercent: ['handleY', '%'],
handle_yString: ['handleY', 'raw'],
lineJoin: ['lineJoin', 'raw'],
lineWidth: ['lineWidth', 'round'],
method: ['method', 'raw'],
offset_xAbsolute: ['offsetX', 'round'],
offset_xPercent: ['offsetX', '%'],
offset_yAbsolute: ['offsetY', 'round'],
offset_yPercent: ['offsetY', '%'],
reverse: ['flipReverse', 'boolean'],
roll: ['roll', 'float'],
scale: ['scale', 'float'],
scaleOutline: ['scaleOutline', 'boolean'],
scaleShadow: ['scaleShadow', 'boolean'],
shadowBlur: ['shadowBlur', 'round'],
shadowOffsetX: ['shadowOffsetX', 'round'],
shadowOffsetY: ['shadowOffsetY', 'round'],
start_xAbsolute: ['startX', 'round'],
start_xPercent: ['startX', '%'],
start_xString: ['startX', 'raw'],
start_yAbsolute: ['startY', 'round'],
start_yPercent: ['startY', '%'],
start_yString: ['startY', 'raw'],
upend: ['flipUpend', 'boolean'],
},
});Setup form
scrawl.initializeDomInputs([
['input', 'displacement', '60'],
['input', 'innerRadius', '80'],
['input', 'outerRadius', '120'],
['select', 'displayIntersect', 0],
['input', 'handle_xAbsolute', '150'],
['input', 'handle_xPercent', '50'],
['input', 'handle_yAbsolute', '100'],
['input', 'handle_yPercent', '50'],
['input', 'lineWidth', '4'],
['input', 'offset_xAbsolute', '0'],
['input', 'offset_xPercent', '0'],
['input', 'offset_yAbsolute', '0'],
['input', 'offset_yPercent', '0'],
['input', 'roll', '0'],
['input', 'scale', '1'],
['input', 'shadowBlur', '0'],
['input', 'shadowOffsetX', '0'],
['input', 'shadowOffsetY', '0'],
['input', 'start_xAbsolute', '300'],
['input', 'start_xPercent', '50'],
['input', 'start_yAbsolute', '200'],
['input', 'start_yPercent', '50'],
['select', 'handle_xString', 1],
['select', 'handle_yString', 1],
['select', 'lineJoin', 1],
['select', 'method', 4],
['select', 'reverse', 0],
['select', 'scaleOutline', 1],
['select', 'scaleShadow', 0],
['select', 'start_xString', 1],
['select', 'start_yString', 1],
['select', 'upend', 0],
]);console.log(scrawl.library);