Skip to content

Instantly share code, notes, and snippets.

@dplesca
Created September 23, 2017 11:48
Show Gist options
  • Save dplesca/bf6542923ecf6a9620688700800b4f90 to your computer and use it in GitHub Desktop.
Save dplesca/bf6542923ecf6a9620688700800b4f90 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"os/exec"
"path/filepath"
"sync"
)
const maxConcurrency = 2
const fileCount = 225
var wg sync.WaitGroup
var throttle = make(chan int, maxConcurrency)
func main() {
index := 1
for index <= fileCount {
filename := fmt.Sprintf("%03d.png", index)
i := filepath.Join("in", filename)
o := filepath.Join("out", filename)
args := []string{
"-in", i,
"-out", o,
"-max=5000",
}
//log.Println(filename, i, o)
throttle <- 1
wg.Add(1)
go generateTriangle(args, throttle, index)
index++
}
wg.Wait()
log.Println("done...")
}
func generateTriangle(args []string, throtte chan int, index int) {
if err := exec.Command("triangle", args...).Run(); err != nil {
//log.Println(args)
log.Fatal(err)
}
log.Printf("generated image %d\n", index)
wg.Done()
<-throttle
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment