Spaces:
Sleeping
Sleeping
File size: 5,058 Bytes
58c878c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | const puppeteer = require('puppeteer');
const html = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Cinematic Motion Graphics 30s</title>
<style>
html,body{margin:0;width:100%;height:100%;overflow:hidden;background:#050814}
canvas{position:fixed;inset:0}
#ui{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;pointer-events:none}
.title{
position:absolute;
font-family:Georgia,serif;
font-weight:700;
font-size:clamp(60px,9vw,180px);
letter-spacing:.08em;
color:white;
opacity:0;
transform:translateY(40px) scale(.9);
text-transform:uppercase;
text-shadow:0 0 30px rgba(255,255,255,.25);
}
.sub{
position:absolute;
top:62%;
font-family:Arial,sans-serif;
letter-spacing:.6em;
font-size:14px;
color:rgba(255,255,255,.8);
opacity:0;
text-transform:uppercase;
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<div id="ui">
<div class="title" id="title">MOTION</div>
<div class="sub" id="sub">DESIGN • RHYTHM • STORY</div>
</div>
<script>
const canvas=document.getElementById('c');
const ctx=canvas.getContext('2d',{alpha:false,willReadFrequently:true});
canvas.width=1920; canvas.height=1080;
const title=document.getElementById('title');
const sub=document.getElementById('sub');
const D=30000;
function lerp(a,b,t){return a+(b-a)*t;}
function clamp(x,a,b){return Math.max(a,Math.min(b,x));}
function drawBackground(t){
ctx.fillStyle='#050814';
ctx.fillRect(0,0,1920,1080);
for(let i=0;i<80;i++){
let y=i*14 + Math.sin(t*0.001+i*0.4)*25;
ctx.strokeStyle='rgba(80,160,255,.08)';
ctx.beginPath();
ctx.moveTo(0,y*4);
ctx.lineTo(1920,y*4);
ctx.stroke();
}
}
function sceneLines(local){
for(let i=0;i<30;i++){
let p=clamp(local-i*0.03,0,1);
let len=1200*p;
let y=120+i*28;
ctx.strokeStyle='rgba(180,220,255,'+(0.08+p*0.35)+')';
ctx.lineWidth=2;
ctx.beginPath();
ctx.moveTo(960-len/2,y);
ctx.lineTo(960+len/2,y);
ctx.stroke();
}
}
function sceneNetwork(local){
const pts=[];
for(let i=0;i<24;i++){
let a=i/24*Math.PI*2+local*2;
let r=260+Math.sin(a*3+local*4)*70;
pts.push([960+Math.cos(a)*r,540+Math.sin(a)*r]);
}
ctx.strokeStyle='rgba(255,255,255,.15)';
for(let i=0;i<pts.length;i++){
let a=pts[i], b=pts[(i+1)%pts.length];
ctx.beginPath(); ctx.moveTo(a[0],a[1]); ctx.lineTo(b[0],b[1]); ctx.stroke();
}
}
function sceneRibbons(local){
for(let i=0;i<120;i++){
let p=(i/120+local*0.2)%1;
let x=1920*(1-p);
let y=540+Math.sin(p*10+local*8+i)*220;
ctx.strokeStyle='rgba(220,120,255,.12)';
ctx.beginPath();
ctx.moveTo(x,y);
ctx.lineTo(x+180,y+Math.cos(i)*30);
ctx.stroke();
}
}
function sceneFinal(local){
ctx.save();
ctx.translate(960,540);
ctx.rotate(local*0.5);
for(let i=0;i<8;i++){
ctx.strokeStyle='rgba(255,220,120,.15)';
ctx.strokeRect(-260-i*18,-260-i*18,520+i*36,520+i*36);
}
ctx.restore();
}
function animate(ms){
const t=ms%D;
drawBackground(ms);
title.style.opacity=0;
sub.style.opacity=0;
if(t<7000){
sceneLines(t/7000);
if(t>1500){
let p=(t-1500)/2000;
title.style.opacity=clamp(p,0,1);
title.style.transform=\`translateY(\${40-40*clamp(p,0,1)}px) scale(\${0.9+0.1*clamp(p,0,1)})\`;
}
}
else if(t<14000){
sceneNetwork((t-7000)/1000);
title.innerText="KINETIC";
title.style.opacity=1;
sub.style.opacity=.8;
}
else if(t<22000){
sceneRibbons((t-14000)/1000);
title.innerText="STORY";
title.style.opacity=1;
sub.style.opacity=.8;
}
else{
sceneFinal((t-22000)/8000);
title.innerText="CREATE";
title.style.opacity=1;
sub.style.opacity=.8;
}
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>`;
(async () => {
const browser = await puppeteer.launch({ headless: 'new', args: ['--no-sandbox', '--disable-gpu'] });
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 });
await page.setContent(html);
// Wait for 1 second of animation
await new Promise(r => setTimeout(r, 1000));
// Simulate the injection
await page.evaluate(() => {
const c = document.querySelector('canvas');
const dataUrl = c.toDataURL('image/png');
let img = document.getElementById('test-img');
if(!img) {
img = document.createElement('img');
img.id = 'test-img';
img.style.position = 'fixed';
img.style.pointerEvents = 'none';
const computedStyle = window.getComputedStyle(c);
img.style.zIndex = computedStyle.zIndex || '0';
c.parentNode.insertBefore(img, c.nextSibling);
}
img.src = dataUrl;
const rect = c.getBoundingClientRect();
img.style.left = rect.left + 'px';
img.style.top = rect.top + 'px';
img.style.width = rect.width + 'px';
img.style.height = rect.height + 'px';
c.style.visibility = 'hidden';
});
await page.screenshot({ path: 'test_html2.jpg' });
await browser.close();
})();
|