Angle gradient in canvas

后端 未结 3 1293
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 16:59

I\'m looking for a code that permits to have this effect on a canvas\' stroke. I\'ve already got an animated circular stroke, I only need to get the ANGLE gradient, not line

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 17:29

    A context strokeStyle can be a gradient:

    // create a gradient
    
    gradient = ctx.createLinearGradient(xStart, yStart, xEnd, yEnd);
    gradient.addColorStop(0.0,"blue");
    gradient.addColorStop(1.0,"purple");
    
    
    // stroke using that gradient
    
    ctx.strokeStyle = gradient;
    

    Example code and a Demo using a gradient strokeStyle: http://jsfiddle.net/m1erickson/w46ps/

    enter image description here

    
    
    
     
    
    
    
    
    
        
    
    
    

提交回复
热议问题