Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created September 2, 2013 14:18
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 zeffii/6413361 to your computer and use it in GitHub Desktop.
Save zeffii/6413361 to your computer and use it in GitHub Desktop.
coffee_nautilus_3

[ Launch: coffee_nautilus_2 ] 6413361 by zeffii
[ Launch: coffee_circledots_Edges ] 6411197 by zeffii
[ Launch: coffee_circledots ] 6404636 by zeffii
[ Launch: coffee_template_2 ] 6403820 by zeffii
[ Launch: coffee_template_2 ] 6400624 by zeffii
[ Launch: coffee_template ] 6400306 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6399870 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6382272 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6382237 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6379220 by zeffii
[ Launch: boomstick_motion_wcolor ] 6376715 by zeffii
[ Launch: boomstick_motion2 ] 6365156 by zeffii
[ Launch: boomstick_motion ] 6364686 by zeffii
[ Launch: boomstick ] 6364584 by zeffii
[ Launch: zeffii default ] 6364028 by zeffii
[ Launch: zeffii default ] 5033869 by zeffii

{"description":"coffee_nautilus_3","endpoint":"","display":"svg","public":true,"require":[{"name":"randomseed","url":"http://davidbau.com/encode/seedrandom-min.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"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},"data2.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"util.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"injet.coffee":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.coffee":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"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,"thumbnail":"http://i.imgur.com/WZh7LOU.png"}
# after: #366 The nautilus fracture by @Tilman (Geometry Daily)
# recode: zeffii
# Why? to learn CoffeeScript.
# random seed. (uses import library)
# http://davidbau.com/encode/seedrandom-min.js
Math.seedrandom('105e');
# helpers
distance = (pos1, pos2) ->
a = Math.max(pos1[0], pos2[0]) - Math.min(pos1[0], pos2[0])
b = Math.max(pos1[1], pos2[1]) - Math.min(pos1[1], pos2[1])
Math.sqrt((a * a) + (b * b))
pts_to_edge = (pts1, pts2) ->
[pts1[0], pts1[1], pts2[0], pts2[1]]
get_points = (angle, amp) ->
x: Math.cos(angle) * amp
y: -Math.sin(angle) * amp
plist = (pts) -> [pts.x, pts.y]
# variables & config
svg = d3.select("svg")
defs = svg.append("defs")
group1 = svg.append("g").classed("group1", true)
mid_x = tributary.sw / 2
mid_y = tributary.sh / 2
group1
.attr
transform: "translate(" + [mid_x, mid_y] + ")"
.style
fill: "#aeaeae", stroke: "none"
d3.select("body").style "background-color", d3.rgb(25, 25, 25)
[verts, edges, data2] = [[], [], []]
begin_count = 14
begin_amp = 33
amp_growth = begin_amp/2
extra_dots = 5
num_rings = 11
dot_radius = 1.3248
edge_width = 2
max_span = amp_growth * 1.140394464
angle_offset = 0.22848 * Math.PI
# get points for each ring, as function of point index (n)
assemble_points = ->
for ring in [0..num_rings]
dots = begin_count + extra_dots*ring
amp = begin_amp + amp_growth*ring
magic = -5.36 * Math.random()*8 - 16
make_magic2 = ->
if Math.random() < 0.348
-0.0431999999999999
else
0.5
magic2 = make_magic2()
angle_offset_per_ring = angle_offset * magic + magic2
gpts = (n) ->
angle = n * 2*Math.PI / dots
angle += angle_offset_per_ring
{i:n, pts: plist(get_points(angle, amp)), ring:ring}
datum = (gpts(n) for n in d3.range(dots))
verts.push(d) for d in datum
data2.push(d.pts for d in datum)
# this is highly inefficient, use pivot instead and revere!
# go through rings, do distance check
assemble_edges = ->
for i in [1 .. num_rings]
for v1 in data2[i - 1]
for v2 in data2[i]
dist = distance(v1, v2)
if dist < max_span
edge = pts_to_edge(v1, v2)
edges.push({line: edge})
assemble_points()
assemble_edges()
# populate the svg
balls = group1.append('g').classed('balls', true)
.style
fill: '#46A2B9'
.selectAll('circle').data(verts)
edges = group1.append('g').classed('edges', true)
.style
stroke: '#aeaeae'
'stroke-width': edge_width
.selectAll('path').data(edges)
balls.enter()
.append('circle')
.attr
r: dot_radius
transform: (d) -> "translate(" + d.pts + ")"
edges.enter()
.append('path')
.attr
d: (d) -> "M " + d.line + "z"
.cm-s-elegant.CodeMirror { background: #1e2426; color: #696969; }
.cm-s-elegant div.CodeMirror-selected {background: #064968 !important;} /* 33322B*/
.cm-s-elegant span.cm-variable { color:#22EFFF; }
.cm-s-elegant span.cm-variable-2 { color: #FFCCB4; }
.cm-s-elegant span.cm-variable-3 { color: white; }
.cm-s-elegant span.cm-string { color: Chartreuse; }
.cm-s-elegant span.cm-string-2 {color: Chartreuse;}
.cm-s-elegant span.cm-def {color: #FFCCB4; opacity: 1.0}
.cm-s-elegant span.cm-bracket { color: #EBEFE7; }
.cm-s-elegant pre { color:#FFF; }
.cm-s-elegant span.cm-qualifier { color:#C0C0C0; }
.cm-s-elegant span.cm-comment { color: #AFB4B4;}
.cm-s-elegant span.cm-property {color: #FDA676;}
.cm-s-elegant span.cm-number { color: #FF92EE;}
.cm-s-elegant span.cm-keyword { color: #FFFF18; }
.cm-s-elegant .CodeMirror-cursor { border-left: 1px solid white !important; }
.cm-s-elegant .CodeMirror-gutters {background: #505050;}
.cm-s-elegant .CodeMirror-linenumber {color: #D3D3D3;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment