User Tools

Site Tools


part_13-_abbreviated_reference_guide

Processing Tutorial

Appendix: An Abbreviated Reference Guide

–Text stuff???

Images

background()

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 refresh the display window between frames.

Syntax:

background(gray);
background(R, G, B);

blendColor()

Blends two color values together based on the blending mode given as the MODE parameter. Modes: BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, or BURN.

Syntax:

blendColor(color1, color2, MODE);

blue()

Extracts the blue value from a color. Syntax:

blue(color);

blend()

Blends a region of pixels from one image into another (or in itself again). There is a choice of the following modes to blend the 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.

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.

The imageMode() function changes the way the parameters work. For example, a call to imageMode(CORNERS) will change the width and height related parameters to define the x and y values of the opposite corner of the image.

Syntax:

blend(x, y, width, height, dx, dy, dwidth, dheight, MODE)
blend(srcImg, x, y, width, height, dx, dy, dwidth, dheight, MODE)

Parameters starting with “d” are “destination” parameters.

color()

Creates colors for storing in variables of the “color” datatype.

Syntax:

color(gray)
color(R, G, B)

copy()

Copies a region of pixels from the display window to another area of the display window and copies a region of pixels from an image used as the srcImg parameter into the display window. If the source and destination regions aren't the same size, it will automatically resize the source pixels to fit the specified target region. The imageMode() function changes the way the parameters work.

Syntax:

copy(x, y, width, height, dx, dy, dwidth, dheight)
copy(srcImg, x, y, width, height, dx, dy, dwidth, dheight)

The parameters starting with “d” are “destination” parameters.

createImage()

Creates a new PImage (the datatype for storing images). This provides a fresh buffer of pixels to play with. Set the size of the buffer with the width and height parameters. The last argument will always be “RGB”.

Syntax:

createImage(width, height, RGB)

fill()

Sets the color used to fill shapes.

filter()

Filters the display window 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

Syntax:

filter(MODE)
filter(MODE, level)

Syntax:

fill(gray)
fill(value1, value2, value3)

get()

Reads the color of any pixel or grabs a section of an image. If no parameters are specified, the entire image is returned. If the pixel requested is outside of the image window, black is returned. The imageMode() function changes the way the parameters work. For example, 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.

Syntax:

get()
get(x, y)
get(x, y, width, height)

green()

Extracts the green value from a color.

Syntax:

green(color);

image()

Displays images to the screen. The images must be in the sketch's “data” directory to load correctly. 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.

Syntax:

image(img, x, y)
image(img, x, y, width, height)

imageMode()

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. The parameter to imageMode() must be written in “ALL CAPS” because Processing is a case sensitive language.

Syntax:

imageMode(MODE)

Parameters MODE Either CORNER or CORNERS

lerpColor()

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.

Syntax:

lerpColor(color1, color2, amt);

loadImage()

Loads an image into a variable of type PImage. Four types of images ( .gif, .jpg, .tga, .png) may be loaded. To load correctly, images must be located in the data directory of the current sketch.

Syntax:

loadImage(filename)

loadPixels()

Loads the pixel data for the display window (or an image) into the pixels[] array. This function must always be called before reading from or writing to pixels[].

Syntax:

loadPixels()

noFill()

Disables filling geometry. Makes the fill of shapes transparent.

Syntax:

noFill();

noStroke()

Disables drawing the stroke (outline).

Syntax:

noStroke();

noTint()

Removes the current fill value for displaying images and reverts to displaying images with their original hues.

Syntax:

noTint()
PImage

Datatype for storing images. Processing can display of .gif, .jpg, .tga, and .png images. Before an image is used, it must be loaded with the loadImage() function. The PImage object contains fields for the width and height of the image, as well as an array called pixels[] which contains the values for every pixel in the image.

Fields: width image width

height image height

pixels[] array containing the color of every pixel in the image

Methods:

get() Reads the color of any pixel or grabs a rectangle of pixels

set() Writes a color to any pixel or writes an image into another

copy() Copies the entire image

blend() Copies a pixel or rectangle of pixels using different blending modes

filter() Converts the image to grayscale or black and white

save() Saves the image to a TIFF, TARGA, PNG, or JPEG file

Constructors:

PImage()

PImage(width, height)

PImage(img)

pixels[]

Array containing the values for all the pixels in the display window. These values are of the color datatype. This array is the size of the display window. Before accessing this array, the data must loaded with the loadPixels() functions. After the array data has been modified, the updatePixels() function must be loaded to update the changes.

Syntax:

pixels[index]

red()

Extracts the red value from a color.

Syntax:

red(color);

rotate()

Rotates an object the amount specified by the angle parameter. Angles should be specified in radians. Objects are always rotated around their relative position to the origin and positive numbers rotate objects in a clockwise direction. Transformations apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling rotate(PI/2) and then rotate(PI/2) is the same as rotate(PI). If rotate() is called within the draw(), the transformation is reset when the loop begins again.

Syntax:

rotate(angle);

scale()

Scale objects. Objects always scale from their relative origin to the coordinate system. Transformations apply to everything that happens after and subsequent calls to the function multiply the effect. For example, calling scale(2.0) and then scale(1.5) is the same as scale(3.0). If scale() is called within draw(), the transformation is reset when the loop begins again.

Syntax:

scale(x, y);

set()

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. When setting an image, the x and y parameters define the coordinates for the upper-left corner of the image (the placement of the image is not affected by the imageMode() function).

Syntax:

set(x, y, color)
set(x, y, PImage)

stroke()

Sets the color used to draw lines and borders around shapes.

Syntax:

stroke(gray)
stroke(R, G, B)

tint()

Sets the fill value for displaying images. Images can be tinted to specified colors.

Syntax:

tint(gray)
tint(value1, value2, value3)

translate()

Specifies an amount to displace objects within the display window. The x parameter specifies left/right translation and the y parameter specifies up/down translation. Transformations apply to everything that happens after and subsequent calls to the function accumulates the effect. For example, calling translate(50, 0) and then translate(20, 0) is the same as translate(70, 0). If translate() is called within draw(), the transformation is reset when the loop begins again.

Syntax:

translate(x,y);

updatePixels()

Updates the display window (or an image) when data in the pixels[] array has been modified. Use in conjunction with loadPixels(). If you're only reading pixels from the array, there's no need to call updatePixels() unless there are changes.

Syntax:

updatePixels()

Input

key

The system variable key always contains the value of the most recently pressed key on the keyboard. For detecting the arrow keys, the keyCode variable is set to either UP, DOWN, LEFT, or RIGHT.

keyPressed

The boolean system variable keyPressed is true if any key is pressed and false if no keys are pressed.

keyPressed()

The keyPressed() function is called once every time a key is pressed. Because of how operating systems handle key repeats, holding down a key will cause multiple calls to keyPressed(), the rate is set by the operating system and how each computer is configured.

Syntax:

void keyPressed() { 
  statements
}

keyReleased()

The keyReleased() function is called once every time a key is released.

Syntax:

void keyReleased() { 
  statements
}

keyTyped()

The keyTyped() function is called once every time a key is pressed, but action keys such as Ctrl, Shift, and Alt are ignored. Holding down a key will cause multiple calls to keyTyped().

Syntax:

void keyTyped() {
  statements
}

mouseButton

Processing automatically tracks if the mouse button is pressed and which button is pressed. The value of the system variable mouseButton is either LEFT, RIGHT, or CENTER depending on which button is pressed.

mouseClicked()

The mouseClicked() function is called once after a mouse button has been pressed and then released.

Syntax:

void mouseClicked() {
  statements
}

mouseDragged()

The mouseDragged() function is called once every time the mouse moves and a mouse button is pressed.

Syntax:

void mouseDragged() {
  statements
}

mouseMoved()

The mouseMoved() function is called every time the mouse moves and a mouse button is not pressed.

Syntax:

void mouseMoved() {
  statements
}

mousePressed

Variable storing if a mouse button is pressed. The value of the system variable mousePressed is true if a mouse button is pressed and false if a button is not pressed.

mousePressed()

The mousePressed() function is called once after every time a mouse button is pressed.

mouseReleased()

The mouseReleased() function is called every time a mouse button is released.

Syntax:

void mouseReleased() {
  statements
}

mouseX

The system variable mouseX always contains the current horizontal coordinate of the mouse.

mouseY

The system variable mouseY always contains the current vertical coordinate of the mouse.

pmouseX

The system variable pmouseX always contains the previous horizontal coordinate of the mouse. This is the horizontal position of the mouse in the frame previous to the current frame.

Syntax:

void mousePressed() { 
  statements
}

pmouseY

The system variable pmouseY always contains the previous vertical coordinate of the mouse. This is the vertical position of the mouse in the frame previous to the current frame.

Output

saveFrame()

Saves a numbered sequence of images, one image each time the function is run. To save an image that is identical to the display window, run the function at the end of draw() or within mouse and key events such as mousePressed() and keyPressed(). If saveFrame() is called without parameters, it will save the files as screen-0000.tif, screen-0001.tif, etc. It is possible to specify the name of the sequence with the filename parameter and make the choice of saving TIFF, TARGA, PNG, or JPEG files with the ext parameter.

Syntax:

saveFrame()
saveFrame("filename-####.ext")

save()

Saves an image from the display window. Images are saved in TIFF, TARGA, JPEG, and PNG format depending on the extension within the filename parameter. If no extension is included in the filename, the image will save in TIFF format and .tif 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.

Syntax:

save(filename)

Time

day()

Returns the current day as a value from 1 - 31.

Syntax:

day()

hour()

Returns the current hour as a value from 0 - 23.

Syntax:

hour()

millis()

Returns the number of milliseconds (thousandths of a second) since starting an applet. This information is often used for timing animation sequences.

Syntax:

millis()

minute()

Returns the current minute as a value from 0 - 59.

Syntax:

minute()

month()

Returns the current month as a value from 1 - 12.

Syntax:

month()

second()

Returns the current second as a value from 0 - 59.

Syntax:

second()

year()

Returns the current year as an integer.

Syntax:

year()



Next: Processing

Last: Part 12- Video

part_13-_abbreviated_reference_guide.txt · Last modified: 2007/08/30 13:53 (external edit)