Search processing.org:

Reference for Processing version 1.0.1+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Name

### set()

Examples

    color black = color(0);
    set(30, 20, black);
    set(85, 20, black);
    set(85, 75, black);
    set(30, 75, black);

    for (int i = 30; i < width-15; i++) {
      for(int j = 20; j < height-25; j++) {
        color c = color(204-j, 153-i, 0);
        set(i, j, c);
      }
    }

    size(100, 100, P3D);
    PImage myImage = loadImage("topanga.jpg");
    set(0, 0, myImage);
    line(0, 0, width, height);
    line(0, height, width, 0);

Description

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 0149, this function ignores imageMode().

Syntax

    set(x, y, color)
    set(x, y, image)

Parameters

x | int: x-coordinate of the pixel
y | int: y-coordinate of the pixel
color | color: any value of the color datatype
image | PImage: any valid variable of type PImage

Returns | None
Usage | Web & Application
Related | get() pixels[] imageMode

Updated on November 22, 2008 08:39:25pm PST