Spaces:
Sleeping
Sleeping
File size: 3,806 Bytes
2fb1736 | 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 | 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.0">
<title>Cinematic Motion Graphics</title>
<style>
html,body{
margin:0;
overflow:hidden;
width:100%;
height:100%;
background:#050816;
font-family:Arial,sans-serif;
}
canvas{
position:fixed;
inset:0;
}
.overlay{
position:absolute;
inset:0;
display:flex;
align-items:center;
justify-content:center;
pointer-events:none;
}
.title{
color:white;
font-size:clamp(2rem,6vw,6rem);
letter-spacing:.4em;
text-transform:uppercase;
mix-blend-mode:screen;
animation:pulse 6s ease-in-out infinite;
}
@keyframes pulse{
0%,100%{opacity:.8;transform:scale(1)}
50%{opacity:1;transform:scale(1.05)}
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<div class="overlay">
<div class="title">MOTION</div>
</div>
<script>
const canvas=document.getElementById("c");
const ctx=canvas.getContext("2d", { willReadFrequently: true });
let w,h;
function resize(){
w=canvas.width=window.innerWidth;
h=canvas.height=window.innerHeight;
}
window.addEventListener("resize",resize);
resize();
const particles=[];
for(let i=0;i<1200;i++){
particles.push({
a:Math.random()*Math.PI*2,
r:50+Math.random()*700,
s:0.2+Math.random()*2,
o:Math.random()*Math.PI*2
});
}
let t=0;
function draw(){
t+=0.008;
const g=ctx.createRadialGradient(w/2,h/2,0,w/2,h/2,Math.max(w,h));
g.addColorStop(0,"#101a45");
g.addColorStop(.5,"#070b1d");
g.addColorStop(1,"#020205");
ctx.fillStyle=g;
ctx.fillRect(0,0,w,h);
ctx.save();
ctx.translate(w/2,h/2);
particles.forEach((p,i)=>{
const ang=p.a+t*p.s;
const rr=p.r*(0.75+0.25*Math.sin(t+p.o));
const x=Math.cos(ang)*rr;
const y=Math.sin(ang)*rr;
const size=1.5+2*Math.sin(t*2+p.o);
ctx.fillStyle=\`hsla(\${(ang*100+t*300)%360},100%,70%,0.8)\`;
ctx.beginPath();
ctx.arc(x,y,Math.abs(size),0,Math.PI*2);
ctx.fill();
});
for(let ring=0; ring<8; ring++){
ctx.beginPath();
for(let i=0;i<360;i++){
const a=i*Math.PI/180;
const r=140+ring*50+Math.sin(a*6+t*3+ring)*18;
const x=Math.cos(a+t*0.2*ring)*r;
const y=Math.sin(a+t*0.2*ring)*r;
if(i===0) ctx.moveTo(x,y);
else ctx.lineTo(x,y);
}
ctx.closePath();
ctx.strokeStyle=\`hsla(\${(ring*45+t*120)%360},90%,65%,0.18)\`;
ctx.lineWidth=2;
ctx.stroke();
}
for(let i=0;i<6;i++){
const k=i*Math.PI/3;
ctx.save();
ctx.rotate(k+t*0.1);
ctx.lineWidth=1.5;
ctx.globalAlpha=0.4+0.3*Math.sin(t*2+i);
ctx.scale(1+(Math.sin(t*3+i)*0.15), 1+(Math.cos(t*3+i+1)*0.15));
ctx.beginPath();
for(let j=0;j<200;j++){
const a=j/200*Math.PI*2;
const r=260+Math.sin(a*12+t*4+k)*45;
ctx.lineTo(Math.cos(a)*r,Math.sin(a)*r);
}
ctx.closePath();
ctx.strokeStyle=\`hsla(\${(k*60+t*100)%360},100%,60%,0.25)\`;
ctx.stroke();
ctx.restore();
}
ctx.restore();
requestAnimationFrame(draw);
}
draw();
</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 1 second to let it draw
await new Promise(r => setTimeout(r, 1000));
const w = await page.evaluate(() => window.innerWidth);
const h = await page.evaluate(() => window.innerHeight);
const cw = await page.evaluate(() => document.getElementById('c').width);
console.log('Viewport:', w, h, 'Canvas:', cw);
await page.screenshot({ path: 'test_html.jpg' });
await browser.close();
})();
|