forked from zouboyun/robot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2.js
More file actions
41 lines (33 loc) · 942 Bytes
/
Copy pathmain2.js
File metadata and controls
41 lines (33 loc) · 942 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
require(['robot'], function(Robot){
var bobby = new Robot(150, 150, 'Bobby');
var clark = new Robot(450, 150, 'Clark');
var canvas = document.getElementById("MyCanvas");
var context = canvas.getContext("2d");
var drawRobot = function(robot) {
drawBox(robot.getBody());
drawBox(robot.getHead());
}
function eraseCanvas(){
context.beginPath();
context.fillStyle = "White";
context.fillRect(0, 0, 600, 300);
}
function drawBox(box){
drawLine(box.leftLine());
drawLine(box.rightLine());
drawLine(box.topLine());
drawLine(box.bottomLine());
}
function drawLine(line) {
context.moveTo(line.start.x, line.start.y);
context.lineTo(line.end.x, line.end.y);
context.stroke();
}
setInterval(eraseCanvas, 1000);
setTimeout(function(){
setInterval(drawRobot, 1000, bobby);
}, 500);
setTimeout(function(){
setInterval(drawRobot, 1000, clark);
}, 500);
});