Pen:
Filter:
Classes | GUI > Accessories

Pen

Draw custom graphics
Location: NOT INSTALLED!

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.

.moveTo

Move the Pen to point.

Arguments:

point

An instance of Point

.lineTo

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

Arguments:

point

An instance of Point

.line

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

.curveTo

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

.quadCurveTo

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

.arcTo

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:

.addArc

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:

.addWedge

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:

.addAnnularWedge

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:

.addRect

Adds a Rect to the drawing.

Discussion:

example:

.addOval

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

Draw the path

.stroke

Outline the previous defined path.

Discussion:

example:

.fill

Fill the previous defined path.

Discussion:

example:

.draw

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:

.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.

.strokeRect

Strokes a Rect into the window.

.fillRect

Draws a filled Rect into the window.

.strokeOval

Strokes an oval into the window.

.fillOval

Draws a filled oval into the window.

Gradients

.fillAxialGradient

Fills an Axial gradient.

Discussion:

example:

.fillRadialGradient

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.

.translate

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

Discussion:

example:

Cumulative translations:

.scale

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

Discussion:

example:

.skew

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

Discussion:

example:

.rotate

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

Discussion:

example:

.matrix

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 ]

.width

Sets the width of the Pen for the whole stroke

.use

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:

.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)

.beginPath

Discard any previous path.

.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.

.endTransparencyLayer

Ends the current transparency layer.

.clip

Use the previously defined path as a clipping path.

Discussion:

example:

.smoothing

Turns on/off anti-aliasing.

Discussion:

example:

.setShadow

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

.joinStyle

Set the lines joining style according to the defined options:

0miter
1round
2bevel

.capStyle

Set the lines joining style according to the defined options:

0butt
1round
2square

Discussion:

example:

.alpha

Set the opacity level.

.blendMode

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

.lineDash

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

.drawImage

Draw a bitmap image using the Image class.

Discussion:

example:

Inherited class methods

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