Skip to content

Instantly share code, notes, and snippets.

@hunterloftis
Created July 3, 2017 23:48
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 hunterloftis/328f79c6c794d3352a248c37d2032b62 to your computer and use it in GitHub Desktop.
Save hunterloftis/328f79c6c794d3352a248c37d2032b62 to your computer and use it in GitHub Desktop.
// Start starts rendering based on CLI parameters
func (c Cli) Start() {
out := flag.String("out", "render.png", "Output png filename.")
concurrency := flag.Int("frames", runtime.NumCPU(), "Number of frames to combine.")
samples := flag.Float64("samples", math.Inf(1), "Average per pixel samples to take.")
heat := flag.String("heat", "", "Heatmap png filename.")
flag.Parse()
running := make(chan struct{})
ch := make(chan os.Signal, 2)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
go func() { <-ch; close(running) }()
fmt.Printf("Rendering (concurrency: %v, per pixel sample cutoff: %v)\n", *concurrency, *samples)
var results chan []float64
for i := 0; i < *concurrency; i++ {
go c.sampler.Worker(i, running, results) // TODO: instantiate a worker ala https://play.golang.org/p/Sfx1JL_6K2
}
for i := 0; i < *concurrency; i++ {
result := <-results
// TODO: add results to total
}
c.renderer.Write(c.sampler.Values(), *out)
if len(*heat) > 0 {
c.renderer.Write(c.sampler.Counts(), *heat)
}
fmt.Printf("\n -> %v\n", out)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment