Para la segunda actuación del Colectivo Artístico «Mi Lana Bonita» desarrollé este experimento con Canvas 2D, gráficos SVG y transformaciones y animaciones CSS3.
El código fuente es muy sencillo:
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<title>Toro rotante</title>
<style type="text/css">
body {
width: 100%;
height: 100%;
background-color: silver;
}
h1 {
font-size: 15pt;
}
@-webkit-keyframes lienzo {
from {-webkit-transform: rotateY(0deg);}
to {-webkit-transform: rotateY(-360deg);}
}
#lienzo {
background-color: transparent;
border: 1px solid gray;
-webkit-animation-name: lienzo;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 6s;
}
#lienzo:hover {
-webkit-animation-play-state: paused;
}
select {
display: block;
}
</style>
</head>
<body>
<center>
<h1>Experimento con canvas 2D, gráficos SVG y<br />transformaciones y animaciones CSS3</h1>
<canvas id="lienzo" width="600" height="480"></canvas>
<select onchange="cambia_imagen();" id="opcion">
<option value="hierro_toro.svg">Hierro Toro</option>
<option value="hierro_mlb.svg">Hierro MLB</option>
<option value="hierro_milanabonita.svg">Hierro Mi Lana Bonita</option>
</select>
</center>
<script>
var canvas = document.getElementById("lienzo");
var context = canvas.getContext("2d");
var imagen = new Image();
imagen.onload = function() {
context.drawImage(imagen, 0, 0);
}
imagen.src = "hierro_toro.svg";
function cambia_imagen() {
var opcion = document.getElementById("opcion");
context.clearRect(0, 0, canvas.width, canvas.height);
imagen.src = opcion.value;
}
</script>
</body>
</html>
El único archivo externo es un gráfico vectorial en formato SVG que trabajé con Illustrator y luego exporté. (Luego aprenderé cómo codificar ese archivo directamente con BASE64 :))
Y aquí el experimento.