tmpvar / livecad

live coding of 3d surfaces and objects
livecad.wtf
53 stars 2 forks source link

cleanup a 'killed' eval #72

Open tmpvar opened 9 years ago

tmpvar commented 9 years ago

This will probably need to be done in another context. Contenders are iframe or Worker. While both approaches require some hoop jumping, the Worker seems more inline with what we're trying to do.

here's how to duplicate undesired behavior

first populate the textbox with:

var c = cube(10);
var pos = 0;
setInterval(function() {
  display(c, c.translate(pos++, 0, 0))
}, 1000);

then paste over it with:

var request = require('hyperquest')
var baseUrl = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/'
var url = baseUrl + 'all_day.geojson'
request.get(url, function(e, r) {
    r.on('data', function(d) {
    var o = JSON.parse(d);
    var spheres = [];
    var magnifier = 1.0;
    o.features.forEach(function(feature) {
      if (!feature.properties.mag) { return; }

      var coords = feature.geometry.coordinates;
      spheres.push(
        cube(feature.properties.mag * magnifier)
                   .translate(coords[0], coords[1], coords[2])
       );
    });

    display(spheres);
  });
});

results in:

screen shot 2014-11-15 at 10 09 22 am