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) }
// 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 := openvg.VGfloat(w) * 0.50 lmargin := openvg.VGfloat(w) * 0.10 top := openvg.VGfloat(h) * .9 mid := openvg.VGfloat(h) * .6 bot := openvg.VGfloat(h) * .3 fontsize := 24 leading := openvg.VGfloat(40.0) lfontsize := fontsize * 2 midb := ((leading * 2) + (leading / 2)) - openvg.VGfloat(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() }
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 = 0.5 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) }
// 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 openvg.VGfloat np := 10 polyx := make([]openvg.VGfloat, np) polyy := make([]openvg.VGfloat, np) openvg.Start(width, height) for i := 0; i < n; i++ { openvg.FillRGB(randcolor(), randcolor(), randcolor(), openvg.VGfloat(rand.Float32())) 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() }
// showgrid xrays a slide func showgrid(d deck.Deck, n int, p float64) { w := openvg.VGfloat(d.Canvas.Width) h := openvg.VGfloat(d.Canvas.Height) percent := openvg.VGfloat(p) fs := (w / 100) // labels are 1% of the width xpct := (percent / 100.0) * w ypct := (percent / 100.0) * h openvg.StrokeColor("lightgray", 0.5) openvg.StrokeWidth(3) // horizontal gridlines xl := percent for x := xpct; x <= w; x += xpct { openvg.Line(x, 0, x, h) openvg.Text(x, percent, fmt.Sprintf("%.0f%%", xl), "sans", int(fs)) xl += percent } // vertical gridlines yl := percent for y := ypct; y <= h; y += ypct { openvg.Line(0, y, w, y) openvg.Text(percent, y, fmt.Sprintf("%.0f%%", yl), "sans", int(fs)) yl += percent } // show boundary and location of images if n < 0 || n > len(d.Slide) { return } for _, im := range d.Slide[n].Image { x := pct(im.Xp, w) y := pct(im.Yp, h) iw := openvg.VGfloat(im.Width) ih := openvg.VGfloat(im.Height) if im.Scale > 0 { iw *= openvg.VGfloat(im.Scale / 100) ih *= openvg.VGfloat(im.Scale / 100) } openvg.FillRGB(127, 0, 0, 0.3) openvg.Circle(x, y, fs) openvg.FillRGB(255, 0, 0, 0.1) openvg.Rect(x-iw/2, y-ih/2, iw, ih) } openvg.End() }
//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) } }
// 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 } } }
// rotext draws text, rotated around the center of the screen, progressively faded func rotext(w, h, n int, s string) { fade := (100.0 / openvg.VGfloat(n)) / 100.0 deg := 360.0 / openvg.VGfloat(n) x := openvg.VGfloat(w) / 2.0 y := openvg.VGfloat(h) / 2.0 alpha := openvg.VGfloat(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() }
// textwrap draws text at location, wrapping at the specified width func textwrap(x, y, w openvg.VGfloat, s string, font string, fs, leading, factor openvg.VGfloat) { size := int(fs) if font == "mono" { factor = 1.0 } wordspacing := openvg.TextWidth("m", font, size) words := strings.FieldsFunc(s, whitespace) xp := x yp := y edge := x + w for _, s := range words { tw := openvg.TextWidth(s, font, size) openvg.Text(xp, yp, s, font, size) xp += tw + (wordspacing * factor) if xp > edge { xp = x yp -= leading } } }
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() }
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) }
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) }
// 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() }