Skip to content

Instantly share code, notes, and snippets.

@roundrobin
Created January 27, 2013 07:13
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 roundrobin/4647186 to your computer and use it in GitHub Desktop.
Save roundrobin/4647186 to your computer and use it in GitHub Desktop.
pattern - magic eye
{"description":"pattern - magic eye","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"tab":"edit","display_percent":0.6304687500000006,"hidepanel":false,"fullscreen":false,"thumbnail":"http://i.imgur.com/yaEbvXg.png"}
function Path(canvas, path){
this.dataPoints = [];
if(path != undefined){
this.path = path;
} else {
this.path = canvas.append('svg:path')
.attr("stroke","black")
.attr("stroke-width",3)
.attr("fill","none");
}
}
Path.prototype.el = function(wayPoint){
return this.path;
}
Path.prototype.add = function(wayPoint){
this.dataPoints.push(wayPoint);
}
Path.prototype.render = function(){
this.path.attr("d",this.pathWay());
}
Path.prototype.pathWay = function(){
var way = '';
for(var i=0; i < this.dataPoints.length; i++){
var elem = this.dataPoints[i];
way += elem.join(' ');
}
return way;
}
var colors = [
'#0900E2'
, '#4881A3'
, '#5AC505'
, '#253FA5'
]
var k, color_scale;
//interpolate over multiple colors
var sw = tributary.sw;
//make the sin waves extend past the width a little
sw += .1 * sw
var sh = tributary.sh
var svg = d3.select("svg")
svg.append("rect")
.attr("width", sw)
.attr("height", sh)
.attr("fill", "#F1F1F1")
var defs = d3.select('svg').append('defs')
var pattern = defs.append('pattern')
.attr('id','pattern1')
.attr('patternTransform','')
.attr('height',100)
.attr('width',100)
.attr('patternUnits','userSpaceOnUse')
var n = 3;
var cx = 200;
var cy = 200;
var opacity = 1;
var iterations = 3.84;
var stepSize = 1 / iterations * 2;
var toggle = 1;
for(var j = 0; j < iterations; j++){
var path = new Path(pattern)
var strokeWidth = (toggle == 1 ? 6 : 4)
path.el()
.attr('fill','none')
.attr('stroke','#2A1C1C')
.attr('stroke-width',strokeWidth)
.attr('stroke-opacity', 1)
.attr("transform","translate("+[51,60]+")rotate("+30+")")
var r = -9 + (j * 38);
path.add(['M',r,0]);
for(var i = 0; i < n; i++){
var cx = r * Math.cos(2 * Math.PI * i / n);
var cy = r * Math.sin(2 * Math.PI * i / n);
path.add(['L',cx,cy]);
}
path.add(['z']);
console.log(toggle);
toggle *= -1;
path.render();
}
d3.select('svg').append('rect')
.attr('height',tributary.sh)
.attr('width',tributary.sw)
.attr('fill','url(#pattern1)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment