Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created October 23, 2016 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orcaman/54442e1dd1f5bf81f27ebab6fe97911d to your computer and use it in GitHub Desktop.
Save orcaman/54442e1dd1f5bf81f27ebab6fe97911d to your computer and use it in GitHub Desktop.
var concurrencyLevel = flag.Int("c", 20, "concurrency level")
func main() {
flag.Parse()
sem = make(chan bool, *concurrencyLevel)
// ...
// ...
// ...
}
func renderImage() {
for i := 0; i < imHeight; i++ {
for j := 0; j < imWidth; j++ {
plotPixel(complex(float64(i), float64(j)))
currentPixel++
}
}
for i := 0; i < cap(sem); i++ {
sem <- true
}
}
// check if c belongs to set, assign color accordingly and plot
func plotPixel(c complex128) {
sem <- true
switch *coloringMethod {
case "ml":
go func(c complex128) {
res := getColorFromMLMandelbrot(c)
<-sem
plot(res.C, res.Color)
}(c)
case "classic":
go func(c complex128) {
res := getColorFromClassicMandelbrot(c)
<-sem
plot(res.C, res.Color)
}(c)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment