作者:sequoia
项目:openv
// 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()
}
作者:xranb
项目:openv
// 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 := "[email protected]"
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()
}
作者:jhautefeuill
项目:openv
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()
}
作者:sequoia
项目:openv
// 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()
}
作者:sequoia
项目:openv
//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()
}
作者:sequoia
项目:openv
// 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 := "[email protected]"
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()
}
作者:sequoia
项目:openv
// 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()
}
作者:jhautefeuill
项目:openv
// 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()
}
作者:xranb
项目:openv
func imagetable(w, h int) {
imgw, imgh := 422, 238
itable := []string{
"desert0.jpg",
"desert1.jpg",
"desert2.jpg",
"desert3.jpg",
"desert4.jpg",
"desert5.jpg",
"desert6.jpg",
"desert7.jpg",
}
left := 50.0
bot := float64(h-imgh) - 50.0
gutter := 50.0
x := left
y := bot
openvg.Start(w, h)
openvg.BackgroundColor("black")
for _, iname := range itable {
openvg.Image(x, y, imgw, imgh, iname)
openvg.FillRGB(255, 255, 255, 0.3)
openvg.Rect(x, y, float64(imgw), 32)
openvg.FillRGB(0, 0, 0, 1)
openvg.TextMid(x+float64(imgw/2), y+10, iname, "sans", 16)
x += float64(imgw) + gutter
if x > float64(w) {
x = left
y -= float64(imgh) + gutter
}
}
y = float64(h) * 0.1
openvg.FillRGB(128, 128, 128, 1)
openvg.TextMid(float64(w/2), 100, "Joshua Tree National Park", "sans", 48)
openvg.End()
}
作者:jhautefeuill
项目:openv
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()
}
作者:xranb
项目:openv
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, 77, 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.SaveEnd("hello.raw") // End the picture
bufio.NewReader(os.Stdin).ReadBytes('\n') // Pause until [RETURN]
openvg.Finish() // Graphics cleanup
}
作者:Ebirol
项目:openv
// 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()
}
作者:jhautefeuill
项目:openv
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)
}
作者:sequoia
项目:openv
func main() {
width, height := openvg.Init() // OpenGL, etc initialization
w2 := float64(width / 2)
h2 := float64(height / 2)
w := float64(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
bufio.NewReader(os.Stdin).ReadBytes('\n') // Pause until [RETURN]
openvg.Finish() // Graphics cleanup
}
作者:sequoia
项目:openv
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()
}
作者:jhautefeuill
项目:openv
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()
}
作者:jhautefeuill
项目:openv
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
}
作者:Ebirol
项目:openv
// gerror makes a graphical error message
func (d *dimen) gerror(bgcolor, textcolor, message string) {
d.regionFill(bgcolor, textcolor)
openvg.TextMid(d.x+d.width/2, d.y+d.height/2, message, "sans", int(d.width/20))
openvg.End()
}
作者:sequoia
项目:openv
// 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 float64, 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 []float64
if needpoly {
xpoly = make([]float64, nd+2)
ypoly = make([]float64, 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 := 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 := math.Floor(miny)
top := math.Ceil(maxy)
yrange := top - bot
interval := yrange / float64(settings.size["yinterval"])
for yax := bot; yax <= top; yax += interval {
yaxp := fmap(yax, bot, top, float64(y), float64(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)
//.........这里部分代码省略.........
作者:sequoia
项目:openv
// textlines writes openvg.Lines of text
func textlines(x, y float64, text []string, f string, fontsize int, leading float64) {
for _, s := range text {
openvg.TextMid(x, y, s, f, fontsize)
y -= leading
}
}