diff --git a/core/build.xml b/core/build.xml index facb7aa38..5a8836abe 100644 --- a/core/build.xml +++ b/core/build.xml @@ -7,10 +7,10 @@ - - + +
hint(ENABLE_OPENGL_4X_SMOOTH) - Enable 4x anti-aliasing for OpenGL. This can help force anti-aliasing if it has not been enabled by the user. On some graphics cards, this can also be set by the graphics driver's control panel, however not all cards make this available. This hint must be called immediately after the size() command because it resets the renderer, obliterating any settings and anything drawn (and like size(), re-running the code that came before it again). + *

hint(DISABLE_OPENGL_2X_SMOOTH) - In Processing 1.0, Processing always enables 2x smoothing when the OpenGL renderer is used. This hint disables the default 2x smoothing and returns the smoothing behavior found in earlier releases, where smooth() and noSmooth() could be used to enable and disable smoothing, though the quality was inferior. + *

hint(ENABLE_NATIVE_FONTS) - Use the native version fonts when they are installed, rather than the bitmapped version from a .vlw file. This is useful with the JAVA2D renderer setting, as it will improve font rendering speed. This is not enabled by default, because it can be misleading while testing because the type will look great on your machine (because you have the font installed) but lousy on others' machines if the identical font is unavailable. This option can only be set per-sketch, and must be called before any use of textFont(). + *

hint(DISABLE_DEPTH_TEST) - Disable the zbuffer, allowing you to draw on top of everything at will. When depth testing is disabled, items will be drawn to the screen sequentially, like a painting. This hint is most often used to draw in 3D, then draw in 2D on top of it (for instance, to draw GUI controls in 2D on top of a 3D interface). Starting in release 0149, this will also clear the depth buffer. Restore the default with hint(ENABLE_DEPTH_TEST), but note that with the depth buffer cleared, any 3D drawing that happens later in draw() will ignore existing shapes on the screen. + *

hint(ENABLE_DEPTH_SORT) - Enable primitive z-sorting of triangles and lines in P3D and OPENGL. This can slow performance considerably, and the algorithm is not yet perfect. Restore the default with hint(DISABLE_DEPTH_SORT). + *

hint(DISABLE_OPENGL_ERROR_REPORT) - Speeds up the OPENGL renderer setting by not checking for errors while running. Undo with hint(ENABLE_OPENGL_ERROR_REPORT). + *

As of release 0149, unhint() has been removed in favor of adding additional ENABLE/DISABLE constants to reset the default behavior. This prevents the double negatives, and also reinforces which hints can be enabled or disabled. + * + * @webref rendering + * @param which name of the hint to be enabled or disabled + * + * @see processing.core.PGraphics + * @see processing.core.PApplet#createGraphics(int, int, String, String) + * @see processing.core.PApplet#size(int, int) + */ public void hint(int which) { if (recorder != null) recorder.hint(which); g.hint(which); } + /** + * Start a new shape of type POLYGON + */ public void beginShape() { if (recorder != null) recorder.beginShape(); g.beginShape(); } + /** + * Start a new shape. + *

+ * Differences between beginShape() and line() and point() methods. + *

+ * beginShape() is intended to be more flexible at the expense of being + * a little more complicated to use. it handles more complicated shapes + * that can consist of many connected lines (so you get joins) or lines + * mixed with curves. + *

+ * The line() and point() command are for the far more common cases + * (particularly for our audience) that simply need to draw a line + * or a point on the screen. + *

+ * From the code side of things, line() may or may not call beginShape() + * to do the drawing. In the beta code, they do, but in the alpha code, + * they did not. they might be implemented one way or the other depending + * on tradeoffs of runtime efficiency vs. implementation efficiency &mdash + * meaning the speed that things run at vs. the speed it takes me to write + * the code and maintain it. for beta, the latter is most important so + * that's how things are implemented. + */ public void beginShape(int kind) { if (recorder != null) recorder.beginShape(kind); g.beginShape(kind); } + /** + * Sets whether the upcoming vertex is part of an edge. + * Equivalent to glEdgeFlag(), for people familiar with OpenGL. + */ public void edge(boolean edge) { if (recorder != null) recorder.edge(edge); g.edge(edge); } + /** + * Sets the current normal vector. Only applies with 3D rendering + * and inside a beginShape/endShape block. + *

+ * This is for drawing three dimensional shapes and surfaces, + * allowing you to specify a vector perpendicular to the surface + * of the shape, which determines how lighting affects it. + *

+ * For the most part, PGraphics3D will attempt to automatically + * assign normals to shapes, but since that's imperfect, + * this is a better option when you want more control. + *

+ * For people familiar with OpenGL, this function is basically + * identical to glNormal3f(). + */ public void normal(float nx, float ny, float nz) { if (recorder != null) recorder.normal(nx, ny, nz); g.normal(nx, ny, nz); } + /** + * Set texture mode to either to use coordinates based on the IMAGE + * (more intuitive for new users) or NORMALIZED (better for advanced chaps) + */ public void textureMode(int mode) { if (recorder != null) recorder.textureMode(mode); g.textureMode(mode); } + /** + * Set texture image for current shape. + * Needs to be called between @see beginShape and @see endShape + * + * @param image reference to a PImage object + */ public void texture(PImage image) { if (recorder != null) recorder.texture(image); g.texture(image); @@ -7483,6 +7555,11 @@ public class PApplet extends Applet } + /** + * Used by renderer subclasses or PShape to efficiently pass in already + * formatted vertex information. + * @param v vertex parameters, as a float array of length VERTEX_FIELD_COUNT + */ public void vertex(float[] v) { if (recorder != null) recorder.vertex(v); g.vertex(v); @@ -7501,6 +7578,7 @@ public class PApplet extends Applet } + /** This feature is in testing, do not use or rely upon its implementation */ public void breakShape() { if (recorder != null) recorder.breakShape(); g.breakShape(); @@ -7553,6 +7631,26 @@ public class PApplet extends Applet } + /** + * Draws a point, a coordinate in space at the dimension of one pixel. + * The first parameter is the horizontal value for the point, the second + * value is the vertical value for the point, and the optional third value + * is the depth value. Drawing this shape in 3D using the z + * parameter requires the P3D or OPENGL parameter in combination with + * size as shown in the above example. + *

Due to what appears to be a bug in Apple's Java implementation, + * the point() and set() methods are extremely slow in some circumstances + * when used with the default renderer. Using P2D or P3D will fix the + * problem. Grouping many calls to point() or set() together can also + * help. (Bug 1094) + * + * @webref shape:2d_primitives + * @param x x-coordinate of the point + * @param y y-coordinate of the point + * @param z z-coordinate of the point + * + * @see PGraphics#beginShape() + */ public void point(float x, float y, float z) { if (recorder != null) recorder.point(x, y, z); g.point(x, y, z); @@ -7565,6 +7663,31 @@ public class PApplet extends Applet } + /** + * Draws a line (a direct path between two points) to the screen. + * The version of line() with four parameters draws the line in 2D. + * To color a line, use the stroke() function. A line cannot be + * filled, therefore the fill() method will not affect the color + * of a line. 2D lines are drawn with a width of one pixel by default, + * but this can be changed with the strokeWeight() function. + * The version with six parameters allows the line to be placed anywhere + * within XYZ space. Drawing this shape in 3D using the z parameter + * requires the P3D or OPENGL parameter in combination with size as shown + * in the above example. + * + * @webref shape:2d_primitives + * @param x1 x-coordinate of the first point + * @param y1 y-coordinate of the first point + * @param z1 z-coordinate of the first point + * @param x2 x-coordinate of the second point + * @param y2 y-coordinate of the second point + * @param z2 z-coordinate of the second point + * + * @see PGraphics#strokeWeight(float) + * @see PGraphics#strokeJoin(int) + * @see PGraphics#strokeCap(int) + * @see PGraphics#beginShape() + */ public void line(float x1, float y1, float z1, float x2, float y2, float z2) { if (recorder != null) recorder.line(x1, y1, z1, x2, y2, z2); @@ -7572,6 +7695,21 @@ public class PApplet extends Applet } + /** + * A triangle is a plane created by connecting three points. The first two + * arguments specify the first point, the middle two arguments specify + * the second point, and the last two arguments specify the third point. + * + * @webref shape:2d_primitives + * @param x1 x-coordinate of the first point + * @param y1 y-coordinate of the first point + * @param x2 x-coordinate of the second point + * @param y2 y-coordinate of the second point + * @param x3 x-coordinate of the third point + * @param y3 y-coordinate of the third point + * + * @see PApplet#beginShape() + */ public void triangle(float x1, float y1, float x2, float y2, float x3, float y3) { if (recorder != null) recorder.triangle(x1, y1, x2, y2, x3, y3); @@ -7579,6 +7717,24 @@ public class PApplet extends Applet } + /** + * A quad is a quadrilateral, a four sided polygon. It is similar to + * a rectangle, but the angles between its edges are not constrained + * ninety degrees. The first pair of parameters (x1,y1) sets the + * first vertex and the subsequent pairs should proceed clockwise or + * counter-clockwise around the defined shape. + * + * @webref shape:2d_primitives + * @param x1 x-coordinate of the first corner + * @param y1 y-coordinate of the first corner + * @param x2 x-coordinate of the second corner + * @param y2 y-coordinate of the second corner + * @param x3 x-coordinate of the third corner + * @param y3 y-coordinate of the third corner + * @param x4 x-coordinate of the fourth corner + * @param y4 y-coordinate of the fourth corner + * + */ public void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { if (recorder != null) recorder.quad(x1, y1, x2, y2, x3, y3, x4, y4); @@ -7592,24 +7748,90 @@ public class PApplet extends Applet } + /** + * Draws a rectangle to the screen. A rectangle is a four-sided shape with + * every angle at ninety degrees. The first two parameters set the location, + * the third sets the width, and the fourth sets the height. The origin is + * changed with the rectMode() function. + * + * @webref shape:2d_primitives + * @param a x-coordinate of the rectangle + * @param b y-coordinate of the rectangle + * @param c width of the rectangle + * @param d height of the rectangle + * + * @see PGraphics#rectMode(int) + * @see PGraphics#quad(float, float, float, float, float, float, float, float) + */ public void rect(float a, float b, float c, float d) { if (recorder != null) recorder.rect(a, b, c, d); g.rect(a, b, c, d); } + /** + * The origin of the ellipse is modified by the ellipseMode() + * function. The default configuration is ellipseMode(CENTER), + * which specifies the location of the ellipse as the center of the shape. + * The RADIUS mode is the same, but the width and height parameters to + * ellipse() specify the radius of the ellipse, rather than the + * diameter. The CORNER mode draws the shape from the upper-left corner + * of its bounding box. The CORNERS mode uses the four parameters to + * ellipse() to set two opposing corners of the ellipse's bounding + * box. The parameter must be written in "ALL CAPS" because Processing + * syntax is case sensitive. + * + * @webref shape:attributes + * + * @param mode Either CENTER, RADIUS, CORNER, or CORNERS. + * @see PApplet#ellipse(float, float, float, float) + */ public void ellipseMode(int mode) { if (recorder != null) recorder.ellipseMode(mode); g.ellipseMode(mode); } + /** + * Draws an ellipse (oval) in the display window. An ellipse with an equal + * width and height is a circle. The first two parameters set + * the location, the third sets the width, and the fourth sets the height. + * The origin may be changed with the ellipseMode() function. + * + * @webref shape:2d_primitives + * @param a x-coordinate of the ellipse + * @param b y-coordinate of the ellipse + * @param c width of the ellipse + * @param d height of the ellipse + * + * @see PApplet#ellipseMode(int) + */ public void ellipse(float a, float b, float c, float d) { if (recorder != null) recorder.ellipse(a, b, c, d); g.ellipse(a, b, c, d); } + /** + * Draws an arc in the display window. + * Arcs are drawn along the outer edge of an ellipse defined by the + * x, y, width and height parameters. + * The origin or the arc's ellipse may be changed with the + * ellipseMode() function. + * The start and stop parameters specify the angles + * at which to draw the arc. + * + * @webref shape:2d_primitives + * @param a x-coordinate of the arc's ellipse + * @param b y-coordinate of the arc's ellipse + * @param c width of the arc's ellipse + * @param d height of the arc's ellipse + * @param start angle to start the arc, specified in radians + * @param stop angle to stop the arc, specified in radians + * + * @see PGraphics#ellipseMode(int) + * @see PGraphics#ellipse(float, float, float, float) + */ public void arc(float a, float b, float c, float d, float start, float stop) { if (recorder != null) recorder.arc(a, b, c, d, start, stop); @@ -7617,52 +7839,243 @@ public class PApplet extends Applet } + /** + * @param size dimension of the box in all dimensions, creates a cube + */ public void box(float size) { if (recorder != null) recorder.box(size); g.box(size); } + /** + * A box is an extruded rectangle. A box with equal dimension + * on all sides is a cube. + * + * @webref shape:3d_primitives + * @param w dimension of the box in the x-dimension + * @param h dimension of the box in the y-dimension + * @param d dimension of the box in the z-dimension + * + * @see PApplet#sphere(float) + */ public void box(float w, float h, float d) { if (recorder != null) recorder.box(w, h, d); g.box(w, h, d); } + /** + * @param res number of segments (minimum 3) used per full circle revolution + */ public void sphereDetail(int res) { if (recorder != null) recorder.sphereDetail(res); g.sphereDetail(res); } + /** + * Controls the detail used to render a sphere by adjusting the number of + * vertices of the sphere mesh. The default resolution is 30, which creates + * a fairly detailed sphere definition with vertices every 360/30 = 12 + * degrees. If you're going to render a great number of spheres per frame, + * it is advised to reduce the level of detail using this function. + * The setting stays active until sphereDetail() is called again with + * a new parameter and so should not be called prior to every + * sphere() statement, unless you wish to render spheres with + * different settings, e.g. using less detail for smaller spheres or ones + * further away from the camera. To control the detail of the horizontal + * and vertical resolution independently, use the version of the functions + * with two parameters. + * + * =advanced + * Code for sphereDetail() submitted by toxi [031031]. + * Code for enhanced u/v version from davbol [080801]. + * + * @webref shape:3d_primitives + * @param ures number of segments used horizontally (longitudinally) + * per full circle revolution + * @param vres number of segments used vertically (latitudinally) + * from top to bottom + * + * @see PGraphics#sphere(float) + */ + /** + * Set the detail level for approximating a sphere. The ures and vres params + * control the horizontal and vertical resolution. + * + */ public void sphereDetail(int ures, int vres) { if (recorder != null) recorder.sphereDetail(ures, vres); g.sphereDetail(ures, vres); } + /** + * Draw a sphere with radius r centered at coordinate 0, 0, 0. + * A sphere is a hollow ball made from tessellated triangles. + * =advanced + *

+ * Implementation notes: + *

+ * cache all the points of the sphere in a static array + * top and bottom are just a bunch of triangles that land + * in the center point + *

+ * sphere is a series of concentric circles who radii vary + * along the shape, based on, er.. cos or something + *

+   * [toxi 031031] new sphere code. removed all multiplies with
+   * radius, as scale() will take care of that anyway
+   *
+   * [toxi 031223] updated sphere code (removed modulos)
+   * and introduced sphereAt(x,y,z,r)
+   * to avoid additional translate()'s on the user/sketch side
+   *
+   * [davbol 080801] now using separate sphereDetailU/V
+   * 
+ * + * @webref shape:3d_primitives + * @param r the radius of the sphere + */ public void sphere(float r) { if (recorder != null) recorder.sphere(r); g.sphere(r); } + /** + * Evalutes quadratic bezier at point t for points a, b, c, d. + * The parameter t varies between 0 and 1. The a and d parameters are the + * on-curve points, b and c are the control points. To make a two-dimensional + * curve, call this function once with the x coordinates and a second time + * with the y coordinates to get the location of a bezier curve at t. + * + * =advanced + * For instance, to convert the following example:
+   * stroke(255, 102, 0);
+   * line(85, 20, 10, 10);
+   * line(90, 90, 15, 80);
+   * stroke(0, 0, 0);
+   * bezier(85, 20, 10, 10, 90, 90, 15, 80);
+   *
+   * // draw it in gray, using 10 steps instead of the default 20
+   * // this is a slower way to do it, but useful if you need
+   * // to do things with the coordinates at each step
+   * stroke(128);
+   * beginShape(LINE_STRIP);
+   * for (int i = 0; i <= 10; i++) {
+   *   float t = i / 10.0f;
+   *   float x = bezierPoint(85, 10, 90, 15, t);
+   *   float y = bezierPoint(20, 10, 90, 80, t);
+   *   vertex(x, y);
+   * }
+   * endShape();
+ * + * @webref shape:curves + * @param a coordinate of first point on the curve + * @param b coordinate of first control point + * @param c coordinate of second control point + * @param d coordinate of second point on the curve + * @param t value between 0 and 1 + * + * @see PGraphics#bezier(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#bezierVertex(float, float, float, float, float, float) + * @see PGraphics#curvePoint(float, float, float, float, float) + */ public float bezierPoint(float a, float b, float c, float d, float t) { return g.bezierPoint(a, b, c, d, t); } + /** + * Calculates the tangent of a point on a Bezier curve. There is a good + * definition of "tangent" at Wikipedia: http://en.wikipedia.org/wiki/Tangent + * + * =advanced + * Code submitted by Dave Bollinger (davol) for release 0136. + * + * @webref shape:curves + * @param a coordinate of first point on the curve + * @param b coordinate of first control point + * @param c coordinate of second control point + * @param d coordinate of second point on the curve + * @param t value between 0 and 1 + * + * @see PGraphics#bezier(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#bezierVertex(float, float, float, float, float, float) + * @see PGraphics#curvePoint(float, float, float, float, float) + */ public float bezierTangent(float a, float b, float c, float d, float t) { return g.bezierTangent(a, b, c, d, t); } + /** + * Sets the resolution at which Beziers display. The default value is 20. This function is only useful when using the P3D or OPENGL renderer as the default (JAVA2D) renderer does not use this information. + * + * @webref shape:curves + * @param detail resolution of the curves + * + * @see PApplet#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PApplet#curveVertex(float, float) + * @see PApplet#curveTightness(float) + */ public void bezierDetail(int detail) { if (recorder != null) recorder.bezierDetail(detail); g.bezierDetail(detail); } + /** + * Draws a Bezier curve on the screen. These curves are defined by a series + * of anchor and control points. The first two parameters specify the first + * anchor point and the last two parameters specify the other anchor point. + * The middle parameters specify the control points which define the shape + * of the curve. Bezier curves were developed by French engineer Pierre + * Bezier. Using the 3D version of requires rendering with P3D or OPENGL + * (see the Environment reference for more information). + * + * =advanced + * Draw a cubic bezier curve. The first and last points are + * the on-curve points. The middle two are the 'control' points, + * or 'handles' in an application like Illustrator. + *

+ * Identical to typing: + *

beginShape();
+   * vertex(x1, y1);
+   * bezierVertex(x2, y2, x3, y3, x4, y4);
+   * endShape();
+   * 
+ * In Postscript-speak, this would be: + *
moveto(x1, y1);
+   * curveto(x2, y2, x3, y3, x4, y4);
+ * If you were to try and continue that curve like so: + *
curveto(x5, y5, x6, y6, x7, y7);
+ * This would be done in processing by adding these statements: + *
bezierVertex(x5, y5, x6, y6, x7, y7)
+   * 
+ * To draw a quadratic (instead of cubic) curve, + * use the control point twice by doubling it: + *
bezier(x1, y1, cx, cy, cx, cy, x2, y2);
+ * + * @webref shape:curves + * @param x1 coordinates for the first anchor point + * @param y1 coordinates for the first anchor point + * @param z1 coordinates for the first anchor point + * @param x2 coordinates for the first control point + * @param y2 coordinates for the first control point + * @param z2 coordinates for the first control point + * @param x3 coordinates for the second control point + * @param y3 coordinates for the second control point + * @param z3 coordinates for the second control point + * @param x4 coordinates for the second anchor point + * @param y4 coordinates for the second anchor point + * @param z4 coordinates for the second anchor point + * + * @see PGraphics#bezierVertex(float, float, float, float, float, float) + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + */ public void bezier(float x1, float y1, float x2, float y2, float x3, float y3, @@ -7681,28 +8094,137 @@ public class PApplet extends Applet } + /** + * Evalutes the Catmull-Rom curve at point t for points a, b, c, d. The + * parameter t varies between 0 and 1, a and d are points on the curve, + * and b and c are the control points. This can be done once with the x + * coordinates and a second time with the y coordinates to get the + * location of a curve at t. + * + * @webref shape:curves + * @param a coordinate of first point on the curve + * @param b coordinate of second point on the curve + * @param c coordinate of third point on the curve + * @param d coordinate of fourth point on the curve + * @param t value between 0 and 1 + * + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#curveVertex(float, float) + * @see PGraphics#bezierPoint(float, float, float, float, float) + */ public float curvePoint(float a, float b, float c, float d, float t) { return g.curvePoint(a, b, c, d, t); } + /** + * Calculates the tangent of a point on a Catmull-Rom curve. There is a good definition of "tangent" at Wikipedia: http://en.wikipedia.org/wiki/Tangent. + * + * =advanced + * Code thanks to Dave Bollinger (Bug #715) + * + * @webref shape:curves + * @param a coordinate of first point on the curve + * @param b coordinate of first control point + * @param c coordinate of second control point + * @param d coordinate of second point on the curve + * @param t value between 0 and 1 + * + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#curveVertex(float, float) + * @see PGraphics#curvePoint(float, float, float, float, float) + * @see PGraphics#bezierTangent(float, float, float, float, float) + */ public float curveTangent(float a, float b, float c, float d, float t) { return g.curveTangent(a, b, c, d, t); } + /** + * Sets the resolution at which curves display. The default value is 20. + * This function is only useful when using the P3D or OPENGL renderer as + * the default (JAVA2D) renderer does not use this information. + * + * @webref shape:curves + * @param detail resolution of the curves + * + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#curveVertex(float, float) + * @see PGraphics#curveTightness(float) + */ public void curveDetail(int detail) { if (recorder != null) recorder.curveDetail(detail); g.curveDetail(detail); } + /** + * Modifies the quality of forms created with curve() and + *curveVertex(). The parameter squishy determines how the + * curve fits to the vertex points. The value 0.0 is the default value for + * squishy (this value defines the curves to be Catmull-Rom splines) + * and the value 1.0 connects all the points with straight lines. + * Values within the range -5.0 and 5.0 will deform the curves but + * will leave them recognizable and as values increase in magnitude, + * they will continue to deform. + * + * @webref shape:curves + * @param tightness amount of deformation from the original vertices + * + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#curveVertex(float, float) + * + */ public void curveTightness(float tightness) { if (recorder != null) recorder.curveTightness(tightness); g.curveTightness(tightness); } + /** + * Draws a curved line on the screen. The first and second parameters + * specify the beginning control point and the last two parameters specify + * the ending control point. The middle parameters specify the start and + * stop of the curve. Longer curves can be created by putting a series of + * curve() functions together or using curveVertex(). + * An additional function called curveTightness() provides control + * for the visual quality of the curve. The curve() function is an + * implementation of Catmull-Rom splines. Using the 3D version of requires + * rendering with P3D or OPENGL (see the Environment reference for more + * information). + * + * =advanced + * As of revision 0070, this function no longer doubles the first + * and last points. The curves are a bit more boring, but it's more + * mathematically correct, and properly mirrored in curvePoint(). + *

+ * Identical to typing out:

+   * beginShape();
+   * curveVertex(x1, y1);
+   * curveVertex(x2, y2);
+   * curveVertex(x3, y3);
+   * curveVertex(x4, y4);
+   * endShape();
+   * 
+ * + * @webref shape:curves + * @param x1 coordinates for the beginning control point + * @param y1 coordinates for the beginning control point + * @param z1 coordinates for the beginning control point + * @param x2 coordinates for the first point + * @param y2 coordinates for the first point + * @param z2 coordinates for the first point + * @param x3 coordinates for the second point + * @param y3 coordinates for the second point + * @param z3 coordinates for the second point + * @param x4 coordinates for the ending control point + * @param y4 coordinates for the ending control point + * @param z4 coordinates for the ending control point + * + * @see PGraphics#curveVertex(float, float) + * @see PGraphics#curveTightness(float) + * @see PGraphics#bezier(float, float, float, float, float, float, float, float, float, float, float, float) + */ public void curve(float x1, float y1, float x2, float y2, float x3, float y3, @@ -7721,18 +8243,46 @@ public class PApplet extends Applet } + /** + * If true in PImage, use bilinear interpolation for copy() + * operations. When inherited by PGraphics, also controls shapes. + */ public void smooth() { if (recorder != null) recorder.smooth(); g.smooth(); } + /** + * Disable smoothing. See smooth(). + */ public void noSmooth() { if (recorder != null) recorder.noSmooth(); g.noSmooth(); } + /** + * Modifies the location from which images draw. The default mode is + * imageMode(CORNER), which specifies the location to be the + * upper-left corner and uses the fourth and fifth parameters of + * image() to set the image's width and height. The syntax + * imageMode(CORNERS) uses the second and third parameters of + * image() to set the location of one corner of the image and + * uses the fourth and fifth parameters to set the opposite corner. + * Use imageMode(CENTER) to draw images centered at the given + * x and y position. + *

The parameter to imageMode() must be written in + * ALL CAPS because Processing syntax is case sensitive. + * + * @webref image:loading_displaying + * @param mode Either CORNER, CORNERS, or CENTER + * + * @see processing.core.PApplet#loadImage(String, String) + * @see processing.core.PImage + * @see processing.core.PApplet#image(PImage, float, float, float, float) + * @see processing.core.PGraphics#background(float, float, float, float) + */ public void imageMode(int mode) { if (recorder != null) recorder.imageMode(mode); g.imageMode(mode); @@ -7745,12 +8295,50 @@ public class PApplet extends Applet } + /** + * Displays images to the screen. The images must be in the sketch's "data" + * directory to load correctly. Select "Add file..." from the "Sketch" menu + * to add the image. Processing currently works with GIF, JPEG, and Targa + * images. The color of an image may be modified with the tint() + * function and if a GIF has transparency, it will maintain its transparency. + * The img parameter specifies the image to display and the x + * and y parameters define the location of the image from its + * upper-left corner. The image is displayed at its original size unless + * the width and height parameters specify a different size. + * The imageMode() function changes the way the parameters work. + * A call to imageMode(CORNERS) will change the width and height + * parameters to define the x and y values of the opposite corner of the + * image. + * + * =advanced + * Starting with release 0124, when using the default (JAVA2D) renderer, + * smooth() will also improve image quality of resized images. + * + * @webref image:loading_displaying + * @param image the image to display + * @param x x-coordinate of the image + * @param y y-coordinate of the image + * @param c width to display the image + * @param d height to display the image + * + * @see processing.core.PApplet#loadImage(String, String) + * @see processing.core.PImage + * @see processing.core.PGraphics#imageMode(int) + * @see processing.core.PGraphics#tint(float) + * @see processing.core.PGraphics#background(float, float, float, float) + * @see processing.core.PGraphics#alpha(int) + */ public void image(PImage image, float x, float y, float c, float d) { if (recorder != null) recorder.image(image, x, y, c, d); g.image(image, x, y, c, d); } + /** + * Draw an image(), also specifying u/v coordinates. + * In this method, the u, v coordinates are always based on image space + * location, regardless of the current textureMode(). + */ public void image(PImage image, float a, float b, float c, float d, int u1, int v1, int u2, int v2) { @@ -7759,6 +8347,26 @@ public class PApplet extends Applet } + /** + * Modifies the location from which shapes draw. + * The default mode is shapeMode(CORNER), which specifies the + * location to be the upper left corner of the shape and uses the third + * and fourth parameters of shape() to specify the width and height. + * The syntax shapeMode(CORNERS) uses the first and second parameters + * of shape() to set the location of one corner and uses the third + * and fourth parameters to set the opposite corner. + * The syntax shapeMode(CENTER) draws the shape from its center point + * and uses the third and forth parameters of shape() to specify the + * width and height. + * The parameter must be written in "ALL CAPS" because Processing syntax + * is case sensitive. + * + * @param mode One of CORNER, CORNERS, CENTER + * + * @webref shape:loading_displaying + * @see PGraphics#shape(PShape) + * @see PGraphics#rectMode(int) + */ public void shapeMode(int mode) { if (recorder != null) recorder.shapeMode(mode); g.shapeMode(mode); @@ -7771,64 +8379,138 @@ public class PApplet extends Applet } + /** + * Convenience method to draw at a particular location. + */ public void shape(PShape shape, float x, float y) { if (recorder != null) recorder.shape(shape, x, y); g.shape(shape, x, y); } + /** + * Displays shapes to the screen. The shapes must be in the sketch's "data" + * directory to load correctly. Select "Add file..." from the "Sketch" menu + * to add the shape. + * Processing currently works with SVG shapes only. + * The sh parameter specifies the shape to display and the x + * and y parameters define the location of the shape from its + * upper-left corner. + * The shape is displayed at its original size unless the width + * and height parameters specify a different size. + * The shapeMode() function changes the way the parameters work. + * A call to shapeMode(CORNERS), for example, will change the width + * and height parameters to define the x and y values of the opposite corner + * of the shape. + *

+ * Note complex shapes may draw awkwardly with P2D, P3D, and OPENGL. Those + * renderers do not yet support shapes that have holes or complicated breaks. + * + * @param shape + * @param x x-coordinate of the shape + * @param y y-coordinate of the shape + * @param c width to display the shape + * @param d height to display the shape + * + * @webref shape:loading_displaying + * @see PShape + * @see PGraphics#loadShape(String) + * @see PGraphics#shapeMode(int) + */ public void shape(PShape shape, float x, float y, float c, float d) { if (recorder != null) recorder.shape(shape, x, y, c, d); g.shape(shape, x, y, c, d); } + /** + * Sets the alignment of the text to one of LEFT, CENTER, or RIGHT. + * This will also reset the vertical text alignment to BASELINE. + */ public void textAlign(int align) { if (recorder != null) recorder.textAlign(align); g.textAlign(align); } + /** + * Sets the horizontal and vertical alignment of the text. The horizontal + * alignment can be one of LEFT, CENTER, or RIGHT. The vertical alignment + * can be TOP, BOTTOM, CENTER, or the BASELINE (the default). + */ public void textAlign(int alignX, int alignY) { if (recorder != null) recorder.textAlign(alignX, alignY); g.textAlign(alignX, alignY); } + /** + * Returns the ascent of the current font at the current size. + * This is a method, rather than a variable inside the PGraphics object + * because it requires calculation. + */ public float textAscent() { return g.textAscent(); } + /** + * Returns the descent of the current font at the current size. + * This is a method, rather than a variable inside the PGraphics object + * because it requires calculation. + */ public float textDescent() { return g.textDescent(); } + /** + * Sets the current font. The font's size will be the "natural" + * size of this font (the size that was set when using "Create Font"). + * The leading will also be reset. + */ public void textFont(PFont which) { if (recorder != null) recorder.textFont(which); g.textFont(which); } + /** + * Useful function to set the font and size at the same time. + */ public void textFont(PFont which, float size) { if (recorder != null) recorder.textFont(which, size); g.textFont(which, size); } + /** + * Set the text leading to a specific value. If using a custom + * value for the text leading, you'll have to call textLeading() + * again after any calls to textSize(). + */ public void textLeading(float leading) { if (recorder != null) recorder.textLeading(leading); g.textLeading(leading); } + /** + * Sets the text rendering/placement to be either SCREEN (direct + * to the screen, exact coordinates, only use the font's original size) + * or MODEL (the default, where text is manipulated by translate() and + * can have a textSize). The text size cannot be set when using + * textMode(SCREEN), because it uses the pixels directly from the font. + */ public void textMode(int mode) { if (recorder != null) recorder.textMode(mode); g.textMode(mode); } + /** + * Sets the text size, also resets the value for the leading. + */ public void textSize(float size) { if (recorder != null) recorder.textSize(size); g.textSize(size); @@ -7840,52 +8522,87 @@ public class PApplet extends Applet } + /** + * Return the width of a line of text. If the text has multiple + * lines, this returns the length of the longest line. + */ public float textWidth(String str) { return g.textWidth(str); } + /** + * TODO not sure if this stays... + */ public float textWidth(char[] chars, int start, int length) { return g.textWidth(chars, start, length); } + /** + * Write text where we just left off. + */ public void text(char c) { if (recorder != null) recorder.text(c); g.text(c); } + /** + * Draw a single character on screen. + * Extremely slow when used with textMode(SCREEN) and Java 2D, + * because loadPixels has to be called first and updatePixels last. + */ public void text(char c, float x, float y) { if (recorder != null) recorder.text(c, x, y); g.text(c, x, y); } + /** + * Draw a single character on screen (with a z coordinate) + */ public void text(char c, float x, float y, float z) { if (recorder != null) recorder.text(c, x, y, z); g.text(c, x, y, z); } + /** + * Write text where we just left off. + */ public void text(String str) { if (recorder != null) recorder.text(str); g.text(str); } + /** + * Draw a chunk of text. + * Newlines that are \n (Unix newline or linefeed char, ascii 10) + * are honored, but \r (carriage return, Windows and Mac OS) are + * ignored. + */ public void text(String str, float x, float y) { if (recorder != null) recorder.text(str, x, y); g.text(str, x, y); } + /** + * Method to draw text from an array of chars. This method will usually be + * more efficient than drawing from a String object, because the String will + * not be converted to a char array before drawing. + */ public void text(char[] chars, int start, int stop, float x, float y) { if (recorder != null) recorder.text(chars, start, stop, x, y); g.text(chars, start, stop, x, y); } + /** + * Same as above but with a z coordinate. + */ public void text(String str, float x, float y, float z) { if (recorder != null) recorder.text(str, x, y, z); g.text(str, x, y, z); @@ -7899,6 +8616,19 @@ public class PApplet extends Applet } + /** + * Draw text in a box that is constrained to a particular size. + * The current rectMode() determines what the coordinates mean + * (whether x1/y1/x2/y2 or x/y/w/h). + *

+ * Note that the x,y coords of the start of the box + * will align with the *ascent* of the text, not the baseline, + * as is the case for the other text() functions. + *

+ * Newlines that are \n (Unix newline or linefeed char, ascii 10) + * are honored, and \r (carriage return, Windows and Mac OS) are + * ignored. + */ public void text(String str, float x1, float y1, float x2, float y2) { if (recorder != null) recorder.text(str, x1, y1, x2, y2); g.text(str, x1, y1, x2, y2); @@ -7923,6 +8653,13 @@ public class PApplet extends Applet } + /** + * This does a basic number formatting, to avoid the + * generally ugly appearance of printing floats. + * Users who want more control should use their own nf() cmmand, + * or if they want the long, ugly version of float, + * use String.valueOf() to convert the float to a String first. + */ public void text(float num, float x, float y) { if (recorder != null) recorder.text(num, x, y); g.text(num, x, y); @@ -7935,78 +8672,131 @@ public class PApplet extends Applet } + /** + * Push a copy of the current transformation matrix onto the stack. + */ public void pushMatrix() { if (recorder != null) recorder.pushMatrix(); g.pushMatrix(); } + /** + * Replace the current transformation matrix with the top of the stack. + */ public void popMatrix() { if (recorder != null) recorder.popMatrix(); g.popMatrix(); } + /** + * Translate in X and Y. + */ public void translate(float tx, float ty) { if (recorder != null) recorder.translate(tx, ty); g.translate(tx, ty); } + /** + * Translate in X, Y, and Z. + */ public void translate(float tx, float ty, float tz) { if (recorder != null) recorder.translate(tx, ty, tz); g.translate(tx, ty, tz); } + /** + * Two dimensional rotation. + * + * Same as rotateZ (this is identical to a 3D rotation along the z-axis) + * but included for clarity. It'd be weird for people drawing 2D graphics + * to be using rotateZ. And they might kick our a-- for the confusion. + * + * Additional background. + */ public void rotate(float angle) { if (recorder != null) recorder.rotate(angle); g.rotate(angle); } + /** + * Rotate around the X axis. + */ public void rotateX(float angle) { if (recorder != null) recorder.rotateX(angle); g.rotateX(angle); } + /** + * Rotate around the Y axis. + */ public void rotateY(float angle) { if (recorder != null) recorder.rotateY(angle); g.rotateY(angle); } + /** + * Rotate around the Z axis. + * + * The functions rotate() and rotateZ() are identical, it's just that it make + * sense to have rotate() and then rotateX() and rotateY() when using 3D; + * nor does it make sense to use a function called rotateZ() if you're only + * doing things in 2D. so we just decided to have them both be the same. + */ public void rotateZ(float angle) { if (recorder != null) recorder.rotateZ(angle); g.rotateZ(angle); } + /** + * Rotate about a vector in space. Same as the glRotatef() function. + */ public void rotate(float angle, float vx, float vy, float vz) { if (recorder != null) recorder.rotate(angle, vx, vy, vz); g.rotate(angle, vx, vy, vz); } + /** + * Scale in all dimensions. + */ public void scale(float s) { if (recorder != null) recorder.scale(s); g.scale(s); } + /** + * Scale in X and Y. Equivalent to scale(sx, sy, 1). + * + * Not recommended for use in 3D, because the z-dimension is just + * scaled by 1, since there's no way to know what else to scale it by. + */ public void scale(float sx, float sy) { if (recorder != null) recorder.scale(sx, sy); g.scale(sx, sy); } + /** + * Scale in X, Y, and Z. + */ public void scale(float x, float y, float z) { if (recorder != null) recorder.scale(x, y, z); g.scale(x, y, z); } + /** + * Set the current transformation matrix to identity. + */ public void resetMatrix() { if (recorder != null) recorder.resetMatrix(); g.resetMatrix(); @@ -8025,6 +8815,9 @@ public class PApplet extends Applet } + /** + * Apply a 3x2 affine transformation matrix. + */ public void applyMatrix(float n00, float n01, float n02, float n10, float n11, float n12) { if (recorder != null) recorder.applyMatrix(n00, n01, n02, n10, n11, n12); @@ -8038,6 +8831,9 @@ public class PApplet extends Applet } + /** + * Apply a 4x4 transformation matrix. + */ public void applyMatrix(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, float n20, float n21, float n22, float n23, @@ -8052,34 +8848,54 @@ public class PApplet extends Applet } + /** + * Copy the current transformation matrix into the specified target. + * Pass in null to create a new matrix. + */ public PMatrix2D getMatrix(PMatrix2D target) { return g.getMatrix(target); } + /** + * Copy the current transformation matrix into the specified target. + * Pass in null to create a new matrix. + */ public PMatrix3D getMatrix(PMatrix3D target) { return g.getMatrix(target); } + /** + * Set the current transformation matrix to the contents of another. + */ public void setMatrix(PMatrix source) { if (recorder != null) recorder.setMatrix(source); g.setMatrix(source); } + /** + * Set the current transformation to the contents of the specified source. + */ public void setMatrix(PMatrix2D source) { if (recorder != null) recorder.setMatrix(source); g.setMatrix(source); } + /** + * Set the current transformation to the contents of the specified source. + */ public void setMatrix(PMatrix3D source) { if (recorder != null) recorder.setMatrix(source); g.setMatrix(source); } + /** + * Print the current model (or "transformation") matrix. + */ public void printMatrix() { if (recorder != null) recorder.printMatrix(); g.printMatrix(); @@ -8158,41 +8974,91 @@ public class PApplet extends Applet } + /** + * Given an x and y coordinate, returns the x position of where + * that point would be placed on screen, once affected by translate(), + * scale(), or any other transformations. + */ public float screenX(float x, float y) { return g.screenX(x, y); } + /** + * Given an x and y coordinate, returns the y position of where + * that point would be placed on screen, once affected by translate(), + * scale(), or any other transformations. + */ public float screenY(float x, float y) { return g.screenY(x, y); } + /** + * Maps a three dimensional point to its placement on-screen. + *

+ * Given an (x, y, z) coordinate, returns the x position of where + * that point would be placed on screen, once affected by translate(), + * scale(), or any other transformations. + */ public float screenX(float x, float y, float z) { return g.screenX(x, y, z); } + /** + * Maps a three dimensional point to its placement on-screen. + *

+ * Given an (x, y, z) coordinate, returns the y position of where + * that point would be placed on screen, once affected by translate(), + * scale(), or any other transformations. + */ public float screenY(float x, float y, float z) { return g.screenY(x, y, z); } + /** + * Maps a three dimensional point to its placement on-screen. + *

+ * Given an (x, y, z) coordinate, returns its z value. + * This value can be used to determine if an (x, y, z) coordinate + * is in front or in back of another (x, y, z) coordinate. + * The units are based on how the zbuffer is set up, and don't + * relate to anything "real". They're only useful for in + * comparison to another value obtained from screenZ(), + * or directly out of the zbuffer[]. + */ public float screenZ(float x, float y, float z) { return g.screenZ(x, y, z); } + /** + * Returns the model space x value for an x, y, z coordinate. + *

+ * This will give you a coordinate after it has been transformed + * by translate(), rotate(), and camera(), but not yet transformed + * by the projection matrix. For instance, his can be useful for + * figuring out how points in 3D space relate to the edge + * coordinates of a shape. + */ public float modelX(float x, float y, float z) { return g.modelX(x, y, z); } + /** + * Returns the model space y value for an x, y, z coordinate. + */ public float modelY(float x, float y, float z) { return g.modelY(x, y, z); } + /** + * Returns the model space z value for an x, y, z coordinate. + */ public float modelZ(float x, float y, float z) { return g.modelZ(x, y, z); } @@ -8234,12 +9100,26 @@ public class PApplet extends Applet } + /** + * Disables drawing the stroke (outline). If both noStroke() and + * noFill() are called, no shapes will be drawn to the screen. + * + * @webref color:setting + * + * @see PGraphics#stroke(float, float, float, float) + */ public void noStroke() { if (recorder != null) recorder.noStroke(); g.noStroke(); } + /** + * Set the tint to either a grayscale or ARGB value. + * See notes attached to the fill() function. + * @param rgb color value in hexadecimal notation + * (i.e. #FFCC00 or 0xFFFFCC00) or any value of the color datatype + */ public void stroke(int rgb) { if (recorder != null) recorder.stroke(rgb); g.stroke(rgb); @@ -8252,6 +9132,10 @@ public class PApplet extends Applet } + /** + * + * @param gray specifies a value between white and black + */ public void stroke(float gray) { if (recorder != null) recorder.stroke(gray); g.stroke(gray); @@ -8270,30 +9154,70 @@ public class PApplet extends Applet } + /** + * Sets the color used to draw lines and borders around shapes. This color + * is either specified in terms of the RGB or HSB color depending on the + * current colorMode() (the default color space is RGB, with each + * value in the range from 0 to 255). + *

When using hexadecimal notation to specify a color, use "#" or + * "0x" before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six + * digits to specify a color (the way colors are specified in HTML and CSS). + * When using the hexadecimal notation starting with "0x", the hexadecimal + * value must be specified with eight characters; the first two characters + * define the alpha component and the remainder the red, green, and blue + * components. + *

The value for the parameter "gray" must be less than or equal + * to the current maximum value as specified by colorMode(). + * The default maximum value is 255. + * + * @webref color:setting + * @param alpha opacity of the stroke + * @param x red or hue value (depending on the current color mode) + * @param y green or saturation value (depending on the current color mode) + * @param z blue or brightness value (depending on the current color mode) + */ public void stroke(float x, float y, float z, float a) { if (recorder != null) recorder.stroke(x, y, z, a); g.stroke(x, y, z, a); } + /** + * Removes the current fill value for displaying images and reverts to displaying images with their original hues. + * + * @webref image:loading_displaying + * @see processing.core.PGraphics#tint(float, float, float, float) + * @see processing.core.PGraphics#image(PImage, float, float, float, float) + */ public void noTint() { if (recorder != null) recorder.noTint(); g.noTint(); } + /** + * Set the tint to either a grayscale or ARGB value. + */ public void tint(int rgb) { if (recorder != null) recorder.tint(rgb); g.tint(rgb); } + /** + * @param rgb color value in hexadecimal notation + * (i.e. #FFCC00 or 0xFFFFCC00) or any value of the color datatype + * @param alpha opacity of the image + */ public void tint(int rgb, float alpha) { if (recorder != null) recorder.tint(rgb, alpha); g.tint(rgb, alpha); } + /** + * @param gray any valid number + */ public void tint(float gray) { if (recorder != null) recorder.tint(gray); g.tint(gray); @@ -8312,18 +9236,60 @@ public class PApplet extends Applet } + /** + * Sets the fill value for displaying images. Images can be tinted to + * specified colors or made transparent by setting the alpha. + *

To make an image transparent, but not change it's color, + * use white as the tint color and specify an alpha value. For instance, + * tint(255, 128) will make an image 50% transparent (unless + * colorMode() has been used). + * + *

When using hexadecimal notation to specify a color, use "#" or + * "0x" before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six + * digits to specify a color (the way colors are specified in HTML and CSS). + * When using the hexadecimal notation starting with "0x", the hexadecimal + * value must be specified with eight characters; the first two characters + * define the alpha component and the remainder the red, green, and blue + * components. + *

The value for the parameter "gray" must be less than or equal + * to the current maximum value as specified by colorMode(). + * The default maximum value is 255. + *

The tint() method is also used to control the coloring of + * textures in 3D. + * + * @webref image:loading_displaying + * @param x red or hue value + * @param y green or saturation value + * @param z blue or brightness value + * + * @see processing.core.PGraphics#noTint() + * @see processing.core.PGraphics#image(PImage, float, float, float, float) + */ public void tint(float x, float y, float z, float a) { if (recorder != null) recorder.tint(x, y, z, a); g.tint(x, y, z, a); } + /** + * Disables filling geometry. If both noStroke() and noFill() + * are called, no shapes will be drawn to the screen. + * + * @webref color:setting + * + * @see PGraphics#fill(float, float, float, float) + * + */ public void noFill() { if (recorder != null) recorder.noFill(); g.noFill(); } + /** + * Set the fill to either a grayscale value or an ARGB int. + * @param rgb color value in hexadecimal notation (i.e. #FFCC00 or 0xFFFFCC00) or any value of the color datatype + */ public void fill(int rgb) { if (recorder != null) recorder.fill(rgb); g.fill(rgb); @@ -8336,6 +9302,9 @@ public class PApplet extends Applet } + /** + * @param gray number specifying value between white and black + */ public void fill(float gray) { if (recorder != null) recorder.fill(gray); g.fill(gray); @@ -8354,6 +9323,24 @@ public class PApplet extends Applet } + /** + * Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), all subsequent shapes will be filled with orange. This color is either specified in terms of the RGB or HSB color depending on the current colorMode() (the default color space is RGB, with each value in the range from 0 to 255). + *

When using hexadecimal notation to specify a color, use "#" or "0x" before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six digits to specify a color (the way colors are specified in HTML and CSS). When using the hexadecimal notation starting with "0x", the hexadecimal value must be specified with eight characters; the first two characters define the alpha component and the remainder the red, green, and blue components. + *

The value for the parameter "gray" must be less than or equal to the current maximum value as specified by colorMode(). The default maximum value is 255. + *

To change the color of an image (or a texture), use tint(). + * + * @webref color:setting + * @param x red or hue value + * @param y green or saturation value + * @param z blue or brightness value + * @param alpha opacity of the fill + * + * @see PGraphics#noFill() + * @see PGraphics#stroke(float) + * @see PGraphics#tint(float) + * @see PGraphics#background(float, float, float, float) + * @see PGraphics#colorMode(int, float, float, float, float) + */ public void fill(float x, float y, float z, float a) { if (recorder != null) recorder.fill(x, y, z, a); g.fill(x, y, z, a); @@ -8480,48 +9467,119 @@ public class PApplet extends Applet } + /** + * Set the background to a gray or ARGB color. + *

+ * For the main drawing surface, the alpha value will be ignored. However, + * alpha can be used on PGraphics objects from createGraphics(). This is + * the only way to set all the pixels partially transparent, for instance. + *

+ * Note that background() should be called before any transformations occur, + * because some implementations may require the current transformation matrix + * to be identity before drawing. + * + * @param rgb color value in hexadecimal notation (i.e. #FFCC00 or 0xFFFFCC00)
or any value of the color datatype + */ public void background(int rgb) { if (recorder != null) recorder.background(rgb); g.background(rgb); } + /** + * See notes about alpha in background(x, y, z, a). + */ public void background(int rgb, float alpha) { if (recorder != null) recorder.background(rgb, alpha); g.background(rgb, alpha); } + /** + * Set the background to a grayscale value, based on the + * current colorMode. + */ public void background(float gray) { if (recorder != null) recorder.background(gray); g.background(gray); } + /** + * See notes about alpha in background(x, y, z, a). + * @param gray specifies a value between white and black + * @param alpha opacity of the background + */ public void background(float gray, float alpha) { if (recorder != null) recorder.background(gray, alpha); g.background(gray, alpha); } + /** + * Set the background to an r, g, b or h, s, b value, + * based on the current colorMode. + */ public void background(float x, float y, float z) { if (recorder != null) recorder.background(x, y, z); g.background(x, y, z); } + /** + * The background() function sets the color used for the background of the Processing window. The default background is light gray. In the draw() function, the background color is used to clear the display window at the beginning of each frame. + *

An image can also be used as the background for a sketch, however its width and height must be the same size as the sketch window. To resize an image 'b' to the size of the sketch window, use b.resize(width, height). + *

Images used as background will ignore the current tint() setting. + *

It is not possible to use transparency (alpha) in background colors with the main drawing surface, however they will work properly with createGraphics. + * + * =advanced + *

Clear the background with a color that includes an alpha value. This can + * only be used with objects created by createGraphics(), because the main + * drawing surface cannot be set transparent.

+ *

It might be tempting to use this function to partially clear the screen + * on each frame, however that's not how this function works. When calling + * background(), the pixels will be replaced with pixels that have that level + * of transparency. To do a semi-transparent overlay, use fill() with alpha + * and draw a rectangle.

+ * + * @webref color:setting + * @param x red or hue value (depending on the current color mode) + * @param y green or saturation value (depending on the current color mode) + * @param z blue or brightness value (depending on the current color mode) + * + * @see PGraphics#stroke(float) + * @see PGraphics#fill(float) + * @see PGraphics#tint(float) + * @see PGraphics#colorMode(int) + */ public void background(float x, float y, float z, float a) { if (recorder != null) recorder.background(x, y, z, a); g.background(x, y, z, a); } + /** + * Takes an RGB or ARGB image and sets it as the background. + * The width and height of the image must be the same size as the sketch. + * Use image.resize(width, height) to make short work of such a task. + *

+ * Note that even if the image is set as RGB, the high 8 bits of each pixel + * should be set opaque (0xFF000000), because the image data will be copied + * directly to the screen, and non-opaque background images may have strange + * behavior. Using image.filter(OPAQUE) will handle this easily. + *

+ * When using 3D, this will also clear the zbuffer (if it exists). + */ public void background(PImage image) { if (recorder != null) recorder.background(image); g.background(image); } + /** + * @param mode Either RGB or HSB, corresponding to Red/Green/Blue and Hue/Saturation/Brightness + * @param max range for all color elements + */ public void colorMode(int mode) { if (recorder != null) recorder.colorMode(mode); g.colorMode(mode); @@ -8534,12 +9592,34 @@ public class PApplet extends Applet } + /** + * Set the colorMode and the maximum values for (r, g, b) + * or (h, s, b). + *

+ * Note that this doesn't set the maximum for the alpha value, + * which might be confusing if for instance you switched to + *

colorMode(HSB, 360, 100, 100);
+ * because the alpha values were still between 0 and 255. + */ public void colorMode(int mode, float maxX, float maxY, float maxZ) { if (recorder != null) recorder.colorMode(mode, maxX, maxY, maxZ); g.colorMode(mode, maxX, maxY, maxZ); } + /** + * Changes the way Processing interprets color data. By default, the parameters for fill(), stroke(), background(), and color() are defined by values between 0 and 255 using the RGB color model. The colorMode() function is used to change the numerical range used for specifying colors and to switch color systems. For example, calling colorMode(RGB, 1.0) will specify that values are specified between 0 and 1. The limits for defining colors are altered by setting the parameters range1, range2, range3, and range 4. + * + * @webref color:setting + * @param maxX range for the red or hue depending on the current color mode + * @param maxY range for the green or saturation depending on the current color mode + * @param maxZ range for the blue or brightness depending on the current color mode + * @param maxA range for the alpha + * + * @see PGraphics#background(float) + * @see PGraphics#fill(float) + * @see PGraphics#stroke(float) + */ public void colorMode(int mode, float maxX, float maxY, float maxZ, float maxA) { if (recorder != null) recorder.colorMode(mode, maxX, maxY, maxZ, maxA); @@ -8547,106 +9627,310 @@ public class PApplet extends Applet } + /** + * Extracts the alpha value from a color. + * + * @webref color:creating_reading + * @param what any value of the color datatype + */ public final float alpha(int what) { return g.alpha(what); } + /** + * Extracts the red value from a color, scaled to match current colorMode(). This value is always returned as a float so be careful not to assign it to an int value.

The red() function is easy to use and undestand, but is slower than another technique. To achieve the same results when working in colorMode(RGB, 255), but with greater speed, use the >> (right shift) operator with a bit mask. For example, the following two lines of code are equivalent:
float r1 = red(myColor);
float r2 = myColor >> 16 & 0xFF;
+ * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#green(int) + * @see PGraphics#blue(int) + * @see PGraphics#hue(int) + * @see PGraphics#saturation(int) + * @see PGraphics#brightness(int) + * @ref rightshift + */ public final float red(int what) { return g.red(what); } + /** + * Extracts the green value from a color, scaled to match current colorMode(). This value is always returned as a float so be careful not to assign it to an int value.

The green() function is easy to use and undestand, but is slower than another technique. To achieve the same results when working in colorMode(RGB, 255), but with greater speed, use the >> (right shift) operator with a bit mask. For example, the following two lines of code are equivalent:
float r1 = green(myColor);
float r2 = myColor >> 8 & 0xFF;
+ * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#blue(int) + * @see PGraphics#hue(int) + * @see PGraphics#saturation(int) + * @see PGraphics#brightness(int) + * @ref rightshift + */ public final float green(int what) { return g.green(what); } + /** + * Extracts the blue value from a color, scaled to match current colorMode(). This value is always returned as a float so be careful not to assign it to an int value.

The blue() function is easy to use and undestand, but is slower than another technique. To achieve the same results when working in colorMode(RGB, 255), but with greater speed, use a bit mask to remove the other color components. For example, the following two lines of code are equivalent:
float r1 = blue(myColor);
float r2 = myColor & 0xFF;
+ * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#green(int) + * @see PGraphics#hue(int) + * @see PGraphics#saturation(int) + * @see PGraphics#brightness(int) + */ public final float blue(int what) { return g.blue(what); } + /** + * Extracts the hue value from a color. + * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#green(int) + * @see PGraphics#blue(int) + * @see PGraphics#saturation(int) + * @see PGraphics#brightness(int) + */ public final float hue(int what) { return g.hue(what); } + /** + * Extracts the saturation value from a color. + * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#green(int) + * @see PGraphics#blue(int) + * @see PGraphics#hue(int) + * @see PGraphics#brightness(int) + */ public final float saturation(int what) { return g.saturation(what); } + /** + * Extracts the brightness value from a color. + * + * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#green(int) + * @see PGraphics#blue(int) + * @see PGraphics#hue(int) + * @see PGraphics#saturation(int) + */ public final float brightness(int what) { return g.brightness(what); } + /** + * Calculates a color or colors between two color at a specific increment. The amt parameter is the amount to interpolate between the two values where 0.0 equal to the first point, 0.1 is very near the first point, 0.5 is half-way in between, etc. + * + * @webref color:creating_reading + * @param c1 interpolate from this color + * @param c2 interpolate to this color + * @param amt between 0.0 and 1.0 + * + * @see PGraphics#blendColor(int, int, int) + * @see PGraphics#color(float, float, float, float) + */ public int lerpColor(int c1, int c2, float amt) { return g.lerpColor(c1, c2, amt); } + /** + * Interpolate between two colors. Like lerp(), but for the + * individual color components of a color supplied as an int value. + */ static public int lerpColor(int c1, int c2, float amt, int mode) { return PGraphics.lerpColor(c1, c2, amt, mode); } + /** + * Return true if this renderer should be drawn to the screen. Defaults to + * returning true, since nearly all renderers are on-screen beasts. But can + * be overridden for subclasses like PDF so that a window doesn't open up. + *

+ * A better name? showFrame, displayable, isVisible, visible, shouldDisplay, + * what to call this? + */ public boolean displayable() { return g.displayable(); } + /** + * Store data of some kind for a renderer that requires extra metadata of + * some kind. Usually this is a renderer-specific representation of the + * image data, for instance a BufferedImage with tint() settings applied for + * PGraphicsJava2D, or resized image data and OpenGL texture indices for + * PGraphicsOpenGL. + */ public void setCache(Object parent, Object storage) { if (recorder != null) recorder.setCache(parent, storage); g.setCache(parent, storage); } + /** + * Get cache storage data for the specified renderer. Because each renderer + * will cache data in different formats, it's necessary to store cache data + * keyed by the renderer object. Otherwise, attempting to draw the same + * image to both a PGraphicsJava2D and a PGraphicsOpenGL will cause errors. + * @param parent The PGraphics object (or any object, really) associated + * @return data stored for the specified parent + */ public Object getCache(Object parent) { return g.getCache(parent); } + /** + * Remove information associated with this renderer from the cache, if any. + * @param parent The PGraphics object whose cache data should be removed + */ public void removeCache(Object parent) { if (recorder != null) recorder.removeCache(parent); g.removeCache(parent); } + /** + * Returns an ARGB "color" type (a packed 32 bit int with the color. + * If the coordinate is outside the image, zero is returned + * (black, but completely transparent). + *

+ * If the image is in RGB format (i.e. on a PVideo object), + * the value will get its high bits set, just to avoid cases where + * they haven't been set already. + *

+ * If the image is in ALPHA format, this returns a white with its + * alpha value set. + *

+ * This function is included primarily for beginners. It is quite + * slow because it has to check to see if the x, y that was provided + * is inside the bounds, and then has to check to see what image + * type it is. If you want things to be more efficient, access the + * pixels[] array directly. + */ public int get(int x, int y) { return g.get(x, y); } + /** + * Reads the color of any pixel or grabs a group of pixels. If no parameters are specified, the entire image is returned. Get the value of one pixel by specifying an x,y coordinate. Get a section of the display window by specifing an additional width and height parameter. If the pixel requested is outside of the image window, black is returned. The numbers returned are scaled according to the current color ranges, but only RGB values are returned by this function. Even though you may have drawn a shape with colorMode(HSB), the numbers returned will be in RGB. + *

Getting the color of a single pixel with get(x, y) is easy, but not as fast as grabbing the data directly from pixels[]. The equivalent statement to "get(x, y)" using pixels[] is "pixels[y*width+x]". Processing requires calling loadPixels() to load the display window data into the pixels[] array before getting the values. + *

As of release 0149, this function ignores imageMode(). + * + * @webref + * @brief Reads the color of any pixel or grabs a rectangle of pixels + * @param x x-coordinate of the pixel + * @param y y-coordinate of the pixel + * @param w width of pixel rectangle to get + * @param h height of pixel rectangle to get + * + * @see processing.core.PImage#set(int, int, int) + * @see processing.core.PImage#pixels + * @see processing.core.PImage#copy(PImage, int, int, int, int, int, int, int, int) + */ public PImage get(int x, int y, int w, int h) { return g.get(x, y, w, h); } + /** + * Returns a copy of this PImage. Equivalent to get(0, 0, width, height). + */ public PImage get() { return g.get(); } + /** + * Changes the color of any pixel or writes an image directly into the display window. The x and y parameters specify the pixel to change and the color parameter specifies the color value. The color parameter is affected by the current color mode (the default is RGB values from 0 to 255). When setting an image, the x and y parameters define the coordinates for the upper-left corner of the image. + *

Setting the color of a single pixel with set(x, y) is easy, but not as fast as putting the data directly into pixels[]. The equivalent statement to "set(x, y, #000000)" using pixels[] is "pixels[y*width+x] = #000000". You must call loadPixels() to load the display window data into the pixels[] array before setting the values and calling updatePixels() to update the window with any changes. + *

As of release 1.0, this function ignores imageMode(). + *

Due to what appears to be a bug in Apple's Java implementation, the point() and set() methods are extremely slow in some circumstances when used with the default renderer. Using P2D or P3D will fix the problem. Grouping many calls to point() or set() together can also help. (Bug 1094) + * =advanced + *

As of release 0149, this function ignores imageMode(). + * + * @webref image:pixels + * @param x x-coordinate of the pixel + * @param y y-coordinate of the pixel + * @param c any value of the color datatype + */ public void set(int x, int y, int c) { if (recorder != null) recorder.set(x, y, c); g.set(x, y, c); } + /** + * Efficient method of drawing an image's pixels directly to this surface. + * No variations are employed, meaning that any scale, tint, or imageMode + * settings will be ignored. + */ public void set(int x, int y, PImage src) { if (recorder != null) recorder.set(x, y, src); g.set(x, y, src); } + /** + * Set alpha channel for an image. Black colors in the source + * image will make the destination image completely transparent, + * and white will make things fully opaque. Gray values will + * be in-between steps. + *

+ * Strictly speaking the "blue" value from the source image is + * used as the alpha color. For a fully grayscale image, this + * is correct, but for a color image it's not 100% accurate. + * For a more accurate conversion, first use filter(GRAY) + * which will make the image into a "correct" grayscale by + * performing a proper luminance-based conversion. + * + * @param maskArray any array of Integer numbers used as the alpha channel, needs to be same length as the image's pixel array + */ public void mask(int maskArray[]) { if (recorder != null) recorder.mask(maskArray); g.mask(maskArray); } + /** + * Masks part of an image from displaying by loading another image and using it as an alpha channel. + * This mask image should only contain grayscale data, but only the blue color channel is used. + * The mask image needs to be the same size as the image to which it is applied. + * In addition to using a mask image, an integer array containing the alpha channel data can be specified directly. + * This method is useful for creating dynamically generated alpha masks. + * This array must be of the same length as the target image's pixels array and should contain only grayscale data of values between 0-255. + * @webref + * @brief Masks part of the image from displaying + * @param maskImg any PImage object used as the alpha channel for "img", needs to be same size as "img" + */ public void mask(PImage maskImg) { if (recorder != null) recorder.mask(maskImg); g.mask(maskImg); @@ -8659,12 +9943,41 @@ public class PApplet extends Applet } + /** + * Filters an image as defined by one of the following modes:

THRESHOLD - converts the image to black and white pixels depending if they are above or below the threshold defined by the level parameter. The level must be between 0.0 (black) and 1.0(white). If no level is specified, 0.5 is used.

GRAY - converts any colors in the image to grayscale equivalents

INVERT - sets each pixel to its inverse value

POSTERIZE - limits each channel of the image to the number of colors specified as the level parameter

BLUR - executes a Guassian blur with the level parameter specifying the extent of the blurring. If no level parameter is used, the blur is equivalent to Guassian blur of radius 1.

OPAQUE - sets the alpha channel to entirely opaque.

ERODE - reduces the light areas with the amount defined by the level parameter.

DILATE - increases the light areas with the amount defined by the level parameter + * =advanced + * Method to apply a variety of basic filters to this image. + *

+ *

    + *
  • filter(BLUR) provides a basic blur. + *
  • filter(GRAY) converts the image to grayscale based on luminance. + *
  • filter(INVERT) will invert the color components in the image. + *
  • filter(OPAQUE) set all the high bits in the image to opaque + *
  • filter(THRESHOLD) converts the image to black and white. + *
  • filter(DILATE) grow white/light areas + *
  • filter(ERODE) shrink white/light areas + *
+ * Luminance conversion code contributed by + * toxi + *

+ * Gaussian blur code contributed by + * Mario Klingemann + * + * @webref + * @brief Converts the image to grayscale or black and white + * @param kind Either THRESHOLD, GRAY, INVERT, POSTERIZE, BLUR, OPAQUE, ERODE, or DILATE + * @param param in the range from 0 to 1 + */ public void filter(int kind, float param) { if (recorder != null) recorder.filter(kind, param); g.filter(kind, param); } + /** + * Copy things from one area of this image + * to another area in the same image. + */ public void copy(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) { if (recorder != null) recorder.copy(sx, sy, sw, sh, dx, dy, dw, dh); @@ -8672,6 +9985,25 @@ public class PApplet extends Applet } + /** + * Copies a region of pixels from one image into another. If the source and destination regions aren't the same size, it will automatically resize source pixels to fit the specified target region. No alpha information is used in the process, however if the source image has an alpha channel set, it will be copied as well. + *

As of release 0149, this function ignores imageMode(). + * + * @webref + * @brief Copies the entire image + * @param sx X coordinate of the source's upper left corner + * @param sy Y coordinate of the source's upper left corner + * @param sw source image width + * @param sh source image height + * @param dx X coordinate of the destination's upper left corner + * @param dy Y coordinate of the destination's upper left corner + * @param dw destination image width + * @param dh destination image height + * @param src an image variable referring to the source image. + * + * @see processing.core.PGraphics#alpha(int) + * @see processing.core.PImage#blend(PImage, int, int, int, int, int, int, int, int, int) + */ public void copy(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) { @@ -8680,11 +10012,80 @@ public class PApplet extends Applet } + /** + * Blend two colors based on a particular mode. + *

    + *
  • REPLACE - destination colour equals colour of source pixel: C = A. + * Sometimes called "Normal" or "Copy" in other software. + * + *
  • BLEND - linear interpolation of colours: + * C = A*factor + B + * + *
  • ADD - additive blending with white clip: + * C = min(A*factor + B, 255). + * Clipped to 0..255, Photoshop calls this "Linear Burn", + * and Director calls it "Add Pin". + * + *
  • SUBTRACT - substractive blend with black clip: + * C = max(B - A*factor, 0). + * Clipped to 0..255, Photoshop calls this "Linear Dodge", + * and Director calls it "Subtract Pin". + * + *
  • DARKEST - only the darkest colour succeeds: + * C = min(A*factor, B). + * Illustrator calls this "Darken". + * + *
  • LIGHTEST - only the lightest colour succeeds: + * C = max(A*factor, B). + * Illustrator calls this "Lighten". + * + *
  • DIFFERENCE - subtract colors from underlying image. + * + *
  • EXCLUSION - similar to DIFFERENCE, but less extreme. + * + *
  • MULTIPLY - Multiply the colors, result will always be darker. + * + *
  • SCREEN - Opposite multiply, uses inverse values of the colors. + * + *
  • OVERLAY - A mix of MULTIPLY and SCREEN. Multiplies dark values, + * and screens light values. + * + *
  • HARD_LIGHT - SCREEN when greater than 50% gray, MULTIPLY when lower. + * + *
  • SOFT_LIGHT - Mix of DARKEST and LIGHTEST. + * Works like OVERLAY, but not as harsh. + * + *
  • DODGE - Lightens light tones and increases contrast, ignores darks. + * Called "Color Dodge" in Illustrator and Photoshop. + * + *
  • BURN - Darker areas are applied, increasing contrast, ignores lights. + * Called "Color Burn" in Illustrator and Photoshop. + *
+ *

A useful reference for blending modes and their algorithms can be + * found in the SVG + * specification.

+ *

It is important to note that Processing uses "fast" code, not + * necessarily "correct" code. No biggie, most software does. A nitpicker + * can find numerous "off by 1 division" problems in the blend code where + * >>8 or >>7 is used when strictly speaking + * /255.0 or /127.0 should have been used.

+ *

For instance, exclusion (not intended for real-time use) reads + * r1 + r2 - ((2 * r1 * r2) / 255) because 255 == 1.0 + * not 256 == 1.0. In other words, (255*255)>>8 is not + * the same as (255*255)/255. But for real-time use the shifts + * are preferrable, and the difference is insignificant for applications + * built with Processing.

+ */ static public int blendColor(int c1, int c2, int mode) { return PGraphics.blendColor(c1, c2, mode); } + /** + * Blends one area of this image to another area. + * + * @see processing.core.PImage#blendColor(int,int,int) + */ public void blend(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mode) { if (recorder != null) recorder.blend(sx, sy, sw, sh, dx, dy, dw, dh, mode); @@ -8692,6 +10093,42 @@ public class PApplet extends Applet } + /** + * Blends a region of pixels into the image specified by the img parameter. These copies utilize full alpha channel support and a choice of the following modes to blend the colors of source pixels (A) with the ones of pixels in the destination image (B):

+ * BLEND - linear interpolation of colours: C = A*factor + B

+ * ADD - additive blending with white clip: C = min(A*factor + B, 255)

+ * SUBTRACT - subtractive blending with black clip: C = max(B - A*factor, 0)

+ * DARKEST - only the darkest colour succeeds: C = min(A*factor, B)

+ * LIGHTEST - only the lightest colour succeeds: C = max(A*factor, B)

+ * DIFFERENCE - subtract colors from underlying image.

+ * EXCLUSION - similar to DIFFERENCE, but less extreme.

+ * MULTIPLY - Multiply the colors, result will always be darker.

+ * SCREEN - Opposite multiply, uses inverse values of the colors.

+ * OVERLAY - A mix of MULTIPLY and SCREEN. Multiplies dark values, and screens light values.

+ * HARD_LIGHT - SCREEN when greater than 50% gray, MULTIPLY when lower.

+ * SOFT_LIGHT - Mix of DARKEST and LIGHTEST. Works like OVERLAY, but not as harsh.

+ * DODGE - Lightens light tones and increases contrast, ignores darks. Called "Color Dodge" in Illustrator and Photoshop.

+ * BURN - Darker areas are applied, increasing contrast, ignores lights. Called "Color Burn" in Illustrator and Photoshop.

+ * All modes use the alpha information (highest byte) of source image pixels as the blending factor. If the source and destination regions are different sizes, the image will be automatically resized to match the destination size. If the srcImg parameter is not used, the display window is used as the source image.

+ * As of release 0149, this function ignores imageMode(). + * + * @webref + * @brief Copies a pixel or rectangle of pixels using different blending modes + * @param src an image variable referring to the source image + * @param sx X coordinate of the source's upper left corner + * @param sy Y coordinate of the source's upper left corner + * @param sw source image width + * @param sh source image height + * @param dx X coordinate of the destinations's upper left corner + * @param dy Y coordinate of the destinations's upper left corner + * @param dw destination image width + * @param dh destination image height + * @param mode Either BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN + * + * @see processing.core.PGraphics#alpha(int) + * @see processing.core.PGraphics#copy(PImage, int, int, int, int, int, int, int, int) + * @see processing.core.PImage#blendColor(int,int,int) + */ public void blend(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mode) {