mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Add seeding to marketplace
This commit is contained in:
33
dev/marketplace-scripts/rotating-logo/source.js
Normal file
33
dev/marketplace-scripts/rotating-logo/source.js
Normal file
@@ -0,0 +1,33 @@
|
||||
async function init(context, state) {
|
||||
const asset = Array.isArray(context.assets) ? context.assets[0] : null;
|
||||
if (!asset?.blob) {
|
||||
return;
|
||||
}
|
||||
state.rotation = 0;
|
||||
state.imageReady = false;
|
||||
try {
|
||||
state.image = await createImageBitmap(asset.blob);
|
||||
state.imageReady = true;
|
||||
} catch (error) {
|
||||
state.imageError = error;
|
||||
}
|
||||
}
|
||||
|
||||
function tick(context, state) {
|
||||
const { ctx, width, height, deltaMs } = context;
|
||||
if (!ctx) {
|
||||
return;
|
||||
}
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
const image = state?.image;
|
||||
if (!image || !state.imageReady) {
|
||||
return;
|
||||
}
|
||||
const size = Math.min(width, height) * 0.35;
|
||||
state.rotation = (state.rotation + (deltaMs || 0) * 0.002) % (Math.PI * 2);
|
||||
ctx.save();
|
||||
ctx.translate(width / 2, height / 2);
|
||||
ctx.rotate(state.rotation);
|
||||
ctx.drawImage(image, -size / 2, -size / 2, size, size);
|
||||
ctx.restore();
|
||||
}
|
||||
Reference in New Issue
Block a user