-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
55 lines (47 loc) · 975 Bytes
/
script2.js
File metadata and controls
55 lines (47 loc) · 975 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
window.onload = function()
{
var canvasWidht = 900;
var canvasHeigt = 600;
var blockSize = 30;
var ctx;
var tps = 100;
var niska;
function init ()
{
var canvas = document.createElement('canvas');
canvas.width = canvasWidht;
canvas.height= canvasHeigt;
canvas.style.border = "1px solid";
document.body.appendChild(canvas);
ctx = canvas.getContext('2d');
niska = new create_Snake([[6,4],[5,4],[4,4]]);
refreshCanvas();
}
function refreshCanvas()
{
ctx.clearRect(0,0,canvasWidth,canvasHeight);
niska.draw()
setTimeout(refreshCanvas,tps);
}
function drawBlock(ctx,position)
{
var x = position[0] * blockSize;
var y = position[1] * blockSize;
ctx.fillRect(x,y,blockSize,blockSize);
}
function create_Snake(body)
{
this.body = body;
this.draw = function()
{
ctx.save();
ctx.fillStyle = red;
for(var i = 0 ; i < this.body.length; i++)
{
drawBlock(ctx,this.body[i]);
}
ctx.restore();
};
}
init();
}