Skip to content

Instantly share code, notes, and snippets.

@NuckChorris
Last active December 10, 2015 09:48
Show Gist options
  • Select an option

  • Save NuckChorris/4416278 to your computer and use it in GitHub Desktop.

Select an option

Save NuckChorris/4416278 to your computer and use it in GitHub Desktop.
Math.TAU = Math.PI * 2
CanvasRenderingContext2D.prototype.circularGradient = function (x, y, r, fn) {
var circum = Math.TAU * r
var width = 5
var lines = circum / (width-1)
console.log(lines)
this.lineWidth = width
for (var i = 0; i < lines; i++) {
this.beginPath()
this.moveTo(x, y)
var theta = (i / lines) * Math.TAU
console.log(i, lines, theta / (Math.PI / 180));
var end = (new Polar(r, theta)).toCartesian()
this.lineTo(x + end.x, y + end.y)
this.strokeStyle = fn(i / lines)
this.stroke()
}
};
$(function(){
doItFgt($('#cocks'));
})
var degree = Math.PI / 180;
var doItFgt = function (el) {
var size = el.height()
var mid = size / 2
var ctx = el[0].getContext('2d')
ctx.circularGradient(mid, mid, size / 2, function (i) {
console.log(i);
return '#' + Array(4).join(Math.round(i * 255).toString(16))
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment