/* JD 12 May 2013 */ // < • P R E P A R A T O R Y S T U F F • > var std_screen = 96, // pixels per inch px2mm = function(mm) {return mm * std_screen / 25.4}, w = 254, h = 132.3, scale = px2mm(1), vflip_all = " matrix(1 0 0 -1 0 " + h + ") ", vflip_text = " matrix(1 0 0 -1 0 "+ h + ") ", svg = d3.select("body").append("svg") .attr({"width": w * scale, "height": h * scale}), background = svg.append("rect") .attr("id", "background") .attr ({"y": 1 * scale, "width": scale * (w - 1) , "height": scale * (h-1)}), g0 = svg.append("g") .attr("id", "g0") .attr("transform", "scale(" + scale + ") " + vflip_all); // • E N D O F P R E P A R A T O R Y S T U F F • > // ——————————◊——————————— S E E S A W S T U F F ———————————————◊—————— var run = function(tim) { var seesaw_length = 110, seesaw_centre = Math.random() * seesaw_length; var g_seesaw = g0.append("g") .attr("id", "g_seesaw") .attr("transform", "translate(" + (w/2) + " " + ( 1/2 * h) + ")") var seesaw = g_seesaw.append("path") .attr("id", "seesaw") .attr("transform", "rotate(35)") .attr("d", "M " + (-seesaw_centre) + " 0, h " + (seesaw_centre - 2) + "a 2 2,0 0 0,4 0, \ a 2 2,0 1 0,-4 0, m 4 0, h " + (seesaw_length - seesaw_centre - 4) + " 0") .transition() .ease("linear") .duration(tim) .attr("transform", "rotate(-35)") this; } background .on("click", function() {seesaw.remove(); run(1700); this} ); run(6000);