|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.paulhertz.aifile.DisplayComponent
net.paulhertz.aifile.BezShape
public class BezShape
Implements shapes composed of cubic Bezier curves and lines and methods to draw geometry to a display, perform geometric transforms, and write geometry to an Adobe Illustrator 7.0 file format.
The default initializations create a shape with the current fill, stroke, and stroke weight in Processing,
closed unless you specify otherwise. You can call setColors
at any time
to capture Processing's current fill, stroke, and strokeWeight, and call setIsClosed
with a value of false
to make an open shape. Unlike Processing, closed shapes
will be drawn as closed only if the start point and the end point are equal: this is required
for correct output to Illustrator. You can also set fill, stroke, and weight with BezShape's own methods
setFillColor
, setStrokeColor
and setWeight
.
Geometry is stored as an initial vertex (startPoint) and a list of vertices (Vertex2DINF
), which may be lines or Bezier curves.
The curveIterator
method returns an iterator over the vertices: note that the initial vertex is
not included, but is easily accessed with x
and y
. The center of the shape is initially set
to (0,0), as it would be in Processing. You can set the center to the center point of the geometry with a call to
calculateCenter
or to any desired point with setCenter
.
Geometric transforms around the current center point can be executed with calls to
translateShape
, rotateShape
and scaleShape
.
Generalized transforms around an arbitrary point can be executed by passing a transformation matrix to transform
.
Calling transform()
with no argument uses the most recent transformation matrix, effectively repeating the previous
call to transform
. On initialization, Processing's current transform is store in ctm
,
but it is not used to transform the shape. You can retrieve ctm
with getCtm
.
A call to getMatrix(PApplet)
will set the internal matrix
to Processing's current transformation matrix. This way you can synchronize BezShape transforms
to Processing transforms. BezShape transforms are affected by Processing's current transforms
(i.e., by calls to translate, rotate, and scale). Calling a BezShape transform while a Processing transform
is active may lead to unexpected results. See sample code for examples of
how to use and synchronize transforms.
The write()
method writes the geometry and attributes of a shape in Adobe Illustrator 7.0 format.
It is far easier to call write()
than to call AIFileWriter directly to output geometry. See the
various coding examples for different methods of writing an Illustrator file. In some instances, one line of code will do all the work.
Static methods provide automatic creation of multiCurves, multiLines, regular polygons, equilateral triangles, general triangles, rectangles, lines, curves, multilines and multicurves. These may become subclasses in the future.
/* * Sample code for IgnoCodeLib 0.3 Processing library by Paul Hertz. * Updated June 25, 2013, for IgonoCodeLib 0.3 release, not compatible with previous versions. * The writeNoTransform call is only available in 0.3 and the packages have been renamed * from com.ignotus to net.paulhertz in the import section. * Demonstrates the basics of creating BezShapes and loading them into a list. * Steps through the list to draw shapes to the display or write them to a file. * Demonstrates methods for creating colors and adding them to a palette that can * be used in Processing and exported to an Illustrator file. * Note that display in Illustrator appears flipped on a horizontal axis because * Illustrator and Processing use different coordinate systems. Other examples * show various solutions to this problem: the simplest remedy is to use the * writeWithAITransform() method in a DocumentComponent. */ import java.util.*; import java.io.*; import net.paulhertz.aifile.*; // library that defines AIFileWriter and static file i/o methods import net.paulhertz.geom.*; /** a list of shapes to draw and save */ ArrayListshapes; /** a palette of colors, stored as 32-bit integers */ ArrayList farben; /** the file we'll save to */ String fileName = "simple.ai"; /** IgnoCodeLib library */ IgnoCodeLib igno; public void setup() { size(480,720); background(127); smooth(); // Set up the library, which will store a reference to the host PApplet // for other classes in the library to use. igno = new IgnoCodeLib(this); shapes = new ArrayList (); farben = new ArrayList (); createColors(); createShapes(); println("type 's' to output file"); } /** * To draw, we just step through the shapes and tell each one to draw, passing * in a reference to the Processing PApplet "this" so that the shapes have access * to Processing's drawing functions. */ public void draw() { for (BezShape bez : shapes) { bez.draw(); } } void keyPressed() { if (key == 's') { saveAI(fileName, shapes, farben); } } /** * Add some colors to the farben array. The static method Palette.colorPermutation * returns an array of all the unique permutations of the r, g and b color volues. */ public void createColors() { color c = color(32, 64, 128); farben.add(c); c = color(76, 123, 199); color[] perm = Palette.colorPermutation(c); for (color pc : perm) { farben.add(pc); } } /** * We create some shapes */ public void createShapes() { float x, y, radius, h, w; int sides; color c; int[] channelValues = {34, 55, 89, 144, 233}; // add a background rectangle shapes.add(bgRect()); for (int i = 0; i < 10; i++) { x = random(width); y = random(height); radius = random(2, 48); sides = int(random(3, 18)); // call static method BezShape.bezRegularPoly to create a regular polygon BezShape bez = BezRegularPoly.makeCenterRadiusSides(x, y, radius, sides); // generate a color using randomly selected values from an array for r, g and b c = Palette.randColor(channelValues); farben.add(c); bez.setFillColor(c); bez.setStrokeColor(0); shapes.add(bez); } for (int i = 0; i < 10; i++) { x = random(width); y = random(height); w = random(16, 96); h = random(16, 96); sides = int(random(4, 7)); // call static method BezShape.bezEllipse to create an ellipse BezShape bez = BezEllipse.makeCenterWidthHeightSectors(x, y, w, h, sides); c = Palette.randColor(channelValues); farben.add(c); bez.setFillColor(c); bez.setNoStroke(); shapes.add(bez); } } /** * Creates a rectangle from four points, with fill and stroke colors */ public BezShape bezRect(float left, float top, float right, float bottom, color f, color s) { BezShape r = new BezShape(left, top); r.setFillColor(f); r.setStrokeColor(s); r.setWeight(3.0); r.append(right, top); r.append(right, bottom); r.append(left, bottom); r.append(left, top); return r; } public BezShape bgRect() { color f = color(233, 231, 236); color s = color(21, 34, 55); return bezRect(0, height, width, 0, f, s); } /** * saves shapes to an Adobe Illustrator file * Illustrator and Porcessing use different coordinate systems, so the AI file * will look the Processing window flipped on its horizontal axis. * @param aiFilename name fo the file to save to * @param comps an array of BezShapes to save to the file * @param colors an array of Processing colors to use as the palette */ public void saveAI(String aiFilename, ArrayList comps, ArrayList colors) { println("saving Adobe Illustrator file " + aiFilename + "..."); PrintWriter output = createWriter(aiFilename); // create the document DocumentComponent doc = new DocumentComponent("Simple Shape Export"); // get its palette Palette pal = doc.getPalette(); // add black, white, and gray to the palette pal.addBlackWhiteGray(); // add our array of colors to the palette pal.addColors(colors); // include some information for Illustrator's header doc.setCreator("Ignotus"); doc.setOrg("IgnoStudio"); // set width and height of the document doc.setWidth(width); doc.setHeight(height); println("adding components..."); // add the components to the the default layer of the document for (BezShape b : comps) { doc.add(b); } // In IgnoCodeLib 0.3, write(output) now performs a transform // to make the saved file's orientation identical to the display, the same as // writeWithAITransform. Call writeNoTransform to omit the transform. doc.writeNoTransform(output); }
Nested Class Summary | |
---|---|
static class |
BezShape.BezType
|
Field Summary | |
---|---|
BezShape.BezType |
bezType
type of BEZ_PATH, BEZ_TRIANGLE, BEZ_CIRCLE, BEZ_ELLIPSE, BEZ_CURVE_POLY, BEZ_REGULAR_POLY, etc. |
static int |
CURVE_SEGMENT
flag for curve segment type, associated with BezVertex |
static double |
KAPPA
KAPPA = (distance between Bezier anchor and its associated control point) / (circle radius) when a circle is divided into 4 sectors of 90 degrees. |
static int |
LINE_SEGMENT
flag for line segment type, associated with LineVertex |
Constructor Summary | |
---|---|
BezShape()
Creates a closed shape with initial point 0,0, obtains parent PApplet from initialized IgnoCodeLib , which must be correctly initialized in setup. |
|
BezShape(float x,
float y)
Creates a closed shape with initial point x,y, obtains parent PApplet from initialized IgnoCodeLib , which must be correctly initialized in setup. |
|
BezShape(float ax1,
float ay1,
float cx1,
float cy1,
float cx2,
float cy2,
float ax2,
float ay2)
Creates a closed BezShape with initial point ax1, ay1, and appends a curve segment, obtains parent PApplet from initialized IgnoCodeLib . |
|
BezShape(float ax1,
float ay1,
float cx1,
float cy1,
float cx2,
float cy2,
float ax2,
float ay2,
boolean isClosed)
Creates a BezShape with initial point ax1, ay1, and appends a curve segment, obtains parent PApplet from initialized IgnoCodeLib . |
|
BezShape(PApplet parent)
Creates a closed shape with initial point 0,0 Fill, stroke, and weight of shapes are set from their values in the Processing environment. |
|
BezShape(PApplet parent,
float x,
float y)
Creates a closed shape with initial point x,y. |
|
BezShape(PApplet parent,
float x,
float y,
boolean isClosed)
Creates a BezShape with initial point x,y, closed or open according to the value of isClosed. |
|
BezShape(PApplet parent,
float ax1,
float ay1,
float cx1,
float cy1,
float cx2,
float cy2,
float ax2,
float ay2)
Creates a closed BezShape with initial point ax1, ay1, and appends a curve segment. |
|
BezShape(PApplet parent,
float ax1,
float ay1,
float cx1,
float cy1,
float cx2,
float cy2,
float ax2,
float ay2,
boolean isClosed)
Creates a BezShape with initial point ax1, ay1, and appends a curve segment. |
Method Summary | |
---|---|
void |
accept(ComponentVisitor visitor)
Accepts a ComponentVisitor that traverses a document structure tree. |
void |
accept(ComponentVisitor visitor,
boolean order)
Accepts a ComponentVisitor that traverses a document structure tree in preorder or postorder. |
void |
add(ArrayList<? extends DisplayComponent> comps)
Adds all components in a list to this component, throws an UnsupportedOperationException if component is terminal. |
void |
add(DisplayComponent component)
Adds a component to children of this component, throws an UnsupportedOperationException if component is terminal. |
void |
append(float x,
float y)
Appends a LineVertex (line segment) to this BezShape. |
void |
append(float cx1,
float cy1,
float cx2,
float cy2,
float x,
float y)
Appends a BezVertex (cubic Bˇzier segment) to this BezShape. |
void |
append(Vertex2DINF vt)
Appends a Vertex2DINF to this BezShape |
float[] |
asPolygon()
|
float[] |
asPolygon(int steps)
|
float[] |
asPolygon(PApplet parent)
Extracts an approximated polygon from path data. |
float[] |
asPolygon(PApplet parent,
int steps)
Extracts an approximated polygon from path data, returning it as an array of floats. |
static BezCircle |
bezCircle(PApplet parent,
float xctr,
float yctr,
float radius,
int sectors)
Deprecated. Call factory methods in the returned class instead. |
static BezShape |
bezCurve(PApplet parent,
float ax1,
float ay1,
float cx1,
float cy1,
float cx2,
float cy2,
float ax2,
float ay2)
Deprecated. Call factory methods in the returned class instead. |
static BezCurveShape |
bezCurveShape(PApplet parent,
float[] coords)
Deprecated. Call factory methods in the returned class instead. |
static BezEllipse |
bezEllipse(PApplet parent,
float xctr,
float yctr,
float width,
float height,
int sectors)
Deprecated. Call factory methods in the returned class instead. |
static BezLine |
bezLine(PApplet parent,
float x1,
float y1,
float x2,
float y2)
Deprecated. Call factory methods in the returned class instead. |
static BezMultiCurve |
bezMultiCurve(PApplet parent,
float[] coords)
Deprecated. Call factory methods in the returned class instead. |
static BezMultiLine |
bezMultiLine(PApplet parent,
float[] coords)
Deprecated. Call factory methods in the returned class instead. |
static BezPoly |
bezPoly(PApplet parent,
float[] coords)
Deprecated. Call factory methods in the returned class instead. |
static BezRectangle |
bezRectangle(PApplet parent,
float left,
float top,
float right,
float bottom)
Deprecated. Call factory methods in the returned class instead. |
static BezRegularPoly |
bezRegularPoly(PApplet parent,
float xctr,
float yctr,
float radius,
int sides)
Deprecated. Call factory methods in the returned class instead. |
static BezTriangle |
bezTriangle(PApplet parent,
float xctr,
float yctr,
float radius)
Deprecated. Call factory methods in the returned class instead. |
static BezTriangle |
bezTriangle(PApplet parent,
float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Deprecated. Call factory methods in the returned class instead. |
BezShape.BezType |
bezType()
|
float[] |
bounds()
returns array of floats with top, left, bottom, right coordinates of bounding box These are an approximation based on the derived polygon, accuracy can be improved by first calling asPolygon with an argument greater than the default of 16 segments per curve. |
float[] |
bounds(PApplet parent)
returns array of floats with top, left, bottom, right coordinates of bounding box These are an approximation based on the derived polygon, accuracy can be improved by first calling asPolygon with an argument greater than the default of 16 segments per curve. |
BezRectangle |
boundsRect()
Returns the bounding rectangle of this shape. |
void |
calculateCenter()
Sets the center of transformation to the center of the bounding rectangle of this shape. |
LineVertex |
centerVertex()
|
List<DisplayComponent> |
children()
Returns empty list: this is a terminal node, with no children. |
BezShape |
clone()
Creates a deep copy of this BezShape. |
boolean |
containsPoint(float x,
float y)
|
boolean |
containsPoint(PApplet parent,
float x,
float y)
Tests if a point is inside this shape by generating a polygon approximation to curved paths and testing that. |
ListIterator<Vertex2DINF> |
curveIterator()
Returns an iterator over the geometry of this shape. |
ArrayList<Vertex2DINF> |
curves()
Returns the geometry of this shape as an ArrayList . |
ArrayList<Vertex2DINF> |
curvesCopy()
Returns a copy of the geometry of this shape as an ArrayList . |
void |
draw()
Draws this shape to the display. |
void |
draw(PGraphics pg)
Draws this shape to an offscreen PGraphics. |
void |
drawQuick()
Draws this shape to the display. |
int |
fillColor()
|
int |
fillOpacity()
|
DisplayComponent |
get(int index)
Returns the component at index from the children of this component, throws an UnsupportedOperationException if component is terminal. |
LineVertex |
getAnchorCenter(BezShape shape)
Returns the average of all anchor points of the vertices of this shape. |
LineVertex |
getBoundsCenter()
Returns the center of the bounding rectangle of this shape as a LineVertex. |
float[] |
getCoords()
Returns an array of all vertex coordinates. |
Matrix3 |
getCtm()
Returns a copy of the most recent transformation matrix. |
LineVertex |
getGeoCenter()
Returns the average of the x- and y-coordinates of this shape as a LineVertex . |
static Matrix3 |
getMatrix(PApplet applet)
Captures a transformation matrix from a PApplet, for later use. |
boolean |
hasFill()
|
boolean |
hasStroke()
|
boolean |
isClosed()
|
boolean |
isTerminal()
Returns true : this is a terminal component. |
Iterator<DisplayComponent> |
iterator()
Returns an iterator over children, throws an UnsupportedOperationException if component is terminal. |
void |
moveTo(float newXCtr,
float newYCtr)
Handy method to translate center point (xctr, yctr) and shape to a new location. |
int |
polySize()
|
int |
polySize(PApplet parent)
|
int |
polySteps()
Returns the number of straight line segments used in fast calculation |
boolean |
remove(DisplayComponent component)
Removes a component from children of this component, throws an UnsupportedOperationException if component is terminal. |
void |
rotateShape(float theta)
Rotates this shape around its center point. |
void |
rotateShape(float xctr,
float yctr,
float theta)
Rotates this shape around a supplied center point. |
void |
scaleShape(float xyScale)
Uniformly scales this shape around its center point. |
void |
scaleShape(float xScale,
float yScale)
Scales this shape around its center point. |
void |
scaleShape(float xyScale,
float x0,
float y0)
Uniformly scales this shape around a given point. |
void |
scaleShape(float xScale,
float yScale,
float x0,
float y0)
Scales this shape around a given point. |
void |
setBezType(BezShape.BezType newBezType)
|
void |
setCenter(float xctr,
float yctr)
Sets center point for geometric transforms on this shape. |
void |
setCenter(LineVertex centerPoint)
Sets the values of xctr and yctr |
void |
setCenter(Point2D pt)
Sets center point for geometric transforms on this shape. |
void |
setColors(PApplet host)
Sets fill and stroke using the current graphics state. |
void |
setCtm(Matrix3 ctm)
|
void |
setCtm(PApplet applet)
Captures the current transformation matrix from a PApplet and uses it to set our ctm. |
void |
setCtm(PMatrix2D m)
Sets our ctm from a PMatrix2D. |
void |
setCurves(ArrayList<Vertex2DINF> newCurves)
|
void |
setFillColor(int newFillColor)
Sets the current fill color. |
void |
setFillOpacity(int opacity)
Sets opacity of current fill color. |
void |
setHasFill(boolean newHasFill)
|
void |
setHasStroke(boolean newHasStroke)
|
void |
setIsClosed(boolean newIsClosed)
|
void |
setNoFill()
Equivalent to setHasFill(false). |
void |
setNoStroke()
Equivalent to setHasStroke(false). |
void |
setPolySteps(int newPolySteps)
|
void |
setStartPoint(float newX,
float newY)
Sets a new initial vertex for this BezShape. |
void |
setStartPoint(LineVertex startPoint)
|
void |
setStartPoint(Point2D pt)
Sets a new initial vertex for this BezShape. |
void |
setStrokeColor(int newStrokeColor)
Sets the current stroke color. |
void |
setStrokeOpacity(int opacity)
Sets opacity of current stroke color. |
static void |
setUseTransparency(boolean useTransparency)
Deprecated. preferred usage is AIFileWriter.setUseTransparency() . |
void |
setWeight(float newWeight)
|
void |
setX(float newX)
Sets the x-coordinate of the initial point of the geometry of this shape. |
void |
setY(float newY)
Sets the y-coordinate of the initial point of the geometry of this shape. |
LineVertex |
startVertex()
|
float[] |
startVertexArray()
return initial vertex as an array of two floats |
int |
strokeColor()
|
int |
strokeOpacity()
|
void |
transform()
Calls transform with this shape's ctm, current transformation matrix. |
void |
transform(Matrix3 matx)
Performs an affine geometric transformation on this shape using 3x3 matrix multiplication. |
void |
transformShape(Matrix3 matx)
Deprecated. |
void |
translateShape(float xTrans,
float yTrans)
Translates this shape. |
static boolean |
useTransparency()
|
float |
weight()
Returns the current weight (in points) of stroked lines. |
void |
write(int pathOp,
PrintWriter output)
Writes Adobe Illustrator 7.0 tags describing the geometry of this shape to PrintWriter. |
void |
write(PrintWriter pw)
Writes Adobe Illustrator 7.0 tags describing the geometry of this shape to PrintWriter. |
float |
x()
Returns the x-coordinate of the initial point of the geometry of this shape. |
float[] |
xcoords()
|
float[] |
xcoords(PApplet parent)
Returns x-coordinates of the geometry of this shape. |
float |
xctr()
Returns the value of the x-coordinate of center of transformation. |
float |
y()
Returns the y-coordinate of the initial point of the geometry of this shape. |
float[] |
ycoords()
|
float[] |
ycoords(PApplet parent)
Returns y-coordinates of the geometry of this shape. |
float |
yctr()
Returns the of the y-coordinate of center of transformation. |
Methods inherited from class net.paulhertz.aifile.DisplayComponent |
---|
hide, id, isLocked, isVisible, parentComponent, setLocked, setParentComponent, setVisible, show |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int LINE_SEGMENT
public static final int CURVE_SEGMENT
public BezShape.BezType bezType
public static final double KAPPA
Constructor Detail |
---|
public BezShape(PApplet parent, float x, float y, boolean isClosed)
ctm
, but no transform is performed. Note that drawing
is affected by the current Processing transform.
parent
- PApplet used for calls to the Processing environment, notably for drawingx
- x-coordinate of initial pointy
- y-coordinate of initial pointisClosed
- true if shape is closed, false if it is openpublic BezShape(PApplet parent)
ctm
, but no transform is performed. Note that drawing
is affected by the current Processing transform.
parent
- PApplet used for calls to the Processing environment, notably for drawingpublic BezShape(PApplet parent, float x, float y)
ctm
, but no transform is performed. Note that drawing
is affected by the current Processing transform.
parent
- PApplet used for calls to the Processing environment, notably for drawingx
- x-coordinate of initial pointy
- y-coordinate of initial pointpublic BezShape(PApplet parent, float ax1, float ay1, float cx1, float cy1, float cx2, float cy2, float ax2, float ay2)
ctm
, but no transform is performed. Note that drawing
is affected by the current Processing transform.
parent
- PApplet used for calls to the Processing environment, notably for drawingax1
- x-coordinate of initial anchor pointay1
- y-coordinate of initial anchor pointcx1
- x-coordinate of first control pointcy1
- y-coordinate of first control pointcx2
- x-coordinate of second control pointcy2
- y-coordinate of second control pointax2
- x-coordinate of terminal anchor pointay2
- y-coordinate of terminal anchor pointpublic BezShape(PApplet parent, float ax1, float ay1, float cx1, float cy1, float cx2, float cy2, float ax2, float ay2, boolean isClosed)
ctm
, but no transform is performed. Note that drawing
is affected by the current Processing transform.
parent
- PApplet used for calls to the Processing environment, notably for drawingax1
- x-coordinate of initial anchor pointay1
- y-coordinate of initial anchor pointcx1
- x-coordinate of first control pointcy1
- y-coordinate of first control pointcx2
- x-coordinate of second control pointcy2
- y-coordinate of second control pointax2
- x-coordinate of terminal anchor pointay2
- y-coordinate of terminal anchor pointisClosed
- true if shape is closed, false if it is openpublic BezShape()
IgnoCodeLib
, which must be correctly initialized in setup.
If IgnoCodeLib does not have a reference to a PApplet, it throws a NullPointerException.
Fill, stroke, and weight of shapes are set from their values in the Processing environment.
The Processing transformation matrix (set by calls to rotate, translate and scale) is saved
to the instance variable ctm
, but no transform is performed. Note that drawing
is affected by the current Processing transform.
public BezShape(float x, float y)
IgnoCodeLib
, which must be correctly initialized in setup.
If IgnoCodeLib does not have a reference to a PApplet, it throws a NullPointerException.
Fill, stroke, and weight of shapes are set from their values in the Processing environment.
The Processing transformation matrix (set by calls to rotate, translate and scale) is saved
to the instance variable ctm
, but no transform is performed. Note that drawing
is affected by the current Processing transform.
x
- x-coordinate of initial pointy
- y-coordinate of initial pointpublic BezShape(float ax1, float ay1, float cx1, float cy1, float cx2, float cy2, float ax2, float ay2)
IgnoCodeLib
.
If IgnoCodeLib does not have a reference to a PApplet, it throws a NullPointerException.
Fill, stroke, and weight of shapes are set from their values in the Processing environment.
The Processing transformation matrix (set by calls to rotate, translate and scale) is saved
to the instance variable ctm
, but no transform is performed. Note that drawing
is affected by the current Processing transform.
ax1
- x-coordinate of initial anchor pointay1
- y-coordinate of initial anchor pointcx1
- x-coordinate of first control pointcy1
- y-coordinate of first control pointcx2
- x-coordinate of second control pointcy2
- y-coordinate of second control pointax2
- x-coordinate of terminal anchor pointay2
- y-coordinate of terminal anchor pointpublic BezShape(float ax1, float ay1, float cx1, float cy1, float cx2, float cy2, float ax2, float ay2, boolean isClosed)
IgnoCodeLib
.
If IgnoCodeLib does not have a reference to a PApplet, it throws a NullPointerException.
Fill, stroke, and weight of shapes are set from their values in the Processing environment.
The Processing transformation matrix (set by calls to rotate, translate and scale) is saved
to the instance variable ctm
, but no transform is performed. Note that drawing
is affected by the current Processing transform.
ax1
- x-coordinate of initial anchor pointay1
- y-coordinate of initial anchor pointcx1
- x-coordinate of first control pointcy1
- y-coordinate of first control pointcx2
- x-coordinate of second control pointcy2
- y-coordinate of second control pointax2
- x-coordinate of terminal anchor pointay2
- y-coordinate of terminal anchor pointisClosed
- true if shape is closed, false if it is openMethod Detail |
---|
public BezShape clone()
clone
in class Object
Object.clone()
public void add(DisplayComponent component)
DisplayComponent
UnsupportedOperationException
if component is terminal.
add
in class DisplayComponent
component
- DisplayComponent to add to this component's children
UnsupportedOperationException,
- BezShape is a terminal (leaf) nodepublic void add(ArrayList<? extends DisplayComponent> comps)
DisplayComponent
UnsupportedOperationException
if component is terminal.
add
in class DisplayComponent
comps
- an ArrayList of DisplayComponents
UnsupportedOperationException,
- BezShape is a terminal (leaf) nodepublic boolean remove(DisplayComponent component)
DisplayComponent
UnsupportedOperationException
if component is terminal.
remove
in class DisplayComponent
component
- DisplayComponent to remove from this component's children
UnsupportedOperationException,
- BezShape is a terminal (leaf) nodepublic DisplayComponent get(int index)
DisplayComponent
UnsupportedOperationException
if component is terminal.
Throws an IndexOutOfBoundsException
if index is out of range (index < 0 || index >= size).
get
in class DisplayComponent
index
- index to component
UnsupportedOperationException,
- BezShape is a terminal (leaf) nodepublic Iterator<DisplayComponent> iterator()
DisplayComponent
UnsupportedOperationException
if component is terminal.
iterator
in class DisplayComponent
UnsupportedOperationException,
- BezShape is a terminal (leaf) nodepublic List<DisplayComponent> children()
children
in class DisplayComponent
public boolean isTerminal()
true
: this is a terminal component.
isTerminal
in class DisplayComponent
public void append(Vertex2DINF vt)
vt
- a Vertex2DINF (line segment or curve segment)public void append(float cx1, float cy1, float cx2, float cy2, float x, float y)
cx1
- x-coordinate of first control pointcy1
- y-coordinate of first control pointcx2
- x-coordinate of second control pointcy2
- y-coordinate of second control pointx
- x-coordinate of terminal anchor pointy
- y-coordinate of terminal anchor pointpublic void append(float x, float y)
x
- y
- public boolean isClosed()
true
if this shape is closed, false
otherwise.public void setIsClosed(boolean newIsClosed)
newIsClosed
- true
if this shape is closed, false
otherwisepublic void setColors(PApplet host)
public boolean hasFill()
hasFill
in interface ColorableINF
public void setHasFill(boolean newHasFill)
newHasFill
- pass true if this shape has a fill, false otherwise. Note that
the current fillColor will not be discarded by setting hasFill to false: the shape
simply won't display or save to file with a fill.public void setNoFill()
setNoFill
in interface ColorableINF
public boolean hasStroke()
hasStroke
in interface ColorableINF
public void setHasStroke(boolean newHasStroke)
newHasStroke
- pass true if this shape has a stroke, false otherwise. Note that
the current strokeColor will not be discarded by setting hasStroke to false: the shape
simply won't display or save to file with a stroke.public void setNoStroke()
setNoStroke
in interface ColorableINF
public int fillColor()
fillColor
in interface ColorableINF
public void setFillColor(int newFillColor)
ColorableINF
setFillColor
in interface ColorableINF
newFillColor
- a Processing color (32-bit int with ARGB bytes).public int strokeColor()
strokeColor
in interface ColorableINF
public void setStrokeColor(int newStrokeColor)
ColorableINF
setStrokeColor
in interface ColorableINF
newStrokeColor
- a Processing color (32-bit int with ARGB bytes).public static boolean useTransparency()
public static void setUseTransparency(boolean useTransparency)
AIFileWriter.setUseTransparency()
.
write(PrintWriter)
.
useTransparency
- public void setFillOpacity(int opacity)
setFillOpacity
in interface ColorableINF
opacity
- a number in the range 0..255. Value is not checked!public int fillOpacity()
fillOpacity
in interface ColorableINF
public void setStrokeOpacity(int opacity)
setStrokeOpacity
in interface ColorableINF
opacity
- a number in the range 0..255. Value is not checked!public int strokeOpacity()
strokeOpacity
in interface ColorableINF
public float weight()
weight
in interface ColorableINF
public void setWeight(float newWeight)
setWeight
in interface ColorableINF
newWeight
- the new weight of stroked lines.public BezShape.BezType bezType()
public void setBezType(BezShape.BezType newBezType)
newBezType
- type of shape (BEZ_PATH, BEZ_TRIANG, BEZ_CIRCLE, BEZ_ELLIPSE, BEZ_CURVE_POLY, BEZ_REGULAR_POLY)public float x()
public void setX(float newX)
newX
- new x-coordinate of initial vertexpublic float y()
public void setY(float newY)
newY
- new y-coordinate of initial vertexpublic LineVertex startVertex()
public void setStartPoint(LineVertex startPoint)
startPoint
- the startPoint to setpublic void setStartPoint(Point2D pt)
pt
- a Point2Dpublic void setStartPoint(float newX, float newY)
newX
- newY
- public float[] startVertexArray()
public float xctr()
public float yctr()
public LineVertex centerVertex()
public void setCenter(float xctr, float yctr)
xctr
- yctr
- public void setCenter(Point2D pt)
pt
- public void setCenter(LineVertex centerPoint)
xctr
and yctr
centerPoint
- a LineVertext encapsulating the center coordinates to setpublic void calculateCenter()
xcoords
and ycoords
arrays, if required.
By default, the center point is (0,0), as in Processing. If you want shapes to transform around their
center points (i.e., to scale or rotate in place), call calculateCenter before calling
rotateShape
or scaleShape
.
transform
uses the point of transformation set in its
transformation matrix, so you can use it for transformations around any arbitrary point.
public LineVertex getBoundsCenter()
xcoords
and ycoords
arrays, if required.
public LineVertex getAnchorCenter(BezShape shape)
public LineVertex getGeoCenter()
LineVertex
.
The result is an approximation based on the derived polygon. Accuracy can be improved by first
calling asPolygon with an argument greater than the default of 16 segments per curve.
public ListIterator<Vertex2DINF> curveIterator()
public ArrayList<Vertex2DINF> curves()
ArrayList
. Note that the startPoint is not included,
you can obtain that separately from startVertex()
or from x()
and y()
.
transform()
and other
built-in methods can have unexpected consequences.
Call curvesCopy instead.public ArrayList<Vertex2DINF> curvesCopy()
ArrayList
. Note that the startPoint is not included,
you can obtain that separately from startVertex()
or from x()
and y()
.
public void setCurves(ArrayList<Vertex2DINF> newCurves)
newCurves
- an ArrayList of Vertex2DINF segments that will define the geometry of this shape.
Does not change the startPoint. You can do that with setStartPoint(float, float)
or with
setX(float)
and setY(float)
.
Sets xcoords and ycoords to null.
Does not update centerPoint
. You can do that with calculateCenter()
or the various
methods for setting centerPoint
directly, setCenter(LineVertex)
, setCenter(float, float)
.
Use with caution.public float[] getCoords()
LineVertex
adds two values to the array
and a BezVertex
adds six values (two control points and an anchor point). There is no
inherent way to distinguish which values represent control points and which represent anchor points.
float
generated from the vertices of this shape.asPolygon(PApplet, int).
public float[] asPolygon(PApplet parent, int steps)
xcoords
and ycoords
arrays. Polygon data is not cached, but the
xcoords
and ycoords
arrays are. You can use them to construct a polygon once
they have been initialized. If, against our good advice, you munge around with
shape geometry, you can reset xcoords
and ycoords
with a call to
this method, which always recalculates xcoords
and ycoords
and boundsRect
steps
- number of straight line segments to divide Bezier curves intoparent
- reference to a PApplet needed to build a polygon from a Bezier curvepublic float[] asPolygon(PApplet parent)
setPolySteps()
to change the level of approximation of the polygon to the actual paths.
parent
- reference to a PApplet needed to build a polygon from a Bezier curvepublic float[] asPolygon(int steps)
public float[] asPolygon()
public boolean containsPoint(PApplet parent, float x, float y)
parent
- reference to a Processing PApplet, probably the one calling this codex
- x-coordinate of test pointy
- y-coordinate of test point
public boolean containsPoint(float x, float y)
public float[] xcoords(PApplet parent)
asPolygon
) for details.
parent
- reference to a PApplet needed to build a polygon from a Bezier curve
public float[] xcoords()
public float[] ycoords(PApplet parent)
asPolygon
) for details.
parent
- reference to a PApplet needed to build a polygon from a Bezier curve
public float[] ycoords()
public int polySize(PApplet parent)
parent
- reference to a PApplet needed to build a polygon from a Bezier curve
public int polySize()
public int polySteps()
public void setPolySteps(int newPolySteps)
newPolySteps
- default number of steps in polyline representation of a curve segmentpublic float[] bounds(PApplet parent)
parent
- reference to a PApplet needed to build a polygon from a Bezier curve
public float[] bounds()
boundsRect()
method, which returns cached data.
public BezRectangle boundsRect()
boundsRect
is
aligned to the x- and y-axes. It is cached in between calls, and set to null after a transform.
public void translateShape(float xTrans, float yTrans)
xcoords()
or ycoords()
are called.
xTrans
- translation on x-axisyTrans
- translation on y-axispublic void moveTo(float newXCtr, float newYCtr)
newXCtr
- newYCtr
- public void scaleShape(float xScale, float yScale, float x0, float y0)
xcoords()
or ycoords()
are called.
xScale
- scaling on x-axisyScale
- scaling on y-axispublic void scaleShape(float xScale, float yScale)
setCenter
or calculateCenter
.
Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform,
which will be done through lazy initialization when xcoords()
or ycoords()
are called.
xScale
- scaling on x-axisyScale
- scaling on y-axispublic void scaleShape(float xyScale)
setCenter
or calculateCenter
.
Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform,
which will be done through lazy initialization when xcoords()
or ycoords()
are called.
xyScale
- uniform scaling on x-axis and y-axispublic void scaleShape(float xyScale, float x0, float y0)
xyScale
- uniform scaling on x-axis and y-axispublic void rotateShape(float theta)
setCenter
or calculateCenter
.
Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform,
which will be done through lazy initialization when xcoords()
or ycoords()
are called.
theta
- degrees to rotate (in radians)
TODO for theta very near PI, 0, or TWO_PI, insure correct rotation.public void rotateShape(float xctr, float yctr, float theta)
theta
- degrees to rotate (in radians)
TODO for theta very near PI, 0, or TWO_PI, insure correct rotation.public static Matrix3 getMatrix(PApplet applet)
applet
- a PApplet, probably the one that's running the show.
public Matrix3 getCtm()
transform
.
It can be used directly (and repeatedly) with a call to transform
.
public void setCtm(Matrix3 ctm)
ctm
- the ctm to setpublic void setCtm(PApplet applet)
applet
- a PApplet from which the current matrix will be used to set the ctmpublic void setCtm(PMatrix2D m)
m
- a PMatrix2D to set the ctmpublic void transformShape(Matrix3 matx)
transform
.
matx
- public void transform(Matrix3 matx)
xcoords()
or ycoords()
are called.
transform
in class DisplayComponent
matx
- a 3x3 matrix see Matrix3 class for methods of loading transformspublic void transform()
public void draw()
draw
in class DisplayComponent
public void draw(PGraphics pg)
draw
in class DisplayComponent
pg
- a PGraphics instancepublic void drawQuick()
public void write(PrintWriter pw)
setUseTransparency()
with a argument of
true
before calling write()
. Because Illustrator does not support separate transparency
for fill and stroke, assigning a transparent color to either on will make the the entire object transparent.
If stroke and fill transparency have different values, stroke transparency will be assigned to the object.
write
in class DisplayComponent
pw
- a PrintWriter for file output.public void write(int pathOp, PrintWriter output)
write(PrintWriter)
. It is primarily of use
in writing out files with direct calls to AiFileWriter.
pathOp
- @see net.paulhertz.aifile.AIFileWriter#paintPathoutput
- a PrintWriter that writes vector graphics in the Adobe Illustrator 7.0 file formatpublic void accept(ComponentVisitor visitor)
Visitable
When called from an object that implements the Visitable
interface:
accept( visitor )
on all its children
The reference is passed back to the visitor through a method of the form
visitor.visit<ComponentClassName>( this );
See ComponentVisitor
The order of steps 1 and 2 determines if traversal of the composite structure is preorder or postorder. As shown above, it's preorder. Depending on what you want to do, one traversal may be better suited than the other. Preorder visits parents first, postorder visits children first.
accept
in interface Visitable
visitor
- a ComponentVisitor
public void accept(ComponentVisitor visitor, boolean order)
Visitable
accept
in interface Visitable
visitor
- a ComponentVisitor
order
- boolean to determine if traversal is preorder or postorder
accept( visitor )
should implement the default order of traversal,
accept( visitor, <false>
) should implement the other order.public static BezCircle bezCircle(PApplet parent, float xctr, float yctr, float radius, int sectors)
sectors
- number of equal divisions of circleradius
- radius of circlexctr
- x-coordinate of center of circleyctr
- y-coordinate of center of circle
public static BezEllipse bezEllipse(PApplet parent, float xctr, float yctr, float width, float height, int sectors)
sectors
- integer for number of equal divisions of circlewidth
- width of the ellipseheight
- height of the ellipsexctr
- x-coordinate of center of circleyctr
- y-coordinate of center of circle
public static BezRegularPoly bezRegularPoly(PApplet parent, float xctr, float yctr, float radius, int sides)
sides
edges and radius radius
.
Fill, stroke, and weight are set from their values in the Processing environment.
xctr
- x-coordinate of center of polygonyctr
- y-coordinate of center of polygonradius
- radius of the polygonsides
- number of sides of the polygon
public static BezCurveShape bezCurveShape(PApplet parent, float[] coords)
coords
- an array of coordinate pairs
public static BezTriangle bezTriangle(PApplet parent, float xctr, float yctr, float radius)
xctr
- x-coordinate of center of triangleyctr
- y-coordinate of center of triangleradius
- radius of the triangle
public static BezTriangle bezTriangle(PApplet parent, float x1, float y1, float x2, float y2, float x3, float y3)
x1
- x-coordinate of first pointy1
- y-coordinate of first pointx2
- x-coordinate of second pointy2
- y-coordinate of second pointx3
- x-coordinate of third pointy3
- y-coordinate of third point
public static BezRectangle bezRectangle(PApplet parent, float left, float top, float right, float bottom)
left
- the left x-coordinate of the rectangletop
- the top y-coordinate of the rectangleright
- the right x-coordinate of the rectanglebottom
- the bottom y-coordinate of the rectangle
public static BezLine bezLine(PApplet parent, float x1, float y1, float x2, float y2)
x1
- x-coordinate of first pointy1
- y-coordinate of first pointx2
- x-coordinate of second pointy2
- y-coordinate of second point
public static BezShape bezCurve(PApplet parent, float ax1, float ay1, float cx1, float cy1, float cx2, float cy2, float ax2, float ay2)
ax1
- x-coordinate of initial anchor pointay1
- y-coordinate of initial anchor pointcx1
- x-coordinate of first control pointcy1
- y-coordinate of first control pointcx2
- x-coordinate of second control pointcy2
- y-coordinate of second control pointax2
- x-coordinate of terminal anchor pointay2
- y-coordinate of terminal anchor point
public static BezMultiLine bezMultiLine(PApplet parent, float[] coords)
coords
- an array of coordinate pairs
public static BezPoly bezPoly(PApplet parent, float[] coords)
coords
- an array of coordinate pairs
public static BezMultiCurve bezMultiCurve(PApplet parent, float[] coords)
coords
- an array of coordinate pairs
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |