Created
July 1, 2012 07:55
-
-
Save roundrobin/3027437 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
amplitude = 11; | |
freq = 11; | |
freq2 = -1; | |
var data1 = [{x:0,y:0}, | |
{x:7,y:21}, | |
{x:285,y:33}, | |
{x:390,y:-31}, | |
{x:106,y:-36}, | |
{x:19,y:97}]; | |
// Modes form Point to Point | |
// Left to Right | |
// Top to Bottom | |
// Or Combi | |
toogle = 1; | |
//A,F;G;H;I,L,X,Y,Z | |
function toPath (data){ | |
var path = 'M0,0' | |
for(i in data ){ | |
var p = data[i]; | |
var nextPoint = data[parseInt(i)+1]; | |
path += 'L'+p.x+','+p.y; | |
if(i < (data.length-1)){ | |
var two_point_form = (nextPoint.y - p.y) / (nextPoint.x - p.x); | |
if(nextPoint.x >= p.x){ | |
for(var j = p.x; j < nextPoint.x-1; j++){ | |
path = addElements(path, j, p, two_point_form); | |
}; | |
} | |
if(nextPoint.x <= p.x){ | |
for(var j = p.x; j >= nextPoint.x-1; j--){ | |
path = addElements(path, j, p,two_point_form); | |
} | |
} | |
} | |
} | |
//path += 'Z'; | |
return path; | |
} | |
function addElements(path, j, p,two_point_form){ | |
var x = j; | |
var y = (two_point_form * (j - p.x)) + p.y; | |
if(j % freq == 0) { | |
y-= (amplitude * toogle) | |
toogle *= -1; | |
} | |
if(j % freq2 == 0) { | |
path += 'L'+x+','+(y) | |
} | |
return path; | |
} | |
g.selectAll("path") | |
.data([data1]) | |
.enter() | |
.append("svg:path") | |
.attr("d", toPath(data1)) | |
.attr('fill',"none") | |
.attr('stroke',"#1949C5") | |
.attr('stroke-width',4) | |
.attr('stroke-linejoin','round') | |
.attr('transform','translate(200,200)scale(2)') | |
for (i in data1){ | |
createCircle(data1[i],'red') | |
} | |
function createCircle(pointD,color){ | |
if(!color){ | |
color = "#B40505"; | |
} | |
var circleHandler = g.append('circle') | |
.attr('r',1) | |
.attr('stroke',color) | |
.attr('stroke-width',1) | |
.attr('fill',"#C940C9") | |
.attr('cx',pointD.x) | |
.attr('cy',pointD.y) | |
.attr('class','circleHandle') | |
.on('mouseover',function(){ d3.select(this).attr('fill',"#B6B623")}) | |
.on('mouseout',function(){ d3.select(this).attr('fill',"#FFFFFF") }) | |
.attr('transform','translate(200,200)scale(2)') | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment