const canvas = document.getElementById('bikeCanvas');
const ctx = canvas.getContext('2d');
let bikeX = 0;
function drawBike(x, y) {
// Draw bike frame
ctx.strokeStyle = '#4caf50';
ctx.lineWidth = 4;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + 50, y - 30);
ctx.lineTo(x + 100, y);
ctx.lineTo(x + 50, y + 30);
ctx.closePath();
ctx.stroke();
// Draw wheels
ctx.fillStyle = '#616161';
ctx.beginPath();
ctx.arc(x, y, 20, 0, Math.PI * 2);
ctx.arc(x + 100, y, 20, 0, Math.PI * 2);
ctx.fill();
// Draw rider (Andrey)
ctx.fillStyle = '#ff5722';
ctx.beginPath();
ctx.arc(x + 50, y - 40, 10, 0, Math.PI * 2); // Head
ctx.fill();
ctx.strokeStyle = '#ff5722';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(x + 50, y - 30);
ctx.lineTo(x + 50, y - 10); // Body
ctx.lineTo(x + 40, y); // Left leg
ctx.moveTo(x + 50, y - 10);
ctx.lineTo(x + 60, y); // Right leg
ctx.stroke();
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawBike(bikeX, canvas.height / 2);
bikeX += 2;
if (bikeX > canvas.width) {
bikeX = -100; // Reset position to create a seamless loop
}
requestAnimationFrame(animate);
}
animate();
Этот код создает простую анимацию велосипеда с человеком, едущим по экрану. Конечно, это базовый пример и его можно улучшить, добавив более сложные детали, улучшив изображение персонажа, а также управляя анимацией более продвинуто.