Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created December 28, 2012 12:15
Show Gist options
  • Save zeffii/4397252 to your computer and use it in GitHub Desktop.
Save zeffii/4397252 to your computer and use it in GitHub Desktop.
snowflake2b
{"description":"snowflake2b","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"snowfl.svg":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.3653840449411173,"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,"hidepanel":false}
var svg = d3.select("svg");
function posTo(t, p){
return ["", t, p.x, p.y].join(" ")
}
function posTo2(t, p){
return ["", t, p.x1, p.y1, p.x2, p.y2].join(" ")
}
function random_between(i, j){
return i + Math.floor(Math.random() * (j - i + 1))
}
function draw_flake(pos){
var flake_group = svg.append("g").classed("flake", true)
.attr("transform", "translate("+[pos.x,pos.y] +") scale(.3)")
.style({"fill": "none",
"stroke": "3D7DAB",
"stroke-opacity": 1.0,
"stroke-width": 32 + "px"})
// var c1 = 0, c2 = 163, c3 = 55, c4 = 127, c5 = 97;
var c1 = 0,
c2 = random_between(47,163),
c3 = random_between(25,78),
c4 = random_between(20,127),
c5 = random_between(22,121);
var nupath = posTo('M', {x:c1, y:c2})
+ posTo('L', {x:c1, y:-c2})
+ posTo('M', {x:c3, y:-c4})
+ posTo2('L', {x1:c1, y1:-c5, x2:-c3, y2:-c4})
+ posTo('M', {x:c3, y:c4})
+ posTo2('L', {x1:c1, y1:c5, x2:-c3, y2:c4})
flake_group.append("path")
.attr({"id": "arm",
"d": nupath })
flake_group.append("use").attr({
"xlink:href": "#arm",
"transform": "rotate(-60, 0, 0)"
})
flake_group.append("use").attr({
"xlink:href": "#arm",
"transform": "rotate(-120, 0, 0)"
})
}
draw_flake({x:66, y:89})
draw_flake({x:179, y:89})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment