mirror of
https://github.com/ful1e5/apple_cursor.git
synced 2025-05-16 16:14:45 -04:00
🎥 Render animated Cursors
This commit is contained in:
parent
0dba4cdd9c
commit
4cd1397c15
1 changed files with 20 additions and 10 deletions
30
src/index.ts
30
src/index.ts
|
@ -11,7 +11,8 @@ import {
|
||||||
animatedClip,
|
animatedClip,
|
||||||
} from "./config";
|
} from "./config";
|
||||||
import { matchImages } from "./utils/matchImages";
|
import { matchImages } from "./utils/matchImages";
|
||||||
import { saveFrames } from "./utils/saveFrames";
|
import { saveFrames, Frames } from "./utils/saveFrames";
|
||||||
|
import { getKeyName } from "./utils/getKeyName";
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
|
@ -78,16 +79,18 @@ const main = async () => {
|
||||||
// Render Config
|
// Render Config
|
||||||
let index = 1;
|
let index = 1;
|
||||||
let breakLoop = false;
|
let breakLoop = false;
|
||||||
const frames: Buffer[] = [];
|
const frames: Frames = {};
|
||||||
|
const firstKey = getKeyName(index, svg);
|
||||||
|
console.log(firstKey);
|
||||||
|
|
||||||
// 1st Frame
|
// 1st Frame
|
||||||
frames.push(
|
frames[firstKey] = {
|
||||||
await svgElement.screenshot({
|
buffer: await svgElement.screenshot({
|
||||||
omitBackground: true,
|
omitBackground: true,
|
||||||
clip: animatedClip,
|
clip: animatedClip,
|
||||||
encoding: "binary",
|
encoding: "binary",
|
||||||
})
|
}),
|
||||||
);
|
};
|
||||||
|
|
||||||
// Pushing frames until it match to 1st frame
|
// Pushing frames until it match to 1st frame
|
||||||
index++;
|
index++;
|
||||||
|
@ -97,15 +100,22 @@ const main = async () => {
|
||||||
clip: animatedClip,
|
clip: animatedClip,
|
||||||
encoding: "binary",
|
encoding: "binary",
|
||||||
});
|
});
|
||||||
const diff = matchImages(frames[0], newFrame);
|
const key = getKeyName(index, svg);
|
||||||
console.log(diff, "frames", 1, "--", index);
|
console.log(key);
|
||||||
if (diff < 3000) {
|
const diff = matchImages({
|
||||||
|
img1Buff: frames[firstKey].buffer,
|
||||||
|
img2Buff: newFrame,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!(diff < 3000)) {
|
||||||
|
frames[key] = { buffer: newFrame };
|
||||||
|
} else {
|
||||||
breakLoop = true;
|
breakLoop = true;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFrames({ fileName: svg, frames });
|
saveFrames(frames);
|
||||||
|
|
||||||
await page.close();
|
await page.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue