summaryrefslogtreecommitdiff
path: root/src/main/scala/graphyx/tests/Joints2.scala
blob: c190bc96f9dbf1988d94e3fe9be7d99662337cd0 (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
/*
 * Graphyx
 * copyright (c) 2009 Jakob Odersky
 * made available under the MIT License
*/

package graphyx.tests

import sims.dynamics._
import sims.dynamics.joints._
import sims.geometry._
import sims.util._
import sims.util.Positioning._

object Joints2 extends Test{
  override val title = "Joints2"
  val world = new World
  def init() = {
    val length = 100
    val distance = 0.2
    val anchors = for (i <- (0 until length).toList) yield new Body(new Circle(0.03,1) {pos = Vector2D(i * distance,5)}) {fixed = true}
    val balls = for (i <- (0 until length).toList) yield new Body(new Circle(0.1,1) {pos = Vector2D(i * distance,0); restitution = 1})
    balls(0).pos = Vector2D(0, 5) + Polar(5, -math.Pi / 1.5).toCarthesian
    val joints = for (i <- (0 until length).toList) yield new DistanceJoint(anchors(i), balls(i))
    for (a <- anchors) world += a
    for (b <- balls) world += b
    for (j <- joints) world += j
  }
}