openvg: github.com/ajstarks/openvg Index | Files | Directories

package openvg

import "github.com/ajstarks/openvg"

Package openvg is a wrapper to a C library of high-level 2D graphics operations built on OpenVG 1.1

The typical "hello world" program looks like this:

package main

import (
	"bufio"
	"github.com/ajstarks/openvg"
	"os"
)

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("rgb(100,255,123)")                      // 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
}

Functions

The Init function provides the necessary graphics subsystem initialization and the dimensions of the whole canvas. The Init() call must be paired with a corresponding Finish() call, which performs an orderly shutdown.

Typically a "drawing" begins with the Start() call, and ends with End(). A program can have an arbitrary set of Start()/End() pairs.

The coordinate system uses float64 coordinates, with the origin at the lower left, with x increasing to the right, and y increasing upwards.

Currently, the library provides no mouse or keyboard events, other than those provided by the base operating system. It is typical to pause for user input between drawings by reading standard input.

The library's functionally includes shapes, attributes, transformations, text, images, and convenince functions. Shape functions include Polygon, Polyline, Cbezier, Qbezier, Rect, Roundrect, Line, Elipse, Circle, and Arc. Transformation functions are: Translate, Rotate, Shear, and Scale. For displaying and measuring text: Text, TextMid, TextEnd, and TextWidth. The attribute functions are StrokeColor, StrokeRGB, StrokeWidth, and FillRGB, FillColor, FillLinearGradient, and FillRadialGradient. Colors are specfied with RGB triples (0-255) with alpha values (0.0-1.0), or named colors as specified by the SVG standard.

Convenience functions are used to set the Background color, start the drawing with a background color, and save the raster to a file. The input terminal may be set/restored to/from raw and cooked mode.

Package openvg is a high-level 2D vector graphics library built on OpenVG

Index

Package Files

doc.go openvg.go

func Arc Uses

func Arc(x, y, w, h, sa, aext VGfloat)

Arc draws an arc at (x,y) with dimensions (w,h). the arc starts at the angle sa, extended to aext

func AreaClear Uses

func AreaClear(x, y, w, h int)

AreaClear clears a given rectangle in window coordinates

func Background Uses

func Background(r, g, b uint8)

Background clears the screen with the specified solid background color using RGB triples

func BackgroundColor Uses

func BackgroundColor(s string, alpha ...VGfloat)

BackgroundColor sets the background color

func BackgroundRGB Uses

func BackgroundRGB(r, g, b uint8, alpha VGfloat)

BackgroundRGB clears the screen with the specified background color using a RGBA quad

func Cbezier Uses

func Cbezier(sx, sy, cx, cy, px, py, ex, ey VGfloat)

Cbezier draws a cubic bezier curve with extrema (sx, sy) and (ex, ey). Control points at (cx, cy) and (px, py)

func Circle Uses

func Circle(x, y, r VGfloat)

Circle draws a circle centered at (x,y), with radius r

func ClipEnd Uses

func ClipEnd()

ClipEnd stops limiting drawing area to specified rectangle

func ClipRect Uses

func ClipRect(x, y, w, h int)

ClipRect limits the drawing area to specified rectangle

func Ellipse Uses

func Ellipse(x, y, w, h VGfloat)

Ellipse draws an ellipse at (x,y) with dimensions (w,h)

func End Uses

func End()

End ends the picture

func FillColor Uses

func FillColor(s string, alpha ...VGfloat)

FillColor sets the fill color using names to specify the color, optionally applying alpha.

func FillLinearGradient Uses

func FillLinearGradient(x1, y1, x2, y2 VGfloat, ramp []Offcolor)

FillLinearGradient sets up a linear gradient between (x1,y2) and (x2, y2) using the specified offsets and colors in ramp

func FillRGB Uses

func FillRGB(r, g, b uint8, alpha VGfloat)

FillRGB sets the fill color, using RGB triples and alpha values

func FillRadialGradient Uses

func FillRadialGradient(cx, cy, fx, fy, radius VGfloat, ramp []Offcolor)

FillRadialGradient sets up a radial gradient centered at (cx, cy), radius r, with a focal point at (fx, fy) using the specified offsets and colors in ramp

func Finish Uses

func Finish()

Finish shuts down the graphics subsystem

func Image Uses

func Image(x, y VGfloat, w, h int, s string)

Image places the named image at (x,y) with dimensions (w,h) the specified derived image dimensions override the native ones.

func Img Uses

func Img(x, y VGfloat, im image.Image)

Img places an image object at (x,y)

func Init Uses

func Init() (int, int)

Init initializes the graphics subsystem

func InitWindowSize Uses

func InitWindowSize(x, y, w, h int)

InitWidowSize initialized the graphics subsystem with specified dimensions

func Line Uses

func Line(x1, y1, x2, y2 VGfloat)

Line draws a line between two points

func Polygon Uses

func Polygon(x, y []VGfloat)

Polygon draws a polygon with coordinate in x,y

func Polyline Uses

func Polyline(x, y []VGfloat)

Polyline draws a polyline with coordinates in x, y

func Qbezier Uses

func Qbezier(sx, sy, cx, cy, ex, ey VGfloat)

Qbezier draws a quadratic bezier curve with extrema (sx, sy) and (ex, ey) Control points are at (cx, cy)

func RawTerm Uses

func RawTerm()

RawTerm sets the terminal to raw mode

func Rect Uses

func Rect(x, y, w, h VGfloat)

Rect draws a rectangle at (x,y) with dimesions (w,h)

func RestoreTerm Uses

func RestoreTerm()

RestoreTerm retores terminal settings

func Rotate Uses

func Rotate(r VGfloat)

Rotate rotates the coordinate system around the specifed angle

func Roundrect Uses

func Roundrect(x, y, w, h, rw, rh VGfloat)

Roundrect draws a rounded rectangle at (x,y) with dimesions (w,h). the corner radii are at (rw, rh)

func SaveEnd Uses

func SaveEnd(filename string)

SaveEnd ends the picture, saving the raw raster

func SaveTerm Uses

func SaveTerm()

SaveTerm saves terminal settings

func Scale Uses

func Scale(x, y VGfloat)

Scale scales the coordinate system by (x,y)

func Shear Uses

func Shear(x, y VGfloat)

Shear warps the coordinate system by (x,y)

func Start Uses

func Start(w, h int, color ...uint8)

Start begins a picture

func StartColor Uses

func StartColor(w, h int, color string, alpha ...VGfloat)

StartColor begins the picture with the specified color background

func StrokeColor Uses

func StrokeColor(s string, alpha ...VGfloat)

StrokeColor sets the fill color using names to specify the color, optionally applying alpha.

func StrokeRGB Uses

func StrokeRGB(r, g, b uint8, alpha VGfloat)

StrokeRGB sets the stroke color, using RGB triples

func StrokeWidth Uses

func StrokeWidth(w VGfloat)

StrokeWidth sets the stroke width

func Text Uses

func Text(x, y VGfloat, s string, font string, size int)

Text draws text whose aligment begins (x,y)

func TextEnd Uses

func TextEnd(x, y VGfloat, s string, font string, size int)

TextEnd draws text end-aligned at (x,y)

func TextMid Uses

func TextMid(x, y VGfloat, s string, font string, size int)

TextMid draws text centered at (x,y)

func Translate Uses

func Translate(x, y VGfloat)

Translate translates the coordinate system to (x,y)

func WindowClear Uses

func WindowClear()

WindowClear clears the window to previously set background color

func WindowOpacity Uses

func WindowOpacity(a uint)

WindowOpacity sets the window's opacity

func WindowPosition Uses

func WindowPosition(x, y int)

WindowPostion places a window

type Offcolor Uses

type Offcolor struct {
    Offset VGfloat
    RGB
    Alpha VGfloat
}

Offcolor defines the offset, color and alpha values used in gradients the Offset ranges from 0..1, colors as RGB triples, alpha ranges from 0..1

type RGB Uses

type RGB struct {
    Red, Green, Blue uint8
}

RGB defines the red, green, blue triple that makes up colors.

func Colorlookup Uses

func Colorlookup(s string) RGB

Colorlookup returns a RGB triple corresponding to the named color, or "rgb(r,g,b)" string. On error, return black.

type VGfloat Uses

type VGfloat C.VGfloat

VGfloat defines the basic type for coordinates, dimensions and other values

func TextDepth Uses

func TextDepth(font string, size int) VGfloat

TextDepth returns the distance below the baseline for a specified font

func TextHeight Uses

func TextHeight(font string, size int) VGfloat

TextHeight returns a font's height (ascent)

func TextWidth Uses

func TextWidth(s string, font string, size int) VGfloat

TextWidth returns the length of text at a specified font and size

type VGint Uses

type VGint C.VGint

Directories

PathSynopsis
go-client/bubtrailbubtrail draws a randmonized trail of bubbles
go-client/charsfirst OpenVG program
go-client/clipclip: test rectangular clipping
go-client/clockclock
go-client/colortabcolortab -- make a color/code placemat
go-client/hellovgfirst OpenVG program
go-client/hgradfirst OpenVG program, with gradients
go-client/particles
go-client/picshowpicshow: show pictures
go-client/planetsplanets: an exploration of scale
go-client/randcirclerandcircle -- random circles
go-client/raspiraspberry pi self-portrait
go-client/shapedemoshapedemo demonstrates the OpenVG library
go-client/splashsplash: show a splash screen image suggested by Mike Kazantsev
go-client/twhtwh: time, weather, headlines
go-client/vgplotvgplot -- plot data (a stream of x,y coordinates)
utilraw2png - convert RGBA bytes to PNG

Package openvg imports 10 packages (graph) and is imported by 18 packages. Updated 2016-07-21. Refresh now. Tools for package owners.