| 1 | <!DOCTYPE html> |
| 2 | <html lang="es"> |
| 3 | |
| 4 | <head> |
| 5 | <meta charset="UTF-8"> |
| 6 | <meta name="viewport" |
| 7 | content="width=device-width"> |
| 8 | <title>Gira</title> |
| 9 | <style> |
| 10 | .sprite { |
| 11 | position: fixed; |
| 12 | font-size: 3rem; |
| 13 | } |
| 14 | </style> |
| 15 | </head> |
| 16 | |
| 17 | <body> |
| 18 | <h1>Gira</h1> |
| 19 | <output id="mariposa" |
| 20 | class="sprite"> |
| 21 | 🦋 |
| 22 | </output> |
| 23 | <script> |
| 24 | const REFRESCO = 120 |
| 25 | const VELOCIDAD = 0.3 |
| 26 | let angulo = 0 |
| 27 | setInterval(gira, REFRESCO) |
| 28 | |
| 29 | function gira() { |
| 30 | const xBase = innerWidth / 2 |
| 31 | const amplitudX = innerWidth / 3 |
| 32 | const yBase = innerHeight / 2 |
| 33 | const amplitudY = |
| 34 | innerHeight / 3 |
| 35 | const x = xBase + |
| 36 | amplitudX * Math.cos(angulo) |
| 37 | const y = yBase + |
| 38 | amplitudY * Math.sin(angulo) |
| 39 | mariposa.style = |
| 40 | `left: ${x}px; bottom: ${y}px` |
| 41 | angulo += VELOCIDAD |
| 42 | } |
| 43 | </script> |
| 44 | </body> |
| 45 | |
| 46 | </html> |