-
Notifications
You must be signed in to change notification settings - Fork 1
/
canvas.js
59 lines (48 loc) · 1.3 KB
/
canvas.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var canWidth = 600;
var canHeight = canWidth;
var slitWidth = 30;
var slitHeight = slitWidth;
var canvas = document.getElementById('can');
var clipPoint;
function clipper(point){
var obj=document.getElementById("block1");
obj.style.height=point.y - slitHeight;
obj=document.getElementById("block2");
obj.style.width=(canWidth - point.x) - slitWidth;
obj=document.getElementById("block3");
obj.style.height=(canHeight - point.y) - slitHeight;
obj=document.getElementById("block4");
obj.style.width= point.x - slitWidth;
}
// hide canvase http://robertnyman.com/2011/07/26/using-the-html5-canvas-clip-method-to-hide-certain-content/
function drawLine(x1,y1,x2,y2,color){
if(canvas.getContext){
var ctx = canvas.getContext('2d');
ctx.strokeStyle=color;
ctx.beginPath();
ctx.moveTo(x1,y1);
ctx.lineTo(x2,y2);
ctx.stroke();
}
}
function drawPoint(x,y,color){
if(canvas.getContext){
var ctx = canvas.getContext('2d');
ctx.strokeStyle=color;
ctx.beginPath();
dot(ctx,x,y,3,color);
ctx.stroke();
}
}
function dot(ctx,x,y,rad,color){
ctx.arc(x,y,rad,0,2*Math.PI,false);
ctx.fillStyle=color;
ctx.fill();
}
function clearCanvas(){
canvas = document.getElementById('can');
if(canvas.getContext){
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
}