Пример #1
0
func newVehicle(id int, context *httpcanvas.Context) *Vehicle {
	x := rand.Float64() * context.Width
	y := rand.Float64() * context.Height

	v := &Vehicle{*newMover(x, y, context),
		id}
	v.acceleration = noc.RandomPVector(0.75, 1.25)
	v.maxSpeed = 4
	v.maxForce = 0.25
	v.color = "rgba(175, 175, 175, 0.75)"
	return v
}
Пример #2
0
func (self *Mover) Step() {
	self.acceleration = noc.RandomPVector(0.75, 1.25)
	self.velocity.Add(self.acceleration)
	self.velocity.Limit(4)
	self.location.Add(self.velocity)

	if self.location.X > self.context.Width || self.location.X < 0 {
		self.location.X = self.context.Width - self.location.X
		//		self.velocity.X = -self.velocity.X
	}
	if self.location.Y > self.context.Height || self.location.Y < 0 {
		self.location.Y = self.context.Height - self.location.Y
		//		self.velocity.Y = -self.velocity.Y
	}
}