I create a simple circle with the arc function:
/* ctx is the 2d context */
ctx.beginPath();
var gradient = ctx.createLinearGradient(0, 0, this.radius, this.radius);
gradient.addColorStop(0, '#FF0000');
gradient.addColorStop(1, '#FFFFFF');
ctx.lineWidth = 10;
ctx.arc(this.radius, this.radius, this.radius, 0, 2*Math.PI, true);
ctx.strokeStyle = gradient;
ctx.stroke();
So I want to rotate the gradient, is that possible?
I’ve tried with ctx.rotate(x) but that rotates the whole circle!
Yes. Your gradient is going from
x1,y1tox2,y2, which are the four last arguments ofcreateLinearGradientFor example, to reverse your gradient do this:
var gradient = ctx.createLinearGradient(this.radius, this.radius, 0, 0);Or change it up however you please:
var gradient = ctx.createLinearGradient(this.radius, 0, 0, 0);And so on.