コード例 #1
0
ファイル: shapedemo.go プロジェクト: Ebiroll/openvg
// imgtest draws images at the corners and center
func imagetest(w, h int) {
	openvg.Start(w, h)
	imgw := 422
	imgh := 238
	fiw := openvg.VGfloat(imgw)
	fih := openvg.VGfloat(imgh)
	fw := openvg.VGfloat(w)
	fh := openvg.VGfloat(h)
	vgzero := openvg.VGfloat(0.0)
	cx := (fw / 2) - (fiw / 2)
	cy := (fh / 2) - (fih / 2)
	ulx := vgzero
	uly := fh - fih
	urx := fw - fiw
	ury := uly
	llx := vgzero
	lly := vgzero
	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()
}
コード例 #2
0
ファイル: shapedemo.go プロジェクト: Ebiroll/openvg
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()
}
コード例 #3
0
ファイル: shapedemo.go プロジェクト: Ebiroll/openvg
// advert is an ad for the package
func advert(w, h int) {
	y := openvg.VGfloat(h) / 4
	fontsize := (w * 4) / 100
	f3 := fontsize / 3
	s := "github.com/ajstarks/openvg"
	a := "*****@*****.**"

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

	openvg.Start(w, h)
	makepi(midx-openvg.VGfloat(rw/2), openvg.VGfloat(h/2), rw, rh)
	openvg.FillRGB(128, 0, 0, 1)
	openvg.TextMid(midx, y-openvg.VGfloat(fontsize/4), s, "sans", fontsize)
	y -= 100
	openvg.FillRGB(128, 128, 128, 1)
	openvg.TextMid(midx, y, a, "sans", f3)
	openvg.Image(openvg.VGfloat(w/2)-openvg.VGfloat(imw/2), 20, imw, imh, "starx.jpg")
	openvg.End()
}
コード例 #4
0
ファイル: sl.go プロジェクト: Ebiroll/openvg
func main() {
	var sreenHeight, cx, cy, cw, ch, midy int
	message := "Scrolling texts could be useful if the information does not fit on screen"

	w, h := openvg.Init()
	sreenHeight = h
	var speed openvg.VGfloat = 0.5
	var x openvg.VGfloat = 0
	midy = (h / 2)
	fontsize := w / 50
	cx = 0
	ch = fontsize * 2
	cw = w
	cy = midy - (ch / 2)
	var jsonData SLData

	for {
		response, err := http.Get("http://localhost:8000")

		if err == nil {
			defer response.Body.Close()
			contents, err := ioutil.ReadAll(response.Body)
			if err != nil {
				fmt.Printf("Error reading http data, %s", err)
			} else {
				fmt.Printf("Got: %s\n", string(contents))
				if err := json.Unmarshal(contents, &jsonData); err != nil {
					panic(err)
				}
				fmt.Println(jsonData)
			}
		}

		openvg.Start(w, h)
		imgw, imgh := 0, 0
		openvg.Background(255, 255, 255)

		//SLHeight = 60
		var imgPosY = openvg.VGfloat(sreenHeight - 70)
		openvg.Image(4, imgPosY, imgw, imgh, "SL.jpg")

		var TAB1 = openvg.VGfloat(4 * w / 20)
		var TAB2 = openvg.VGfloat(8 * w / 20)

		rx1, rw1, rh1 := openvg.VGfloat(cx), openvg.VGfloat(cw), openvg.VGfloat(ch)
		ty := 0
		rix := 0

		// Buses
		for ty = sreenHeight - (80 + int(rh1)); ty > 0 && rix < len(jsonData.ResponseData.Buses); ty -= ch {
			tempy := openvg.VGfloat(ty)
			//ry := openvg.VGfloat(ty)
			if rix%2 == 0 {
				openvg.FillRGB(0, 0, 0, .2)
				//openvg.Rect(rx1, tempy, rw1, rh1)
				openvg.FillRGB(0, 0, 0, 1)
				tempy = tempy + 6.0
			} else {
				openvg.FillRGB(0, 0, 0, .4)
				openvg.Rect(rx1, tempy, rw1, rh1)
				tempy = tempy + 6.0
				openvg.FillRGB(0, 0, 0, 1)
			}
			openvg.Text(rx1, tempy, jsonData.ResponseData.Buses[rix].LineNumber, "sans", fontsize)
			drawTypeOfTransport(rx1+60, tempy+2, rw1, ch-20, jsonData.ResponseData.Buses[rix].TransportMode)

			openvg.Text(rx1+100, tempy, jsonData.ResponseData.Buses[rix].StopPointDesignation, "sans", fontsize)
			openvg.Text(rx1+TAB1, tempy, jsonData.ResponseData.Buses[rix].DisplayTime, "sans", fontsize)
			var dest = jsonData.ResponseData.Buses[rix].Destination
			dest = replaceAO(dest)
			openvg.Text(rx1+TAB2, tempy, dest, "sans", fontsize)

			//openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
			//openvg.Background(255,255,0)
			rix = rix + 1
		}
		var trainIx = 0
		for ty = ty - 20; ty > 0 && trainIx < len(jsonData.ResponseData.Trains); ty -= ch {
			tempy := openvg.VGfloat(ty)
			//ry := openvg.VGfloat(ty)
			if rix%2 == 0 {
				openvg.FillRGB(0, 0, 0, .2)
				//openvg.Rect(rx1, tempy, rw1, rh1)
				openvg.FillRGB(0, 0, 0, 1)
				tempy = tempy + 6.0
			} else {
				openvg.FillRGB(0, 0, 0, .4)
				openvg.Rect(rx1, tempy, rw1, rh1)
				tempy = tempy + 6.0
				openvg.FillRGB(0, 0, 0, 1)
			}
			openvg.Text(rx1, tempy, jsonData.ResponseData.Trains[trainIx].LineNumber, "sans", fontsize)
			drawTypeOfTransport(rx1+55, tempy+4, rw1, ch-20, jsonData.ResponseData.Trains[trainIx].TransportMode)
			openvg.Text(rx1+TAB1, tempy, jsonData.ResponseData.Trains[trainIx].DisplayTime, "sans", fontsize)
			var dest = jsonData.ResponseData.Trains[trainIx].Destination
			dest = replaceAO(dest)
			openvg.Text(rx1+TAB2, tempy, dest, "sans", fontsize)

			//openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
			//openvg.Background(255,255,0)
			trainIx = trainIx + 1
			rix = rix + 1
		}

		//openvg.End()
		openvg.SaveEnd("dump.raw")

		time.Sleep(60 * time.Second)
	}

	bufio.NewReader(os.Stdin).ReadBytes('\n')

	rx, ry, rw, rh := openvg.VGfloat(cx), openvg.VGfloat(cy), openvg.VGfloat(cw), openvg.VGfloat(ch)
	// scroll the text, only in the clipping rectangle
	for x = 0; x < rw+speed; x += speed {
		openvg.Start(w, h)
		openvg.Background(255, 255, 255)
		openvg.FillRGB(0, 0, 0, .2)
		openvg.Rect(rx, ry, rw, rh)
		openvg.ClipRect(cx, cy, cw, ch)
		openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
		openvg.FillRGB(0, 0, 0, 1)
		openvg.Text(0, 0, message, "sans", fontsize)
		openvg.ClipEnd()
		openvg.End()
	}
	bufio.NewReader(os.Stdin).ReadBytes('\n')
	openvg.Finish()
	os.Exit(0)
}
コード例 #5
0
ファイル: viwer.go プロジェクト: Ebiroll/openvg
func main() {
	var sreenHeight, cx, cy, cw, ch int
	message := "Hej Sandra tack forden mysiga kramen ..... <3 <3 Puss puss"
	w, h := openvg.Init()
	sreenHeight = h
	var speed openvg.VGfloat = 4.0
	var x openvg.VGfloat = 0
	//midy = (h / 2)
	fontsize := w / 50
	cx = 0
	ch = fontsize * 2
	cw = w
	//cy = midy - (ch / 2)
	cy = h - 80
	var jsonData SLData
	var lastmill = makeTimestamp()

	response, err := http.Get("http://localhost:8000")

	if err == nil {
		defer response.Body.Close()
		contents, err := ioutil.ReadAll(response.Body)
		if err != nil {
			fmt.Printf("Error reading http data, %s", err)
		} else {
			fmt.Printf("Got: %s\n", string(contents))
			if err := json.Unmarshal(contents, &jsonData); err != nil {
				panic(err)
			}
			fmt.Println(jsonData)
		}
	}

	openvg.Start(w, h)
	openvg.End()
	go PlayVideo(w, h)

	for {

		openvg.Start(w, h)
		//fmt.Println("W,H",w,h)

		rx, ry, rw, rh := openvg.VGfloat(cx), openvg.VGfloat(cy), openvg.VGfloat(cw), openvg.VGfloat(ch)
		// scroll the text, only in the clipping rectangle

		for x = 0; x < rw+speed; x += speed {

			var mill = makeTimestamp()
			var delta = (mill - lastmill) / 5
			//fmt.Println("delta ", delta)
			//speed

			x = openvg.VGfloat(delta)

			imgw, imgh := 0, 0
			openvg.Background(0, 0, 0)

			//SLHeight = 60
			var imgPosY = openvg.VGfloat(sreenHeight - 120)
			openvg.Image(8, imgPosY, imgw, imgh, "DA4FID.png")

			var TAB1 = openvg.VGfloat(4 * w / 20)
			//var TAB2 = openvg.VGfloat(8*w/20)

			rx1, rw1, rh1 := openvg.VGfloat(cx), openvg.VGfloat(cw), openvg.VGfloat(ch)
			ty := 0
			rix := 0

			// - (120 + int(rh1))
			ty = sreenHeight - 140

			var trainIx = 0
			for ty = ty - 20; ty > 0 && trainIx < len(jsonData.ResponseData.Trains); ty -= ch {
				tempy := openvg.VGfloat(ty)
				//ry := openvg.VGfloat(ty)
				if rix%2 == 0 {
					openvg.FillRGB(255, 255, 255, .2)
					//openvg.Rect(rx1, tempy, rw1, rh1)
					tempy = tempy + 6.0
				} else {
					openvg.FillRGB(255, 255, 255, .4)
					openvg.Rect(rx1, tempy, rw1/3, rh1)
					tempy = tempy + 6.0
				}
				openvg.FillRGB(255, 255, 255, 1)
				//openvg.Text(rx1, tempy, jsonData.ResponseData.Trains[trainIx].LineNumber , "sans", fontsize)
				//drawTypeOfTransport(rx1+55,tempy+4,rw1,ch-20,jsonData.ResponseData.Trains[trainIx].TransportMode)
				openvg.Text(rx1, tempy, jsonData.ResponseData.Trains[trainIx].DisplayTime, "sans", fontsize)
				var dest = jsonData.ResponseData.Trains[trainIx].Destination
				dest = replaceAO(dest)
				openvg.Text(rx1+TAB1, tempy, dest, "sans", fontsize)

				//openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
				//openvg.Background(255,255,0)
				trainIx = trainIx + 1
				rix = rix + 1
			}

			imgw = 20
			imgh = 20

			//openvg.Image(8, 100 , imgw, imgh, "no_smoking.png")

			// openvg.Start(w, h)
			//openvg.Background(255, 255, 255)
			openvg.FillRGB(100, 0, 0, 1)
			openvg.Rect(rx, ry, rw, rh)
			//openvg.ClipRect(cx, cy, cw, ch)
			//openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
			openvg.FillRGB(255, 255, 255, 1)
			var pxp openvg.VGfloat = openvg.VGfloat(w) - openvg.VGfloat(x)
			var pyp openvg.VGfloat = openvg.VGfloat(h) - openvg.VGfloat(58)
			openvg.Text(pxp, pyp, message, "sans", fontsize)
			//openvg.ClipEnd()
			openvg.End()
		}

		//openvg.SaveEnd("dump.raw")

		//time.Sleep(60*time.Second);
	}

	bufio.NewReader(os.Stdin).ReadBytes('\n')

	bufio.NewReader(os.Stdin).ReadBytes('\n')
	openvg.Finish()
	os.Exit(0)
}
コード例 #6
0
ファイル: shapedemo.go プロジェクト: Ebiroll/openvg
// 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 := openvg.VGfloat(height) * .95
	sx := openvg.VGfloat(width) * 0.10
	sy := top
	sw := openvg.VGfloat(width) * .05
	sh := openvg.VGfloat(height) * .045
	dotsize := openvg.VGfloat(7.0)
	spacing := openvg.VGfloat(2.0)
	fontsize := int(openvg.VGfloat(height) * .033)
	shapecolor := Color{202, 225, 255, 1.0}

	openvg.Start(width, height)
	openvg.FillRGB(128, 0, 0, 1)
	openvg.TextEnd(openvg.VGfloat(width-20), openvg.VGfloat(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 := []openvg.VGfloat{sx, sx + (sw / 4), sx + (sw / 2), sx + ((sw * 3) / 4), sx + sw}
	py := []openvg.VGfloat{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 openvg.VGfloat
	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()
}