Beispiel #1
0
// tb draws a block of text
func tb(w, h int) {
	para := []string{
		"For lo,",
		"the winter is past,",
		"the rain is over and gone",
		"the flowers appear on the earth;",
		"the time for the singing of birds is come,",
		"and the voice of the turtle is heard in our land",
	}

	tmargin := float64(w) * 0.50
	lmargin := float64(w) * 0.10
	top := float64(h) * .9
	mid := float64(h) * .6
	bot := float64(h) * .3

	fontsize := 24
	leading := 40.0
	lfontsize := fontsize * 2
	midb := ((leading * 2) + (leading / 2)) - float64(lfontsize/2)

	openvg.Start(w, h)
	openvg.FillRGB(49, 79, 79, 1)
	textlines(tmargin, top, para, "serif", fontsize, leading)
	textlines(tmargin, mid, para, "sans", fontsize, leading)
	textlines(tmargin, bot, para, "mono", fontsize, leading)
	openvg.Text(lmargin, top-midb, "Serif", "sans", lfontsize)
	openvg.Text(lmargin, mid-midb, "Sans", "sans", lfontsize)
	openvg.Text(lmargin, bot-midb, "Mono", "sans", lfontsize)
	openvg.End()
}
Beispiel #2
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()
}
Beispiel #3
0
// rshapes draws shapes with random colors, openvg.Strokes, and sizes.
func rshapes(width, height, n int) {

	var sx, sy, cx, cy, px, py, ex, ey, pox, poy float64

	np := 10
	polyx := make([]float64, np)
	polyy := make([]float64, np)
	openvg.Start(width, height)
	for i := 0; i < n; i++ {
		openvg.FillRGB(randcolor(), randcolor(), randcolor(), rand.Float64())
		openvg.Ellipse(randf(width), randf(height), randf(200), randf(100))
		openvg.Circle(randf(width), randf(height), randf(100))
		openvg.Rect(randf(width), randf(height), randf(200), randf(100))
		openvg.Arc(randf(width), randf(height), randf(200), randf(200), randf(360), randf(360))

		sx = randf(width)
		sy = randf(height)
		openvg.StrokeRGB(randcolor(), randcolor(), randcolor(), 1)
		openvg.StrokeWidth(randf(5))
		openvg.Line(sx, sy, sx+randf(200), sy+randf(100))
		openvg.StrokeWidth(0)

		sx = randf(width)
		sy = randf(height)
		ex = sx + randf(200)
		ey = sy
		cx = sx + ((ex - sx) / 2.0)
		cy = sy + randf(100)
		openvg.Qbezier(sx, sy, cx, cy, ex, ey)

		sx = randf(width)
		sy = randf(height)
		ex = sx + randf(200)
		ey = sy
		cx = sx + ((ex - sx) / 2.0)
		cy = sy + randf(100)
		px = cx
		py = sy - randf(100)
		openvg.Cbezier(sx, sy, cx, cy, px, py, ex, ey)

		pox = randf(width)
		poy = randf(height)
		for j := 0; j < np; j++ {
			polyx[j] = pox + randf(200)
			polyy[j] = poy + randf(100)
		}
		openvg.Polygon(polyx, polyy) // , np)

		pox = randf(width)
		poy = randf(height)
		for j := 0; j < np; j++ {
			polyx[j] = pox + randf(200)
			polyy[j] = poy + randf(100)
		}
		openvg.Polyline(polyx, polyy) // , np)
	}
	openvg.FillRGB(128, 0, 0, 1)
	openvg.Text(20, 20, "OpenVG on the Raspberry Pi", "sans", 32)
	openvg.End()
}
Beispiel #4
0
func main() {
	var cx, cy, cw, ch, midy int
	message := "Now is the time for all good men to come to the aid of the party"

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

	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)
}
Beispiel #5
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()
}
Beispiel #6
0
// show the current time, weather and headlines
func main() {
	var (
		section    = flag.String("h", "u.s.", "headline type (arts, health, sports, science, technology, u.s., world, hn)")
		location   = flag.String("loc", "40.6213,-74.4395", "lat,long for weather")
		bgcolor    = flag.String("bg", "slateblue", "background color")
		textcolor  = flag.String("tc", "white", "text color")
		width      = flag.Int("width", 0, "screen width")
		height     = flag.Int("height", 0, "screen height")
		smartcolor = flag.Bool("sc", false, "smart colors")
		thumb      = flag.Bool("tn", false, "show thumbnails")
	)
	flag.Parse()

	// initial display
	dw, dh := openvg.Init()
	if *width > 0 && *height > 0 {
		dw, dh = *width, *height
	}
	openvg.Start(dw, dh)
	canvas := display{
		width:     openvg.VGfloat(dw),
		height:    openvg.VGfloat(dh),
		bgcolor:   *bgcolor,
		textcolor: *textcolor,
	}
	canvas.countdown()
	openvg.End()
	canvas.clock(*smartcolor)
	canvas.weather(*location)
	canvas.headlines(*section, *thumb)

	// update on specific intervals, shutdown on interrupt
	dateticker := time.NewTicker(1 * time.Minute)
	weatherticker := time.NewTicker(5 * time.Minute)
	headticker := time.NewTicker(10 * time.Minute)
	sigint := make(chan os.Signal, 1)
	signal.Notify(sigint, os.Interrupt)

	for {
		select {
		case <-dateticker.C:
			canvas.clock(*smartcolor)
		case <-weatherticker.C:
			canvas.weather(*location)
		case <-headticker.C:
			canvas.headlines(*section, *thumb)
		case <-sigint:
			openvg.Finish()
			os.Exit(0)
		}
	}
}
Beispiel #7
0
// raspberry pi, scaled to the screen dimensions
func raspi(w, h int, s string) {
	midx := float64(w) / 2
	midy := float64(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)-float64(fontsize*2), s, "sans", fontsize)
	openvg.End()
}
Beispiel #8
0
func draw(w, h openvg.VGfloat) {
	paintBG(w, h)

	var p particle
	var grav = openvg.VGfloat(gravity)
	for i := 0; i < nparticles; i++ {
		p = particles[i]
		openvg.FillRGB(p.r, p.g, p.b, 1)
		openvg.Circle(p.x, p.y, p.radius)

		// Apply the velocity
		p.x += p.vx
		p.y += p.vy

		p.vx *= 0.98
		if p.vy > 0 {
			p.vy *= 0.97
		}

		// Gravity
		p.vy -= grav

		// Stop p leaving the canvas
		if p.x < -50 {
			p.x = w + 50
		}
		if p.x > w+50 {
			p.x = -50
		}

		// When particle reaches the bottom of screen reset velocity & start posn
		if p.y < -50 {
			p.x = 0
			p.y = 0
			p.vx = openvg.VGfloat(rand.Intn(maxrand)%30) + 30
			p.vy = openvg.VGfloat(rand.Intn(maxrand)%20) + 40

			if directionRTL {
				p.vx *= -1
				p.x = w
			}
		}

		if p.y > h+50 {
			p.y = -50
		}
		particles[i] = p
	}
	openvg.End()
}
Beispiel #9
0
//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()
}
Beispiel #10
0
// textplay exercises text functions
func textplay(w, h int) {
	forlo := `For lo, the winter is past, the rain is over and gone. The flowers appear on the earth, the time for the singing of birds is come, and the voice of the turtle is heard in our land.`

	// forsince := `For since by man came death, by man came also the resurrection of the dead, for as in Adam all die, even so in Christ shall all be made alive.`

	openvg.Start(w, h)
	tw := 300.0
	for x, y := 50.0, float64(h)-100.0; x < float64(w/2); x += 400 {
		textwrap(x, y, tw, forlo, "sans", 12, 24, 0.25, "black")
		textwrap(x, y-400, tw, forlo, "sans", 12, 24, 0.5, "black")
		tw -= 100
	}
	openvg.End()
}
Beispiel #11
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()
	openvg.Start(w, h)
	openvg.FillColor("white")
	openvg.Rect(0, 0, gwidth, gheight)
	filenames := flag.Args()
	if len(filenames) == 0 {
		doplot(beginx, beginy, "")
	} else {
		plotgrid(beginx, beginy, filenames)
	}
	openvg.End()
	bufio.NewReader(os.Stdin).ReadByte()
	openvg.Finish()
}
Beispiel #12
0
func InitDisplay(iw, ih int) {
	sWidth, sHeight = openvg.Init()
	iWidth, iHeight = iw, ih
	out = make([]C.VGubyte, iw*ih*VG_CHANS)

	// clear screen to opaque black
	openvg.StartColor(sWidth, sHeight, "black", 1.0)
	openvg.End()

	// apply scale transform so images fill the screen
	ScaleImage(float64(sWidth)/float64(iWidth),
		float64(sHeight)/float64(iHeight))

	fmt.Printf("Image display initialised to (%d, %d)\n", iw, ih)
}
Beispiel #13
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()
}
Beispiel #14
0
// clock displays the current time
func (d *display) clock(smartcolor bool) {
	if smartcolor {
		d.bgcolor = daycolor()
	}
	cdim := dimen{x: d.width / 2, y: d.height / 2, width: d.width / 2, height: d.height / 2}
	cdim.regionFill(d.bgcolor, d.textcolor)
	clocksize := d.width / 20
	cs := int(clocksize)
	x := d.width * 0.95
	y := d.height * 0.70

	now := time.Now()
	openvg.TextEnd(x, y, now.Format("3:04 pm"), "sans", cs)
	openvg.TextEnd(x, y+(clocksize*2), now.Format("Monday January _2"), "sans", cs/2)
	openvg.End()
}
Beispiel #15
0
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, 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
}
Beispiel #16
0
func gradient(width, height int) {
	w := float64(width)
	h := float64(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()
}
Beispiel #17
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()
}
Beispiel #18
0
// textplay exercises text functions
func textplay(w, h int) {
	forlo := `For lo, the winter is past, the rain is over and gone. The flowers appear on the earth, the time for the singing of birds is come, and the voice of the turtle is heard in our land.`

	// forsince := `For since by man came death, by man came also the resurrection of the dead, for as in Adam all die, even so in Christ shall all be made alive.`

	openvg.Start(w, h)
	var (
		tw     openvg.VGfloat = 300
		begin  openvg.VGfloat = 50
		xincr  openvg.VGfloat = 400
		offset openvg.VGfloat = 100
	)
	for x, y := begin, openvg.VGfloat(h)-offset; x < openvg.VGfloat(w/2); x += xincr {
		textwrap(x, y, tw, forlo, "sans", 12, 24, 0.25, "black")
		textwrap(x, y-400, tw, forlo, "sans", 12, 24, 0.5, "black")
		tw -= offset
	}
	openvg.End()
}
Beispiel #19
0
// sunearth shows the relative sizes of the sun and the earth
func sunearth(w, h int) {
	var sun, earth, x, y float64

	openvg.Start(w, h)
	openvg.Background(0, 0, 0)
	openvg.FillRGB(255, 255, 255, 1)
	for i := 0; i < w/4; i++ {
		x = randf(w)
		y = randf(h)
		openvg.Circle(x, y, 2)
	}
	earth = float64(w) * 0.010
	sun = earth * 109
	openvg.FillRGB(0, 0, 255, 1)
	openvg.Circle(float64(w/3), float64(h-(h/10)), earth)
	openvg.FillRGB(255, 255, 224, 1)
	openvg.Circle(float64(w), 0, sun)
	openvg.End()
}
Beispiel #20
0
// testpattern shows a test pattern
func testpattern(w, h int, s string) {
	var midx, midy1, midy2, midy3 float64
	fontsize := 256
	h2 := float64(h / 2)
	by := float64(h - 100)
	bx := float64(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 = float64(w / 2)

	// Adjust the baselines to be medial
	midy1 = h2 + 20 + float64((tw1.fontsize)/2)
	midy2 = h2 - float64((tw2.fontsize)/2)
	midy3 = h2 - 20 - float64(tw2.fontsize) - float64((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()
}
Beispiel #21
0
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
		}
	}
}
Beispiel #22
0
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
}
Beispiel #23
0
// rotext draws text, rotated around the center of the screen, progressively faded
func rotext(w, h, n int, s string) {
	fade := (100.0 / float64(n)) / 100.0
	deg := 360.0 / float64(n)
	x := float64(w) / 2.0
	y := float64(h) / 2.0
	alpha := 1.0
	size := w / 8

	openvg.Start(w, h)
	openvg.Background(0, 0, 0)
	openvg.Translate(x, y)
	for i := 0; i < n; i++ {
		openvg.FillRGB(255, 255, 255, alpha)
		openvg.Text(0, 0, s, "serif", size)
		alpha -= fade // fade
		size += n     // enlarge
		openvg.Rotate(deg)
	}
	openvg.End()
}
Beispiel #24
0
// 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)
}
Beispiel #25
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()
}
Beispiel #26
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()
}
Beispiel #27
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()
}
Beispiel #28
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()
}
Beispiel #29
0
// fontrange shows a range of fonts
func fontrange(w, h int) {
	var x, lx, length float64
	y := float64(h) / 2.0
	w2 := float64(w) / 2.0
	spacing := 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 += float64(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 += float64(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()
}
Beispiel #30
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()
}