H5_画布二

线条的样式

lineWidth:设置线条的宽度(不需要加px)
lineCap:设置线条末端线帽的样式(butt 、 round 、 square)

context.lineWidth=10;

context.moveTo(20,20);
context.lineTo(80,20);
context.lineCap='butt';
context.stroke();
			
context.beginPath();
context.moveTo(20,40);
context.lineTo(80,40);
context.lineCap='round';
context.stroke();
			
context.beginPath();
context.moveTo(20,60);
context.lineTo(80,60);
context.lineCap='square';
context.stroke();

在这里插入图片描述

lineJoin:设置两条线交汇时所创建的边角的类型(bevel 、 round 、 miter默认)
注意!!:两条线是一条路径!!

	context.lineWidth=10;
			
	context.moveTo(20,20);
	context.lineTo(80,40);
	context.lineTo(20,60)
	context.lineJoin="bevel";
	context.stroke();		
			
	context.beginPath();
	context.moveTo(20,80);
	context.lineTo(80,100);
	context.lineTo(20,120)
	context.lineJoin="round";
	context.stroke();
					
	context.beginPath();
	context.moveTo(20,140);
	context.lineTo(80,160);
	context.lineTo(20,180)
	context.lineJoin="miter";
	context.stroke();		

在这里插入图片描述

miterLimit:设置最大斜接长度,默认为10

			context.lineWidth=10;
			context.lineJoin='miter';
			context.miterLimit=10;//默认
			
			context.beginPath();
			context.moveTo(20,20);
			context.lineTo(160,40);
			context.lineTo(20,60);
			context.stroke();

在这里插入图片描述

			context.lineWidth=10;
			context.lineJoin='miter';
			context.miterLimit=5;//默认
			
			context.beginPath();
			context.moveTo(20,20);
			context.lineTo(160,40);
			context.lineTo(20,60);
			context.stroke();

在这里插入图片描述

画布转换和状态保存

画布转换指的是转换画布的坐标系

  • 平移——translate(x,y)
    重新映射画布上的 (0,0) 位置
context.moveTo(30,30);
context.lineTo(90,90);
context.lineTo(30,150);
context.lineTo(30,30);
context.lineWidth=10;
context.strokeStyle="darkgreen";
context.stroke();
context.translate(100,100);
context.moveTo(30,30);
context.lineTo(90,90);
context.lineTo(30,150);
context.lineTo(30,30);
context.lineWidth=10;
context.strokeStyle="darkgreen";
context.stroke();

在这里插入图片描述

  • 旋转——rotate(deg)
    改变坐标系 x 与 y 轴的指向
    参数 angle —— 旋转角度,以弧度计。
    • 正值表示顺时针方向旋转
    • 负值表示逆时针方向旋转
    • 将角度转换为弧度公式
angle = degrees/180*Math.PI
  • 缩放——scale(sx,sy)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值