Path
Table of contents
Interface allow to describe a complex shape to be drawn in CanvasView
. See NewPath
, NewPathFromSvg
, FillPath
, StrokePath
and FillAndStrokePath
methods of the Canvas
interface
Create from source
view := rui.NewCanvasView(session, rui.Params{
rui.Width: rui.Percent(100),
rui.Height: rui.Percent(100),
rui.DrawFunction: draw,
})
func draw(canvas rui.Canvas) {
path := canvas.NewPath()
path.Ellipse(100, 100, 20, 20, 0.0, 0, 360, true)
canvas.SetSolidColorFillStyle(rui.LightSalmon)
canvas.FillAndStrokePath(path)
}
Interface description
Arc(x, y, radius, startAngle, endAngle float64, clockwise bool)
Adds a circular arc to the current sub-path. x, y - coordinates of the arc's center; radius - the arc's radius. Must be non-negative; startAngle - the angle at which the arc starts, measured clockwise from the positive x-axis and expressed in radians. endAngle - the angle at which the arc ends, measured clockwise from the positive x-axis and expressed in radians. clockwise - if true, causes the arc to be drawn clockwise between the start and end angles, otherwise - counter-clockwise
ArcTo(x0, y0, x1, y1, radius float64)
Adds a circular arc to the current sub-path, using the given control points and radius. The arc is automatically connected to the path's latest point with a straight line, if necessary. x0, y0 - coordinates of the first control point; x1, y1 - coordinates of the second control point; radius - the arc's radius. Must be non-negative.
BezierCurveTo(cp0x, cp0y, cp1x, cp1y, x, y float64)
Adds a cubic Bézier curve to the current sub-path. The starting point is the latest point in the current path. cp0x, cp0y - coordinates of the first control point; cp1x, cp1y - coordinates of the second control point; x, y - coordinates of the end point.
Close()
Adds a straight line from the current point to the start of the current sub-path. If the shape has already been closed or has only one point, this function does nothing.
Ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle float64, clockwise bool)
Adds an elliptical arc to the current sub-path x, y - coordinates of the ellipse's center; radiusX - the ellipse's major-axis radius. Must be non-negative; radiusY - the ellipse's minor-axis radius. Must be non-negative; rotation - the rotation of the ellipse, expressed in radians; startAngle - the angle at which the ellipse starts, measured clockwise from the positive x-axis and expressed in radians; endAngle - the angle at which the ellipse ends, measured clockwise from the positive x-axis and expressed in radians. clockwise - if true, draws the ellipse clockwise, otherwise draws counter-clockwise
LineTo(x, y float64)
Adds a straight line to the current sub-path by connecting the sub-path's last point to the specified (x, y) coordinates
MoveTo(x, y float64)
Begins a new sub-path at the point specified by the given (x, y) coordinates
QuadraticCurveTo(cpx, cpy, x, y float64)
Adds a quadratic Bézier curve to the current sub-path. cpx, cpy - coordinates of the control point; x, y - coordinates of the end point.