Created
June 23, 2015 08:22
-
-
Save eikaas/831b466f57a0610fe2c4 to your computer and use it in GitHub Desktop.
Particle Count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type Particle struct { | |
x int | |
y int | |
} | |
type ParticleEmitter struct { | |
x int | |
y int | |
Particles []Particle | |
} | |
func main() { | |
var emitters []ParticleEmitter | |
emitters = append(emitters, ParticleEmitter{x: 1, y: 1}) | |
emitters = append(emitters, ParticleEmitter{x: 2, y: 2}) | |
for _, e := range emitters { | |
e.Particles = append(e.Particles, Particle{x: 32, y: 32}) | |
e.Particles = append(e.Particles, Particle{x: 32, y: 32}) | |
e.Particles = append(e.Particles, Particle{x: 32, y: 32}) | |
} | |
// There should be two emitters with three particles each | |
particle_count := 0 | |
emitter_count := 0 | |
for _, e := range emitters { | |
emitter_count++ | |
for _, p := range e.Particles { | |
fmt.Println(p.x) | |
particle_count++ | |
} | |
} | |
fmt.Println("There are", emitter_count, "emitters and", particle_count, "particles") | |
// Output: There are 2 emitters and 0 particles | |
// Expected outpit: There are 2 emitters and 6 particles | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment