Ejemplo n.º 1
0
Archivo: sl.go Proyecto: Ebiroll/openvg
func drawTypeOfTransport(x openvg.VGfloat, y openvg.VGfloat, w openvg.VGfloat, h int, tType string) {

	//openvg.Background(0, 0, 255)

	openvg.FillColor("blue")

	switch tType {
	case "METRO":
		openvg.Text(x, y, "T", "sans", h)
	case "BUS":
		openvg.Text(x, y, "B", "sans", h)
	case "TRAIN":
		openvg.Text(x, y, "J", "sans", h)
	case "TRAM":
		openvg.Text(x, y, "S", "sans", h)
	default:
		openvg.Text(x, y, "D", "sans", h)

	}

	openvg.FillColor("black")

	//openvg.Background(0, 0, 0)

}
Ejemplo n.º 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()
		}
	}
}
Ejemplo n.º 3
0
func main() {
	var color string
	openvg.Start(width, height)
	openvg.Background(200, 200, 200)
	for i := 0; i < niter; i++ {
		x := random(0, width)
		y := random(height/3, (height*2)/3)
		r := random(0, 10000)
		switch {
		case r >= 0 && r <= 2500:
			color = "white"
		case r > 2500 && r <= 5000:
			color = "maroon"
		case r > 5000 && r <= 7500:
			color = "gray"
		case r > 7500 && r <= 10000:
			color = "black"
		}
		openvg.FillColor(color, openvg.VGfloat(opacity))
		openvg.Circle(openvg.VGfloat(x), openvg.VGfloat(y), openvg.VGfloat(size))
	}
	openvg.End()
	bufio.NewReader(os.Stdin).ReadByte()
	openvg.Finish()
}
Ejemplo n.º 4
0
func roundhand(cx, cy, px, py, stroke openvg.VGfloat, color string) {
	openvg.StrokeWidth(stroke)
	openvg.StrokeColor(color)
	openvg.Line(cx, cy, px, py)
	openvg.StrokeWidth(0)
	openvg.FillColor(color)
	openvg.Ellipse(px, py, stroke, stroke)
}
Ejemplo n.º 5
0
func secondhand(cx, cy, sx, sy, textsize openvg.VGfloat) {
	openvg.FillColor(secolor, 0.4)
	openvg.Ellipse(sx, sy, textsize, textsize)
	if secline {
		openvg.StrokeWidth(textsize / 6)
		openvg.StrokeColor(secolor)
		openvg.Line(cx, cy, sx, sy)
		openvg.StrokeWidth(0)
	}
}
Ejemplo n.º 6
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)

}
Ejemplo n.º 7
0
func arrowhand(cx, cy, px, py, r openvg.VGfloat, t float64, value int, color string) {
	ax := []openvg.VGfloat{cx, 0, px, 0, cx}
	ay := []openvg.VGfloat{cy, 0, py, 0, cy}
	t = minadjust(t, value) * deg2rad
	rf := float64(r * 0.9)
	tf := math.Pi / 45.0
	ax[1] = cx + openvg.VGfloat(rf*math.Cos(t-tf))
	ay[1] = cy + openvg.VGfloat(rf*math.Sin(t-tf))
	ax[3] = cx + openvg.VGfloat(rf*math.Cos(t+tf))
	ay[3] = cy + openvg.VGfloat(rf*math.Sin(t+tf))
	openvg.FillColor(color)
	openvg.Polygon(ax, ay)
}
Ejemplo n.º 8
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()
}
Ejemplo n.º 9
0
func combohand(cx, cy, px, py, r, stroke openvg.VGfloat, t float64, value int, color string) {
	thinr := float64(r * 0.25)
	t = minadjust(t, value) * deg2rad
	tx := cx + openvg.VGfloat(thinr*math.Cos(t))
	ty := cy + openvg.VGfloat(thinr*math.Sin(t))
	openvg.FillColor(color)
	openvg.Ellipse(px, py, stroke*2, stroke*2)
	openvg.Ellipse(tx, ty, stroke*2, stroke*2)
	openvg.StrokeWidth(stroke)
	openvg.StrokeColor(color)
	openvg.Line(cx, cy, tx, ty)
	openvg.StrokeWidth(stroke * 2)
	openvg.Line(tx, ty, px, py)
	openvg.StrokeWidth(0)
}
Ejemplo n.º 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()
}
Ejemplo n.º 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
}
Ejemplo n.º 12
0
// textwrap draws text at location, wrapping at the specified width
func textwrap(x, y, w openvg.VGfloat, s string, font string, size int, leading, factor openvg.VGfloat, color string) {
	openvg.FillColor(color)
	wordspacing := openvg.TextWidth("M", font, size)
	words := strings.Split(s, " ")
	xp := x
	yp := y
	edge := x + w
	for i := 0; i < len(words); i++ {
		tw := openvg.TextWidth(words[i], font, size)
		openvg.Text(xp, yp, words[i], font, size)
		xp += tw + (wordspacing * factor)
		if xp > edge {
			xp = x
			yp -= leading
		}

	}
}
Ejemplo n.º 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()
}
Ejemplo n.º 14
0
// main plots data from specified files or standard input in a
// grid where plotc specifies the number of columns.
func main() {
	w, h := openvg.Init()
	i := 1
	filenames := flag.Args()

	for i <= 1000 {
		openvg.Start(w, h)
		openvg.FillColor("white")
		openvg.Rect(0, 0, gwidth, gheight)
		if len(filenames) == 0 {
			doplot(beginx, beginy, "")
		} else {
			plotgrid(beginx, beginy, filenames)
		}
		openvg.End()
		i = i + 1
	}
	bufio.NewReader(os.Stdin).ReadByte()
	openvg.Finish()
}
Ejemplo n.º 15
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
}
Ejemplo n.º 16
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()
}
Ejemplo n.º 17
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)
}
Ejemplo n.º 18
0
// interact controls the display of the deck
func interact(filename, searchterm string, w, h, slidenum int, gp float64) {
	openvg.SaveTerm()
	defer openvg.RestoreTerm()
	var d deck.Deck
	var err error
	d, err = deck.Read(filename, w, h)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}
	openvg.RawTerm()
	r := bufio.NewReader(os.Stdin)
	lastslide := len(d.Slide) - 1
	if slidenum > lastslide {
		slidenum = lastslide
	}
	if slidenum < 0 {
		slidenum = 0
	}
	if len(searchterm) > 0 {
		sr := deck.Search(d, searchterm)
		if sr >= 0 {
			slidenum = sr
		}
	}
	n := slidenum
	xray := 1
	initial := 0
	imap := make(map[string]image.Image)
	// respond to keyboard commands, 'q' to exit
	for cmd := byte('0'); cmd != 'q'; cmd = readcmd(r) {
		switch cmd {
		// read/reload
		case 'r', 18: // r, Ctrl-R
			d, err = deck.Read(filename, w, h)
			if err != nil {
				fmt.Fprintf(os.Stderr, "%v\n", err)
				return
			}
			loadimage(d, imap)
			openvg.Background(0, 0, 0)
			xray = 1
			showslide(d, imap, n)

		// save slide
		case 's', 19: // s, Ctrl-S
			openvg.SaveEnd(fmt.Sprintf("%s-slide-%04d", filename, n))

		// first slide
		case '0', '1', 1, '^': // 0,1,Ctrl-A,^
			initial++
			if initial == 1 {
				loadimage(d, imap)
				n = slidenum
			} else {
				n = 0
			}
			showslide(d, imap, n)

		// last slide
		case '*', 5, '$': // *, Crtl-E, $
			n = lastslide
			showslide(d, imap, n)

		// next slide
		case '+', 'n', '\n', ' ', '\t', '=', 14: // +,n,newline,space,tab,equal,Crtl-N
			n++
			if n > lastslide {
				n = 0
			}
			showslide(d, imap, n)

		// previous slide
		case '-', 'p', 8, 16, 127: // -,p,Backspace,Ctrl-P,Del
			n--
			if n < 0 {
				n = lastslide
			}
			showslide(d, imap, n)

		// x-ray
		case 'x', 24: // x, Ctrl-X
			xray++
			showslide(d, imap, n)
			if xray%2 == 0 {
				showgrid(d, n, gp)
			}
		// Escape sequence from remotes
		case 27:
			remote, rerr := r.ReadString('~')
			if len(remote) > 2 && rerr == nil {
				switch remote[1] {
				case '3': // blank screen
					openvg.Start(d.Canvas.Width, d.Canvas.Height)
					openvg.FillColor("black")
					openvg.Rect(0, 0, openvg.VGfloat(d.Canvas.Width), openvg.VGfloat(d.Canvas.Height))
					openvg.End()

				case '5': // back
					n--
					if n < 0 {
						n = lastslide
					}
					showslide(d, imap, n)
				case '6': // forward
					n++
					if n > lastslide {
						n = 0
					}
					showslide(d, imap, n)
				}
			}
		// search
		case '/', 6: // slash, Ctrl-F
			openvg.RestoreTerm()
			searchterm, serr := r.ReadString('\n')
			openvg.RawTerm()
			if serr != nil {
				continue
			}
			if len(searchterm) > 2 {
				ns := deck.Search(d, searchterm[0:len(searchterm)-1])
				if ns >= 0 {
					showslide(d, imap, ns)
					n = ns
				}
			}
		}
	}
}
Ejemplo n.º 19
0
// showlide displays slides
func showslide(d deck.Deck, imap map[string]image.Image, n int) {

	var video videoType

	if n < 0 || n > len(d.Slide)-1 {
		return
	}
	slide := d.Slide[n]
	if slide.Bg == "" {
		slide.Bg = "white"
	}
	if slide.Fg == "" {
		slide.Fg = "black"
	}
	openvg.Start(d.Canvas.Width, d.Canvas.Height)
	cw := openvg.VGfloat(d.Canvas.Width)
	ch := openvg.VGfloat(d.Canvas.Height)
	if slide.Gradcolor1 != "" && slide.Gradcolor2 != "" {
		oc := []openvg.Offcolor{
			{0, openvg.Colorlookup(slide.Gradcolor1), 1},
			{1, openvg.Colorlookup(slide.Gradcolor2), 1},
		}
		openvg.FillLinearGradient(0, ch, 0, 0, oc)
	} else {
		openvg.FillColor(slide.Bg)
	}
	openvg.Rect(0, 0, cw, ch)
	var x, y, fs openvg.VGfloat

	// every image in the slide
	for _, im := range slide.Image {
		x = pct(im.Xp, cw)
		y = pct(im.Yp, ch)
		imw := openvg.VGfloat(im.Width)
		imh := openvg.VGfloat(im.Height)
		if im.Scale > 0 {
			imw *= openvg.VGfloat(im.Scale / 100)
			imh *= openvg.VGfloat(im.Scale / 100)
		}
		midx := openvg.VGfloat(imw / 2)
		midy := openvg.VGfloat(imh / 2)

		if im.Type == "video" {
			// Only one video per slide supported
			video.name = im.Name
			video.x = x - midx
			video.y = y - midy
			video.w = imw
			video.h = imh
			video.altimg = im.Link
		} else {
			img, ok := imap[im.Name]
			if ok {
				openvg.Img(x-midx, y-midy, img)
			}
			if len(im.Caption) > 0 {
				capfs := pctwidth(im.Sp, cw, cw/100)
				if im.Font == "" {
					im.Font = "sans"
				}
				if im.Color == "" {
					openvg.FillColor(slide.Fg)
				} else {
					openvg.FillColor(im.Color)
				}
				if im.Align == "" {
					im.Align = "center"
				}
				switch im.Align {
				case "left", "start":
					x -= midx
				case "right", "end":
					x += midx
				}
				showtext(x, y-((midy)+(capfs*2.0)), im.Caption, im.Align, im.Font, capfs)
			}
		}
	}

	// every graphic on the slide
	const defaultColor = "rgb(127,127,127)"
	const defaultSw = 1.5
	var strokeopacity float64
	// line
	for _, line := range slide.Line {
		if line.Color == "" {
			line.Color = slide.Fg // defaultColor
		}
		if line.Opacity == 0 {
			strokeopacity = 1
		} else {
			strokeopacity = line.Opacity / 100.0
		}
		x1, y1, sw := dimen(d, line.Xp1, line.Yp1, line.Sp)
		x2, y2, _ := dimen(d, line.Xp2, line.Yp2, 0)
		openvg.StrokeColor(line.Color, openvg.VGfloat(strokeopacity))
		if sw == 0 {
			sw = defaultSw
		}
		openvg.StrokeWidth(openvg.VGfloat(sw))
		openvg.StrokeColor(line.Color)
		openvg.Line(x1, y1, x2, y2)
		openvg.StrokeWidth(0)
	}
	// ellipse
	for _, ellipse := range slide.Ellipse {
		x, y, _ = dimen(d, ellipse.Xp, ellipse.Yp, 0)
		var w, h openvg.VGfloat
		w = pct(ellipse.Wp, cw)
		if ellipse.Hr == 0 { // if relative height not specified, base height on overall height
			h = pct(ellipse.Hp, ch)
		} else {
			h = pct(ellipse.Hr, w)
		}
		if ellipse.Color == "" {
			ellipse.Color = defaultColor
		}
		if ellipse.Opacity == 0 {
			ellipse.Opacity = 1
		} else {
			ellipse.Opacity /= 100
		}
		openvg.FillColor(ellipse.Color, openvg.VGfloat(ellipse.Opacity))
		openvg.Ellipse(x, y, w, h)
	}
	// rect
	for _, rect := range slide.Rect {
		x, y, _ = dimen(d, rect.Xp, rect.Yp, 0)
		var w, h openvg.VGfloat
		w = pct(rect.Wp, cw)
		if rect.Hr == 0 { // if relative height not specified, base height on overall height
			h = pct(rect.Hp, ch)
		} else {
			h = pct(rect.Hr, w)
		}
		if rect.Color == "" {
			rect.Color = defaultColor
		}
		if rect.Opacity == 0 {
			rect.Opacity = 1
		} else {
			rect.Opacity /= 100
		}
		openvg.FillColor(rect.Color, openvg.VGfloat(rect.Opacity))
		openvg.Rect(x-(w/2), y-(h/2), w, h)
	}
	// curve
	for _, curve := range slide.Curve {
		if curve.Color == "" {
			curve.Color = defaultColor
		}
		if curve.Opacity == 0 {
			strokeopacity = 1
		} else {
			strokeopacity = curve.Opacity / 100.0
		}
		x1, y1, sw := dimen(d, curve.Xp1, curve.Yp1, curve.Sp)
		x2, y2, _ := dimen(d, curve.Xp2, curve.Yp2, 0)
		x3, y3, _ := dimen(d, curve.Xp3, curve.Yp3, 0)
		openvg.StrokeColor(curve.Color, openvg.VGfloat(strokeopacity))
		openvg.FillColor(slide.Bg, openvg.VGfloat(curve.Opacity))
		if sw == 0 {
			sw = defaultSw
		}
		openvg.StrokeWidth(sw)
		openvg.Qbezier(x1, y1, x2, y2, x3, y3)
		openvg.StrokeWidth(0)
	}

	// arc
	for _, arc := range slide.Arc {
		if arc.Color == "" {
			arc.Color = defaultColor
		}
		if arc.Opacity == 0 {
			strokeopacity = 1
		} else {
			strokeopacity = arc.Opacity / 100.0
		}
		ax, ay, sw := dimen(d, arc.Xp, arc.Yp, arc.Sp)
		w := pct(arc.Wp, cw)
		h := pct(arc.Hp, cw)
		openvg.StrokeColor(arc.Color, openvg.VGfloat(strokeopacity))
		openvg.FillColor(slide.Bg, openvg.VGfloat(arc.Opacity))
		if sw == 0 {
			sw = defaultSw
		}
		openvg.StrokeWidth(sw)
		openvg.Arc(ax, ay, w, h, openvg.VGfloat(arc.A1), openvg.VGfloat(arc.A2))
		openvg.StrokeWidth(0)
	}

	// polygon
	for _, poly := range slide.Polygon {
		if poly.Color == "" {
			poly.Color = defaultColor
		}
		if poly.Opacity == 0 {
			poly.Opacity = 1
		} else {
			poly.Opacity /= 100
		}
		xs := strings.Split(poly.XC, " ")
		ys := strings.Split(poly.YC, " ")
		if len(xs) != len(ys) {
			continue
		}
		if len(xs) < 3 || len(ys) < 3 {
			continue
		}
		px := make([]openvg.VGfloat, len(xs))
		py := make([]openvg.VGfloat, len(ys))
		for i := 0; i < len(xs); i++ {
			x, err := strconv.ParseFloat(xs[i], 32)
			if err != nil {
				px[i] = 0
			} else {
				px[i] = pct(x, cw)
			}
			y, err := strconv.ParseFloat(ys[i], 32)
			if err != nil {
				py[i] = 0
			} else {
				py[i] = pct(y, ch)
			}
		}
		openvg.FillColor(poly.Color, openvg.VGfloat(poly.Opacity))
		openvg.Polygon(px, py)
	}

	openvg.FillColor(slide.Fg)

	// every list in the slide
	var offset, textopacity openvg.VGfloat
	const blinespacing = 2.4
	for _, l := range slide.List {
		if l.Font == "" {
			l.Font = "sans"
		}
		x, y, fs = dimen(d, l.Xp, l.Yp, l.Sp)
		if l.Type == "bullet" {
			offset = 1.2 * fs
		} else {
			offset = 0
		}
		if l.Lp == 0 {
			l.Lp = blinespacing
		}
		if l.Opacity == 0 {
			textopacity = 1
		} else {
			textopacity = openvg.VGfloat(l.Opacity / 100)
		}
		// every list item
		var li, lifont string
		for ln, tl := range l.Li {
			if len(l.Color) > 0 {
				openvg.FillColor(l.Color, textopacity)
			} else {
				openvg.FillColor(slide.Fg)
			}
			if l.Type == "bullet" {
				boffset := fs / 2
				openvg.Ellipse(x, y+boffset, boffset, boffset)
				//openvg.Rect(x, y+boffset/2, boffset, boffset)
			}
			if l.Type == "number" {
				li = fmt.Sprintf("%d. ", ln+1) + tl.ListText
			} else {
				li = tl.ListText
			}
			if len(tl.Color) > 0 {
				openvg.FillColor(tl.Color, textopacity)
			}
			if len(tl.Font) > 0 {
				lifont = tl.Font
			} else {
				lifont = l.Font
			}
			showtext(x+offset, y, li, l.Align, lifont, fs)
			y -= fs * openvg.VGfloat(l.Lp)
		}
	}
	openvg.FillColor(slide.Fg)

	// every text in the slide
	const linespacing = 1.8

	var tdata string
	for _, t := range slide.Text {
		if t.File != "" {
			tdata = includefile(t.File)
		} else {
			tdata = t.Tdata
		}
		if t.Font == "" {
			t.Font = "sans"
		}
		if t.Opacity == 0 {
			textopacity = 1
		} else {
			textopacity = openvg.VGfloat(t.Opacity / 100)
		}
		if t.Lp == 0 {
			t.Lp = linespacing
		}
		x, y, fs = dimen(d, t.Xp, t.Yp, t.Sp)
		td := strings.Split(tdata, "\n")
		if t.Type == "code" {
			ls := fs * openvg.VGfloat(t.Lp)
			t.Font = "mono"
			tdepth := (ls * openvg.VGfloat(len(td))) + fs
			openvg.FillColor("rgb(240,240,240)")
			openvg.Rect(x-20, y-tdepth+(ls), pctwidth(t.Wp, cw, cw-x-20), tdepth)
		}
		if t.Color == "" {
			openvg.FillColor(slide.Fg, textopacity)
		} else {
			openvg.FillColor(t.Color, textopacity)
		}
		if t.Type == "block" {
			textwrap(x, y, pctwidth(t.Wp, cw, cw/2), tdata, t.Font, fs, fs*openvg.VGfloat(t.Lp), 0.3)
		} else {
			// every text line
			ls := fs * openvg.VGfloat(t.Lp)
			for _, txt := range td {
				showtext(x, y, txt, t.Align, t.Font, fs)
				y -= ls
			}
		}
	}
	openvg.FillColor(slide.Fg)
	openvg.End()
	if video.altimg != "" {
		img, ok := imap[video.altimg]
		if ok {
			openvg.Img(video.x, video.y, img)
		}
	}
	if video.name != "" {
		openvg.Video(video.x, video.y, video.w, video.h, video.name)
	}
}
Ejemplo n.º 20
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
}
Ejemplo n.º 21
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)
}
Ejemplo n.º 22
0
func frame(cx, cy, framesize, facesize, textsize openvg.VGfloat, framecolor, facecolor string) {
	openvg.FillColor(framecolor)
	openvg.Roundrect(cx-framesize/2, cy-framesize/2, framesize, framesize, textsize, textsize)
	openvg.FillColor(facecolor)
	openvg.Ellipse(cx, cy, facesize*2.4, facesize*2.4)
}
Ejemplo n.º 23
0
func main() {
	var (
		filename     = flag.String("f", "svgcolors.txt", "input file")
		fontname     = flag.String("font", "sans", "fontname")
		neg          = flag.Bool("neg", false, "negative")
		showrgb      = flag.Bool("rgb", false, "show RGB")
		showcode     = flag.Bool("showcode", true, "show colors and codes")
		circsw       = flag.Bool("circle", true, "circle swatch")
		outline      = flag.Bool("outline", false, "outline swatch")
		fontsize     = flag.Int("fs", 12, "fontsize")
		rowsize      = flag.Int("r", 32, "rowsize")
		colw         = flag.Float64("c", 340, "column size")
		swatch       = flag.Float64("s", 16, "swatch size")
		gutter       = flag.Float64("g", 12, "gutter")
		err          error
		tcolor, line string
	)

	flag.Parse()
	f, oerr := os.Open(*filename)
	if oerr != nil {
		fmt.Fprintf(os.Stderr, "%v\n", oerr)
		return
	}
	width, height := openvg.Init()

	openvg.Start(width, height)
	fw := openvg.VGfloat(width)
	fh := openvg.VGfloat(height)
	if *neg {
		openvg.FillColor("black")
		openvg.Rect(0, 0, fw, fh)
		tcolor = "white"
	} else {
		openvg.FillColor("white")
		openvg.Rect(0, 0, fw, fh)
		tcolor = "black"
	}
	top := fh - 32.0
	left := openvg.VGfloat(32.0)
	cw := openvg.VGfloat(*colw)
	sw := openvg.VGfloat(*swatch)
	g := openvg.VGfloat(*gutter)
	in := bufio.NewReader(f)

	for x, y, nr := left, top, 0; err == nil; nr++ {
		line, err = in.ReadString('\n')
		fields := strings.Split(strings.TrimSpace(line), "\t")
		if nr%*rowsize == 0 && nr > 0 {
			x += cw
			y = top
		}
		if len(fields) == 3 {
			var red, green, blue uint8
			fmt.Sscanf(fields[2], "%d,%d,%d", &red, &green, &blue)
			openvg.FillRGB(red, green, blue, 1)
			if *outline {
				openvg.StrokeColor("black")
				openvg.StrokeWidth(1)
			}
			if *circsw {
				openvg.Circle(x+sw/2, y+sw/2, sw)
			} else {
				openvg.Rect(x, y, sw, sw)
			}
			openvg.StrokeWidth(0)
			openvg.FillColor(tcolor)
			openvg.Text(x+sw+openvg.VGfloat(*fontsize/2), y, fields[0], *fontname, *fontsize)
			var label string
			if *showcode {
				if *showrgb {
					label = fields[1]
				} else {
					label = fields[2]
				}
				openvg.FillColor("gray")
				openvg.TextEnd(x+cw-(sw+g), y, label, *fontname, *fontsize)
			}
		}
		y -= (sw + g)
	}
	openvg.End()
	bufio.NewReader(os.Stdin).ReadBytes('\n')
	openvg.Finish()
}
Ejemplo n.º 24
0
func centerdot(cx, cy, size openvg.VGfloat) {
	openvg.FillColor(centercolor)
	openvg.Ellipse(cx, cy, size, size)
}