Пример #1
0
// testpattern shows a test pattern
func testpattern(w, h int, s string) {
	var midx, midy1, midy2, midy3 openvg.VGfloat
	fontsize := 256
	h2 := openvg.VGfloat(h / 2)
	by := openvg.VGfloat(h - 100)
	bx := openvg.VGfloat(w - 100)
	tw1 := &FW{"mono", 0, fontsize}
	tw2 := &FW{"sans", 0, fontsize}
	tw3 := &FW{"serif", 0, fontsize}

	openvg.Start(w, h)

	// colored squares in the corners
	openvg.FillRGB(255, 0, 0, 1)
	openvg.Rect(0, 0, 100, 100)
	openvg.FillRGB(0, 255, 0, 1)
	openvg.Rect(0, by, 100, 100)
	openvg.FillRGB(0, 0, 255, 1)
	openvg.Rect(bx, 0, 100, 100)
	openvg.FillRGB(128, 128, 128, 1)
	openvg.Rect(bx, by, 100, 100)

	// for each font, (Sans, Serif, Mono), adjust the string to the w
	tw1.fitwidth(w, 20, s)
	tw2.fitwidth(w, 20, s)
	tw3.fitwidth(w, 20, s)

	midx = openvg.VGfloat(w / 2)

	// Adjust the baselines to be medial
	midy1 = h2 + 20 + openvg.VGfloat((tw1.fontsize)/2)
	midy2 = h2 - openvg.VGfloat((tw2.fontsize)/2)
	midy3 = h2 - 20 - openvg.VGfloat(tw2.fontsize) - openvg.VGfloat((tw3.fontsize)/2)

	openvg.FillRGB(128, 128, 128, 1)
	openvg.TextMid(midx, midy1, s, tw1.font, tw1.fontsize)
	openvg.FillRGB(128, 0, 0, 1)
	openvg.TextMid(midx, midy2, s, tw2.font, tw2.fontsize)
	openvg.FillRGB(0, 0, 128, 1)
	openvg.TextMid(midx, midy3, s, tw3.font, tw3.fontsize)
	openvg.End()
}
Пример #2
0
// loadimage loads all the images of the deck into a map for later display
func loadimage(d deck.Deck, m map[string]image.Image) {
	firstrun++
	w, h := d.Canvas.Width, d.Canvas.Height
	cw := openvg.VGfloat(w)
	ch := openvg.VGfloat(h)
	msize := int(cw * .01)
	mx := cw / 2
	my := ch * 0.05
	mbg := "white"
	mfg := "black"
	for ns, s := range d.Slide {
		for ni, i := range s.Image {
			if !modfile(i.Name, StartTime) {
				continue
			}
			openvg.Start(w, h)
			if i.Link != "" {
				fmt.Fprintf(os.Stderr, "Found altimg %s\n", i.Link)
			}
			f, err := os.Open(i.Name)
			if err != nil {
				fmt.Fprintf(os.Stderr, "%v\n", err)
				continue
			}
			img, _, err := image.Decode(f)
			if err != nil {
				fmt.Fprintf(os.Stderr, "%v\n", err)
				continue
			}
			openvg.FillColor(mbg)
			openvg.Rect(0, 0, cw, ch)
			openvg.FillColor(mfg)
			openvg.TextMid(mx, my, fmt.Sprintf("Loading image %s %d from slide %d", i.Name, ni, ns), "sans", msize)
			bounds := img.Bounds()
			iw := i.Width
			ih := i.Height
			if i.Scale > 0 {
				iw = int(float64(iw) * (i.Scale / 100))
				ih = int(float64(ih) * (i.Scale / 100))
			}
			// if the specified dimensions are native use those, otherwise resize
			if iw == (bounds.Max.X-bounds.Min.X) && ih == (bounds.Max.Y-bounds.Min.Y) {
				m[i.Name] = img
			} else {
				g := gift.New(gift.Resize(iw, ih, gift.BoxResampling))
				resized := image.NewRGBA(g.Bounds(img.Bounds()))
				g.Draw(resized, img)
				m[i.Name] = resized
			}
			f.Close()
			openvg.End()
		}
	}
}
Пример #3
0
//showtext displays text
func showtext(x, y openvg.VGfloat, t, align, font string, fs openvg.VGfloat) {
	//t := s // fromUTF8(s)
	fontsize := int(fs)
	switch align {
	case "center", "middle", "mid", "c":
		openvg.TextMid(x, y, t, font, fontsize)
	case "right", "end", "e":
		openvg.TextEnd(x, y, t, font, fontsize)
	default:
		openvg.Text(x, y, t, font, fontsize)
	}
}
Пример #4
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()
}
Пример #5
0
// raspberry pi, scaled to the screen dimensions
func raspi(w, h int, s string) {
	midx := openvg.VGfloat(w) / 2
	midy := openvg.VGfloat(h) / 2
	rw := midx
	rh := (rw * 2) / 3
	fontsize := w / 25
	openvg.Start(w, h)
	openvg.Background(255, 255, 255)
	makepi(midx-(rw/2), midy-(rh/2), rw, rh)
	openvg.FillRGB(128, 0, 0, 1)
	openvg.TextMid(midx, midy-(rh/2)-openvg.VGfloat(fontsize*2), s, "sans", fontsize)
	openvg.End()
}
Пример #6
0
// 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()
}
Пример #7
0
//planets is an exploration of scale
func planets(width, height int, message string) {

	w := openvg.VGfloat(width)
	h := openvg.VGfloat(height)
	y := h / 2

	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 == "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()
}
Пример #8
0
// fontrange shows a range of fonts
func fontrange(w, h int) {
	var x, lx, length openvg.VGfloat
	y := openvg.VGfloat(h) / 2.0
	w2 := openvg.VGfloat(w) / 2.0
	spacing := openvg.VGfloat(50.0)
	s2 := spacing / 2.0
	sizes := []int{6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 21, 24, 36, 48, 60, 72, 96}

	openvg.Start(w, h)
	openvg.Background(255, 255, 255)

	// compute the length so we can center
	length = 0.0
	for _, s := range sizes {
		length += openvg.VGfloat(s) + spacing
	}
	length -= spacing
	lx = w2 - (length / 2) // center point

	// for each size, display a character and label
	x = lx
	for _, s := range sizes {
		openvg.FillRGB(128, 0, 0, 1)
		openvg.TextMid(x, y, "a", "serif", s)
		openvg.FillRGB(128, 128, 128, 1)
		openvg.TextMid(x, y-spacing, fmt.Sprintf("%d", s), "sans", 16)
		x += openvg.VGfloat(s) + spacing
	}
	// draw a openvg.Line below the characters, a curve above
	x -= spacing
	openvg.StrokeRGB(150, 150, 150, 0.5)
	openvg.StrokeWidth(2)
	openvg.Line(lx, y-s2, x, y-s2)
	openvg.FillRGB(255, 255, 255, 1)
	openvg.Qbezier(lx, y+s2, x, y+s2, x, y+(spacing*3))
	openvg.End()
}
Пример #9
0
// raspberry pi, scaled to the screen dimensions
func main() {
	w, h := openvg.Init()
	midx := openvg.VGfloat(w) / 2
	midy := openvg.VGfloat(h) / 2
	rw := midx
	rh := (rw * 2) / 3
	fontsize := w / 25
	openvg.Start(w, h)
	openvg.Background(255, 255, 255)
	makepi(midx-(rw/2), midy-(rh/2), rw, rh)
	makepi(200, 100, 75, 50)
	openvg.FillRGB(128, 0, 0, 1)
	openvg.TextMid(midx, midy-(rh/2)-openvg.VGfloat(fontsize*2), "The Raspberry Pi", "sans", fontsize)
	WaitEnd()
}
Пример #10
0
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()
}
Пример #11
0
func main() {
	width, height := openvg.Init() // OpenGL, etc initialization

	w2 := openvg.VGfloat(width / 2)
	h2 := openvg.VGfloat(height / 2)
	w := openvg.VGfloat(width)

	openvg.Start(width, height)                               // Start the picture
	openvg.BackgroundColor("black")                           // Black background
	openvg.FillRGB(44, 100, 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.End()                                              // End the picture
	bufio.NewReader(os.Stdin).ReadBytes('\n')                 // Pause until [RETURN]
	openvg.Finish()                                           // Graphics cleanup
}
Пример #12
0
func face(x, y, r openvg.VGfloat, ts int) {
	var fx, fy, va openvg.VGfloat
	va = openvg.VGfloat(ts) / 2.0
	secsize := openvg.VGfloat(ts) / 3
	radius := float64(r)
	ir := radius * 1.2
	// hour display
	openvg.FillColor(digitcolor)
	openvg.StrokeColor(digitcolor)
	openvg.StrokeWidth(5)
	for h := 12; h > 0; h-- {
		t := hourangles[h%12] * deg2rad
		fx = x + openvg.VGfloat(radius*math.Cos(t))
		fy = y + openvg.VGfloat(radius*math.Sin(t))
		ix := x + openvg.VGfloat(ir*math.Cos(t))
		iy := y + openvg.VGfloat(ir*math.Sin(t))
		if showdigits {
			openvg.TextMid(fx, fy-va, hourdigits[h%12], "sans", ts)
		} else {
			openvg.Line(fx, fy, ix, iy)
		}
	}
	// second display
	openvg.FillColor(dotcolor)
	openvg.StrokeColor(dotcolor)
	openvg.StrokeWidth(2)
	re := radius * edge
	for a := 0.0; a < 360; a += 6.0 {
		t := a * deg2rad
		sx := x + openvg.VGfloat(re*math.Cos(t))
		sy := y + openvg.VGfloat(re*math.Sin(t))
		if showdots {
			openvg.Ellipse(sx, sy, secsize, secsize)
		} else {
			ix := x + openvg.VGfloat(ir*math.Cos(t))
			iy := y + openvg.VGfloat(ir*math.Sin(t))
			openvg.Line(sx, sy, ix, iy)
		}
	}
	openvg.StrokeWidth(0)

}
Пример #13
0
func gradient(width, height int) {
	w := openvg.VGfloat(width)
	h := openvg.VGfloat(height)
	stops := []openvg.Offcolor{
		{0.0, openvg.RGB{255, 255, 255}, 1.0},
		{0.5, openvg.RGB{128, 128, 128}, 1.0},
		{1.0, openvg.RGB{0, 0, 0}, 1.0},
	}

	x1 := w / 8
	x2 := (w * 3) / 8
	y1 := h / 3
	y2 := (h * 2) / 3
	cx := (w * 3) / 4
	cy := (h / 2)
	r := (x2 - x1)
	fx := cx + (r / 4)
	fy := cy + (r / 4)
	openvg.Start(width, height)
	openvg.BackgroundRGB(128, 128, 128, 1)
	openvg.FillLinearGradient(x1, y1, x2, y2, stops)
	openvg.Rect(x1, y1, x2-x1, y2-y1)
	openvg.FillRadialGradient(cx, cy, fx, fy, r, stops)
	openvg.Circle(cx, cy, r)

	openvg.FillRGB(0, 0, 0, 0.3)
	openvg.Circle(x1, y1, 10)
	openvg.Circle(x2, y2, 10)
	openvg.Circle(cx, cy, 10)
	openvg.Circle(cx+r/2, cy, 10)
	openvg.Circle(fx, fy, 10)

	openvg.FillColor("black")
	SansTypeface := "sans"
	openvg.TextMid(x1, y1-20, "(x1, y1)", SansTypeface, 18)
	openvg.TextMid(x2, y2+10, "(x2, y2)", SansTypeface, 18)
	openvg.TextMid(cx, cy, "(cx, cy)", SansTypeface, 18)
	openvg.TextMid(fx, fy, "(fx, fy)", SansTypeface, 18)
	openvg.TextEnd(cx+(r/2)+20, cy, "r", SansTypeface, 18)

	openvg.TextMid(x1+((x2-x1)/2), h/6, "Linear Gradient", SansTypeface, 36)
	openvg.TextMid(cx, h/6, "Radial Gradient", SansTypeface, 36)
	openvg.End()
}
Пример #14
0
func main() {
	width, height := openvg.Init() // OpenGL, etc initialization

	w2 := openvg.VGfloat(width / 2)
	h2 := openvg.VGfloat(height / 2)
	w := openvg.VGfloat(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
	openvg.End()
	bufio.NewReader(os.Stdin).ReadBytes('\n') // Pause until [RETURN]
	openvg.Finish()                           // Graphics cleanup
}
Пример #15
0
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()
}
Пример #16
0
// plot places a plot at the specified location with the specified dimemsions
// using the specified settings, using the specified data
func plot(x, y, w, h openvg.VGfloat, settings plotset, d []rawdata) {
	nd := len(d)
	if nd < 2 {
		fmt.Fprintf(os.Stderr, "%d is not enough points to plot\n", len(d))
		return
	}
	// Compute the minima and maxima of the data
	maxx, minx := d[0].x, d[0].x
	maxy, miny := d[0].y, d[0].y
	for _, v := range d {

		if v.x > maxx {
			maxx = v.x
		}
		if v.y > maxy {
			maxy = v.y
		}
		if v.x < minx {
			minx = v.x
		}
		if v.y < miny {
			miny = v.y
		}
	}
	// Prepare for a area or line chart by allocating
	// polygon coordinates; for the horizon plot, you need two extra coordinates
	// for the extrema.
	needpoly := settings.opt["area"] || settings.opt["connect"]
	var xpoly, ypoly []openvg.VGfloat
	if needpoly {
		xpoly = make([]openvg.VGfloat, nd+2)
		ypoly = make([]openvg.VGfloat, nd+2)
		// preload the extrema of the polygon,
		// the bottom left and bottom right of the plot's rectangle
		xpoly[0] = x
		ypoly[0] = y
		xpoly[nd+1] = x + w
		ypoly[nd+1] = y
	}
	// Draw the plot's bounding rectangle
	if settings.opt["showbg"] && !settings.opt["sameplot"] {
		openvg.FillColor(settings.attr["bgcolor"])
		openvg.Rect(x, y, w, h)
	}
	// Loop through the data, drawing items as specified
	spacer := openvg.VGfloat(10.0)
	for i, v := range d {
		xp := fmap(v.x, minx, maxx, x, x+w)
		yp := fmap(v.y, miny, maxy, y, y+h)
		if needpoly {
			xpoly[i+1] = xp
			ypoly[i+1] = yp
		}
		if settings.opt["showbar"] {
			openvg.StrokeColor(settings.attr["barcolor"])
			openvg.StrokeWidth(settings.size["barsize"])
			openvg.Line(xp, yp, xp, y)
		}
		if settings.opt["showdot"] {
			openvg.FillColor(settings.attr["dotcolor"])
			openvg.StrokeWidth(0)
			openvg.Circle(xp, yp, settings.size["dotsize"])
		}
		if settings.opt["showx"] {
			if i%int(settings.size["xinterval"]) == 0 {
				openvg.FillColor("black")
				openvg.TextMid(xp, y-(spacer*2), fmt.Sprintf("%d", int(v.x)), settings.attr["font"], int(settings.size["fontsize"]))
				openvg.StrokeColor("silver")
				openvg.StrokeWidth(1)
				openvg.Line(xp, y, xp, y-spacer)
			}
			openvg.StrokeWidth(0)
		}
	}
	// Done constructing the points for the area or line plots, display them in one shot
	if settings.opt["area"] {
		openvg.FillColor(settings.attr["areacolor"])
		openvg.Polygon(xpoly, ypoly)
	}

	if settings.opt["connect"] {
		openvg.StrokeColor(settings.attr["linecolor"])
		openvg.StrokeWidth(settings.size["linesize"])
		openvg.Polyline(xpoly[1:nd+1], ypoly[1:nd+1])
	}
	// Put on the y axis labels, if specified
	if settings.opt["showy"] {
		bot := openvg.VGfloat(math.Floor(float64(miny)))
		top := openvg.VGfloat(math.Ceil(float64(maxy)))
		yrange := top - bot
		interval := yrange / openvg.VGfloat(settings.size["yinterval"])
		for yax := bot; yax <= top; yax += interval {
			yaxp := fmap(yax, bot, top, openvg.VGfloat(y), openvg.VGfloat(y+h))
			openvg.FillColor("black")
			openvg.TextEnd(x-spacer, yaxp, fmt.Sprintf("%.1f", yax), settings.attr["font"], int(settings.size["fontsize"]))
			openvg.StrokeColor("silver")
			openvg.StrokeWidth(1)
			openvg.Line(x-spacer, yaxp, x, yaxp)
		}
		openvg.StrokeWidth(0)
	}
	// Finally, tack on the label, if specified
	if len(settings.attr["label"]) > 0 {
		openvg.FillColor(settings.attr["labelcolor"], 0.3)
		openvg.TextMid(x+(w/2), y+(h/2), settings.attr["label"], settings.attr["font"], int(w/8)) // int(settings.size["fontsize"]))
	}
	openvg.StrokeWidth(0)
}
Пример #17
0
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
}
Пример #18
0
func main() {
	var cy, ch, midy int
	var message []string
	message = []string{" Black", "cats", "skitter", "and", "ghouls", "patter", "Happy", "Halloween"}

	w, h := openvg.Init()
	//var speed openvg.VGfloat = 0.5
	var x openvg.VGfloat = 0
	var vw, vh openvg.VGfloat
	var midxx openvg.VGfloat = openvg.VGfloat(w / 2)
	midy = (h / 2)
	fontsize := w / 8
	//cx = 0
	ch = fontsize * 2
	//cw = w
	cy = midy - (ch / 2)
	var redness uint8
	var index int

	//rx , rw, rh := openvg.VGfloat(cx) , openvg.VGfloat(cw), openvg.VGfloat(ch)
	ry := openvg.VGfloat(cy)
	// scroll the text, only in the clipping rectangle
	index = 0
	for {
		for redness = 255; redness > 16; redness -= 2 {

			ch = fontsize * 2
			//cw = w
			cy = midy - (ch / 2)
			openvg.Start(w, h)
			openvg.Background(redness, 0, 0)
			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)
			var fsiz int
			fsiz = int(255 - redness)
			openvg.TextMid(midxx, 0, message[index], "shf", fsiz)
			openvg.ClipEnd()
			openvg.End()
		}
		index = (index + 1) % 8
		if index == 0 {
			vw = openvg.VGfloat(w) - 200
			vh = openvg.VGfloat(h) - 200
			openvg.Video(100.0, 100.0, vw, vh, "test.h264")
		}
		if index == 0 {
			var test, oix int
			var xpos [40]float32
			var ypos [40]float32
			var rotate [40]float32
			var spdx [40]float32
			var spdy [40]float32

			// Init positions
			for test = 0; test < 40; test++ {
				var rot = rand.Float32()
				var rax = rand.Float32()
				rax = float32(w) * rax
				var ray = rand.Float32()
				ray = float32(h) * ray

				spdx[test] = float32(test) * rand.Float32()
				spdy[test] = float32(test) * rand.Float32()

				ypos[test] = ray
				xpos[test] = rax
				rot = 0
				rotate[test] = rot

			}

			// Move around
			for oix = 0; oix < 100; oix++ {
				openvg.Start(w, h)
				openvg.Background(0, 0, 0)
				openvg.FillColor("red")

				for test = 0; test < 40; test++ {
					var rot = rand.Float32()
					var rax = rand.Float32()*float32(4.0) - float32(2.0)
					var ray = float32(4.0)*rand.Float32() - float32(2.0)

					spdy[test] += ray
					spdx[test] += rax

					xpos[test] = xpos[test] + spdx[test]
					ypos[test] = ypos[test] + spdy[test]
					rotate[test] = rotate[test] + float32(rot*4-2)

					openvg.Rotate(openvg.VGfloat(rotate[test]))
					openvg.Translate(openvg.VGfloat(xpos[test]), openvg.VGfloat(ypos[test]))

					openvg.TextMid(0, 0, "Happy Halloween", "shf", 30)

					openvg.Translate(-openvg.VGfloat(xpos[test]), -openvg.VGfloat(ypos[test]))
					openvg.Rotate(-openvg.VGfloat(rotate[test]))

				}
				openvg.End()
			}

		}
	}
	bufio.NewReader(os.Stdin).ReadBytes('\n')
	openvg.Finish()
	os.Exit(0)
}
Пример #19
0
// textlines writes openvg.Lines of text
func textlines(x, y openvg.VGfloat, text []string, f string, fontsize int, leading openvg.VGfloat) {
	for _, s := range text {
		openvg.TextMid(x, y, s, f, fontsize)
		y -= leading
	}
}