$(function(){
var r0 = 50, width = 600, height = 300,
data = [
{
radius: r0,
color: 0
},
{
radius: r0/2,
color: 0
},
{
radius: r0/2,
color: 0
}
,
{
radius: r0/2,
color: 0
},
{
radius: r0/2,
color: 0
},
{
radius: r0/2,
color: 0
},
{
radius: r0/2,
color: 0
}
,
{
radius: r0/2,
color: 0
},
{
radius: r0/2,
color: 0
}
].map(function(d, i){
return Object.defineProperties(d,
{
v: {
get: function v() {
return {
x: (Math.random() - 0.5) * r0 * 2,
y: (Math.random() - 0.5) * r0 * 2
}
}
},
s: {
get: function s() {
var v = this.v;
return Math.sqrt(v.x * v.x + v.y * v.y)
}
},
x: {
value: width / 2 * (Math.random() + 0.5),
writable: true
},
y: {
value: height / 2 * (Math.random() + 0.5),
writable: true
}
,
i: {
value: i,
writable: true
}
})
}),
$container = $("
").appendTo("body").attr("id", "viz"),
sceneGL = $container.webGL().appendChild("scene")
.attr({"id": "scene", "width": width, "height": height })
.webGL(),
$circles = sceneGL
.bind(data, "sprite")
.attr({opacity: 0.8, anchor: 0.5}),
$lines = sceneGL
.bind(data, "line")
.attr({
"stroke": "red",
"stroke-width": function(d, i, val){return 12 * d.radius/r0;},
"stroke-linecap": "round",
opacity: 0.5
}),
//renderer = Renderer$($container).shadow("distance", r0);
renderer = $container.webGL().Renderer().shadow("distance", r0);
renderer.sprites.init(r0);
renderer.sprites.enter($circles).merge($circles);
renderer.graphics.enter($lines).merge($lines);
function update() {
renderer.draw();
window.requestAnimationFrame(update)
}
update();
});
!(function($){
function Renderer$($container) {
var $view = $("