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 linear and not radial. I've got only 3 colours. The existing one is available here (the review rating)
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
I needed this effect, too a few days ago, and I have managed to create a workaround to achieve it.
What I did was overlay one gradient over the other using something like this:
Here's the complete code and demo in JSFiddle:
https://jsfiddle.net/flamedenise/n9no9Lgw/33/
Hope it helps.
A context strokeStyle can be a gradient:
Example code and a Demo using a gradient strokeStyle: http://jsfiddle.net/m1erickson/w46ps/
In my case, I needed the whole circle to be filled rather than just a stroke around the circumference. Using the answer above and setting the line width to twice the radius gave undesirable results, so I wrote my own.
This method draws lines from the center of the circle to each pixel along the edge of it. You get a cleaner gradient this way.
For large line thicknesses, it's still cleaner.
Its one major drawback is performance. If your radius is very large, the number of lines required to produce a nice circle is about 50 times the radius.
jsFiddle