This repository has been 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_07.html
executable file
·61 lines (54 loc) · 1.68 KB
/
slide_07.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
<!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 animate that circle</h1>
</header>
<div style="height:8px;" class="blackLine"></div>
<section class="code">
<pre>
$(window).load(animationExampleInit);
var canvasContext;
<span class="highlight">var xVal = 50;
var yVal = 50;
var xVelocity = 5;
var yVelocity = 2.2;</span>
function animationExampleInit(e){
canvasContext = $("#myCanvas")[0].getContext("2d");
drawBall();
<span class="highlight">startBall();</span>
}
function drawBall(){
canvasContext.beginPath();
canvasContext.arc(<span class="highlight">xVal, yVal,</span> 20, 0, Math.PI*2, false);
canvasContext.closePath();
canvasContext.fill();
}
<span class="highlight">function startBall(){
//1000 miliseconds / 30 == 33.33333 (video standard)
//don't use setInterval for animation
setTimeout(animateBall, 33);
}
function animateBall(e){
xVal += xVelocity;
yVal += yVelocity;
drawBall();
setTimeout(animateBall, 33);
}</span>
</pre>
</section>
<nav>
<a id="left_btn" href="slide_06.html">Previous</a>
<a id="right_btn" href="slide_08.html">Next</a>
</nav>
</body>