Project

General

Profile

jsclip.html

Constantin Asofiei, 02/19/2016 08:58 AM

Download (846 Bytes)

 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
<canvas id="myCanvas" width="40" height="40" style="border:1px solid black;">
5
Your browser does not support the HTML5 canvas tag.</canvas>
6

    
7
<script>
8
var c = document.getElementById("myCanvas");
9
var ctx = c.getContext("2d");
10
// Clip a rectangular area
11
ctx.rect(2, 2, 10, 10);
12
ctx.clip();
13
// Draw red rectangle after clip()
14
ctx.fillStyle = "red";
15
ctx.fillRect(0, 0, 8, 8);
16

    
17
</script> 
18

    
19

    
20
<canvas id="myCanvas2" width="40" height="40" style="border:1px solid black;">
21
Your browser does not support the HTML5 canvas tag.</canvas>
22

    
23
<script>
24
var c = document.getElementById("myCanvas2");
25
var ctx = c.getContext("2d");
26
ctx.translate(0.5, 0.5);
27
// Clip a rectangular area
28
ctx.rect(2, 2, 10, 10);
29
ctx.clip();
30
// Draw red rectangle after clip()
31
ctx.fillStyle = "red";
32
ctx.fillRect(0, 0, 8.5, 8.5);
33

    
34
</script> 
35

    
36
</body>
37
</html>