Home  >  Article  >  Web Front-end  >  HTML5在canvas中绘制复杂形状附效果截图_html5教程技巧

HTML5在canvas中绘制复杂形状附效果截图_html5教程技巧

WBOY
WBOYOriginal
2016-05-16 15:47:281607browse
一、绘制复杂形状或路径

在简单的矩形不能满足需求的情况下,绘图环境提供了如下方法来绘制复杂的形状或路径。

beginPath() : 开始绘制一个新路径。
closePath() : 通过绘制一条当前点到路径起点的线段来闭合形状。
fill() , stroke() : 填充形状或绘制空心形状。
moveTo() : 将当前点移动到点(x,y)。
lineTo() : 从当前点绘制一条直线到点(x,y)。
arc(x,y,r,sAngle,eAngle,counterclockwise) : 绘制一条指定半径的弧到点(x,y)。

二、用这些方法绘制复杂形状需遵循以下步骤

使用beginPath()方法开始绘制路径。
使用moveTo()、lineTo()、arc()、方法创建线段。
使用closePath()结束绘制并闭合形状(可选)。
使用stroke()或fill()绘制路径的外边框或填充形状。使用fill()会自动闭合所有未闭合路径。

三、弧arc()绘制说明
 
 
四、在canvas中绘制复杂形状

复制代码
代码如下:






HTML5





提示:你的浏览器不支持标签




五、绘制效果
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn