Exemplo n.º 1
0
func roundhand(cx, cy, px, py, stroke openvg.VGfloat, color string) {
	openvg.StrokeWidth(stroke)
	openvg.StrokeColor(color)
	openvg.Line(cx, cy, px, py)
	openvg.StrokeWidth(0)
	openvg.FillColor(color)
	openvg.Ellipse(px, py, stroke, stroke)
}
Exemplo n.º 2
0
// wind shows the windy icon
func (d *dimen) wind(bg, color string) {
	x, y, w, h := d.x, d.y, d.width, d.height
	openvg.FillColor(bg, 0)
	openvg.StrokeWidth(w / 25)
	openvg.StrokeColor(color)
	openvg.Qbezier(x+w*0.10, y+h*0.8, x+w*0.50, y+h*0.60, x+w*0.9, y+h*0.85)
	openvg.Qbezier(x+w*0.10, y+h*0.5, x+w*0.55, y+h*0.30, x+w*0.9, y+h*0.55)
	openvg.Qbezier(x+w*0.10, y+h*0.2, x+w*0.60, y+h*0.10, x+w*0.9, y+h*0.35)
	openvg.StrokeWidth(0)
}
Exemplo n.º 3
0
func secondhand(cx, cy, sx, sy, textsize openvg.VGfloat) {
	openvg.FillColor(secolor, 0.4)
	openvg.Ellipse(sx, sy, textsize, textsize)
	if secline {
		openvg.StrokeWidth(textsize / 6)
		openvg.StrokeColor(secolor)
		openvg.Line(cx, cy, sx, sy)
		openvg.StrokeWidth(0)
	}
}
Exemplo n.º 4
0
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)

}
Exemplo n.º 5
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()
}
Exemplo n.º 6
0
func combohand(cx, cy, px, py, r, stroke openvg.VGfloat, t float64, value int, color string) {
	thinr := float64(r * 0.25)
	t = minadjust(t, value) * deg2rad
	tx := cx + openvg.VGfloat(thinr*math.Cos(t))
	ty := cy + openvg.VGfloat(thinr*math.Sin(t))
	openvg.FillColor(color)
	openvg.Ellipse(px, py, stroke*2, stroke*2)
	openvg.Ellipse(tx, ty, stroke*2, stroke*2)
	openvg.StrokeWidth(stroke)
	openvg.StrokeColor(color)
	openvg.Line(cx, cy, tx, ty)
	openvg.StrokeWidth(stroke * 2)
	openvg.Line(tx, ty, px, py)
	openvg.StrokeWidth(0)
}
Exemplo n.º 7
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()
}
Exemplo n.º 8
0
// flake shows the snowflake icon
func (d *dimen) flake(color string) {
	x, y, w, h := d.x, d.y, d.width, d.height
	cx := x + (w / 2)
	cy := y + (h / 2)
	r := w * 0.30
	openvg.StrokeColor(color)
	openvg.StrokeWidth(w / 20)
	for t := 0.0; t < 2*math.Pi; t += math.Pi / 4 {
		c := openvg.VGfloat(math.Cos(t))
		s := openvg.VGfloat(math.Sin(t))
		x1 := (r * c) + cx
		y1 := (r * s) + cy
		openvg.Line(cx, cy, x1, y1)
	}
	openvg.StrokeWidth(0)
}
Exemplo n.º 9
0
// sun shows the icon for clear weather
func (d *dimen) sun(color string) {
	x, y, w, h := d.x, d.y, d.width, d.height
	cx := x + (w / 2)
	cy := y + (h / 2)
	r0 := w * 0.50
	r1 := w * 0.45
	r2 := w * 0.30
	openvg.FillColor(color)
	openvg.Circle(cx, cy, r0)
	openvg.StrokeColor(color)
	openvg.StrokeWidth(w / 30)
	for t := 0.0; t < 2*math.Pi; t += math.Pi / 6 {
		c := openvg.VGfloat(math.Cos(t))
		s := openvg.VGfloat(math.Sin(t))
		x1 := (r1 * c) + cx
		y1 := (r1 * s) + cy
		x2 := (r2 * c) + cx
		y2 := (r2 * s) + cy
		openvg.Line(x1, y1, x2, y2)
	}
	openvg.StrokeWidth(0)
}
Exemplo n.º 10
0
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()
}
Exemplo n.º 11
0
// 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)
		}
		openvg.StrokeWidth(0)
	}
	// Finally, tack on the label, if specified
	if len(settings.attr["label"]) > 0 {
		openvg.FillColor(settings.attr["labelcolor"], 0.3)
		openvg.TextMid(x+(w/2), y+(h/2), settings.attr["label"], settings.attr["font"], int(w/8)) // int(settings.size["fontsize"]))
	}
	openvg.StrokeWidth(0)
}