Pen:
Filter:
Classes | GUI > Accessories

Pen : Object

Draw custom graphics
Source: QPen.sc
Subclasses: QPen

Description

A class which allows you to draw custom graphics on a UserView or Window.

The following methods must be called within a Window: -drawFunc or a UserView: -drawFunc function, and will only be visible once the window or the view is refreshed. Each call to Window: -refresh or UserView: -refresh will 'overwrite' all previous drawing by executing the currently defined function, unless UserView: -clearOnRefresh is set to false

Class Methods

Construct path

The following methods define paths. You will need to call *stroke or *fill to actually draw them.

Pen.moveTo(point)

Move the Pen to point.

Arguments:

point

An instance of Point

Pen.lineTo(point)

Draw a line (define a path) from the current position to point.

Arguments:

point

An instance of Point

Pen.line(p1, p2)

Draw a line (define a path) from p1 to p2. Current position will be p2.

Arguments:

p1

An instance of Point

p2

An instance of Point

Pen.curveTo(endPoint, cPoint1, cPoint2)

Draws a cubic bezier curve from the current position to point. cpoint1 and cpoint2 are control points determining the curve's curvature.

Arguments:

endPoint

An instance of Point

cPoint1

An instance of Point

cPoint2

An instance of Point

Pen.quadCurveTo(endPoint, cPoint)

Draws a quad bezier curve from the current position to point. cpoint is a control point determining the curve's curvature.

Arguments:

endPoint

An instance of Point

cPoint

An instance of Point

Pen.arcTo(point1, point2, radius)

Draws an arc of a circle using a radius and tangent points.

Arguments:

point1

The end point of the first tangent line. Its start point is the current position. An instance of Point

point2

The end point of the second tangent line. Its start point is point1. An instance of Point

radius

The radius of the arc.

Discussion:

example:

Pen.addArc(center, radius, startAngle, arcAngle)

Draw an arc around the Point center, at radius number of pixels. startAngle and arcAngle refer to the starting angle and the extent of the arc, and are in radians [0..2pi].

Discussion:

example:

Pen.addWedge(center, radius, startAngle, sweepLength)

Draw a wedge around the Point center, at radius number of pixels. startAngle and sweepLength refer to the starting angle and the extent of the arc, and are in radians [0..2pi].

Discussion:

example:

Pen.addAnnularWedge(center, innerRadius, outerRadius, startAngle, sweepLength)

Draw an annular wedge around the Point center, from innerRadius to outerRadius in pixels. startAngle and sweepLength refer to the starting angle and the extent of the arc, and are in radians [0..2pi].

Discussion:

example:

Pen.addRect(aRect)

Adds a Rect to the drawing.

Discussion:

example:

Pen.addOval(rect)

Adds an Oval shape that fits inside the Rect to the current path.

Draw the path

Pen.stroke

Outline the previous defined path.

Discussion:

example:

Pen.fill

Fill the previous defined path.

Discussion:

example:

Pen.draw(style)

Draw the previous defined path using any of the following options:

Arguments:

style
0fill
1fill using even-odd rule
2stroke
3fill and stroke the current path
4fill and stroke using even-odd rule

Discussion:

example:

Pen.fillStroke

Fill and stroke the current path. Shortcut to the draw(3) method.

Construct and draw

These methods do not require separate calls to *stroke or *fill.

Pen.strokeRect(rect)

Strokes a Rect into the window.

Pen.fillRect(rect)

Draws a filled Rect into the window.

Pen.strokeOval(rect)

Strokes an oval into the window.

Pen.fillOval(rect)

Draws a filled oval into the window.

Gradients

Pen.fillAxialGradient(startPoint, endPoint, startColor, endColor)

Fills an Axial gradient.

Discussion:

example:

Pen.fillRadialGradient(innerCircleCenter, outerCircleCenter, startRadius, endRadius, startColor, endColor)

Fills a Radial gradient.

Discussion:

example:

Graphics State Methods

The following commands transform the graphics state, i.e. they effect all subsequent drawing commands. These transformations are cumulative, i.e. each command applies to the previous graphics state, not the original one.

Pen.translate(x: 0, y: 0)

Translate the coordinate system to have its origin moved by x,y

Discussion:

example:

Cumulative translations:

Pen.scale(x: 0, y: 0)

Scales subsequent drawing. x and y are scaling factors (i.e. 1 is normal, 2 is double size, etc.).

Discussion:

example:

Pen.skew(x: 0, y: 0)

Skews subsequent drawing. x and y are skewing factors (i.e. 1 is normal).

Discussion:

example:

Pen.rotate(angle: 0, x: 0, y: 0)

Rotates subsequent drawing around the Point x@y by the amount angle in radians [0..2pi].

Discussion:

example:

Pen.matrix

Pen.matrix = matrixArray

Gets or sets the coordinate system transformation matrix.

See Matrix example for an example.

Arguments:

matrixArray

An array of the form [ zoomX, shearingY, shearingX, zoomY, translateX, translateY ]

Pen.width = width

Sets the width of the Pen for the whole stroke

Pen.use(aFunction)

Draw function, and then revert to the previous graphics state. This allows you to make complex transformations of the graphics state without having to explicitly revert to get back to 'normal'.

Discussion:

example:

Pen.path

Make a path, consisting of the drawing made in function.

NOTE: Unfortunately not working for now... (there's no Pen.endPath which currently is used in this method)

Pen.beginPath

Discard any previous path.

Pen.beginTransparencyLayer

Begins a new transparency layer. Transparency layers are useful when you want to apply an effect to a group of objects or create a composite graphic. See Transparency layer example.

Pen.endTransparencyLayer

Ends the current transparency layer.

Pen.clip

Use the previously defined path as a clipping path.

Discussion:

example:

Pen.smoothing = flag

Turns on/off anti-aliasing.

Discussion:

example:

Pen.setShadow(offsetPoint, blur, color)

Will fill the current path with a shadow. You should use this option between Pen.push / Pen.pop (or Pen.use)

Pen.joinStyle = style

Set the lines joining style according to the defined options:

0miter
1round
2bevel

Pen.capStyle = style

Set the lines joining style according to the defined options:

0butt
1round
2square

Discussion:

example:

Pen.alpha = value

Set the opacity level.

Pen.blendMode = mode

Set the blending mode to use. See Blending modes for more information.

Pen.lineDash = pattern

Set the line dash pattern. pattern should be a FloatArray of values that specify the lengths of the painted segments and not painted segments.

Pen.drawImage(target, image, source, operation: 'sourceOver', opacity: 1.0)

Draw a bitmap image using the Image class.

Discussion:

example:

Inherited class methods

Undocumented class methods

Pen.addCurve(start, c1, c2, end, div: 10)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-addCurve.sc

Pen.addQuadCurve(start, c1, end, div: 10)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-addCurve.sc

Pen.addRoundedRect(aRect, radiusX, radiusY)

Pen.addWedge_Deg(center, radius, startAngle, sweepLength)

Pen.arrow(start, end, width: 5, arrowAngle: 1.5707963267949)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-arrow.sc

Pen.arrow_round(start, end, width: 5, arrowAngle: 1.5707963267949)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-arrow.sc

Pen.circle(rect)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-roundedRect.sc

Pen.color = aColor

Pen.cross(center, radius: 5, shape: '+')

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-arrow.sc

Pen.drawIcon(symbol: 'play', rect ... args)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extDrawIcon.sc

Pen.drawSpline(start, c1, c2, end, strokeColor, controlColor, div: 10)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-addCurve.sc

Pen.extrudedCircle(rect, width: 2, angle, inverse: false, colors)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-roundedRect.sc

Pen.extrudedRect(rect, radius, width: 2, angle, inverse: false, colors)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-roundedRect.sc

Pen.fillColor = aColor

Pen.font

Pen.font = aFont

Pen.nonimpl(methodName)

Pen.pop

Pen.prBegin(aView)

Pen.prEnd

Pen.push

Pen.rotateDeg(angle: 0, x: 0, y: 0)

Pen.roundedRect(rect, radius)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-roundedRect.sc

Pen.splineCurve(point1, point2, cpoint1, cpoint2, div: 10)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/Main Features/Interpolation/extPen-splineCurve.sc

Pen.string(aString)

Pen.stringAtPoint(string, point, font, color)

Pen.stringCenteredIn(string, rect, font, color)

Pen.stringInRect(string, rect, font, color, alignment)

Pen.stringLeftJustIn(string, rect, font, color)

Pen.stringRightJustIn(string, rect, font, color)

Pen.strokeColor = aColor

Pen.tileImage(target, image, source, operation: 'sourceOver', opacity: 1.0)

Pen.transformToRect(rect, fromRect, keepRatio: false, scale: 1, move: 0.5)

From extension in /home/bgola/.local/share/SuperCollider/downloaded-quarks/wslib/wslib-classes/GUI/Drawing/extPen-transformToRect.sc

Instance Methods

Inherited instance methods

Examples

Simple rotating and scaling:

Redraw at random interval, different every time:

Animation

Uses random seed to 'store' data By reseting the seed each time the same random values and shapes are generated for each 'frame' These can then be subjected to cumulative rotation, etc., by simply incrementing the phase var.

Matrix example

Transparency layer example

Blending modes