loadShape() \ Language (API) \ Processing 1.0
Author: Casey Reas & Ben Fry
Description: Processing is an electronic sketchbook for developing ideas. It is a context for learning fundamentals of computer programming within the context of the electronic arts.
Keywords: Processing, Processing, Interactive Media, Electronic Arts, Programming, Java, Ben Fry, Casey Reas

Reference for Processing version 1.5. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name | ### loadShape()
Examples |
    PShape s;
    s = loadShape("bot.svg");
    smooth();
    shape(s, 10, 10, 80, 80);
    // Loading a shape when using setup() and draw()

    PShape s;

    void setup() {
      s = loadShape("bot.svg");
      smooth();
      noLoop();
    }

    void draw() {
      shape(s, 10, 10, 80, 80);
    }
Description | 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.
Syntax |
    loadShape(filename)
Parameters |
filename | String: name of file to load
Returns | PShape or null
Usage | Web & Application
Related | PShape shape() shapeMode()

Updated on August 30, 2010 04:29:39pm EDT