-
-
Save orcaman/54442e1dd1f5bf81f27ebab6fe97911d to your computer and use it in GitHub Desktop.
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
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