CanvasView. Drawing geometric shapes

Rectangle

Three functions can be used to draw rectangles:

FillRect(x, y, width, height float64)
StrokeRect(x, y, width, height float64)
FillAndStrokeRect(x, y, width, height float64)

FillRect draws a filled rectangle.

StrokeRect draws the outline of a rectangle.

FillAndStrokeRect draws a path and fills in the interior.

Rounded Rectangle

Similar to the rectangle, there are three drawing functions

FillRoundedRect(x, y, width, height, r float64)
StrokeRoundedRect(x, y, width, height, r float64)
FillAndStrokeRoundedRect(x, y, width, height, r float64)

where r is the radius of the rounding

Ellipse

Three functions can also be used to draw ellipses:

FillEllipse(x, y, radiusX, radiusY, rotation float64)
StrokeEllipse(x, y, radiusX, radiusY, rotation float64)
FillAndStrokeEllipse(x, y, radiusX, radiusY, rotation float64)

where x, y is the center of the ellipse, radiusX, radiusY are the radii of the ellipse along the X and Y axes,rotation - the angle of rotation of the ellipse relative to the center in radians.

Path

The Path interface allows you to describe a complex shape. Path is created using the NewPath () function.

Once created, you must describe the shape. For this, the following interface functions can be used:

  • MoveTo(x, y float64) - move the current point to the specified coordinates;
  • LineTo(x, y float64) - add a line from the current point to the specified one;
  • ArcTo(x0, y0, x1, y1, radius float64) - add a circular arc using the specified control points and radius.If necessary, the arc is automatically connected to the last point of the path with a straight line.x0, y0 - coordinates of the first control point;x1, y1 - coordinates of the second control point;radius - radius of the arc. Must be non-negative.
  • Arc(x, y, radius, startAngle, endAngle float64, clockwise bool) - add a circular arc.x, y - coordinates of the arc center;radius - radius of the arc. Must be non-negative;startAngle - The angle, in radians, at which the arc begins, measured clockwise from the positive X-axis.endAngle - The angle, in radians, at which the arc ends, measured clockwise from the positive X-axis.clockwise - if true, the arc will be drawn clockwise between the start and end corners, otherwise counterclockwise
  • BezierCurveTo(cp0x, cp0y, cp1x, cp1y, x, y float64) - add a cubic Bezier curve from the current point.cp0x, cp0y - coordinates of the first control point;cp1x, cp1y - coordinates of the second control point;x, y - coordinates of the end point.
  • QuadraticCurveTo(cpx, cpy, x, y float64) - add a quadratic Bezier curve from the current point.cpx, cpy - coordinates of the control point;x, y - coordinates of the end point.
  • Ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle float64, clockwise bool) - add an elliptical arc.x, y - coordinates of the center of the ellipse;radiusX is the radius of the major axis of the ellipse. Must be non-negative;radiusY - radius of the minor axis of the ellipse. Must be non-negative;rotation - the rotation of the ellipse, expressed in radians;startAngle The angle of the start of the ellipse in radians, measured clockwise from the positive x-axis.endAngle The angle, in radians, at which the ellipse ends, measured clockwise from the positive x-axis.clockwise - if true, draws the ellipse clockwise, otherwise counterclockwise.

The Close () function is called at the end and connects the start and end points of the shape. Used only for closed shapes.

After the Path is formed, it can be drawn using the following 3 functions

FillPath(path Path)
StrokePath(path Path)
FillAndStrokePath(path Path)

Line

To draw a line, use the function

DrawLine(x0, y0, x1, y1 float64)