diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index f3c7226cb..d0f33f03b 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -39,6 +39,8 @@ import javax.imageio.ImageIO; import javax.swing.JFileChooser; import javax.swing.SwingUtilities; +import processing.core.PShape; + /** * Base class for all sketches that use processing.core. @@ -3811,7 +3813,21 @@ public class PApplet extends Applet /** - * Load a geometry from a file as a PShape. Currently only supports SVG data. + * Loads vector shapes into a variable of type PShape. Currently, only SVG files may be loaded. + * To load correctly, the file must be located in the data directory of the current sketch. + * In most cases, loadShape() should be used inside setup() because loading shapes inside draw() will reduce the speed of a sketch. + *

+ * The filename parameter can also be a URL to a file found online. + * For security reasons, a Processing sketch found online can only download files from the same server from which it came. + * Getting around this restriction requires a signed applet. + *

+ * If a shape is not loaded successfully, the null value is returned and an error message will be printed to the console. + * The error message does not halt the program, however the null value may cause a NullPointerException if your code does not check whether the value returned from loadShape() is null. + * + * @webref shape:loading_displaying + * @see PShape + * @see PApplet#shape(PShape) + * @see PApplet#shapeMode(int) */ public PShape loadShape(String filename) { if (filename.toLowerCase().endsWith(".svg")) { @@ -7467,13 +7483,26 @@ public class PApplet extends Applet g.image(image, a, b, c, d, u1, v1, u2, v2); } - + /** + * 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 is a case sensitive language. + * @param mode One of CORNER, CORNERS, CENTER + * + * @webref shape:loading_displaying + * @see PApplet#shape(PShape) + * @see PApplet#rectMode(int) + */ public void shapeMode(int mode) { if (recorder != null) recorder.shapeMode(mode); g.shapeMode(mode); } - - + public void shape(PShape shape) { if (recorder != null) recorder.shape(shape); g.shape(shape); @@ -7485,7 +7514,26 @@ public class PApplet extends Applet 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 PApplet#loadShape(String) + * @see PApplet#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);