aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/sims/test/gui/scenes/CloudScene.scala
blob: 660e3090a54fd4414de30b79c5a0d961db6029ac (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package sims.test.gui
package scenes

import sims.math._
import sims.dynamics._

object CloudScene extends Scene {
	override def description = "A cloud of circles."
		
	val MaxItems = 1000
	val MaxItemSize = 0.2
	val Width = 10
	val Height = 10
	
	val random = new scala.util.Random(1234567890)
	def randomCircles(): Seq[Body] = for (i <- 0 until MaxItems) yield {
		val rX = random.nextDouble * Width
		val rY = random.nextDouble * Height
		val c = new Circle(random.nextDouble * MaxItemSize) {
			position = Vector2D(rX, rY)
		}
		new Body(c) {
			linearVelocity = Vector2D(random.nextDouble * (if (random.nextBoolean) 1 else -1), random.nextDouble * (if (random.nextBoolean) 1 else -1))
			angularVelocity = random.nextDouble * (if (random.nextBoolean) 1 else -1) * 10
		}
	}
	
	def frame() = {
		val points = List(Vector2D(-1, -1), Vector2D(11, -1), Vector2D(11, 11), Vector2D(-1, 11))
		for (i <- 0 until points.length) yield {
			val sp = points(i)
			val ep = points((i + 1) % points.length)
			val center = (sp + ep) / 2
			val r = new Rectangle((center - ep).length, 0.2) {
				position = center
				rotation = math.Pi / 2 * i
			}
			new Body(r) {fixed = true}
		}
	}	
	
	override def init() = {
		world.gravity = Vector2D.Null
		for (r <- randomCircles()) world += r
		//for (r <- frame()) world += r
	}
}