Created
August 6, 2012 06:57
-
-
Save ptvans/3271757 to your computer and use it in GitHub Desktop.
just another inlet to tributary
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
//laser math | |
//http://spot.colorado.edu/~lessley/pdf%20stuff/lasermath2.pdf | |
d3.select("#header").style("background-color","#000000") | |
var x0 = 339; | |
var y0 = 274; | |
var a = 555; | |
var b = 638; | |
//var b = (n-1)/(n+10); | |
var hx = 75; | |
var hy = 75; | |
var hxt = hx; | |
var hyt = hy; | |
var phmult = 2; | |
var phxlimit = 69; | |
var phylimit = 70; | |
var trigf = 1; | |
var fbase = 4 / 20; | |
var omega0 = 50 * Math.PI * fbase; | |
var om = 1 * omega0; | |
var speed = 10; | |
var radius = 10; | |
var erasing = 0.03; | |
var linen = 0; | |
var cs = d3.interpolateHsl("#EC3F3F", "#E9D70C"); | |
var sopacity = 1; | |
var cf = d3.interpolateHsl("#EEF800", "#00FFE0"); | |
var fopacity = 1; | |
var nt = 620; | |
var to = 1 + 14.6 / 10; | |
function x(t, o) { | |
//return (a - b) * Math.cos(omega0*t) + h * Math.cos(omega0*t*(a/b-1)); | |
return (a - b) * Math.cos(trigf*o*t) + hx * Math.cos(o*t*(a-b)/b); | |
//return h * Math.cos(t*Math.PI); | |
} | |
function y(t, o) { | |
//return (a - b) * Math.sin(omega0*t) - h * Math.sin(omega0*t*(a/b-1)); | |
return (a - b) * Math.sin(o*t) - hy * Math.sin(o*t*(a-b)/b); | |
//return h * Math.sin(t*Math.PI); | |
} | |
function circle(ctx, p) { | |
//ctx.fillStyle = 'hsla(0,0%,' + 70 +'%,' + 1 + ')'; | |
ctx.beginPath(); | |
ctx.arc(p[0],p[1],radius,0,2*Math.PI); | |
ctx.fill(); | |
} | |
function line(ctx) { | |
ctx.beginPath(); | |
var i; | |
for(i=0;i<linen;i++) { | |
//ctx.strokeStyle = c(i/linen); | |
ctx.lineTo(x0 + x(i/linen, omega0), y0 + y(i/linen, omega0)); | |
} | |
ctx.stroke(); | |
} | |
tributary.init = function(ctx) { | |
d3.select("#display").style("background-color", "#000000") | |
ctx.globalCompositeOperation = 'source-over'; | |
}; | |
tributary.run = function(ctx,t) { | |
//tributary.clear(); //helper function to clear the canvas | |
phaser = Math.tan(t/1); | |
hy = hyt * phaser * phmult % phylimit; | |
hx = hxt * phaser * phmult % phxlimit; | |
ctx.fillStyle = "rgba(9,9,9," + erasing + ")"; | |
ctx.fillRect(0,0,tributary.sw,tributary.sh); | |
var tt = (t % 10)/speed; | |
var p; | |
ctx.strokeStyle = cs(tt); | |
line(ctx); | |
p = [x0 + x(tt, om), y0 + y(tt, om)]; | |
ctx.fillStyle = cf(tt); | |
circle(ctx, p); | |
var i = 0; | |
for(i = 0; i < nt; i++) { | |
//p = [x0 + x(tt+i*tt/2, om), y0 + y(tt+i*tt/2, om)]; | |
p = [x0 + x(tt+i*to, om), y0 + y(tt+i*to, om)]; | |
ctx.fillStyle = cf(tt); | |
circle(ctx, p); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment