<div style="background-image:url(space.jpg); width:1000px; height: 1000px;"> <canvas id="planet" width="300" height="300" style="position: absolute; left:200px; top: 200px;"> </canvas> </div>
$(function(){ var pl_id = 'planet'; var image = new Image(); image.src = 'images/planets/1/1/map.jpg'; // canvas var width = $('#'+pl_id).width(); var height = $('#'+pl_id).height(); var canvas = document.getElementById(pl_id); var id = canvas.getContext("2d"); var newMoveWidth = 0; var newMoveHeight = 0; var drawPl = function(){ id.clearRect(0, 0, width, height); // id.drawImage(image, newMoveWidth, newMoveHeight, width, height, 0, 0, width, height); if (newMoveWidth >= 899.5) newMoveWidth = 0; // , else newMoveWidth = newMoveWidth+0.5; // } setInterval(drawPl, 50); // 50 . });
<div style="background-image:url(space.jpg); width:1000px; height: 1000px;"> <canvas id="planet" width="300" height="300" style="position: absolute; left:200px; top: 200px; border-radius:50%"> </canvas> </div>
$(function(){ var pl_id = 'planet'; var image = new Image(); image.src = 'map2.jpg'; // var fxShadow = new Image(); fxShadow.src = 'planet_shadow.png'; // canvas var width = $('#'+pl_id).width(); var height = $('#'+pl_id).height(); // var beta = 360/900; var beta = (beta*Math.PI)/360; var l = (Math.sqrt(width*width+width*width))/2; var gam = Math.PI - ((Math.PI - (beta * Math.PI)/360)/2) - (Math.PI/4); var b = 2*l*Math.sin(beta/2); var x = b*Math.sin(gam); var y = b*Math.cos(gam); var p1 = Math.cos(beta); var p2 = Math.sin(beta); var canvas = document.getElementById(pl_id); var id = canvas.getContext("2d"); var newMoveWidth = 0; var newMoveHeight = 0; var drawPl = function(){ id.clearRect(0, 0, width, height); // id.transform(p1, p2, -p2, p1, x, -y); // id.drawImage(image, newMoveWidth, newMoveHeight, width, height, 0, 0, width, height); // id.drawImage(fxShadow, 0, 0, width, height); // , if (newMoveWidth >= 899.5) newMoveWidth = 0; else newMoveWidth = newMoveWidth+0.5; // } setInterval(drawPl, 50); // 50 . });
Source: https://habr.com/ru/post/268975/