canvas -颜色,样式 相关

属性 (6个):

 fillStyle : color|gradient|pattern - 填充颜色

 strokeStyle : color|gradient|pattern  - 边框颜色 

 shadowColor : color - 阴影颜色

 shadowBlur  -  设置或者返回阴影的模糊级别

 shadowOffsetX,shadowOffsetY 设置水平和垂直距离

 

方法(4个):

  createLinearGradient(x1,y1,x2,y2)  - 创建渐变

  createPattern(image,"repeat|repeat-x|repeat-y|no-repeat") - 填充模式

  createRadialGradient(x0,y0,r0,x1,y1,r1)

x0渐变的开始圆的 x 坐标
y0渐变的开始圆的 y 坐标
r0开始圆的半径
x1渐变的结束圆的 x 坐标
y1渐变的结束圆的 y 坐标
r1结束圆的半径

  addColorStop(stop,color) - 添加渐变

 

 

 

 

f = ctx.createLinearGradient(0,0,0,200);
f.addColorStop(0,"#FFC19C");
f.addColorStop(0.8,"#B60D1B");
f.addColorStop(1,"#7D0006");

c = ctx.createLinearGradient(0,0,0,200);
c.addColorStop(0,"#F8B592");
c.addColorStop(1,"#FA6167");

ctx.strokeStyle = c;
ctx.fillStyle = f;
ctx.fillRect(10,10,300,300);


ctx.lineWidth = 1;

ctx.strokeRect(10,10,300,300);
ctx.save()
ctx.rect(10,10,300,300);
ctx.clip()


for(var a=1;a<100;a++){
    ctx.moveTo(10,a*6);
    ctx.lineTo(a*6,10);
    ctx.stroke()
}
ctx.restore()

ctx.beginPath()
var grd=ctx.createRadialGradient(100,400,5,100,400,80);
grd.addColorStop(0,"red");
grd.addColorStop(1,"white");

// Fill with gradient
ctx.fillStyle=grd;
ctx.arc(100,400,50,0,Math.PI*2,false);
ctx.stroke();
ctx.fill()

ctx.beginPath()
var i = new Image();
i.src = "./s.jpg";
i.onload =_=>{
    var cI = ctx.createPattern(i,"repeat");
    ctx.fillStyle = cI;
    ctx.strokeRect(30,500,300,300);
    ctx.fillRect(30,500,300,300);
}

 

转载于:https://www.cnblogs.com/Tachi/p/6941306.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值