Created
October 2, 2013 21:10
-
-
Save Kreijstal/6800584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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