Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <meta charset="utf-8">
  3. <body>
  4. <script src="d3.min.js"></script>
  5. <script>
  6.  
  7.  
  8.  
  9.  
  10. var lines = [
  11. {"x1": 20, "y1": 0, "x2": 20, "y2":20, "stroke": "blue", "stroke-width": 6},
  12. {"x1": 20, "y1": 5, "x2":15, "y2": 10, "stroke": "blue", "stroke-width": 6},
  13. {"x1": 20, "y1": 5, "x2":25, "y2": 10, "stroke": "blue", "stroke-width": 6}];
  14.  
  15.  
  16. var svg = d3.select("body").append("svg")
  17. .attr("width", 1000)
  18. .attr("height", 1000);
  19.  
  20. var airplane = svg.selectAll("line")
  21. .data(lines)
  22. .enter().append("line");
  23.  
  24.  
  25. var airplaneAttr = airplane
  26. .attr("x1", function (d) { return d.x1; })
  27. .attr("y1", function (d) { return d.y1; })
  28. .attr("x2", function (d) { return d.x2; })
  29. .attr("y2", function (d) { return d.y2; })
  30. .attr("stroke-width", 2 )
  31. .attr("stroke" , "blue" );
  32.  
  33.  
  34.  
  35.  
  36. function moveAirplane(){
  37. for(i=0; i<30; i++){
  38. var x = Math.random()*1000;
  39. var y = Math.random()*1000;
  40. airplane
  41. .attr("x1", function (d) { return d.x1 +x; })
  42. .attr("y1", function (d) { return d.y1 +y; })
  43. .attr("x2", function (d) { return d.x2 +x; })
  44. .attr("y2", function (d) { return d.y2 +y; });
  45. }
  46. }
  47.  
  48. var nodes = d3.range(20).map(moveAirplane());
  49.  
  50.  
  51.  
  52. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement