-
Notifications
You must be signed in to change notification settings - Fork 833
/
Copy pathhome.html
106 lines (93 loc) · 3.09 KB
/
home.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
<!-- Copyright (c) Microsoft Corporation.
Licensed under the MIT License. -->
<html>
<head>
<title>Custom functions using WebWorker</title>
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
<script src="functions.js" type="text/javascript"></script>
<script type="text/javascript">
let ballX = 100;
let ballY = 10;
let ballDirection = 'downRight';
Office.onReady(function() {
animate();
console.log("Office.onReady");
});
function animate() {
setInterval(drawBall, 10);
}
const drawBall = () => {
const canvas = document.getElementById('mycanvas');
if (canvas.getContext) {
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
moveBall(ctx.canvas.width, ctx.canvas.height);
const radius = 20;
ctx.beginPath();
ctx.arc(ballX, ballY, radius, 0, 2*Math.PI, false);
ctx.fillStyle = 'green';
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = '#003300';
ctx.stroke();
}
}
const moveBall = (width,height) => {
//check for ball collision with context boundaries
if (ballX <= 0) {
if (ballDirection === 'upLeft') {
ballDirection = 'upRight';
} else {
ballDirection = "downRight";
}
}
if (ballY <=0) {
if (ballDirection === 'upLeft') {
ballDirection = 'downLeft';
} else {
ballDirection = "downRight";
}
}
if (ballX >= width) {
if (ballDirection ==='upRight'){
ballDirection = 'upLeft';
} else {
ballDirection = 'downLeft';
}
}
if (ballY >= height) {
if (ballDirection ==='downRight'){
ballDirection = 'upRight';
} else {
ballDirection = 'upLeft';
}
}
switch (ballDirection) {
case 'upRight': {
ballX++;
ballY--;
break;
}
case 'upLeft': {
ballX--;
ballY--;
break;
}
case 'downRight': {
ballX++;
ballY++;
break;
}
case 'downLeft': {
ballX--;
ballY++;
break;
}
}
}
</script>
</head>
<body>
<canvas id = "mycanvas" width = "200" height = "200"></canvas>
</body>
</html>