x
和y
坐标构建画布。当坐标为 x=0, y=0
时,画布位于左上角。x
和 y
坐标。x=0, y=0
。x
值在水平方向增加,而 y
值在垂直方向增加。x=100, y=100
。x=50, y=50
。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 |
<!DOCTYPE HTML>
< html >
< head >
< title >Line Example</ title >
< style >
body {
margin: 0px;
padding: 0px;
}
#myCanvas {
border: 1px solid #9C9898;
}
</ style >
< script >
window.onload = function() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
// blue line with round ends
context.beginPath();
context.moveTo(50, 50);
context.lineTo(300,50);
context.lineWidth = 10;
context.strokeStyle = "#0000FF";
context.lineCap = "round";
context.stroke();
// green line with square ends
context.beginPath();
context.moveTo(50, 100);
context.lineTo(300,100);
context.lineWidth = 20;
context.strokeStyle = "#00FF00";
context.lineCap = "square";
context.stroke();
// purple line with butt ends
context.beginPath();
context.moveTo(50, 150);
context.lineTo(300, 150);
context.lineWidth = 30;
context.strokeStyle = "#FF00FF";
context.lineCap = "butt";
context.stroke();
};
</ script >
</ head >
< body >
< canvas id = "myCanvas" width = "400" height = "200" >
</ canvas >
</ body >
</ html >
|
(责任编辑:12图资源库)