ayuda con rotate y translate
Publicado por valentin (24 intervenciones) el 29/10/2019 02:40:54
que valor tengo que poner (en rotate y translate) para que el planeta tierra orbite donde quiero?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var sun = new Image();
var moon = new Image();
var earth = new Image();
var mars = new Image();
var venus = new Image();
function init(){
sun.src = 'https://mdn.mozillademos.org/files/1456/Canvas_sun.png';
moon.src = 'https://mdn.mozillademos.org/files/1443/Canvas_moon.png';
earth.src = 'https://images.vexels.com/media/users/3/152418/isolated/preview/098366e6994dd75ab46b47cd27b2c9d4-icono-de-planeta-tierra-by-vexels.png';
mars.src = "https://i.dlpng.com/static/png/1817849_thumb.png";
venus.src = "";
window.requestAnimationFrame(draw);
}
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
ctx.globalCompositeOperation = 'destination-over';
ctx.clearRect(0,0,1200,1200); // limpiar canvas
ctx.fillStyle = 'rgba(0,0,0,0.4)';
ctx.strokeStyle = 'rgba(0,153,255,0.4)';
ctx.save();
ctx.translate(450,450);
// Marte
var time = new Date();
ctx.rotate (((2*Math.PI)/60)*time.getSeconds() + ((2*Math.PI)/60000)*time.getMilliseconds() );
ctx.translate(200,0);
ctx.drawImage(mars,-14,-18,30,45);
// La tierra
var time = new Date();
ctx.rotate( ((2*Math.PI)/60)*time.getSeconds() + ((2*Math.PI)/60000)*time.getMilliseconds() );
ctx.translate(20,0);
ctx.drawImage(earth,-34,-54,30,30);
// La luna
ctx.save();
ctx.rotate( ((2*Math.PI)/6)*time.getSeconds() + ((2*Math.PI)/6000)*time.getMilliseconds() );
ctx.translate(0,28.5);
ctx.drawImage(moon,3.5,3.5);
ctx.restore();
ctx.restore();
ctx.beginPath();
ctx.arc(450,450,250,0,Math.PI*2,false); // Órbita terrestre
ctx.stroke();
ctx.closePath();
ctx.beginPath();
ctx.arc(450,450,200,0,Math.PI*2,false); // Órbita marciana
ctx.stroke();
ctx.drawImage(sun,0,0,900,900);
window.requestAnimationFrame(draw);
}
init();
Valora esta pregunta


0