Canvas的Path分享,又一个html5知识点哦!
2014-03-11 14:35
323 查看
我们先画一行
然后,上面的脚本,画了棕色的线。
<div><canvas id="Canvas2" width="600" height = "200" style="border:solid 1px #000000;"></canvas>
<div>
<button onclick="Vertical_line();return true;">Click me to draw a brown vertical line</button>
</div>
</div>
<script>
var c3 = document.getElementById("c3");
var c3_context = c3.getContext("2d");
function Vertical_line() {
c3_context.moveTo(300, 10);
c3_context.lineTo(300, 190);
c3_context.strokeStyle = "brown";
c3_context.stroke();
}
</script>
真正重要的方法是“函数”,“画线”、“stroke”和“strokeStyle”。
上下文方法 描述
函数(x,y) 搬到起点,x和y坐标。
画线(x,y) 画一条线从起点这一点。再次x和y坐标。
strokestyle css线的颜色
stroke的方法 实际上使javascript画一条线
beginPath 在你开始画一个新的和不同的颜色,你将不得不叫“beginPath”。
<div>
<canvas id="c4" width="600" height = "200" style="border:solid 1px #000000;"></canvas>
<div>
<button onclick="Vertical_2px_Red();return true;">Vertical 2px Red line</button>
<button onclick="Vertical_1px_Blue();return true;">Vertical 1px Blue line</button>
<button onclick="Horizontal_2px_Green();return true;">Horizontal 2px Green line</button>
<button onclick="Clear_line();return true;">Erase Everything</button>
</div>
</div>
<script>
var c4 = document.getElementById("c4");
var c4_context = c4.getContext("2d");
function Vertical_2px_Red() {
c4_context.beginPath();
c4_context.moveTo(300, 10);
c4_context.lineTo(300, 190);
c4_context.strokeStyle = "Red";
c4_context.stroke();
}
function Vertical_1px_Blue() {
c4_context.beginPath();
c4_context.moveTo(350.5, 10);
c4_context.lineTo(350.5, 190);
c4_context.strokeStyle = "Blue";
c4_context.stroke();
}
function Horizontal_2px_Green() {
c4_context.beginPath();
c4_context.moveTo(100, 100);
c4_context.lineTo(500, 100);
c4_context.strokeStyle = "Green";
c4_context.stroke();
}
function Clear_line() {
c4_context.clearRect(1, 1, 600, 190);
}
</script>
然后,上面的脚本,画了棕色的线。
<div><canvas id="Canvas2" width="600" height = "200" style="border:solid 1px #000000;"></canvas>
<div>
<button onclick="Vertical_line();return true;">Click me to draw a brown vertical line</button>
</div>
</div>
<script>
var c3 = document.getElementById("c3");
var c3_context = c3.getContext("2d");
function Vertical_line() {
c3_context.moveTo(300, 10);
c3_context.lineTo(300, 190);
c3_context.strokeStyle = "brown";
c3_context.stroke();
}
</script>
真正重要的方法是“函数”,“画线”、“stroke”和“strokeStyle”。
上下文方法 描述
函数(x,y) 搬到起点,x和y坐标。
画线(x,y) 画一条线从起点这一点。再次x和y坐标。
strokestyle css线的颜色
stroke的方法 实际上使javascript画一条线
beginPath 在你开始画一个新的和不同的颜色,你将不得不叫“beginPath”。
<div>
<canvas id="c4" width="600" height = "200" style="border:solid 1px #000000;"></canvas>
<div>
<button onclick="Vertical_2px_Red();return true;">Vertical 2px Red line</button>
<button onclick="Vertical_1px_Blue();return true;">Vertical 1px Blue line</button>
<button onclick="Horizontal_2px_Green();return true;">Horizontal 2px Green line</button>
<button onclick="Clear_line();return true;">Erase Everything</button>
</div>
</div>
<script>
var c4 = document.getElementById("c4");
var c4_context = c4.getContext("2d");
function Vertical_2px_Red() {
c4_context.beginPath();
c4_context.moveTo(300, 10);
c4_context.lineTo(300, 190);
c4_context.strokeStyle = "Red";
c4_context.stroke();
}
function Vertical_1px_Blue() {
c4_context.beginPath();
c4_context.moveTo(350.5, 10);
c4_context.lineTo(350.5, 190);
c4_context.strokeStyle = "Blue";
c4_context.stroke();
}
function Horizontal_2px_Green() {
c4_context.beginPath();
c4_context.moveTo(100, 100);
c4_context.lineTo(500, 100);
c4_context.strokeStyle = "Green";
c4_context.stroke();
}
function Clear_line() {
c4_context.clearRect(1, 1, 600, 190);
}
</script>
相关文章推荐
- 分享一个超酷的开源html5 canvas互动网络图形效果javascript类库 - sig...
- HTML5中canvas知识点详解1-用HTML5绘制一个简单的矩形
- 【Bugly干货分享】一起用 HTML5 Canvas 做一个简单又骚气的粒子引擎
- 【Bugly干货分享】一起用 HTML5 Canvas 做一个简单又骚气的粒子引擎
- 分享一个超酷的开源html5 canvas互动网络图形效果javascript类库 - sigma.js
- html5 canvas 实现一个简单的叮当猫头部
- HTML5中canvas知识点详解6-给图像绘制阴影
- HTML5 canvas标签绘制正三角形 鼠标按下点为中间点,鼠标抬起点为其中一个顶点
- 借助HTML5 Canvas API制作一个简单的猜字游戏
- 分享一个HTML5的video用法
- 没事用html5 canvas画一个仪表盘自用,自适应的哦
- 分享个HTML5 canvas时钟的代码
- 分享一个基于HTML5实现的视频播放器
- 分享一个CLASSPATH的问题导致SERVLET出错却没有任何log
- html5入门:教你用canvas写一个时钟
- 画板社交工具开发分享——HTML5 canvas控件、PHP、社交分享学习(三)
- HTML5 canvas绘制雪花飘落动画(需求分析、知识点、程序编写分布详解)
- 用html5的canvas画一个可以动的时钟
- 玩转html5(四)----使用canvas画一个时钟
- 用HTML5 Canvas做一个画图板