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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
#canvas1 { position:absolute; top: 0; left: 0; background-color: rgb(11, 4, 4); z-index: 11; } #canvas2 { position:absolute; top: 0; left: 0; background: rgb(11, 4, 4); z-index: -11; } </style> </head> <body> <canvas id="canvas1"></canvas> <canvas id="canvas2"></canvas>
<script> const canvas1 = document.getElementById('canvas1') const ctx1 = canvas1.getContext('2d') canvas1.width = 200 canvas1.height= 200 ctx1.lineCap = 'round'; ctx1.shadowColor = 'rgba(0,0,0,0.7)'; ctx1.shadowOffsetX = 10; ctx1.shadowOffsetY = 5; ctx1.shadowBlur = 10;
const canvas2 = document.getElementById('canvas2'); const ctx2 = canvas2.getContext('2d'); canvas2.width = window.innerWidth; canvas2.height = window.innerHeight; function drawLine() { ctx1.beginPath() ctx1.moveTo(0,0) ctx1.lineTo(100, 0) ctx1.lineWidth=4 ctx1.strokeStyle='orange' ctx1.stroke() }
function draw() { ctx1.save() ctx1.translate( canvas1.width/2, canvas1.height/2); for (let i = 0; i < 12; i++){ ctx1.rotate((Math.PI * 2)/12); drawLine(); } ctx1.restore() }
draw()
const image = new Image() image.src = canvas1.toDataURL();
image.onload = function(){ let angle = 1
function animate() {
ctx2.clearRect(0,0,canvas2.width, canvas2.height) ctx2.save() ctx2.translate(canvas2.width/2-100, canvas2.height/2-100) ctx2.rotate(angle * Math.PI/360) ctx2.drawImage(image, 0-100, 0-100, 200, 200) ctx2.restore(); angle+=4
window.requestAnimationFrame(animate) } animate() } </script> </body> </html>
|