-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlanetsPage.html
More file actions
56 lines (53 loc) · 1.2 KB
/
Copy pathPlanetsPage.html
File metadata and controls
56 lines (53 loc) · 1.2 KB
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
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
#myCanvas {
border: 1px solid #9C9898;
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script>
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "planets.xml",
dataType: "xml",
success: handleResponse,
error: failedxml
});
});
function failedxml(){
$("#title").append('FAIL');
}
function handleResponse(xml) {
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var centerX = canvas.width / 10;
var centerY = canvas.height / 10;
$(xml).find("PLANET").each(function()
{
ctx.beginPath();
ctx.fillStyle =$(this).attr("COLOR");
ctx.arc(centerX, centerY, $(this).find("RADIUS").text()/2000*2, 0, 2 * Math.PI, true);
ctx.lineWidth = 5;
ctx.strokeStyle = "black";
ctx.stroke();
ctx.fill();
ctx.closePath();
centerX=centerX+70;
centerY=centerY+50;
});
}
</script>
</head>
<body>
<canvas id="myCanvas" width="2000" height="1000"></canvas>
</body>
</html>