Created
July 22, 2012 19:53
-
-
Save roundrobin/3160886 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
var pathWay =[[183,246,'M',183,246],[323,203,'Q',323,203],[307,498,'Q',307,498],[236,564,'Q',236,564],[155,507,'Q',155,507],[127,399,'Q',127,399],[246,513,'Q',246,513],[277,342,'Q',277,342],[110,367,'Q',110,367],[207,276,'M',207,276],[164,341,'Q',164,341],[275,324,'Q',275,324],[291,252,'Q',291,252]]; | |
var curve = ''; | |
for(i in pathWay){ | |
var p = pathWay[i] | |
curve += p[2]+p[0]+','+p[1]+' '+p[3]+','+p[4]+' '; | |
} | |
function randomXToY(minVal,maxVal,floatVal) | |
{ | |
var randVal = minVal+(Math.random()*(maxVal-minVal)); | |
return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal); | |
} | |
curve += 'Z'; | |
console.log(curve) | |
var path = g.append('path') | |
.attr('stroke','red') | |
.attr('stroke-width','2') | |
.attr('fill',"none") | |
.attr('id','path') | |
.attr('fill-opacity','0.5') | |
.attr('class','drawit') | |
.attr('transform','scale(1)') | |
.attr('id','pathWay') | |
.attr('d',curve) | |
var keying = function(){ | |
console.log('hey',d3.event.keyCode) | |
if(d3.event.keyCode == 32){ | |
return path.attr('d','M0,0') | |
} | |
if(d3.event.keyCode == 80){ | |
path.attr('fill','#'+Math.floor(Math.random()*16777215).toString(16)) | |
path.attr('stroke','#'+Math.floor(Math.random()*16777215).toString(16)) | |
} | |
if(d3.event.keyCode == 79){ | |
var p = path.attr('d').split('Q') | |
var length = p.length -2; | |
var newPath = p.slice(1,randomXToY(2,length)) | |
var curve = p[0]; | |
for(i in newPath){ | |
var p1 = newPath[i] | |
curve += 'Q'+p1; | |
} | |
console.log('sfsd',newPath.length) | |
return path.attr('d',curve); | |
} | |
var x = path.attr('d'); | |
var newPoint = 'Q'+randomXToY(1,1000)+','+randomXToY(1,1000)+' '+randomXToY(1,1000)+','+randomXToY(1,1000) | |
path | |
.attr('d',x+newPoint) | |
} | |
d3.select(window).on("keypress", keying); | |
d3.select(window).on("keyup", keying); | |
d3.select(window).on("keydown", keying); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment