1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Initial sync with Processing 6406. Compiles and runs (on Mac OS X) but probably very buggy.

This commit is contained in:
David A. Mellis
2010-04-21 01:58:57 +00:00
parent d36fbfe1cf
commit 34579ae440
57 changed files with 22913 additions and 2218 deletions

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,8 @@ import java.awt.event.KeyEvent;
* An attempt is made to keep the constants as short/non-verbose
* as possible. For instance, the constant is TIFF instead of
* FILE_TYPE_TIFF. We'll do this as long as we can get away with it.
*
* @usage Web & Application
*/
public interface PConstants {
@ -158,11 +160,52 @@ public interface PConstants {
// useful goodness
/**
* PI is a mathematical constant with the value 3.14159265358979323846.
* It is the ratio of the circumference of a circle to its diameter.
* It is useful in combination with the trigonometric functions <b>sin()</b> and <b>cos()</b>.
*
* @webref constants
* @see processing.core.PConstants#HALF_PI
* @see processing.core.PConstants#TWO_PI
* @see processing.core.PConstants#QUARTER_PI
*
*/
static final float PI = (float) Math.PI;
/**
* HALF_PI is a mathematical constant with the value 1.57079632679489661923.
* It is half the ratio of the circumference of a circle to its diameter.
* It is useful in combination with the trigonometric functions <b>sin()</b> and <b>cos()</b>.
*
* @webref constants
* @see processing.core.PConstants#PI
* @see processing.core.PConstants#TWO_PI
* @see processing.core.PConstants#QUARTER_PI
*/
static final float HALF_PI = PI / 2.0f;
static final float THIRD_PI = PI / 3.0f;
/**
* QUARTER_PI is a mathematical constant with the value 0.7853982.
* It is one quarter the ratio of the circumference of a circle to its diameter.
* It is useful in combination with the trigonometric functions <b>sin()</b> and <b>cos()</b>.
*
* @webref constants
* @see processing.core.PConstants#PI
* @see processing.core.PConstants#TWO_PI
* @see processing.core.PConstants#HALF_PI
*/
static final float QUARTER_PI = PI / 4.0f;
/**
* TWO_PI is a mathematical constant with the value 6.28318530717958647693.
* It is twice the ratio of the circumference of a circle to its diameter.
* It is useful in combination with the trigonometric functions <b>sin()</b> and <b>cos()</b>.
*
* @webref constants
* @see processing.core.PConstants#PI
* @see processing.core.PConstants#HALF_PI
* @see processing.core.PConstants#QUARTER_PI
*/
static final float TWO_PI = PI * 2.0f;
static final float DEG_TO_RAD = PI/180.0f;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -52,9 +52,13 @@ public class PGraphics3D extends PGraphics {
/** Inverse modelview matrix, used for lighting. */
public PMatrix3D modelviewInv;
/**
* The camera matrix, the modelview will be set to this on beginDraw.
/**
* Marks when changes to the size have occurred, so that the camera
* will be reset in beginDraw().
*/
protected boolean sizeChanged;
/** The camera matrix, the modelview will be set to this on beginDraw. */
public PMatrix3D camera;
/** Inverse camera matrix */
@ -306,6 +310,9 @@ public class PGraphics3D extends PGraphics {
* the pixel buffer for the new size.
*
* Note that this will nuke any cameraMode() settings.
*
* No drawing can happen in this function, and no talking to the graphics
* context. That is, no glXxxx() calls, or other things that change state.
*/
public void setSize(int iwidth, int iheight) { // ignore
width = iwidth;
@ -357,13 +364,8 @@ public class PGraphics3D extends PGraphics {
camera = new PMatrix3D();
cameraInv = new PMatrix3D();
// set up the default camera
// camera();
// defaults to perspective, if the user has setup up their
// own projection, they'll need to fix it after resize anyway.
// this helps the people who haven't set up their own projection.
// perspective();
// set this flag so that beginDraw() will do an update to the camera.
sizeChanged = true;
}
@ -409,6 +411,19 @@ public class PGraphics3D extends PGraphics {
// beginDraw/endDraw).
if (!settingsInited) defaultSettings();
if (sizeChanged) {
// set up the default camera
camera();
// defaults to perspective, if the user has setup up their
// own projection, they'll need to fix it after resize anyway.
// this helps the people who haven't set up their own projection.
perspective();
// clear the flag
sizeChanged = false;
}
resetMatrix(); // reset model matrix
// reset vertices
@ -437,6 +452,7 @@ public class PGraphics3D extends PGraphics {
shapeFirst = 0;
// reset textures
Arrays.fill(textures, null);
textureIndex = 0;
normal(0, 0, 1);
@ -1350,7 +1366,10 @@ public class PGraphics3D extends PGraphics {
boolean bClipped = false;
int clippedCount = 0;
// cameraNear = -8;
// This is a hack for temporary clipping. Clipping still needs to
// be implemented properly, however. Please help!
// http://dev.processing.org/bugs/show_bug.cgi?id=1393
cameraNear = -8;
if (vertices[a][VZ] > cameraNear) {
aClipped = true;
clippedCount++;
@ -1364,15 +1383,15 @@ public class PGraphics3D extends PGraphics {
clippedCount++;
}
if (clippedCount == 0) {
// if (vertices[a][VZ] < cameraFar &&
// vertices[b][VZ] < cameraFar &&
// if (vertices[a][VZ] < cameraFar &&
// vertices[b][VZ] < cameraFar &&
// vertices[c][VZ] < cameraFar) {
addTriangleWithoutClip(a, b, c);
// }
// } else if (true) {
// return;
} else if (clippedCount == 3) {
// In this case there is only one visible point. |/|
// So we'll have to make two new points on the clip line <| |

View File

@ -967,6 +967,9 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ {
public float textAscent() {
if (textFont == null) {
defaultFontOrDeath("textAscent");
}
Font font = textFont.getFont();
if (font == null) {
return super.textAscent();
@ -977,6 +980,9 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ {
public float textDescent() {
if (textFont == null) {
defaultFontOrDeath("textAscent");
}
Font font = textFont.getFont();
if (font == null) {
return super.textDescent();
@ -1010,6 +1016,10 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ {
* will get recorded properly.
*/
public void textSize(float size) {
if (textFont == null) {
defaultFontOrDeath("textAscent", size);
}
// if a native version available, derive this font
// if (textFontNative != null) {
// textFontNative = textFontNative.deriveFont(size);

View File

@ -31,13 +31,31 @@ import java.util.HashMap;
import javax.imageio.ImageIO;
/**
* Datatype for storing images. Processing can display <b>.gif</b>, <b>.jpg</b>, <b>.tga</b>, and <b>.png</b> images. Images may be displayed in 2D and 3D space.
* Before an image is used, it must be loaded with the <b>loadImage()</b> function.
* The <b>PImage</b> object contains fields for the <b>width</b> and <b>height</b> of the image,
* as well as an array called <b>pixels[]</b> which contains the values for every pixel in the image.
* A group of methods, described below, allow easy access to the image's pixels and alpha channel and simplify the process of compositing.
* <br><br>Before using the <b>pixels[]</b> array, be sure to use the <b>loadPixels()</b> method on the image to make sure that the pixel data is properly loaded.
* <br><br>To create a new image, use the <b>createImage()</b> function (do not use <b>new PImage()</b>).
* =advanced
*
* Storage class for pixel data. This is the base class for most image and
* pixel information, such as PGraphics and the video library classes.
* <P>
* Code for copying, resizing, scaling, and blending contributed
* by <A HREF="http://www.toxi.co.uk">toxi</A>.
* <P>
*
* @webref image
* @usage Web &amp; Application
* @instanceName img any variable of type PImage
* @see processing.core.PApplet#loadImage(String)
* @see processing.core.PGraphics#imageMode(int)
* @see processing.core.PApplet#createImage(int, int)
*/
public class PImage implements PConstants, Cloneable {
@ -48,8 +66,32 @@ public class PImage implements PConstants, Cloneable {
*/
public int format;
/**
* Array containing the values for all the pixels in the image. These values are of the color datatype.
* This array is the size of the image, meaning if the image is 100x100 pixels, there will be 10000 values
* and if the window is 200x300 pixels, there will be 60000 values.
* The <b>index</b> value defines the position of a value within the array.
* For example, the statement <b>color b = img.pixels[230]</b> will set the variable <b>b</b> equal to the value at that location in the array.
* Before accessing this array, the data must loaded with the <b>loadPixels()</b> method.
* After the array data has been modified, the <b>updatePixels()</b> method must be run to update the changes.
* Without <b>loadPixels()</b>, running the code may (or will in future releases) result in a NullPointerException.
* @webref
* @brief Array containing the color of every pixel in the image
*/
public int[] pixels;
public int width, height;
/**
* The width of the image in units of pixels.
* @webref
* @brief Image width
*/
public int width;
/**
* The height of the image in units of pixels.
* @webref
* @brief Image height
*/
public int height;
/**
* Path to parent object that will be used with save().
@ -125,7 +167,12 @@ public class PImage implements PConstants, Cloneable {
// toxi: agreed and same reasons why i left it out ;)
}
/**
*
* @param width image width
* @param height image height
* @param format Either RGB, ARGB, ALPHA (grayscale alpha channel)
*/
public PImage(int width, int height, int format) {
init(width, height, format);
}
@ -171,6 +218,8 @@ public class PImage implements PConstants, Cloneable {
* Construct a new PImage from a java.awt.Image. This constructor assumes
* that you've done the work of making sure a MediaTracker has been used
* to fully download the data and that the img is valid.
*
* @param img assumes a MediaTracker has been used to fully download the data and the img is valid
*/
public PImage(java.awt.Image img) {
if (img instanceof BufferedImage) {
@ -275,31 +324,39 @@ public class PImage implements PConstants, Cloneable {
/**
* Loads the pixel data for the image into its <b>pixels[]</b> array. This function must always be called before reading from or writing to <b>pixels[]</b>.
* <br><br>Certain renderers may or may not seem to require <b>loadPixels()</b> or <b>updatePixels()</b>. However, the rule is that any time you want to manipulate the <b>pixels[]</b> array, you must first call <b>loadPixels()</b>, and after changes have been made, call <b>updatePixels()</b>. Even if the renderer may not seem to use this function in the current Processing release, this will always be subject to change.
* =advanced
* Call this when you want to mess with the pixels[] array.
* <p/>
* For subclasses where the pixels[] buffer isn't set by default,
* this should copy all data into the pixels[] array
*
* @webref
* @brief Loads the pixel data for the image into its pixels[] array
*/
public void loadPixels() { // ignore
}
/**
* Call this when finished messing with the pixels[] array.
* <p/>
* Mark all pixels as needing update.
*/
public void updatePixels() { // ignore
updatePixelsImpl(0, 0, width, height);
}
/**
* Updates the image with the data in its <b>pixels[]</b> array. Use in conjunction with <b>loadPixels()</b>. If you're only reading pixels from the array, there's no need to call <b>updatePixels()</b>.
* <br><br>Certain renderers may or may not seem to require <b>loadPixels()</b> or <b>updatePixels()</b>. However, the rule is that any time you want to manipulate the <b>pixels[]</b> array, you must first call <b>loadPixels()</b>, and after changes have been made, call <b>updatePixels()</b>. Even if the renderer may not seem to use this function in the current Processing release, this will always be subject to change.
* <br><br>Currently, none of the renderers use the additional parameters to <b>updatePixels()</b>, however this may be implemented in the future.
* =advanced
* Mark the pixels in this region as needing an update.
* <P>
* This is not currently used by any of the renderers, however the api
* is structured this way in the hope of being able to use this to
* speed things up in the future.
* @webref
* @brief Updates the image with the data in its pixels[] array
* @param x
* @param y
* @param w
* @param h
*/
public void updatePixels(int x, int y, int w, int h) { // ignore
// if (imageMode == CORNER) { // x2, y2 are w/h
@ -369,8 +426,14 @@ public class PImage implements PConstants, Cloneable {
/**
* Resize this image to a new width and height.
* Use 0 for wide or high to make that dimension scale proportionally.
* Resize the image to a new width and height. To make the image scale proportionally, use 0 as the value for the <b>wide</b> or <b>high</b> parameter.
*
* @webref
* @brief Changes the size of an image to a new width and height
* @param wide the resized image width
* @param high the resized image height
*
* @see processing.core.PImage#get(int, int, int, int)
*/
public void resize(int wide, int high) { // ignore
// Make sure that the pixels[] array is valid
@ -442,8 +505,20 @@ public class PImage implements PConstants, Cloneable {
/**
* Grab a subsection of a PImage, and copy it into a fresh PImage.
* As of release 0149, no longer honors imageMode() for the coordinates.
* 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 <b>width</b> and <b>height</b> 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 <b>colorMode(HSB)</b>, the numbers returned will be in RGB.
* <br><br>Getting the color of a single pixel with <b>get(x, y)</b> is easy, but not as fast as grabbing the data directly from <b>pixels[]</b>. The equivalent statement to "get(x, y)" using <b>pixels[]</b> is "pixels[y*width+x]". Processing requires calling <b>loadPixels()</b> to load the display window data into the <b>pixels[]</b> array before getting the values.
* <br><br>As of release 0149, this function ignores <b>imageMode()</b>.
*
* @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) {
/*
@ -512,7 +587,17 @@ public class PImage implements PConstants, Cloneable {
/**
* Set a single pixel to the specified color.
* Changes the color of any pixel or writes an image directly into the display window. The <b>x</b> and <b>y</b> parameters specify the pixel to change and the <b>color</b> 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.
* <br><br>Setting the color of a single pixel with <b>set(x, y)</b> is easy, but not as fast as putting the data directly into <b>pixels[]</b>. The equivalent statement to "set(x, y, #000000)" using <b>pixels[]</b> is "pixels[y*width+x] = #000000". You must call <b>loadPixels()</b> to load the display window data into the <b>pixels[]</b> array before setting the values and calling <b>updatePixels()</b> to update the window with any changes.
* <br><br>As of release 1.0, this function ignores <b>imageMode()</b>.
* <br><br>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. (<a href="http://dev.processing.org/bugs/show_bug.cgi?id=1094">Bug 1094</a>)
* =advanced
* <br><br>As of release 0149, this function ignores <b>imageMode()</b>.
*
* @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 ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return;
@ -594,18 +679,20 @@ public class PImage implements PConstants, Cloneable {
* 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" grayscake by
* 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 alpha[]) {
public void mask(int maskArray[]) {
loadPixels();
// don't execute if mask image is different size
if (alpha.length != pixels.length) {
if (maskArray.length != pixels.length) {
throw new RuntimeException("The PImage used with mask() must be " +
"the same size as the applet.");
}
for (int i = 0; i < pixels.length; i++) {
pixels[i] = ((alpha[i] & 0xff) << 24) | (pixels[i] & 0xffffff);
pixels[i] = ((maskArray[i] & 0xff) << 24) | (pixels[i] & 0xffffff);
}
format = ARGB;
updatePixels();
@ -613,10 +700,19 @@ public class PImage implements PConstants, Cloneable {
/**
* Set alpha channel for an image using another image as the source.
* 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 alpha) {
mask(alpha.pixels);
public void mask(PImage maskImg) {
maskImg.loadPixels();
mask(maskImg.pixels);
}
@ -624,26 +720,6 @@ public class PImage implements PConstants, Cloneable {
//////////////////////////////////////////////////////////////
// IMAGE FILTERS
/**
* Method to apply a variety of basic filters to this image.
* <P>
* <UL>
* <LI>filter(BLUR) provides a basic blur.
* <LI>filter(GRAY) converts the image to grayscale based on luminance.
* <LI>filter(INVERT) will invert the color components in the image.
* <LI>filter(OPAQUE) set all the high bits in the image to opaque
* <LI>filter(THRESHOLD) converts the image to black and white.
* <LI>filter(DILATE) grow white/light areas
* <LI>filter(ERODE) shrink white/light areas
* </UL>
* Luminance conversion code contributed by
* <A HREF="http://www.toxi.co.uk">toxi</A>
* <P/>
* Gaussian blur code contributed by
* <A HREF="http://incubator.quasimondo.com">Mario Klingemann</A>
*/
public void filter(int kind) {
loadPixels();
@ -716,20 +792,29 @@ public class PImage implements PConstants, Cloneable {
/**
* Filters an image as defined by one of the following modes:<br><br>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.<br><br>GRAY - converts any colors in the image to grayscale equivalents<br><br>INVERT - sets each pixel to its inverse value<br><br>POSTERIZE - limits each channel of the image to the number of colors specified as the level parameter<br><br>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.<br><br>OPAQUE - sets the alpha channel to entirely opaque.<br><br>ERODE - reduces the light areas with the amount defined by the level parameter.<br><br>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.
* These filters all take a parameter.
* <P>
* <UL>
* <LI>filter(BLUR, int radius) performs a gaussian blur of the
* specified radius.
* <LI>filter(POSTERIZE, int levels) will posterize the image to
* between 2 and 255 levels.
* <LI>filter(THRESHOLD, float center) allows you to set the
* center point for the threshold. It takes a value from 0 to 1.0.
* <LI>filter(BLUR) provides a basic blur.
* <LI>filter(GRAY) converts the image to grayscale based on luminance.
* <LI>filter(INVERT) will invert the color components in the image.
* <LI>filter(OPAQUE) set all the high bits in the image to opaque
* <LI>filter(THRESHOLD) converts the image to black and white.
* <LI>filter(DILATE) grow white/light areas
* <LI>filter(ERODE) shrink white/light areas
* </UL>
* Luminance conversion code contributed by
* <A HREF="http://www.toxi.co.uk">toxi</A>
* <P/>
* Gaussian blur code contributed by
* <A HREF="http://incubator.quasimondo.com">Mario Klingemann</A>
* and later updated by toxi for better speed.
*
* @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) {
loadPixels();
@ -1093,7 +1178,7 @@ public class PImage implements PConstants, Cloneable {
if (idxRight>=maxRowIdx)
idxRight=currIdx;
if (idxUp<0)
idxUp=0;
idxUp=currIdx;
if (idxDown>=maxIdx)
idxDown=currIdx;
@ -1150,7 +1235,7 @@ public class PImage implements PConstants, Cloneable {
if (idxRight>=maxRowIdx)
idxRight=currIdx;
if (idxUp<0)
idxUp=0;
idxUp=currIdx;
if (idxDown>=maxIdx)
idxDown=currIdx;
@ -1212,7 +1297,23 @@ public class PImage implements PConstants, Cloneable {
/**
* Copies area of one image into another PImage object.
* 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.
* <br><br>As of release 0149, this function ignores <b>imageMode()</b>.
*
* @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,
@ -1321,6 +1422,7 @@ public class PImage implements PConstants, Cloneable {
/**
* 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,
@ -1330,7 +1432,39 @@ public class PImage implements PConstants, Cloneable {
/**
* Copies area of one image into another PImage object.
* Blends a region of pixels into the image specified by the <b>img</b> 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):<br><br>
* BLEND - linear interpolation of colours: C = A*factor + B<br><br>
* ADD - additive blending with white clip: C = min(A*factor + B, 255)<br><br>
* SUBTRACT - subtractive blending with black clip: C = max(B - A*factor, 0)<br><br>
* DARKEST - only the darkest colour succeeds: C = min(A*factor, B)<br><br>
* LIGHTEST - only the lightest colour succeeds: C = max(A*factor, B)<br><br>
* DIFFERENCE - subtract colors from underlying image.<br><br>
* EXCLUSION - similar to DIFFERENCE, but less extreme.<br><br>
* MULTIPLY - Multiply the colors, result will always be darker.<br><br>
* SCREEN - Opposite multiply, uses inverse values of the colors.<br><br>
* OVERLAY - A mix of MULTIPLY and SCREEN. Multiplies dark values, and screens light values.<br><br>
* HARD_LIGHT - SCREEN when greater than 50% gray, MULTIPLY when lower.<br><br>
* SOFT_LIGHT - Mix of DARKEST and LIGHTEST. Works like OVERLAY, but not as harsh.<br><br>
* DODGE - Lightens light tones and increases contrast, ignores darks. Called "Color Dodge" in Illustrator and Photoshop.<br><br>
* BURN - Darker areas are applied, increasing contrast, ignores lights. Called "Color Burn" in Illustrator and Photoshop.<br><br>
* 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 <b>srcImg</b> parameter is not used, the display window is used as the source image.<br><br>
* As of release 0149, this function ignores <b>imageMode()</b>.
*
* @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,
@ -2628,6 +2762,16 @@ public class PImage implements PConstants, Cloneable {
protected String[] saveImageFormats;
/**
* Saves the image into a file. Images are saved in TIFF, TARGA, JPEG, and PNG format depending on the extension within the <b>filename</b> parameter.
* For example, "image.tif" will have a TIFF image and "image.png" will save a PNG image.
* If no extension is included in the filename, the image will save in TIFF format and <b>.tif</b> will be added to the name.
* These files are saved to the sketch's folder, which may be opened by selecting "Show sketch folder" from the "Sketch" menu.
* It is not possible to use <b>save()</b> while running the program in a web browser.<br><br>
* To save an image created within the code, rather than through loading, it's necessary to make the image with the <b>createImage()</b>
* function so it is aware of the location of the program and can therefore save the file to the right place.
* See the <b>createImage()</b> reference for more information.
*
* =advanced
* Save this image to disk.
* <p>
* As of revision 0100, this function requires an absolute path,
@ -2651,15 +2795,19 @@ public class PImage implements PConstants, Cloneable {
* The ImageIO API claims to support wbmp files, however they probably
* require a black and white image. Basic testing produced a zero-length
* file with no error.
*
* @webref
* @brief Saves the image to a TIFF, TARGA, PNG, or JPEG file
* @param filename a sequence of letters and numbers
*/
public void save(String path) { // ignore
public void save(String filename) { // ignore
boolean success = false;
File file = new File(path);
File file = new File(filename);
if (!file.isAbsolute()) {
if (parent != null) {
//file = new File(parent.savePath(filename));
path = parent.savePath(path);
filename = parent.savePath(filename);
} else {
String msg = "PImage.save() requires an absolute path. " +
"Use createImage(), or pass savePath() to save().";
@ -2678,24 +2826,24 @@ public class PImage implements PConstants, Cloneable {
}
if (saveImageFormats != null) {
for (int i = 0; i < saveImageFormats.length; i++) {
if (path.endsWith("." + saveImageFormats[i])) {
saveImageIO(path);
if (filename.endsWith("." + saveImageFormats[i])) {
saveImageIO(filename);
return;
}
}
}
if (path.toLowerCase().endsWith(".tga")) {
os = new BufferedOutputStream(new FileOutputStream(path), 32768);
if (filename.toLowerCase().endsWith(".tga")) {
os = new BufferedOutputStream(new FileOutputStream(filename), 32768);
success = saveTGA(os); //, pixels, width, height, format);
} else {
if (!path.toLowerCase().endsWith(".tif") &&
!path.toLowerCase().endsWith(".tiff")) {
if (!filename.toLowerCase().endsWith(".tif") &&
!filename.toLowerCase().endsWith(".tiff")) {
// if no .tif extension, add it..
path += ".tif";
filename += ".tif";
}
os = new BufferedOutputStream(new FileOutputStream(path), 32768);
os = new BufferedOutputStream(new FileOutputStream(filename), 32768);
success = saveTIFF(os); //, pixels, width, height);
}
os.flush();

View File

@ -419,7 +419,7 @@ public class PPolygon implements PConstants {
int tr, tg, tb, ta;
// System.out.println("P2D interp uv " + interpUV + " " +
// vertices[2][U] + " " + vertices[2][V]);
// vertices[2][U] + " " + vertices[2][V]);
for (int x = lx; x <= rx; x++) {
// map texture based on U, V coords in sp[U] and sp[V]
if (interpUV) {

View File

@ -25,8 +25,17 @@ package processing.core;
import java.util.HashMap;
import processing.core.PApplet;
/**
* Datatype for storing shapes. Processing can currently load and display SVG (Scalable Vector Graphics) shapes.
* Before a shape is used, it must be loaded with the <b>loadShape()</b> function. The <b>shape()</b> function is used to draw the shape to the display window.
* The <b>PShape</b> object contain a group of methods, linked below, that can operate on the shape data.
* <br><br>The <b>loadShape()</b> method supports SVG files created with Inkscape and Adobe Illustrator.
* It is not a full SVG implementation, but offers some straightforward support for handling vector data.
* =advanced
*
* In-progress class to handle shape data, currently to be considered of
* alpha or beta quality. Major structural work may be performed on this class
* after the release of Processing 1.0. Such changes may include:
@ -51,6 +60,13 @@ import java.util.HashMap;
* <p>Library developers are encouraged to create PShape objects when loading
* shape data, so that they can eventually hook into the bounty that will be
* the PShape interface, and the ease of loadShape() and shape().</p>
*
* @webref Shape
* @usage Web &amp; Application
* @see PApplet#shape(PShape)
* @see PApplet#loadShape(String)
* @see PApplet#shapeMode(int)
* @instanceName sh any variable of type PShape
*/
public class PShape implements PConstants {
@ -81,7 +97,17 @@ public class PShape implements PConstants {
//protected float y;
//protected float width;
//protected float height;
/**
* The width of the PShape document.
* @webref
* @brief Shape document width
*/
public float width;
/**
* The width of the PShape document.
* @webref
* @brief Shape document height
*/
public float height;
// set to false if the object is hidden in the layers palette
@ -178,21 +204,39 @@ public class PShape implements PConstants {
return name;
}
/**
* Returns a boolean value "true" if the image is set to be visible, "false" if not. This is modified with the <b>setVisible()</b> parameter.
* <br><br>The visibility of a shape is usually controlled by whatever program created the SVG file.
* For instance, this parameter is controlled by showing or hiding the shape in the layers palette in Adobe Illustrator.
*
* @webref
* @brief Returns a boolean value "true" if the image is set to be visible, "false" if not
*/
public boolean isVisible() {
return visible;
}
/**
* Sets the shape to be visible or invisible. This is determined by the value of the <b>visible</b> parameter.
* <br><br>The visibility of a shape is usually controlled by whatever program created the SVG file.
* For instance, this parameter is controlled by showing or hiding the shape in the layers palette in Adobe Illustrator.
* @param visible "false" makes the shape invisible and "true" makes it visible
* @webref
* @brief Sets the shape to be visible or invisible
*/
public void setVisible(boolean visible) {
this.visible = visible;
}
/**
* Disables the shape's style data and uses Processing's current styles. Styles include attributes such as colors, stroke weight, and stroke joints.
* =advanced
* Overrides this shape's style information and uses PGraphics styles and
* colors. Identical to ignoreStyles(true). Also disables styles for all
* child shapes.
* @webref
* @brief Disables the shape's style data and uses Processing styles
*/
public void disableStyle() {
style = false;
@ -204,7 +248,9 @@ public class PShape implements PConstants {
/**
* Re-enables style information (fill and stroke) set in the shape.
* Enables the shape's style data and ignores Processing's current styles. Styles include attributes such as colors, stroke weight, and stroke joints.
* @webref
* @brief Enables the shape's style data and ignores the Processing styles
*/
public void enableStyle() {
style = true;
@ -591,12 +637,21 @@ public class PShape implements PConstants {
return childCount;
}
/**
*
* @param index the layer position of the shape to get
*/
public PShape getChild(int index) {
return children[index];
}
/**
* Extracts a child shape from a parent shape. Specify the name of the shape with the <b>target</b> parameter.
* The shape is returned as a <b>PShape</b> object, or <b>null</b> is returned if there is an error.
* @param target the name of the shape to get
* @webref
* @brief Returns a child element of a shape as a PShape object
*/
public PShape getChild(String target) {
if (name != null && name.equals(target)) {
return this;
@ -675,34 +730,78 @@ public class PShape implements PConstants {
// if matrix is null when one is called,
// it is created and set to identity
public void translate(float tx, float ty) {
checkMatrix(2);
matrix.translate(tx, ty);
}
/**
* Specifies an amount to displace the shape. The <b>x</b> parameter specifies left/right translation, the <b>y</b> parameter specifies up/down translation, and the <b>z</b> parameter specifies translations toward/away from the screen. Subsequent calls to the method accumulates the effect. For example, calling <b>translate(50, 0)</b> and then <b>translate(20, 0)</b> is the same as <b>translate(70, 0)</b>. This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>Using this method with the <b>z</b> parameter requires using the P3D or OPENGL parameter in combination with size.
* @webref
* @param tx left/right translation
* @param ty up/down translation
* @param tz forward/back translation
* @brief Displaces the shape
*/
public void translate(float tx, float ty, float tz) {
checkMatrix(3);
matrix.translate(tx, ty, 0);
}
/**
* Rotates a shape around the x-axis the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
* Subsequent calls to the method accumulates the effect. For example, calling <b>rotateX(HALF_PI)</b> and then <b>rotateX(HALF_PI)</b> is the same as <b>rotateX(PI)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>This method requires a 3D renderer. You need to pass P3D or OPENGL as a third parameter into the <b>size()</b> method as shown in the example above.
* @param angle angle of rotation specified in radians
* @webref
* @brief Rotates the shape around the x-axis
*/
public void rotateX(float angle) {
rotate(angle, 1, 0, 0);
}
/**
* Rotates a shape around the y-axis the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
* Subsequent calls to the method accumulates the effect. For example, calling <b>rotateY(HALF_PI)</b> and then <b>rotateY(HALF_PI)</b> is the same as <b>rotateY(PI)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>This method requires a 3D renderer. You need to pass P3D or OPENGL as a third parameter into the <b>size()</b> method as shown in the example above.
* @param angle angle of rotation specified in radians
* @webref
* @brief Rotates the shape around the y-axis
*/
public void rotateY(float angle) {
rotate(angle, 0, 1, 0);
}
/**
* Rotates a shape around the z-axis the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
* Subsequent calls to the method accumulates the effect. For example, calling <b>rotateZ(HALF_PI)</b> and then <b>rotateZ(HALF_PI)</b> is the same as <b>rotateZ(PI)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>This method requires a 3D renderer. You need to pass P3D or OPENGL as a third parameter into the <b>size()</b> method as shown in the example above.
* @param angle angle of rotation specified in radians
* @webref
* @brief Rotates the shape around the z-axis
*/
public void rotateZ(float angle) {
rotate(angle, 0, 0, 1);
}
/**
* Rotates a shape the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
* Transformations apply to everything that happens after and subsequent calls to the method accumulates the effect.
* For example, calling <b>rotate(HALF_PI)</b> and then <b>rotate(HALF_PI)</b> is the same as <b>rotate(PI)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* @param angle angle of rotation specified in radians
* @webref
* @brief Rotates the shape
*/
public void rotate(float angle) {
checkMatrix(2); // at least 2...
matrix.rotate(angle);
@ -716,20 +815,34 @@ public class PShape implements PConstants {
//
/**
* @param s percentage to scale the object
*/
public void scale(float s) {
checkMatrix(2); // at least 2...
matrix.scale(s);
}
public void scale(float sx, float sy) {
public void scale(float x, float y) {
checkMatrix(2);
matrix.scale(sx, sy);
matrix.scale(x, y);
}
/**
* Increases or decreases the size of a shape by expanding and contracting vertices. Shapes always scale from the relative origin of their bounding box.
* Scale values are specified as decimal percentages. For example, the method call <b>scale(2.0)</b> increases the dimension of a shape by 200%.
* Subsequent calls to the method multiply the effect. For example, calling <b>scale(2.0)</b> and then <b>scale(1.5)</b> is the same as <b>scale(3.0)</b>.
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
* <br><br>Using this fuction with the <b>z</b> parameter requires passing P3D or OPENGL into the size() parameter.
* @param x percentage to scale the object in the x-axis
* @param y percentage to scale the object in the y-axis
* @param z percentage to scale the object in the z-axis
* @webref
* @brief Increases and decreases the size of a shape
*/
public void scale(float x, float y, float z) {
checkMatrix(3);
matrix.scale(x, y, z);

View File

@ -457,7 +457,11 @@ public class PShapeSVG extends PShape {
separate = false;
}
if (c == '-' && !lastSeparate) {
pathBuffer.append("|");
// allow for 'e' notation in numbers, e.g. 2.10e-9
// http://dev.processing.org/bugs/show_bug.cgi?id=1408
if (i == 0 || pathDataChars[i-1] != 'e') {
pathBuffer.append("|");
}
}
if (c != ',') {
pathBuffer.append(c); //"" + pathDataBuffer.charAt(i));

View File

@ -428,8 +428,8 @@ public class PVector {
public float dot(float x, float y, float z) {
return this.x*x + this.y*y + this.z*z;
}
static public float dot(PVector v1, PVector v2) {
return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
}

View File

@ -31,6 +31,10 @@ import processing.core.PApplet;
/**
* XMLElement is a representation of an XML object. The object is able to parse XML code. The methods described here are the most basic. More are documented in the Developer's Reference.
* <br><br>
* The encoding parameter inside XML files is ignored, only UTF-8 (or plain ASCII) are parsed properly.
* =advanced
* XMLElement is an XML element. This is the base class used for the
* Processing XML library, representing a single node of an XML tree.
*
@ -38,6 +42,10 @@ import processing.core.PApplet;
*
* @author Marc De Scheemaecker
* @author processing.org
*
* @webref data:composite
* @usage Web &amp; Application
* @instanceName xml any variable of type XMLElement
*/
public class XMLElement implements Serializable {
@ -103,6 +111,7 @@ public class XMLElement implements Serializable {
/**
* Creates an empty element to be used for #PCDATA content.
* @nowebref
*/
public XMLElement() {
this(null, null, null, NO_LINE);
@ -173,6 +182,7 @@ public class XMLElement implements Serializable {
* @param namespace the namespace URI.
* @param systemID the system ID of the XML data where the element starts.
* @param lineNr the line in the XML data where the element starts.
* @nowebref
*/
public XMLElement(String fullName,
String namespace,
@ -204,21 +214,25 @@ public class XMLElement implements Serializable {
* wraps exception handling, for more advanced exception handling,
* use the constructor that takes a Reader or InputStream.
* @author processing.org
* @param filename
* @param parent
* @param filename name of the XML file to load
* @param parent typically use "this"
*/
public XMLElement(PApplet parent, String filename) {
this();
parseFromReader(parent.createReader(filename));
}
/**
* @nowebref
*/
public XMLElement(Reader r) {
this();
parseFromReader(r);
}
/**
* @nowebref
*/
public XMLElement(String xml) {
this();
parseFromReader(new StringReader(xml));
@ -348,6 +362,8 @@ public class XMLElement implements Serializable {
* Returns the full name (i.e. the name including an eventual namespace
* prefix) of the element.
*
* @webref
* @brief Returns the name of the element.
* @return the name, or null if the element only contains #PCDATA.
*/
public String getName() {
@ -507,9 +523,12 @@ public class XMLElement implements Serializable {
/**
* Returns the number of children.
* Returns the number of children for the element.
*
* @return the count.
* @webref
* @see processing.xml.XMLElement#getChild(int)
* @see processing.xml.XMLElement#getChildren(String)
*/
public int getChildCount() {
return this.children.size();
@ -554,27 +573,35 @@ public class XMLElement implements Serializable {
/**
* Quick accessor for an element at a particular index.
* @author processing.org
* @param index the element
*/
public XMLElement getChild(int which) {
return (XMLElement) children.elementAt(which);
public XMLElement getChild(int index) {
return (XMLElement) children.elementAt(index);
}
/**
* Get a child by its name or path.
* @param name element name or path/to/element
* Returns the child XMLElement as specified by the <b>index</b> parameter. The value of the <b>index</b> parameter must be less than the total number of children to avoid going out of the array storing the child elements.
* When the <b>path</b> parameter is specified, then it will return all children that match that path. The path is a series of elements and sub-elements, separated by slashes.
*
* @return the element
* @author processing.org
*
* @webref
* @see processing.xml.XMLElement#getChildCount()
* @see processing.xml.XMLElement#getChildren(String)
* @brief Get a child by its name or path.
* @param path path to a particular element
*/
public XMLElement getChild(String name) {
if (name.indexOf('/') != -1) {
return getChildRecursive(PApplet.split(name, '/'), 0);
public XMLElement getChild(String path) {
if (path.indexOf('/') != -1) {
return getChildRecursive(PApplet.split(path, '/'), 0);
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
XMLElement kid = getChild(i);
String kidName = kid.getName();
if (kidName != null && kidName.equals(name)) {
if (kidName != null && kidName.equals(path)) {
return kid;
}
}
@ -681,20 +708,27 @@ public class XMLElement implements Serializable {
/**
* Get any children that match this name or path. Similar to getChild(),
* but will grab multiple matches rather than only the first.
* @param name element name or path/to/element
* Returns all of the children as an XMLElement array.
* When the <b>path</b> parameter is specified, then it will return all children that match that path.
* The path is a series of elements and sub-elements, separated by slashes.
*
* @param path element name or path/to/element
* @return array of child elements that match
* @author processing.org
*
* @webref
* @brief Returns all of the children as an XMLElement array.
* @see processing.xml.XMLElement#getChildCount()
* @see processing.xml.XMLElement#getChild(int)
*/
public XMLElement[] getChildren(String name) {
if (name.indexOf('/') != -1) {
return getChildrenRecursive(PApplet.split(name, '/'), 0);
public XMLElement[] getChildren(String path) {
if (path.indexOf('/') != -1) {
return getChildrenRecursive(PApplet.split(path, '/'), 0);
}
// if it's a number, do an index instead
// (returns a single element array, since this will be a single match
if (Character.isDigit(name.charAt(0))) {
return new XMLElement[] { getChild(Integer.parseInt(name)) };
if (Character.isDigit(path.charAt(0))) {
return new XMLElement[] { getChild(Integer.parseInt(path)) };
}
int childCount = getChildCount();
XMLElement[] matches = new XMLElement[childCount];
@ -702,7 +736,7 @@ public class XMLElement implements Serializable {
for (int i = 0; i < childCount; i++) {
XMLElement kid = getChild(i);
String kidName = kid.getName();
if (kidName != null && kidName.equals(name)) {
if (kidName != null && kidName.equals(path)) {
matches[matchCount++] = kid;
}
}
@ -882,12 +916,22 @@ public class XMLElement implements Serializable {
}
}
public String getStringAttribute(String name) {
return getAttribute(name);
}
/**
* Returns a String attribute of the element.
* If the <b>default</b> parameter is used and the attribute doesn't exist, the <b>default</b> value is returned.
* When using the version of the method without the <b>default</b> parameter, if the attribute doesn't exist, the value 0 is returned.
*
* @webref
* @param name the name of the attribute
* @param default Value value returned if the attribute is not found
*
* @brief Returns a String attribute of the element.
*/
public String getStringAttribute(String name, String defaultValue) {
return getAttribute(name, defaultValue);
}
@ -899,18 +943,24 @@ public class XMLElement implements Serializable {
return getAttribute(name, namespace, defaultValue);
}
/**
* Returns an integer attribute of the element.
*/
public int getIntAttribute(String name) {
return getIntAttribute(name, 0);
}
/**
* Returns the value of an attribute.
* Returns an integer attribute of the element.
* If the <b>default</b> parameter is used and the attribute doesn't exist, the <b>default</b> value is returned.
* When using the version of the method without the <b>default</b> parameter, if the attribute doesn't exist, the value 0 is returned.
*
* @param name the non-null full name of the attribute.
* @param defaultValue the default value of the attribute.
* @param name the name of the attribute
* @param defaultValue value returned if the attribute is not found
*
* @webref
* @brief Returns an integer attribute of the element.
* @return the value, or defaultValue if the attribute does not exist.
*/
public int getIntAttribute(String name,
@ -944,12 +994,17 @@ public class XMLElement implements Serializable {
/**
* Returns the value of an attribute.
* Returns a float attribute of the element.
* If the <b>default</b> parameter is used and the attribute doesn't exist, the <b>default</b> value is returned.
* When using the version of the method without the <b>default</b> parameter, if the attribute doesn't exist, the value 0 is returned.
*
* @param name the non-null full name of the attribute.
* @param defaultValue the default value of the attribute.
* @param name the name of the attribute
* @param defaultValue value returned if the attribute is not found
*
* @return the value, or defaultValue if the attribute does not exist.
*
* @webref
* @brief Returns a float attribute of the element.
*/
public float getFloatAttribute(String name,
float defaultValue) {
@ -966,6 +1021,7 @@ public class XMLElement implements Serializable {
* @param defaultValue the default value of the attribute.
*
* @return the value, or defaultValue if the attribute does not exist.
* @nowebref
*/
public float getFloatAttribute(String name,
String namespace,
@ -1253,11 +1309,15 @@ public class XMLElement implements Serializable {
/**
* Returns the content of an element. If there is no such content, <b>null</b> is returned.
* =advanced
* Return the #PCDATA content of the element. If the element has a
* combination of #PCDATA content and child elements, the #PCDATA
* sections can be retrieved as unnamed child objects. In this case,
* this method returns null.
*
* @webref
* @brief Returns the content of an element
* @return the content.
*/
public String getContent() {