Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created October 23, 2016 08:12
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/519f8f9f228d8efc9f69ec6f4ff3cfff to your computer and use it in GitHub Desktop.
Save orcaman/519f8f9f228d8efc9f69ec6f4ff3cfff to your computer and use it in GitHub Desktop.
func main() {
flag.Parse()
log.Printf("coloring method: %s", *coloringMethod)
log.Printf("concurrency level: %d", *concurrencyLevel)
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