Esempio n. 1
0
// imgtest draws images at the corners and center
func imagetest(w, h int) {
	openvg.Start(w, h)
	imgw := 422
	imgh := 238
	fiw := float64(imgw)
	fih := float64(imgh)
	fw := float64(w)
	fh := float64(h)
	cx := (fw / 2) - (fiw / 2)
	cy := (fh / 2) - (fih / 2)
	ulx := 0.0
	uly := fh - fih
	urx := fw - fiw
	ury := uly
	llx := 0.0
	lly := 0.0
	lrx := urx
	lry := lly
	openvg.Start(w, h)
	openvg.Background(0, 0, 0)
	openvg.Image(cx, cy, imgw, imgh, "desert1.jpg")
	openvg.Image(ulx, uly, imgw, imgh, "desert2.jpg")
	openvg.Image(urx, ury, imgw, imgh, "desert3.jpg")
	openvg.Image(llx, lly, imgw, imgh, "desert4.jpg")
	openvg.Image(lrx, lry, imgw, imgh, "desert5.jpg")
	openvg.End()
}
Esempio n. 2
0
// hackernews shows the top n articles from Hackernews
func (d *display) hackernews(n int) {
	hdim := dimen{x: 0, y: 0, width: d.width, height: d.height / 2}
	r, err := netread(HNTopURL)
	if err != nil {
		fmt.Fprintf(os.Stderr, "headline read error: %v\n", err)
		hdim.gerror(d.bgcolor, d.textcolor, "no headlines")
		return
	}
	var hnid HNTop
	err = json.NewDecoder(r).Decode(&hnid)
	if err != nil {
		fmt.Fprintf(os.Stderr, "decode: %v\n", err)
		hdim.gerror(d.bgcolor, d.textcolor, "no headlines")
		r.Close()
		return
	}
	r.Close()

	var item HNitem
	x := d.width / 2
	y := d.height * 0.10
	headsize := d.width / 80
	spacing := headsize * 2.0
	hdim.regionFill(d.bgcolor, d.textcolor)
	for i := n - 1; i >= 0; i-- {
		hnr, err := netread(fmt.Sprintf(HNItemfmt, hnid[i]))
		if err != nil {
			fmt.Fprintf(os.Stderr, "%v: getting id %d\n", err, hnid[i])
			hnr.Close()
			continue
		}
		err = json.NewDecoder(hnr).Decode(&item)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%v: decoding id %d\n", err, hnid[i])
			hnr.Close()
			continue
		}
		openvg.TextMid(x, y, item.Title, "serif", int(headsize))
		y += spacing
		hnr.Close()
	}
	openvg.Image(d.width*0.05, 15, 32, 32, "hn.png")
	openvg.End()
}
Esempio n. 3
0
// advert is an ad for the package
func advert(w, h int) {
	y := (6 * float64(h)) / 10
	fontsize := (w * 4) / 100
	f3 := fontsize / 3
	s := "github.com/ajstarks/openvg"
	a := "*****@*****.**"

	imw := 110
	imh := 110
	midx := float64(w / 2)

	openvg.Start(w, h)
	openvg.FillRGB(128, 0, 0, 1)
	openvg.TextMid(midx, y-float64(fontsize/4), s, "sans", fontsize)
	y -= 150
	openvg.FillRGB(128, 128, 128, 1)
	openvg.TextMid(midx, y, a, "sans", f3)
	openvg.Image(float64(w/2)-float64(imw/2), y-float64(imh*2), imw, imh, "starx.jpg")
	openvg.End()
}
Esempio n. 4
0
// nytheadlines retrieves data from the New York Times API, decodes and displays it.
func (d *display) nytheadlines(section string, thumb bool) {
	hdim := dimen{x: 0, y: 0, width: d.width, height: d.height / 2}
	r, err := netread(fmt.Sprintf(NYTfmt, section, NYTAPIkey))
	if err != nil {
		fmt.Fprintf(os.Stderr, "headline read error: %v\n", err)
		hdim.gerror(d.bgcolor, d.textcolor, "no headlines")
		return
	}
	defer r.Close()
	var data NYTHeadlines
	err = json.NewDecoder(r).Decode(&data)
	if err != nil {
		fmt.Fprintf(os.Stderr, "decode: %v\n", err)
		hdim.gerror(d.bgcolor, d.textcolor, "no headlines")
		return
	}
	x := d.width * 0.10
	y := d.height * 0.10
	thumbsize := int(d.height * 0.05)
	hdim.regionFill(d.bgcolor, d.textcolor)
	headsize := d.width / 80
	spacing := openvg.VGfloat(thumbsize)
	for i := len(data.Results) - 1; i >= 0; i-- {
		openvg.Text(x, y, fromHTML.Replace(data.Results[i].Title), "serif", int(headsize))
		if len(data.Results[i].Thumbnail) > 0 {
			img, imerr := netimage(data.Results[i].Thumbnail)
			if imerr != nil {
				continue
			}
			g := gift.New()
			g.Add(gift.Resize(0, thumbsize, gift.LanczosResampling))
			gift.Resize(thumbsize, thumbsize, gift.BoxResampling)
			resized := image.NewRGBA(g.Bounds(img.Bounds()))
			g.Draw(resized, img)
			openvg.Img(x-100, y-(spacing*0.25), resized)
		}
		y = y + spacing
	}
	openvg.Image(d.width*0.05, 15, 30, 30, "poweredby_nytimes_30a.png")
	openvg.End()
}
Esempio n. 5
0
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()
}
Esempio n. 6
0
// advert is an ad for the package
func advert(w, h int) {
	y := float64(h) / 4
	fontsize := (w * 4) / 100
	f3 := fontsize / 3
	s := "github.com/ajstarks/openvg"
	a := "*****@*****.**"

	imw := 110
	imh := 110
	rw := float64(w / 4)
	rh := (rw * 2) / 3
	midx := float64(w / 2)

	openvg.Start(w, h)
	makepi(midx-float64(rw/2), float64(h/2), rw, rh)
	openvg.FillRGB(128, 0, 0, 1)
	openvg.TextMid(midx, y-float64(fontsize/4), s, "sans", fontsize)
	y -= 100
	openvg.FillRGB(128, 128, 128, 1)
	openvg.TextMid(midx, y, a, "sans", f3)
	openvg.Image(float64(w/2)-float64(imw/2), 20, imw, imh, "starx.jpg")
	openvg.End()
}
Esempio n. 7
0
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()
}
Esempio n. 8
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stdout,
			`usage: %s [ opts ] 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()
	}

	var resize bool
	var bg_color string
	flag.BoolVar(&resize, "resize", false, `Resize image to fit the screen (using "convert" binary.`)
	flag.StringVar(&bg_color, "bg-color", "",
		`Background color to use with centered image, in RRGGBB (hex, e.g. "aabbcc") format.`)

	flag.Parse()
	if flag.NArg() != 1 {
		log.Print("ERROR: Exactly one image-path argument must be specified.")
		flag.Usage()
	}
	var r, g, b uint8
	var err error
	if len(bg_color) == 0 {
		r, g, b = 0, 0, 0
	} else if len(bg_color) == 6 {
		n, err := strconv.ParseUint(bg_color[:2], 16, 8)
		if err == nil {
			r = uint8(n)
			n, err = strconv.ParseUint(bg_color[2:4], 16, 8)
		}
		if err == nil {
			g = uint8(n)
			n, err = strconv.ParseUint(bg_color[4:6], 16, 8)
		}
		if err == nil {
			b = uint8(n)
		}
	}
	if err != nil {
		log.Fatalf("ERROR: Failed to parse bg-color value (%v): %v", bg_color, err)
	}
	image_path := flag.Args()[0]

	exit_code := 0
	defer func() {
		os.Exit(exit_code)
	}()

	openvg.SaveTerm()
	w, h := openvg.Init()
	openvg.RawTerm()
	defer openvg.Finish()
	defer openvg.RestoreTerm()

	image_conf, err := get_image_conf(image_path)
	if err == nil && resize && (image_conf.Width != w || image_conf.Height != h) {
		image_path, err = resize_image(w, h, image_path)
	}
	if err != nil {
		log.Printf("ERROR: Failed to process image (%v): %v", image_path, err)
		exit_code = 1
	} else {
		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.Background(r, g, b)
		if resize {
			openvg.Image(0, 0, w, h, image_path)
		} else {
			x, y := openvg.VGfloat(w)/2-openvg.VGfloat(image_conf.Width)/2,
				openvg.VGfloat(h)/2-openvg.VGfloat(image_conf.Height)/2
			openvg.Image(x, y, image_conf.Width, image_conf.Height, image_path)
		}
		openvg.End()

		_ = <-sig_chan
	}
}
Esempio n. 9
0
// refcard shows a reference card of shapes
func refcard(width, height int) {
	shapenames := []string{
		"Circle",
		"Ellipse",
		"Rectangle",
		"Rounded Rectangle",
		"Line",
		"Polyline",
		"Polygon",
		"Arc",
		"Quadratic Bezier",
		"Cubic Bezier",
		"Image",
	}
	top := float64(height) * .95
	sx := float64(width) * 0.10
	sy := top
	sw := float64(width) * .05
	sh := float64(height) * .045
	dotsize := 7.0
	spacing := 2.0
	fontsize := int(float64(height) * .033)
	shapecolor := Color{202, 225, 255, 1.0}

	openvg.Start(width, height)
	openvg.FillRGB(128, 0, 0, 1)
	openvg.TextEnd(float64(width-20), float64(height/2),
		"OpenVG on the Raspberry Pi", "sans", fontsize+(fontsize/2))
	openvg.FillRGB(0, 0, 0, 1)
	for _, s := range shapenames {
		openvg.Text(sx+sw+sw/2, sy, s, "sans", fontsize)
		sy -= sh * spacing
	}
	sy = top
	cx := sx + (sw / 2)
	ex := sx + sw
	openvg.FillRGB(shapecolor.red, shapecolor.green, shapecolor.blue, shapecolor.alpha)
	openvg.Circle(cx, sy, sw)
	coordpoint(cx, sy, dotsize, shapecolor)
	sy -= sh * spacing
	openvg.Ellipse(cx, sy, sw, sh)
	coordpoint(cx, sy, dotsize, shapecolor)
	sy -= sh * spacing
	openvg.Rect(sx, sy, sw, sh)
	coordpoint(sx, sy, dotsize, shapecolor)
	sy -= sh * spacing
	openvg.Roundrect(sx, sy, sw, sh, 20, 20)
	coordpoint(sx, sy, dotsize, shapecolor)
	sy -= sh * spacing

	openvg.StrokeWidth(1)
	openvg.StrokeRGB(204, 204, 204, 1)
	openvg.Line(sx, sy, ex, sy)
	coordpoint(sx, sy, dotsize, shapecolor)
	coordpoint(ex, sy, dotsize, shapecolor)
	sy -= sh

	px := []float64{sx, sx + (sw / 4), sx + (sw / 2), sx + ((sw * 3) / 4), sx + sw}
	py := []float64{sy, sy - sh, sy, sy - sh, sy}

	openvg.Polyline(px, py) // , 5)
	coordpoint(px[0], py[0], dotsize, shapecolor)
	coordpoint(px[1], py[1], dotsize, shapecolor)
	coordpoint(px[2], py[2], dotsize, shapecolor)
	coordpoint(px[3], py[3], dotsize, shapecolor)
	coordpoint(px[4], py[4], dotsize, shapecolor)
	sy -= sh * spacing

	py[0] = sy
	py[1] = sy - sh
	py[2] = sy - (sh / 2)
	py[3] = py[1] - (sh / 4)
	py[4] = sy
	openvg.Polygon(px, py) // , 5)
	sy -= (sh * spacing) + sh

	openvg.Arc(sx+(sw/2), sy, sw, sh, 0, 180)
	coordpoint(sx+(sw/2), sy, dotsize, shapecolor)
	sy -= sh * spacing

	var cy, ey float64
	cy = sy + (sh / 2)
	ey = sy
	openvg.Qbezier(sx, sy, cx, cy, ex, ey)
	coordpoint(sx, sy, dotsize, shapecolor)
	coordpoint(cx, cy, dotsize, shapecolor)
	coordpoint(ex, ey, dotsize, shapecolor)
	sy -= sh * spacing

	ey = sy
	cy = sy + sh
	openvg.Cbezier(sx, sy, cx, cy, cx, sy, ex, ey)
	coordpoint(sx, sy, dotsize, shapecolor)
	coordpoint(cx, cy, dotsize, shapecolor)
	coordpoint(cx, sy, dotsize, shapecolor)
	coordpoint(ex, ey, dotsize, shapecolor)

	sy -= (sh * spacing * 1.5)
	openvg.Image(sx, sy, 110, 110, "starx.jpg")

	openvg.End()
}