-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
127 lines (95 loc) · 3.9 KB
/
index.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sistema Solar (MDS "Site Mozilla")</title>
<link rel="stylesheet" type="text/css" href="./css/styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Audiowide|Quicksand" type="text/css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="content">
<div class="row">
<h1 class="title col-md-12 col-sm-12">Animated Solar System</h1>
</div>
<div class="row">
<canvas id="canvas" style="border: 2px solid #000" width="300" height="300">
<p>Seu navegador não suporta a tecnologia canvas</p>
</canvas>
</div>
<footer>
<p class="footer_texts">Made by Matheus Binotto</p>
<a class="footer_texts" href="https://github.com/Binotto/animated-solar-system"><i class="fa fa-github"></i> Github</a>
</a>
</br>
<a class="footer_texts" href="https://www.linkedin.com/in/matheus-binotto-a51787143/">
<i class="fa fa-linkedin"></i> My Linkedin
</a>
</footer>
</div>
</div>
</div>
<script>
var sun = new Image();
var moon = new Image();
var earth = new Image();
init();
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://mdn.mozillademos.org/files/1429/Canvas_earth.png";
window.requestAnimationFrame(draw);
}
function draw()
{
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
//Seta o tipo de composição dos objetos
//Composição = Forma de "mesclar" as cores do desenho
ctx.globalCompositeOperation = "destination-over";
//Limpa o canvas retornando as configurações anteriores nas coordenadas informadas
//Posição inicial de x e y
//Posição final de x e y
//Neste exemplo limpa o canvas por completo
ctx.clearRect(0,0,300,300);
//Seta um padrão de cores
//Fundo preto com opacidade de 40%
ctx.fillStyle = "rgba(0,0,0,0.4)";
ctx.strokeStyle = "rgba(0,153,255,0.5)";
ctx.save();
//mova o objeto para a posição de x e y
ctx.translate(150,150);
var time = new Date();
//Desenhar a imagem da terra
//Realiza a rotação do objeto na tela de acordo com os calculos
ctx.rotate(((2*Math.PI)/60)*time.getSeconds() + ((2*Math.PI)/60000)*time.getMilliseconds() );
//Move o objeto
ctx.translate(105,0);
//Desenho a imagem da terra no canvas
ctx.drawImage(earth, -12, -12);
ctx.save();
//Fim desenho da terra
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();
//Orbita da terra
ctx.arc(150,150,105,0,Math.PI*2, false);
ctx.stroke();
//Fim do desenho da lua
ctx.drawImage(sun,0,0,300,300);
window.requestAnimationFrame(draw);
}
</script>
</body>
</html>