HTML
<body>
<canvas width="1080" height="480" id="cId">Canvas elementas negali buti uzkrautas</canvas>
<script>
var c = document.getElementById("cId");
var ctx = c.getContext("2d");
var cWidth = c.width;
var cHeight = c.height;
console.log('w', c.width);
console.log('h', c.height);
var xOff = 1;
var direction = 1;
function playAnimation() {
// Clear area (should clear everything visible)
ctx.clearRect(0, 0, cWidth, cHeight);
// Show cleared area
ctx.save();
ctx.fillStyle = "#333";
ctx.fillRect(0, 0, cWidth, cHeight);
ctx.restore();
// Draw acutal animation
ctx.translate(450, 150);
ctx.save();
ctx.translate(xOff, 0);
drawName();
ctx.restore();
ctx.save();
ctx.translate(-1*xOff, 0);
drawName();
ctx.restore();
ctx.save();
drawName();
ctx.restore();
xOff++;
ctx.translate(-450, -150);
window.requestAnimationFrame(playAnimation);
}
function fDrawRect() {
ctx.beginPath();
ctx.fillStyle = "red";
ctx.rect(5, 5, 80, 60);
ctx.fillRect(5, 5, 80, 60);
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = "blue";
ctx.rect(85, 5, 80, 60);
ctx.fillRect(85, 5, 80, 60);
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = "yellow";
ctx.rect(165, 5, 80, 60);
ctx.fillRect(165, 5, 80, 60);
ctx.stroke();
}
function draw(x, y, xTo, yTo, color) {
ctx.beginPath();
ctx.lineWidth= 2;
ctx.strokeStyle=color;
ctx.moveTo(x,y);
ctx.lineTo(xTo,yTo);
ctx.stroke();
}
function drawName() {
//Draw rect around
fDrawRect();
//L
draw(10, 10, 10, 60, "black");
draw(10, 60, 30, 60, "black");
//A
ctx.beginPath();
ctx.arc(60, 25, 15, 1*Math.PI, 0);
ctx.stroke();
draw(45, 25, 45, 60, "black");
draw(75, 25, 75, 60, "black");
draw(45, 35, 75, 35, "black");
//U
ctx.beginPath();
ctx.moveTo(90, 45);
ctx.quadraticCurveTo(105, 75, 125,...