HTML5 Canvas (二)

9.描边样式

 

//加宽线条
context.lineWidth=4;

//平滑路径的结合点
context.lineJoin='round';

//将颜色改成为棕色
context.strokeStyle='#663300';

//最后绘制

context.stroke();

还有一个未用到的属性-lineCap,可以把它的值设置为butt、square或round

 

10.填充样式

context.fillStyle='#339900';
context.fill();

 

11.填充矩形区域

context.fillStyle='#663300';

context.fillRect(-5,-50,10,50);

12.绘制曲线

context.save();

context.translate(-10,350);
context.beginPath();

//向右上方弯曲
context.moveTo(0,0);
context.quadraticCurveTo(170,-50,260,-190);

//向右下方弯曲
context.quadraticCurveTo(310,-250,410,-250);

//用棕色的粗线条绘制路径
context.strokeStyle='#663300';
context.lineWidth=20;
context.stroke();

context.restore();

 

13.在canvas中插入图片

//加载图片
var bark=new Image();
bark.src="bark.jpg";

//图片加载完成后,将其显示在canvas上
back.onload=function(){
drawTrails();
}

 

14.在canvas上显示图像

context.drawImage(bark,-5,-50,10,50);

 

posted @ 2015-06-12 16:30  yangyu54  阅读(144)  评论(0编辑  收藏  举报