Smalltalk: Twirl Them Particles

Listing 3. Class Leader.


class:				Leader
superclass:			Object 
instance variables:	frame rotation bottle particles 
					maximumParticleSpeed

class methods

instance creation
new
	^super new initialize

instance methods

initializing
shape: aSymbol
	bottle shape: aSymbol.
	self reset

numberOfParticles: anInteger
	particles := (1 to: anInteger) collect: [:index |
		Particle new]

maximumParticleSpeed: aNumber
	maximumParticleSpeed := aNumber
  
initialize
	bottle := Bottle new shape: #sphere.

actions
reset
		frame := Transformation4D identity.
		rotation := Point3D x: 0.0 y: 0.0 z: 0.0. 
		particles do: [:particle |
			particle reset: maximumParticleSpeed]

tick
		rotation := rotation + (Point3D x: 0.0 y: 0.0 z: 5.0).
		particles do: [:particle |
			particle tick: bottle]

drawing
drawOn: aViewScreen
	aViewScreen push;
			multiply: frame;
			rotateBy: rotation.
			particles do: [:particle |
				particle drawUsing: aViewScreen].
	aViewScreen pop

About the Author

Wilf LaLonde is director of Learning Dimensions, Inc., a company focused on 3D gaming development.