This repository was archived by the owner on Dec 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslide_16.html
executable file
·62 lines (57 loc) · 1.7 KB
/
slide_16.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="./images/favicon.ico" rel="shortcut icon">
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="javaScript/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="javaScript/main.js"></script>
</head>
<body>
<header>
<h1>Let's add the math to our animation</h1>
</header>
<div style="height:8px;" class="blackLine"></div>
<section class="code">
<pre>
var canvasContext;
var angle = 0;
<span class="highlight">var xVal = 0;
var yVal = 0;
var xCenter = 300;
var yCenter = 150;
var angleVelocity = 0.07;
var radius = 100;</span>
function animationExampleInit(e){
canvasContext = $("#myCanvas")[0].getContext("2d");
drawBall();
startBall();
}
function drawBall(){
clearCanvas(canvasContext);
canvasContext.beginPath();
<span class="highlight">canvasContext.arc(xVal, yVal, 20, 0, Math.PI*2, false);</span>
canvasContext.closePath();
canvasContext.fill();
setTimeout(animateBall, 33);
}
function startBall(){
setTimeout(animateBall, 33);
}
function animateBall(e){
<span class="highlight"> angle += angleVelocity;
xVal = xCenter + Math.cos(angle) * radius;
yVal = yCenter + Math.sin(angle) * radius;</span>
drawBall();
}
...
</pre>
</section>
<nav>
<a id="left_btn" href="slide_15.html">Previous</a>
<a id="right_btn" href="slide_17.html">Next</a>
</nav>
</body>