-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise.html
More file actions
48 lines (43 loc) · 835 Bytes
/
Copy pathexercise.html
File metadata and controls
48 lines (43 loc) · 835 Bytes
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Area and Distance</title>
</head>
<body>
</body>
<script>
let x = 32;
let y = 44;
let radius = 5;
let centerX = 0;
let centerY = 0;
let width = 600;
let height = 400;
function setup(width, height) {
centerX = width/2;
centerY = height/2;
}
function computeDistance(x1, y1, x2, y2) {
if (x1 != x2 && y1 != y2) {
let dx = x1 - x2;
let dy = y1 - y2;
let d2 = (dx * dx) + (dy * dy);
let d = Math.sqrt(d2);
return d;
} else {
return 0;
}
}
function circleArea(r) {
let area = Math.PI * r * r;
return area;
}
setup(width, height);
let area = circleArea(radius);
let distance = computeDistance(x, y, centerX, centerY);
alert("Area: " + area);
alert("Distance: " + distance);
</script>
</body>
</html>