mirror of
https://github.com/ful1e5/apple_cursor.git
synced 2025-05-22 03:05:22 -04:00
🖼️ frames increased
This commit is contained in:
parent
f44649e90e
commit
2360da1472
1 changed files with 28 additions and 6 deletions
|
@ -75,31 +75,53 @@ const main = async () => {
|
|||
const svg = await getSVGElement(page);
|
||||
|
||||
let index = 1;
|
||||
const playbackRate = 0.1;
|
||||
let breakRendering = false;
|
||||
|
||||
// Rendering 1st frame
|
||||
const img1 = await screenshot(svg);
|
||||
const key1 = getFrameName(index, svgFilePath);
|
||||
const key1 = getFrameName(index, svgFilePath, 4);
|
||||
|
||||
console.log("Saving", key1, "...");
|
||||
saveFrame(key1, img1);
|
||||
|
||||
// stop animation
|
||||
// @ts-ignore
|
||||
await page._client.send("Animation.setPlaybackRate", {
|
||||
playbackRate: 0,
|
||||
});
|
||||
|
||||
// Rendering frames till `imgN` matched to `img1`
|
||||
while (!breakRendering) {
|
||||
++index;
|
||||
const imgN = await screenshot(svg);
|
||||
const keyN = getFrameName(index, svgFilePath);
|
||||
|
||||
console.log("Saving", keyN, "...");
|
||||
saveFrame(keyN, imgN);
|
||||
// resume animation
|
||||
// @ts-ignore
|
||||
await page._client.send("Animation.setPlaybackRate", {
|
||||
playbackRate,
|
||||
});
|
||||
|
||||
const imgN = await screenshot(svg);
|
||||
const keyN = getFrameName(index, svgFilePath, 4);
|
||||
|
||||
const { data: img1Data, width, height } = PNG.sync.read(img1);
|
||||
const { data: imgNData } = PNG.sync.read(imgN);
|
||||
|
||||
const diff = Pixelmatch(img1Data, imgNData, null, width, height);
|
||||
const diff = Pixelmatch(img1Data, imgNData, null, width, height, {
|
||||
threshold: 0.2,
|
||||
});
|
||||
|
||||
if (diff <= 100) {
|
||||
breakRendering = !breakRendering;
|
||||
} else {
|
||||
console.log("Saving", keyN, "...");
|
||||
saveFrame(keyN, imgN);
|
||||
|
||||
// stop animation
|
||||
// @ts-ignore
|
||||
await page._client.send("Animation.setPlaybackRate", {
|
||||
playbackRate: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue