// countdown shows a countdown display to the top of minute func (d *display) countdown() { tick := time.NewTicker(1 * time.Second) ty := d.height / 2 th := d.height / 20 size := d.width / 70 for delay := 60 - time.Now().Second(); delay > 0; delay-- { select { case <-tick.C: tx := d.width * (openvg.VGfloat(60-delay) / 60) openvg.BackgroundColor(d.bgcolor) openvg.FillColor("black") openvg.Rect(0, ty, d.width, th) openvg.FillColor("white") openvg.TextEnd(tx, ty+(th/4), fmt.Sprintf("start in %d ", delay), "sans", int(size)) openvg.Rect(tx, ty, d.width-tx, th) openvg.End() } } openvg.BackgroundColor(d.bgcolor) }
//planets is an exploration of scale func planets(width, height int, message string) { w := float64(width) h := float64(height) y := h / 2 margin := 100.0 minsize := 7.0 labeloc := 100.0 bgcolor := "black" labelcolor := "white" maxsize := (h / 2) * 0.05 origin := sun.distance mostDistant := neptune.distance firstSize := mercury.radius lastSize := neptune.radius openvg.Start(width, height) openvg.BackgroundColor(bgcolor) for _, p := range SolarSystem { x := vmap(p.distance, origin, mostDistant, margin, w-margin) r := vmap(p.radius, firstSize, lastSize, minsize, maxsize) if p.name == "Sun" { openvg.FillRGB(p.color.Red, p.color.Green, p.color.Blue, 1) openvg.Circle(margin-(r/2), y, r) } else { light(x, y, r, p.color) openvg.Circle(x, y, r) if p.name == "Saturn" { ringwidth := r * 2.35 // Saturn's rings are over 2x the planet radius openvg.StrokeWidth(3) openvg.StrokeRGB(p.color.Red, p.color.Green, p.color.Blue, 1) openvg.Line((x - ringwidth/2), y, (x + ringwidth/2), y) openvg.StrokeWidth(0) } } if p.name == "Earth" && len(message) > 1 { openvg.StrokeColor(labelcolor) openvg.StrokeWidth(1) openvg.Line(x, y+(r/2), x, y+labeloc) openvg.StrokeWidth(0) openvg.FillColor(labelcolor) openvg.TextMid(x, y+labeloc+10, message, "sans", 12) } } openvg.End() }
func main() { width, height := openvg.Init() w := openvg.VGfloat(width) h := openvg.VGfloat(height) y := h / 2 var ( margin openvg.VGfloat = 100.0 minsize openvg.VGfloat = 7.0 labeloc openvg.VGfloat = 100.0 ) bgcolor := "black" labelcolor := "white" maxsize := (h / 2) * 0.05 origin := sun.distance mostDistant := neptune.distance firstSize := mercury.radius lastSize := neptune.radius openvg.Start(width, height) openvg.BackgroundColor(bgcolor) for _, p := range solarSystem { x := vmap(p.distance, origin, mostDistant, margin, w-margin) r := vmap(p.radius, firstSize, lastSize, minsize, maxsize) if p.name == "Sun" { openvg.FillRGB(p.color.Red, p.color.Green, p.color.Blue, 1) openvg.Circle(margin-(r/2), y, r) } else { light(x, y, r, p.color) openvg.Circle(x, y, r) } if p.name == "Earth" && len(os.Args) > 1 { openvg.StrokeColor(labelcolor) openvg.StrokeWidth(1) openvg.Line(x, y+(r/2), x, y+labeloc) openvg.StrokeWidth(0) openvg.FillColor(labelcolor) openvg.TextMid(x, y+labeloc+10, os.Args[1], "sans", 12) } } openvg.End() bufio.NewReader(os.Stdin).ReadByte() openvg.Finish() }
func main() { width, height := openvg.Init() // OpenGL, etc initialization w2 := float64(width / 2) h2 := float64(height / 2) w := float64(width) openvg.Start(width, height) // Start the picture openvg.BackgroundColor("black") // Black background openvg.FillRGB(44, 77, 232, 1) // Big blue marble openvg.Circle(w2, 0, w) // The "world" openvg.FillColor("white") // White text openvg.TextMid(w2, h2, "hello, world", "serif", width/10) // Greetings openvg.SaveEnd("hello.raw") // End the picture bufio.NewReader(os.Stdin).ReadBytes('\n') // Pause until [RETURN] openvg.Finish() // Graphics cleanup }
func main() { var loop = flag.Bool("loop", false, "Loop the show") var resize = flag.Bool("resize", false, `Resize image to fit the screen.`) var bgcolor = flag.String("bg", "black", `Background color (named color or rgb(r,g,b)).`) var delay = flag.Duration("delay", 2*time.Second, "Delay between pictures") flag.Usage = func() { fmt.Fprintf(os.Stderr, "usage: %s [ flags ] images...\n", os.Args[0]) flag.PrintDefaults() os.Exit(1) } flag.Parse() w, h := openvg.Init() images := []image.Image{} imgcount := 0 for _, imgfile := range flag.Args() { fmt.Fprintf(os.Stderr, "loading %q ", imgfile) img, err := getimage(imgfile, w, h, *resize) if err != nil { fmt.Fprintln(os.Stderr, err) continue } images = append(images, img) imgcount++ fmt.Fprintln(os.Stderr, "ok") } for { for _, img := range images { ib := img.Bounds() imw, imh := ib.Max.X-ib.Min.X, ib.Max.Y-ib.Min.Y openvg.Start(w, h) openvg.BackgroundColor(*bgcolor) x, y := openvg.VGfloat(w)/2-openvg.VGfloat(imw)/2, openvg.VGfloat(h)/2-openvg.VGfloat(imh)/2 openvg.Img(x, y, img) openvg.End() time.Sleep(*delay) } if !*loop { break } } }
func main() { width, height := openvg.Init() // OpenGL, etc initialization w := openvg.VGfloat(width) h := openvg.VGfloat(height) openvg.Start(width, height) // Start the picture openvg.BackgroundColor("white") // Black background openvg.FillColor("black") var x, y, spacing openvg.VGfloat x = w * 0.10 y = h * 0.90 fontsize := 24 spacing = openvg.VGfloat(fontsize) * 2 var data = []string{ "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f", "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f", "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f", "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f", "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f", "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f", "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f", "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf", "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf", "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf", "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf", "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef", "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", } for i, s := range data { openvg.Text(x-(spacing*2), y, fmt.Sprintf("%2x", i), "mono", fontsize) openvg.Text(x, y, s, "mono", fontsize) y -= spacing } openvg.End() // End the picture bufio.NewReader(os.Stdin).ReadBytes('\n') // Pause until [RETURN] openvg.Finish() // Graphics cleanup }
func imagetable(w, h int) { imgw, imgh := 422, 238 itable := []it{ {"desert0.jpg", imgw, imgh}, {"desert1.jpg", imgw, imgh}, {"desert2.jpg", imgw, imgh}, {"desert3.jpg", imgw, imgh}, {"desert4.jpg", imgw, imgh}, {"desert5.jpg", imgw, imgh}, {"desert6.jpg", imgw, imgh}, {"desert7.jpg", imgw, imgh}, //{"http://farm4.static.flickr.com/3546/3338566612_9c56bfb53e_m.jpg", 240, 164}, //{"http://farm4.static.flickr.com/3642/3337734413_e36baba755_m.jpg", 240, 164}, } offset := openvg.VGfloat(50) left := offset bot := openvg.VGfloat(h-imgh) - offset gutter := offset x := left y := bot openvg.Start(w, h) openvg.BackgroundColor("black") for _, iname := range itable { openvg.Image(x, y, iname.width, iname.height, iname.name) openvg.FillRGB(255, 255, 255, 0.3) openvg.Rect(x, y, openvg.VGfloat(imgw), 32) openvg.FillRGB(0, 0, 0, 1) openvg.TextMid(x+openvg.VGfloat(imgw/2), y+10, iname.name, "sans", 16) x += openvg.VGfloat(iname.width) + gutter if x > openvg.VGfloat(w) { x = left y -= openvg.VGfloat(iname.height) + gutter } } y = openvg.VGfloat(h) * 0.1 openvg.FillRGB(128, 128, 128, 1) openvg.TextMid(openvg.VGfloat(w/2), 100, "Joshua Tree National Park", "sans", 48) openvg.End() }
func main() { width, height := openvg.Init() // OpenGL, etc initialization w2 := float64(width / 2) h2 := float64(height / 2) w := float64(width) stops := []openvg.Offcolor{ {0.0, openvg.RGB{44, 100, 232}, 1.0}, // blue-ish {0.5, openvg.RGB{22, 50, 151}, 1.0}, // darker blue {1.0, openvg.RGB{88, 200, 255}, 1.0}, // lighter blue } openvg.Start(width, height) // Start the picture openvg.BackgroundColor("black") // Black background openvg.FillRadialGradient(w2, 0, w2, w2, w*.5, stops) // Big blue marble openvg.Circle(w2, 0, w) // The "world" openvg.FillColor("white") // White text openvg.TextMid(w2, h2, "hello, world", "serif", width/10) // Greetings openvg.SaveEnd("hvg.raw") // End the picture bufio.NewReader(os.Stdin).ReadBytes('\n') // Pause until [RETURN] openvg.Finish() // Graphics cleanup }
func main() { var nr = flag.Int("n", 500, "number of objects") var message = flag.String("m", "Go/OpenVG", "message") var bgcolor = flag.String("bg", "white", "background color") var fgcolor = flag.String("fg", "maroon", "text color") flag.Parse() rseed() width, height := openvg.Init() fw := openvg.VGfloat(width) fh := openvg.VGfloat(height) openvg.Start(width, height) openvg.BackgroundColor(*bgcolor) for i := 0; i < *nr; i++ { red := uint8(rand.Intn(255)) green := uint8(rand.Intn(255)) blue := uint8(rand.Intn(255)) alpha := randf() x := randf() * fw y := randf() * fh radius := randf() * fw / 10 openvg.FillRGB(red, green, blue, alpha) openvg.Circle(x, y, radius) } openvg.FillColor(*fgcolor) openvg.TextMid(fw/2, fh/2, *message, "sans", width/25) openvg.End() bufio.NewReader(os.Stdin).ReadBytes('\n') openvg.Finish() }
func imagetable(w, h int) { imgw, imgh := 422, 238 itable := []string{ "desert0.jpg", "desert1.jpg", "desert2.jpg", "desert3.jpg", "desert4.jpg", "desert5.jpg", "desert6.jpg", "desert7.jpg", } left := 50.0 bot := float64(h-imgh) - 50.0 gutter := 50.0 x := left y := bot openvg.Start(w, h) openvg.BackgroundColor("black") for _, iname := range itable { openvg.Image(x, y, imgw, imgh, iname) openvg.FillRGB(255, 255, 255, 0.3) openvg.Rect(x, y, float64(imgw), 32) openvg.FillRGB(0, 0, 0, 1) openvg.TextMid(x+float64(imgw/2), y+10, iname, "sans", 16) x += float64(imgw) + gutter if x > float64(w) { x = left y -= float64(imgh) + gutter } } y = float64(h) * 0.1 openvg.FillRGB(128, 128, 128, 1) openvg.TextMid(float64(w/2), 100, "Joshua Tree National Park", "sans", 48) openvg.End() }
func main() { var resize = flag.Bool("resize", false, "Resize image to fit the screen.") var bgcolor = flag.String("bg", "black", "Background color (named color or rgb(r,g,b)).") var fgcolor = flag.String("fg", "white", "text color (named color or rgb(r,g,b)).") var title = flag.String("t", "", "text annotation") var fontsize = flag.Float64("fp", 2.0, "fontsize %") var px = flag.Float64("px", 50, "x position %") var py = flag.Float64("py", 50, "y position %") var texty = flag.Float64("ty", 0, "text y %") var exit_code int defer func() { os.Exit(exit_code) }() flag.Usage = func() { fmt.Fprintf(os.Stderr, `usage: %s [ flags ] image-path Set specified image as an overlay screen via OpenVG lib. Default is to put this image to the center. `, os.Args[0]) flag.PrintDefaults() exit_code = 1 return } flag.Parse() if flag.NArg() != 1 { fmt.Fprintf(os.Stderr, "Exactly one image-path argument must be specified.\n") flag.Usage() exit_code = 2 return } openvg.SaveTerm() w, h := openvg.Init() openvg.RawTerm() defer openvg.Finish() defer openvg.RestoreTerm() img, err := getimage(flag.Args()[0], w, h, *resize) if err != nil { exit_code = 3 return } ib := img.Bounds() imw, imh := ib.Max.X-ib.Min.X, ib.Max.Y-ib.Min.Y sig_chan := make(chan os.Signal, 1) signal.Notify(sig_chan, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGALRM) openvg.Start(w, h) openvg.BackgroundColor(*bgcolor) var x, y openvg.VGfloat if *px < 0 || *px > 100 { x = openvg.VGfloat(w)/2 - openvg.VGfloat(imw)/2 } else { x = openvg.VGfloat(w)*openvg.VGfloat(*px/100) - openvg.VGfloat(imw)/2 } if *py < 0 || *py > 100 { y = openvg.VGfloat(h)/2 - openvg.VGfloat(imh)/2 } else { y = openvg.VGfloat(h)*openvg.VGfloat(*py/100) - openvg.VGfloat(imh)/2 } openvg.Img(x, y, img) if len(*title) > 0 { var typ openvg.VGfloat fs := openvg.VGfloat(*fontsize/100.0) * openvg.VGfloat(w) if *texty == 0 { typ = y - fs*1.5 } else { typ = openvg.VGfloat(h) * openvg.VGfloat(*texty/100) } openvg.FillColor(*fgcolor) openvg.TextMid(x+openvg.VGfloat(imw)/2, typ, *title, "sans", int(fs)) } openvg.End() _ = <-sig_chan }