-
Notifications
You must be signed in to change notification settings - Fork 1
/
step2.js
41 lines (34 loc) · 761 Bytes
/
step2.js
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
var canvas = document.getElementById("canvas");
var WIDTH = canvas.width;
var HEIGHT = canvas.height;
var context = canvas.getContext("2d");
function rect(r) {
context.fillStyle = r.color;
context.beginPath();
context.rect(r.x, r.y, r.w, r.h);
context.fill();
context.closePath();
}
function circle(c) {
context.fillStyle = c.color;
context.beginPath();
context.arc(c.x, c.y, c.r, 0, Math.PI*2, true);
context.fill();
context.closePath();
}
function clear() { context.clearRect(0,0,WIDTH,HEIGHT); }
var paddle = {
w: 60,
h: 15,
y: HEIGHT - 30,
color: "white"
}
paddle.x = WIDTH/2 - paddle.w/2;
var ball = {
r: 10,
y: HEIGHT - 45,
color: "white"
}
ball.x = WIDTH/2;// arc is already centered!
rect(paddle);
circle(ball);