action
action = sur la plupart des slides, il se passe quelque chose quand on clique (surtout les slides 4, 9, 19, 31 et 38 :-)
avec CSS3, SVG, Canvas et WebGL
Martin Gorner
République Tchèque, 25-26 Février 2013
left: 0px;
-webkit-transform:
rotate(0deg);
-webkit-transition: 1s;
|
onclick
|
left: 500px;
-webkit-transform:
rotate(360deg);
-webkit-transition: 1s;
|
.move {-webkit-animation: anim2 ease-in-out 3s infinite alternate; }
@-webkit-keyframes anim2
{
from {left: 0px; -webkit-transform: scale(1.0) rotate(0deg) }
50% {left: 250px; -webkit-transform: scale(0.8) rotate(10deg) }
to {left: 500px; -webkit-transform: scale(1.2) rotate(-20deg) }
}
![]() |
![]() |
![]() |
-webkit-transform: |
-webkit-transform: |
-webkit-transform: |
liste complète des transformations 2D:
rotate, scale, skew, translate, matrix
-webkit-transition: -webkit-transition-delay: -webkit-transition-duration: -webkit-transition-timing-function: -webkit-transition-property:
-webkit-animation:
-webkit-animation-delay / duration / timing-function:
-webkit-animation-name: foo => @keyframes foo { from {} to {}}
-webkit-animation-direction:
-webkit-animation-fill-mode:
-webkit-animation-iteration-count:
-webkit-transform: rotate / scale / skew / translate / matrix
translateX, Y, Z, rotateX, Y, Z, matrix3d
-webkit-transform: translateZ(150px) /* first picture */ -webkit-transform: translateZ(-150px) /* second picture */ -webkit-transform: rotateY(360deg) /* their container */
-webkit-perspective: 1000px;
-webkit-perspective: f
-webkit-transform-style: flat; /* default value */
-webkit-transform-style: preserve-3d;
FACE
.SCENE {
-webkit-perspective: 1000px;
width: 600px;
height: 340px;
}
.OBJECT {
-webkit-transform-style: preserve-3d;
-webkit-transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
position: absolute;
width: 100%;
height: 100%;
}
.FACE {
position: absolute;
left: 165px;
top: 15px;
}
.FACE.im1 { -webkit-transform: translateZ(150px); }
.FACE.im2 { -webkit-transform: translateZ(-150px); }
.FACE.im3 { -webkit-transform: translateX(150px) rotateY(90deg);}
.FACE.im4 { -webkit-transform: translateX(-150px) rotateY(-90deg);}
.FACE.im5 { -webkit-transform: translateY(150px) rotateX(90deg);}
.FACE.im6 { -webkit-transform: translateY(-150px) rotateX(-90deg);}
<line x1 y1 x2 y2>
<rect x y width height>
<circle cx cy r>
<path d>
<image x y width height xlink:href>
<svg> <rect x="5" y="5" width="140" height="140" stroke="#000000" stroke-width="4" fill="#AAAAFF" opacity="1"/> </svg>
L - ligne |
C - bézier cubique |
Q - bézier quadratique |
A - arc d'ellipse |
M - Marqueur (nlle. pos. stylo) |
z - pour fermer la courbe |
<svg> <path d="M 30,240 Q 170,40 260,230" stroke="#F00" /> <path d="M 30,240 C 70,90 210,150 260,230" stroke="#F00" /> </svg>
INKSCAPE
transform = |
transform = |
transform = |
liste complète des transformations 2D:
translate, rotate, scale, skewX, skewY, matrix
<rect ... transform="translate(10,10) rotate(25) scale(2)">
<circle cx="200" cy="205" r="80" > <animate dur="3s" attributeName="r" values="80; 150; 80" repeatCount="indefinite" /> </circle>
<path fill="#fff">
<animate attributeName="d" dur="2s" repeatCount="indefinite"
values="m 0,0 c 1,15 -13,45 -45,45 -32,0 -44,-28 -44,-44 z;
m 0,0 c -4,15 -66,106 -98,106 -32,0 3,-89 9,-105 z" />
</path>
<g> ... <!-- formes SVG groupées ici --> <animateTransform dur="3s" repeatCount="indefinite" additive="sum" attributeName="transform" type="translate" values="0,0; 200,-130" /> <animateTransform dur="3s" repeatCount="indefinite" additive="sum" attributeName="transform" type="rotate" values="0; 20" /> </g>
<g>
... <!-- formes SVG groupées ici -->
<animateMotion dur="1s" repeatCount="indefinite"
path="m 0,0 a 15,11 0 1 1 -30,0 15,11 0 1 1 30,0 z" />
</g>
<animateTransform calcMode="spline" dur="3s" attributeName="transform" type="rotate" repeatCount="indefinite" keySplines="0.35 0 0.65 1; 0.35 0 0.65 1" values="20,310,400; -20,310,400; 20,310,400" />
unpauseAnimations()
pauseAnimations()
setCurrentTime(0)
<g onclick="document.getElementById('svg_id').pauseAnimations()">...</g>
| <line> <rect> <circle> | <path> <image> <text> |
<animate>
<animateTransform>
<animateMotion>
pauseAnimations()
unpauseAnimations()
setCurrentTime(0)
| CSS3 | déclaratif | objets HTML uniquement, aucun contrôle de trajectoire |
| SVG + SMIL | déclaratif | courbes, trajectoires courbes mais préprogrammées |
| Canvas + Javascript | programmatique | boucle d'animation avec modèle et interactions libres, 2D uniquement |
| WebGL + Three.js | program- matique | full 3D |
moteur physique: box2dweb.js
<canvas id = "my-canvas"
width = "400"
height = "400"
style = "width: 400px;
height: 400px;">
</canvas>
Javascript:
var canvasElement = document.getElementById("my-canvas");
var ctx = canvasElement.getContext("2d");
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.strokeStyle = "red"; // CSS color ctx.fillStyle = "blue"; // CSS color ctx.lineWidth = 5; // pixels ctx.globalAlpha = 0.5;
ctx.beginPath(); ctx.closePath();
ctx.moveTo(x, y); ctx.lineTo(x, y); ctx.rect(x1, y1, w, h); ctx.arc(x, y, r, bAng, eAng, dir); ctx.bezierCurveTo(vx, vy, wx, wy, x, y);
ctx.stroke(); ctx.fill();
var img = new Image();
img.onload = function()
{
ctx.drawImage(img, x,y, w,h);
};
img.src = "myimage.png";
var data = "<svg>...</svg>";
var svg = new Blob([data],{type:"image/svg+xml"});
var DOMURL = self.URL || self.webkitURL;
var url = DOMURL.createObjectURL(svg);
var img = new Image();
img.onload = function()
{ ctx.drawImage(img, x, y, w, h); };
img.src = url;
ctx.translate(x, y);Translation |
ctx.rotate(rads);Rotation |
ctx.scale(sx, sy);Zoom |
/*5*/ ctx.translate(x, y);
/*4*/ ctx.rotate(4.5);
/*3*/ ctx.scale(0.6, 0.6);
/*2*/ ctx.translate(-width/2, -height/2);
/*1*/ ctx.beginPath(); // dessiner ici
function runAnimation()
{
world.Draw(context); // votre code de dessin
webkitRequestAnimationFrame(runAnimation);
}
function runWorld()
{
world.Step(1000/60); // votre code de simulation
setTimeout(runWorld, 1000/60);
}
var renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(width, height);
renderer.setClearColorHex(0x000000, 0); // color, transparency
document.ouvousvoulez.appendChild(renderer.domElement);
// THREE.PerspectiveCamera( FOV, viewAspectRatio, zNear, zFar ); var camera = new THREE.PerspectiveCamera(35, width/height, 1, 10000); camera.position.z = 300;
var light = new THREE.DirectionalLight(0xffffff, 1); //color, intens. light.position.set(1, 1, 0.3); // direction
var texture = THREE.ImageUtils.loadTexture('Fernando Togni.jpg');
var cube = new THREE.Mesh(
new THREE.CubeGeometry(100, 100, 100),
new THREE.MeshLambertMaterial({map: texture}) );
var scene = new THREE.Scene(); scene.add(cube); scene.add(light);
renderer.render(scene, camera);
function runAnimation(t)
{
// animer les objets en fonction du temps
cube.rotation.y = t/1000;
cube.position.x = ...
renderer.render(scene, camera); // afficher
requestAnimationFrame(runAnimation); // boucler
}
var loader = new THREE.ColladaLoader();
loader.load("Android.dae", function(collada)
{
var model = collada.scene;
model.position = ...; // x, y, z
model.rotation = ...; // x, y, z
scene.add(model);
},
function progress(p) {} );
utilisez:
SKETCHUP
renderer = new THREE.WebGLRenderer(...)
camera = new THREE.PerspectiveCamera(...)
light = new THREE.DirectionalLight(...)
new THREE.ColladaLoader().load(modelUrl, finishedCallback)
scene = new THREE.Scene()
scene.add(...); // lights, models, ...
window.requestAnimationFrame(animate);
function animate(t)
{
// animation: modifier la scène en fonction du temps t ici
renderer.render(scene, camera);
window.requestAnimationFrame(animate);
}
| CSS3 | déclaratif | objets HTML uniquement, aucun contrôle de trajectoire |
| SVG + SMIL | déclaratif | courbes, trajectoires courbes mais préprogrammées |
| Canvas + Javascript | programmatique | boucle d'animation avec modèle et interactions libres, 2D uniquement |
| WebGL + Three.js | program- matique | full 3D |
chrome
Contact:
Martin Gorner, Relations Développeurs, Google
Google+: gplus.to/martin.gorner
Cette présentation est en ligne:
http://animateyourhtml5.appspot.com
Tutoriel WebGL et THREE.JS
http://fhtr.org/BasicsOfThreeJS par Ilmari Heikkinen
Plus d'infos:
http://html5rocks.com