github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2013/bestpractices/funcdraw/cmd/funcdraw.go (about) 1 // +build ignore,OMIT 2 3 package main 4 5 import ( 6 "flag" 7 "image/png" 8 "log" 9 "os" 10 ) 11 12 // IMPORT OMIT 13 import ( 14 "golang.org/x/talks/2013/bestpractices/funcdraw/drawer" 15 "golang.org/x/talks/2013/bestpractices/funcdraw/parser" 16 ) 17 18 // ENDIMPORT OMIT 19 20 var ( 21 width = flag.Int("width", 300, "image width") 22 height = flag.Int("height", 300, "image height") 23 xmin = flag.Float64("xmin", -10, "min value for x") 24 xmax = flag.Float64("xmax", 10, "max value for x") 25 ) 26 27 func main() { 28 flag.Parse() 29 if flag.NArg() != 1 { 30 log.Fatal("missing expression to parse") 31 } 32 33 text := flag.Arg(0) 34 // START OMIT 35 // Parse the text into an executable function. 36 f, err := parser.Parse(text) 37 if err != nil { 38 log.Fatalf("parse %q: %v", text, err) 39 } 40 41 // Create an image plotting the function. 42 m := drawer.Draw(f, *width, *height, *xmin, *xmax) 43 44 // Encode the image into the standard output. 45 err = png.Encode(os.Stdout, m) 46 if err != nil { 47 log.Fatalf("encode image: %v", err) 48 } 49 // END OMIT 50 }