   #controls.addEventListener 'change', render
 
   curves = new FlyingCurves
-    
-  mesh = curves.group
-  scene.add mesh
+
+  lines = new THREE.Object3D
+  lines.add curves.group
+  scene.add lines
   
   #
   renderer = new THREE.WebGLRenderer(antialias: false)

    @setDirty()

class FlyingCurves
  constructor: ->

    pattern = parseRle "$3b2o$2bobob2o$2bo5bo$7b2o$b2o$bo5bo$2b2obobo$5b2oo"
    simulator = new Simulator 32, 32 #field size
    simulator.put pattern, 12, 12 #pattern roughly at the center
    
    order = 3
    interpSteps = 3
    smoothing = 12
    @isim = new CircularInterpolatingSimulator simulator, order, interpSteps, smoothing

    #Create geometry
    @segments = 500
    @scale = 30
    state = @isim.getInterpolatedState()
    z0 = -1400
    z1 = 400
    @group = new THREE.Object3D
    @lines = for i in [0...state.length] by 2
      line = new FlowingLine @segments, palette[ (i/2) % palette.length ]
      line.initial (state[i]-16)*@scale, (state[i+1]-16)*@scale, z0, z1
      @group.add line.mesh
      line
    console.log "Created #{@lines.length} lines"
  step: ->
    @isim.nextTime 1
    state = @isim.getInterpolatedState()
    for line, i in @lines
      i2 = i*2
      line.flow (state[i2]-16)*@scale, (state[i2+1]-16)*@scale
      #if i is 0
      #  console.log "Point 0: #{state[i2]}, #{state[i2+1]}"
    return
      
curves = undefined    

      ps[i3+1] = ps[i3+4]
    i3 = (@segments-1)*3
    delta = Math.abs(ps[i3]-x) + Math.abs(ps[i3+1]-y)
    if delta > 4
      ps[i3-3]=NaN
      ps[i3-2]=NaN
    ps[i3]   =x
