canvas教程

Canvas学习笔记一(2)

字号+ 作者:H5之家 来源:H5之家 2015-09-14 13:04 我要评论( )

!DOCTYPE htmlhtml body canvas id=myCanvas width=300 height=300 style=border:1px solid #d3d3d3;Your browser does not support the HTML5 canvas tag. /canvas scriptvar c=document.getElementById(myCanvas)

      <!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag. </canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.beginPath(); ctx.lineWidth="5"; ctx.strokeStyle="red"; // 红色路径 ctx.moveTo(0,75); ctx.lineTo(250,75); ctx.stroke(); // 进行绘制 ctx.beginPath(); ctx.strokeStyle="blue"; // 蓝色路径 ctx.moveTo(50,0); ctx.lineTo(150,130); ctx.stroke(); cxt.fill(); </script> </body> </html>

      beginPath:beginPath() 方法开始一条路径,或重置当前的路径。

      moveTo(x , y):一条路径的开始,x/y分别是起始位置的横纵坐标。

      lineTo(x , y) : 添加一个新点,然后创建从该点到画布中最后指定点的线条.

      stroke() : 绘制当前路径.

      closePath() : 方法关闭一条打开的子路径

11. strokeStyle属性:

      和fillStyle 相似,不过fillStyle  是用于整个图形上色,而strokeStyle是给边缘上色。


 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • html5canvas核心技术图形、动画与游戏开发源码

    html5canvas核心技术图形、动画与游戏开发源码

    2017-05-02 17:42

  • 打印html5中Canvas的方法

    打印html5中Canvas的方法

    2017-05-01 15:03

  • HTML5+Canvas调用手机拍照功能实现图片上传(下)

    HTML5+Canvas调用手机拍照功能实现图片上传(下)

    2017-04-30 17:00

  • HTML5新特性详解(三)

    HTML5新特性详解(三)

    2017-04-30 16:03

网友点评