-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsolar-system.html
167 lines (161 loc) · 8.5 KB
/
solar-system.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
h1{text-align:center;color:red;text-shadow:2px 2px 8px olive;}
#div1, #div2, #div3, #div4,#div5, #div6, #div7, #div8,#div9, #div10,#div11,#div12, #div13, #div14, #div15,#div16,#div17, #div18, #div19, #div20,#div21, #div22, #div23, #div24,#div25, #div26,#div27,#div28,
#div29, #div30, #div31, #div32, #div33, #div34, #div35
{float:left; width:50px; height:50px; margin:5px;padding:2px;border:1px dotted #8d67ff;text-align:center;}
</style>
</head>
<body>
<h1>Animated Solar System</h1>
<canvas id="Canvas_Six" width="500" class="img-responsive" height="500" style="border:dotted lightblue 2px;background-image:url('images/night.jpg');"></canvas>
<br /><br />
<input type="button" value="Start" onclick='orbitting()' />
<script type="text/javascript">
var canvas = document.getElementById('Canvas_Six');
var context_six = canvas.getContext('2d');
// x:angle; b:increment; m:months; d:day
var y = new Date();
var s = y.getSeconds();
var year = y.getFullYear();
x = 0; b = 1; m = 1; d = 1; angM = 0; angV = 0; angMa = 0; angJ = 270; angS = 20; angU = 180; angN = 120; angP = 300; angC = 0;
// variables for the sun, earth and moon
var imgSn = new Image();
var imgErth = new Image();
var imgMn = new Image();
var imgMerc = new Image();
var imgVenus = new Image();
var imgMars = new Image();
var imgJup = new Image();
var imgSat = new Image();
var imgUr = new Image();
var imgNep = new Image();
var imgPluto = new Image();
var imgComet = new Image();
//document.getElementById('Canvas_Six').style.backgroundImage = "url('"+ imgClctn[4] +"')";
//window.setInterval('orbit()', 180);
function orbit() {
x = x + b; d = d + 1;
var z;
// the earth makes the full circle; year updated;
if (x == 360) { x = 0; year = year + 1; m = 0; }
// days and months are updated
if (x % 30 == 0) { m = m + 1; d = 0; }
context_six.clearRect(0, 0, 500, 500);
// image of the sun
context_six.beginPath();
context_six.drawImage(imgSn, 220, 220);
imgSn.src = 'images/sun.png';
// image of the moving mercury
angM = angM + 0.2 * b;
if (angM >= 360) { angM = 0; }
var xm = 250 + 40 * Math.sin(angM * Math.PI / 180);
var ym = 250 + 40 * Math.cos(angM * Math.PI / 180);
context_six.drawImage(imgMerc, xm - 5, ym - 5);
imgMerc.src = 'images/mercury.png';
// image of the moving venus
angV = angV + 0.7 * b;
if (angV >= 360) { angV = 0; }
var xv = 250 + 60 * Math.sin(angV * Math.PI / 180);
var yv = 250 + 60 * Math.cos(angV * Math.PI / 180);
context_six.drawImage(imgVenus, xv - 10, yv - 10);
imgVenus.src = 'images/venus.png';
// image of the moving earth
var xe = 250 + 110 * Math.sin(x * Math.PI / 180);
var ye = 250 + 110 * Math.cos(x * Math.PI / 180);
context_six.drawImage(imgErth, xe - 10, ye - 10);
imgErth.src = 'images/earth.png';
// image of the moving moon
var x2 = xe + 20 * Math.sin(13 * x * Math.PI / 180);
var y2 = ye + 20 * Math.cos(13 * x * Math.PI / 180);
context_six.drawImage(imgMn, x2 - 4, y2 - 4);
imgMn.src = 'images/moon.png';
// image of the moving mars
angMa = angMa + 0.5 * b;
if (angMa >= 360) { angMa = 0; }
var xMa = 250 + 150 * Math.sin(angMa * Math.PI / 180);
var yMa = 250 + 150 * Math.cos(angMa * Math.PI / 180);
context_six.drawImage(imgMars, xMa - 5, yMa - 5);
imgMars.src = 'images/mars.png';
// image of the moving jupiter
angJ = angJ + 0.03 * b;
if (angJ >= 360) { angJ = 0; }
var xj = 250 + 180 * Math.sin(angJ * Math.PI / 180);
var yj = 250 + 180 * Math.cos(angJ * Math.PI / 180);
context_six.drawImage(imgJup, xj - 15, yj - 15);
imgJup.src = 'images/jupiter.png';
// image of the moving saturn
angS = angS + 2 * 0.04 * b;
if (angS >= 360) { angS = 0; }
var xs = 250 + 205 * Math.sin(angS * Math.PI / 180);
var ys = 250 + 205 * Math.cos(angS * Math.PI / 180);
context_six.drawImage(imgSat, xs - 15, ys - 15);
imgSat.src = 'images/saturn.png';
// image of the moving uranus
angU = angU + 0.05 * b;
if (angU >= 360) { angU = 0; }
var xu = 250 + 235 * Math.sin(angU * Math.PI / 180);
var yu = 250 + 235 * Math.cos(angU * Math.PI / 180);
context_six.drawImage(imgUr, xu + 15, yu - 15);
imgUr.src = 'images/uranus.png';
// image of the moving neptune
angN = angN + 0.04 * b;
if (angN >= 360) { angN = 0; }
var xn = 250 + 265 * Math.sin(angN * Math.PI / 180);
var yn = 250 + 265 * Math.cos(angN * Math.PI / 180);
context_six.drawImage(imgNep, xn - 15, yn - 15);
imgNep.src = 'images/neptune.png';
context_six.font = '12pt Calibri';
context_six.fillStyle = 'white';
context_six.fillText('Year: ' + year, 40, 20);
context_six.fillStyle = 'white';
context_six.fillText('Month: ' + m, 130, 20);
context_six.fillStyle = 'white';
context_six.fillText('Day: ' + d, 220, 20);
context_six.fillStyle = 'white';
z = x / 15;
if (x < 180)
{ context_six.fillText('Time - snap shot at: ' + Math.round(z) + ' .00 am', 300, 20); }
else if (x > 180) { context_six.fillText('Time - snap shot at: ' + (Math.round(z) - 12) + ' .00 pm', 300, 20); }
else { context_six.fillText('Time - snap shot at: ' + Math.round(z) + ' .00 noon', 300, 20); }
//colours of the sky
if (z >= 5 && z < 7) {
document.getElementById('Canvas_Six').style.backgroundImage = "";
document.getElementById('Canvas_Six').style.backgroundColor = "#98afc7";
}
else if (z >= 7 && z < 9) {
document.getElementById('Canvas_Six').style.backgroundImage = "";
document.getElementById('Canvas_Six').style.backgroundColor = "#4863a0"; ;
}
else if (z >= 9 && z < 16) {
document.getElementById('Canvas_Six').style.backgroundImage = "";
document.getElementById('Canvas_Six').style.backgroundColor = "#000080"; ;
}
else if (z >= 16 && z < 18) {
document.getElementById('Canvas_Six').style.backgroundImage = "";
document.getElementById('Canvas_Six').style.backgroundColor = "#4863a0"; ;
}
else if (z >= 18 && z < 20) {
document.getElementById('Canvas_Six').style.backgroundImage = "";
document.getElementById('Canvas_Six').style.backgroundColor = "#000011"; ;
}
else {
document.getElementById('Canvas_Six').style.backgroundImage = "url('images/night.jpg')";
document.getElementById('Canvas_Six').style.backgroundColor = "#000000"; ;
}
}
context_six.font = '10pt Calibri';
context_six.fillStyle = 'white';
context_six.fillText('Programmed by Vivax Solutions', 20, 490);
function orbitting() {
j = window.setInterval('orbit()', 180);
}
function stopping() {
window.clearInterval(j);
}
</script>
</body>
</html>