Example #1
0
func light(x, y, r openvg.VGfloat, c openvg.RGB) {
	stops := []openvg.Offcolor{
		{0.0, c, 1},
		{0.50, openvg.RGB{c.Red / 2, c.Green / 2, c.Blue / 2}, 1},
	}
	openvg.FillRadialGradient(x, y, (x+r)*.90, y, r, stops)
}
Example #2
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()
}
Example #3
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
}