summaryrefslogtreecommitdiff
path: root/src/graphyx/tests/Spring.scala
blob: 4eec8dec44145586e7b3bc4ccf7d5945e7ad6f5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package graphyx.tests

import sims.dynamics._
import sims.dynamics.joints._
import sims.geometry._
import java.io._

object Spring extends Test{
  val title = "Spring"
  val fout = new java.io.FileOutputStream("out.csv")
  val sout = new java.io.PrintStream(fout)
  val world = new World {
    override def postStep = {
      //for (b <- bodies; if (b.monitor)) sout.println(monitors(0)._2(b))
    }
  }
  
  def init = {
    val anchor = Circle(0.05, 10).asBody
    anchor.fixed = true
    val particle = (new Circle(0.1, 10) {pos = Vector2D(0, -1)}).asBody
    val spring = new SpringJoint(anchor, particle, 500, 0.6)
    //val spring = new PrismaticJoint(anchor, particle)
    spring.damping = 1
    particle.monitor = true
    world.monitors += ("", _.pos.y.toString)
    
    world += anchor
    world += particle
    world += spring
  }
}