Skip to content

Instantly share code, notes, and snippets.

@Kreijstal
Created October 2, 2013 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kreijstal/6800584 to your computer and use it in GitHub Desktop.
Save Kreijstal/6800584 to your computer and use it in GitHub Desktop.
fibspiralS: (function (angle) {
return (function init() {
var direction = angle;
var fibwords = [0, 1],
addchang = Math.PI / 2;
function fibbonacci() {
var i = fibwords[1];
fibwords[1] += fibwords[0];
return fibwords[0] = i;
}
return function (currentPoint, iter, ctx, strokelength, length) {
var fib = fibbonacci();
console.log(fib);
var sleng = strokelength * fib
ctx.beginPath();
ctx.moveTo.apply(ctx, currentPoint);
currentPoint[0] += Math.cos(direction) * sleng;
ctx.lineTo.apply(ctx, currentPoint);
var fag = currentPoint.slice(0);
currentPoint[1] += Math.sin(direction) * sleng;
ctx.lineTo.apply(ctx, currentPoint);
currentPoint[0] -= Math.cos(direction) * sleng;
var asdf = currentPoint.slice(0);
ctx.lineTo.apply(ctx, currentPoint);
currentPoint[1] -= Math.sin(direction) * sleng;
ctx.lineTo.apply(ctx, currentPoint);
currentPoint[0] += Math.cos(direction) * sleng;
currentPoint[1] += Math.sin(direction) * sleng;
ctx.moveTo.apply(ctx, fag);
ctx.lineTo((asdf[0] + fag[0]) / 2, (asdf[1] + fag[1]) / 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo((asdf[0] + fag[0]) / 2, (asdf[1] + fag[1]) / 2);
ctx.setStrokeColor("#f00");
ctx.lineTo.apply(ctx, asdf);
ctx.moveTo.apply(ctx, currentPoint);
ctx.stroke();
ctx.beginPath();
ctx.setStrokeColor("#000")
//ctx.lineTo.apply(ctx,fag);
console.log(Math.cos(direction) * sleng + Math.sin(direction) * sleng);
window.ctx = ctx;
ctx.arc(asdf[0], asdf[1], Math.abs(Math.cos(direction) * sleng + Math.sin(direction) * sleng), 0, Math.PI / 2)
ctx.moveTo.apply(ctx, currentPoint);
//ctx.lineTo.apply(ctx,currentPoint);
ctx.stroke();
direction += addchang;
direction %= 2 * Math.PI;
}
}())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment