Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


  <button id=generate>Generate</button>
  <label>&alpha;: <input type=range id=alpha min=0 max=1 step=0.01 value=0.15></label>
  <label>&beta;: <input type=range id=beta min=0 max=1 step=0.01 value=0.2></label>
  <label>N: <input type=range id=n min=10 max=100 step=1 value=40></label>
<div><svg id=topology>
  <g id=edges></g>
  <g id=nodes></g>


  stroke: #aaa


                $ = document~get-element-by-id

width = 500; height = 500

function uniform a, b
  Math.random! * (b - a) + a

function distance {x: x1, y: y1}, {x: x2, y: y2}
  (x2 - x1)**2 + (y2 - y1)**2 |> Math.sqrt

# generate random node locations
var nodes  
gen-nodes = !->
  num-nodes = $ \n .value |> parseInt _, 10
  nodes := for i til num-nodes
    x: uniform 0 width
    y: uniform 0 width
# create random topo, waxman model
# TODO unsure how the random model is
# supposed to create connected topologies
# I guess that once the nodes are randomly
# connected, the nodes that are isolated
# connect to their nearest neighbor...
!function generate
  alpha = $ \alpha .value |> parseFloat
  beta = $ \beta .value |> parseFloat
  # max possible distance across diagonal
  max-dist = Math.sqrt width**2 + height**2

  # for all node pairs
  edges = []
  for n1, i in nodes
    for n2 in nodes.slice i + 1
      d = distance n1, n2
      # waxman probability model of edge
      probability = beta * Math.exp -d / (alpha * max-dist)
      if Math.random! < probability
        edges.push [[n1.x, n1.y], [n2.x, n2.y]]

  # draw topology \#topology
    ..attr {width, height} \#edges .select-all \.edge .data edges 
      ..enter!append \path
      ..attr do
        class: \edge
        d: d3.svg.line! \#nodes .select-all \.node .data nodes 
      ..enter!append \circle 
      ..attr do
        class: \node
        cx: (.x)
        cy: (.y)
        r: 5
$ \generate
  .add-event-listener \click generate
for <[alpha beta]>
  $ .. .add-event-listener \input generate
$ \n .add-event-listener \input gen-nodes >> generate