processing.core
Class PGraphics2D

java.lang.Object
  extended by processing.core.PImage
      extended by processing.core.PGraphics
          extended by processing.core.PGraphics2D
All Implemented Interfaces:
java.lang.Cloneable, PConstants

public class PGraphics2D
extends PGraphics

Subclass of PGraphics that handles fast 2D rendering using a MemoryImageSource. The renderer found in this class is not as accurate as PGraphicsJava2D, but offers certain speed tradeoffs, particular when messing with the pixels array, or displaying image or video data.


Field Summary
 
Fields inherited from class processing.core.PGraphics
ambientB, ambientG, ambientR, backgroundColor, bezierDetail, colorMode, colorModeA, colorModeX, colorModeY, colorModeZ, curveTightness, edge, ellipseMode, emissiveB, emissiveG, emissiveR, fill, fillColor, image, imageMode, normalX, normalY, normalZ, pixelCount, rectMode, shapeMode, shininess, smooth, specularB, specularG, specularR, sphereDetailU, sphereDetailV, stroke, strokeCap, strokeColor, strokeJoin, strokeWeight, textAlign, textAlignY, textFont, textLeading, textMode, textSize, textureImage, textureMode, textureU, textureV, tint, tintColor
 
Fields inherited from class processing.core.PImage
format, height, parent, pixels, width
 
Fields inherited from interface processing.core.PConstants
A, AB, ADD, AG, ALPHA, ALPHA_MASK, ALT, AMBIENT, AR, ARC, ARGB, ARROW, B, BACKSPACE, BASELINE, BEEN_LIT, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BURN, CENTER, CENTER_DIAMETER, CENTER_RADIUS, CHATTER, CLOSE, CMYK, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DA, DARKEST, DB, DEG_TO_RAD, DELETE, DG, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_OPENGL_2X_SMOOTH, DISABLE_OPENGL_ERROR_REPORT, DODGE, DOWN, DR, DXF, EB, EDGE, EG, ELLIPSE, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENABLE_OPENGL_ERROR_REPORT, ENTER, EPSILON, ER, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, G, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINE, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MOVE, MULTIPLY, NORMAL, NORMALIZED, NX, NY, NZ, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, platformNames, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD, QUAD_STRIP, QUADS, QUARTER_PI, R, RAD_TO_DEG, RADIUS, RECT, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SA, SB, SCREEN, SG, SHAPE, SHIFT, SHINE, SOFT_LIGHT, SPB, SPG, SPHERE, SPOT, SPR, SQUARE, SR, SUBTRACT, SW, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, TX, TY, TZ, U, UP, V, VERTEX_FIELD_COUNT, VW, VX, VY, VZ, WAIT, WHITESPACE, WINDOWS, X, Y, Z
 
Constructor Summary
PGraphics2D()
           
 
Method Summary
 void applyMatrix(float n00, float n01, float n02, float n10, float n11, float n12)
          Apply a 3x2 affine transformation matrix.
 void applyMatrix(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, float n20, float n21, float n22, float n23, float n30, float n31, float n32, float n33)
          Apply a 4x4 transformation matrix.
 void beginDraw()
          Prepares the PGraphics for drawing.
 void beginShape(int kind)
          Start a new shape.
 void bezier(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)
           
 void box(float size)
           
 void box(float w, float h, float d)
           
 void breakShape()
          This feature is in testing, do not use or rely upon its implementation
 boolean canDraw()
          Some renderers have requirements re: when they are ready to draw.
 void curve(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)
           
 void endDraw()
          This will finalize rendering so that it can be shown on-screen.
 void endShape(int mode)
           
 void point(float x, float y, float z)
           
 void popMatrix()
          Replace the current transformation matrix with the top of the stack.
 void printMatrix()
          Print the current model (or "transformation") matrix.
 void pushMatrix()
          Push a copy of the current transformation matrix onto the stack.
 void resetMatrix()
          Load identity as the transform/model matrix.
 void rotate(float angle)
          Two dimensional rotation.
 void rotate(float angle, float vx, float vy, float vz)
          Rotate about a vector in space.
 void rotateX(float angle)
          Rotate around the X axis.
 void rotateY(float angle)
          Rotate around the Y axis.
 void rotateZ(float angle)
          Rotate around the Z axis.
 void scale(float s)
          Scale in all dimensions.
 void scale(float sx, float sy)
          Scale in X and Y.
 void scale(float x, float y, float z)
          Scale in X, Y, and Z.
 float screenX(float x, float y)
          Given an x and y coordinate, returns the x position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations.
 float screenY(float x, float y)
          Given an x and y coordinate, returns the y position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations.
 void sphere(float r)
          Draw a sphere with radius r centered at coordinate 0, 0, 0.
 void sphereDetail(int res)
           
 void sphereDetail(int ures, int vres)
          Set the detail level for approximating a sphere.
 void translate(float tx, float ty)
          Translate in X and Y.
 void translate(float tx, float ty, float tz)
          Translate in X, Y, and Z.
 void vertex(float x, float y, float z)
           
 void vertex(float x, float y, float z, float u, float v)
           
 
Methods inherited from class processing.core.PGraphics
alpha, ambient, ambient, ambient, ambientLight, ambientLight, applyMatrix, applyMatrix, applyMatrix, arc, background, background, background, background, background, background, background, beginCamera, beginRaw, beginShape, bezier, bezierDetail, bezierPoint, bezierTangent, bezierVertex, bezierVertex, blue, brightness, camera, camera, color, color, color, color, color, color, color, color, color, colorMode, colorMode, colorMode, colorMode, curve, curveDetail, curvePoint, curveTangent, curveTightness, curveVertex, curveVertex, directionalLight, displayable, dispose, edge, ellipse, ellipseMode, emissive, emissive, emissive, endCamera, endRaw, endShape, fill, fill, fill, fill, fill, fill, flush, frustum, getMatrix, getMatrix, getMatrix, getStyle, getStyle, green, hint, hue, image, image, image, imageMode, is2D, is3D, lerpColor, lerpColor, lightFalloff, lights, lightSpecular, line, line, modelX, modelY, modelZ, noFill, noLights, normal, noSmooth, noStroke, noTint, ortho, ortho, perspective, perspective, point, pointLight, popStyle, printCamera, printProjection, pushStyle, quad, rect, rectMode, red, saturation, screenX, screenY, screenZ, setMatrix, setMatrix, setMatrix, setParent, setPath, setPrimary, setSize, shape, shape, shape, shapeMode, shininess, showException, showWarning, smooth, specular, specular, specular, spotLight, stroke, stroke, stroke, stroke, stroke, stroke, strokeCap, strokeJoin, strokeWeight, style, text, text, text, text, text, text, text, text, text, text, text, text, text, text, textAlign, textAlign, textAscent, textDescent, textFont, textFont, textLeading, textMode, textSize, texture, textureMode, textWidth, textWidth, tint, tint, tint, tint, tint, tint, triangle, vertex, vertex, vertex
 
Methods inherited from class processing.core.PImage
blend, blend, blendColor, clone, copy, copy, filter, filter, get, get, get, getCache, getImage, init, isModified, loadPixels, mask, mask, removeCache, resize, save, set, set, setCache, setModified, setModified, updatePixels, updatePixels
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PGraphics2D

public PGraphics2D()
Method Detail

canDraw

public boolean canDraw()
Description copied from class: PGraphics
Some renderers have requirements re: when they are ready to draw.

Overrides:
canDraw in class PGraphics

beginDraw

public void beginDraw()
Description copied from class: PGraphics
Prepares the PGraphics for drawing.

When creating your own PGraphics, you should call this before drawing anything.

Overrides:
beginDraw in class PGraphics

endDraw

public void endDraw()
Description copied from class: PGraphics
This will finalize rendering so that it can be shown on-screen.

When creating your own PGraphics, you should call this when you're finished drawing.

Overrides:
endDraw in class PGraphics

beginShape

public void beginShape(int kind)
Description copied from class: PGraphics
Start a new shape.

Differences between beginShape() and line() and point() methods.

beginShape() is intended to be more flexible at the expense of being a little more complicated to use. it handles more complicated shapes that can consist of many connected lines (so you get joins) or lines mixed with curves.

The line() and point() command are for the far more common cases (particularly for our audience) that simply need to draw a line or a point on the screen.

From the code side of things, line() may or may not call beginShape() to do the drawing. In the beta code, they do, but in the alpha code, they did not. they might be implemented one way or the other depending on tradeoffs of runtime efficiency vs. implementation efficiency &mdash meaning the speed that things run at vs. the speed it takes me to write the code and maintain it. for beta, the latter is most important so that's how things are implemented.

Overrides:
beginShape in class PGraphics

vertex

public void vertex(float x,
                   float y,
                   float z)
Overrides:
vertex in class PGraphics

vertex

public void vertex(float x,
                   float y,
                   float z,
                   float u,
                   float v)
Overrides:
vertex in class PGraphics

breakShape

public void breakShape()
Description copied from class: PGraphics
This feature is in testing, do not use or rely upon its implementation

Overrides:
breakShape in class PGraphics

endShape

public void endShape(int mode)
Overrides:
endShape in class PGraphics

point

public void point(float x,
                  float y,
                  float z)
Overrides:
point in class PGraphics

box

public void box(float size)
Overrides:
box in class PGraphics

box

public void box(float w,
                float h,
                float d)
Overrides:
box in class PGraphics

sphereDetail

public void sphereDetail(int res)
Overrides:
sphereDetail in class PGraphics

sphereDetail

public void sphereDetail(int ures,
                         int vres)
Description copied from class: PGraphics
Set the detail level for approximating a sphere. The ures and vres params control the horizontal and vertical resolution. Code for sphereDetail() submitted by toxi [031031]. Code for enhanced u/v version from davbol [080801].

Overrides:
sphereDetail in class PGraphics

sphere

public void sphere(float r)
Description copied from class: PGraphics
Draw a sphere with radius r centered at coordinate 0, 0, 0.

Implementation notes:

cache all the points of the sphere in a static array top and bottom are just a bunch of triangles that land in the center point

sphere is a series of concentric circles who radii vary along the shape, based on, er.. cos or something

 [toxi 031031] new sphere code. removed all multiplies with
 radius, as scale() will take care of that anyway

 [toxi 031223] updated sphere code (removed modulos)
 and introduced sphereAt(x,y,z,r)
 to avoid additional translate()'s on the user/sketch side

 [davbol 080801] now using separate sphereDetailU/V
 

Overrides:
sphere in class PGraphics

bezier

public void bezier(float x1,
                   float y1,
                   float z1,
                   float x2,
                   float y2,
                   float z2,
                   float x3,
                   float y3,
                   float z3,
                   float x4,
                   float y4,
                   float z4)
Overrides:
bezier in class PGraphics

curve

public void curve(float x1,
                  float y1,
                  float z1,
                  float x2,
                  float y2,
                  float z2,
                  float x3,
                  float y3,
                  float z3,
                  float x4,
                  float y4,
                  float z4)
Overrides:
curve in class PGraphics

translate

public void translate(float tx,
                      float ty)
Description copied from class: PGraphics
Translate in X and Y.

Overrides:
translate in class PGraphics

translate

public void translate(float tx,
                      float ty,
                      float tz)
Description copied from class: PGraphics
Translate in X, Y, and Z.

Overrides:
translate in class PGraphics

rotate

public void rotate(float angle)
Description copied from class: PGraphics
Two dimensional rotation. Same as rotateZ (this is identical to a 3D rotation along the z-axis) but included for clarity. It'd be weird for people drawing 2D graphics to be using rotateZ. And they might kick our a-- for the confusion. Additional background.

Overrides:
rotate in class PGraphics

rotateX

public void rotateX(float angle)
Description copied from class: PGraphics
Rotate around the X axis.

Overrides:
rotateX in class PGraphics

rotateY

public void rotateY(float angle)
Description copied from class: PGraphics
Rotate around the Y axis.

Overrides:
rotateY in class PGraphics

rotateZ

public void rotateZ(float angle)
Description copied from class: PGraphics
Rotate around the Z axis. The functions rotate() and rotateZ() are identical, it's just that it make sense to have rotate() and then rotateX() and rotateY() when using 3D; nor does it make sense to use a function called rotateZ() if you're only doing things in 2D. so we just decided to have them both be the same.

Overrides:
rotateZ in class PGraphics

rotate

public void rotate(float angle,
                   float vx,
                   float vy,
                   float vz)
Description copied from class: PGraphics
Rotate about a vector in space. Same as the glRotatef() function.

Overrides:
rotate in class PGraphics

scale

public void scale(float s)
Description copied from class: PGraphics
Scale in all dimensions.

Overrides:
scale in class PGraphics

scale

public void scale(float sx,
                  float sy)
Description copied from class: PGraphics
Scale in X and Y. Equivalent to scale(sx, sy, 1). Not recommended for use in 3D, because the z-dimension is just scaled by 1, since there's no way to know what else to scale it by.

Overrides:
scale in class PGraphics

scale

public void scale(float x,
                  float y,
                  float z)
Description copied from class: PGraphics
Scale in X, Y, and Z.

Overrides:
scale in class PGraphics

pushMatrix

public void pushMatrix()
Description copied from class: PGraphics
Push a copy of the current transformation matrix onto the stack.

Overrides:
pushMatrix in class PGraphics

popMatrix

public void popMatrix()
Description copied from class: PGraphics
Replace the current transformation matrix with the top of the stack.

Overrides:
popMatrix in class PGraphics

resetMatrix

public void resetMatrix()
Load identity as the transform/model matrix. Same as glLoadIdentity().

Overrides:
resetMatrix in class PGraphics

applyMatrix

public void applyMatrix(float n00,
                        float n01,
                        float n02,
                        float n10,
                        float n11,
                        float n12)
Apply a 3x2 affine transformation matrix.

Overrides:
applyMatrix in class PGraphics

applyMatrix

public void applyMatrix(float n00,
                        float n01,
                        float n02,
                        float n03,
                        float n10,
                        float n11,
                        float n12,
                        float n13,
                        float n20,
                        float n21,
                        float n22,
                        float n23,
                        float n30,
                        float n31,
                        float n32,
                        float n33)
Description copied from class: PGraphics
Apply a 4x4 transformation matrix.

Overrides:
applyMatrix in class PGraphics

printMatrix

public void printMatrix()
Print the current model (or "transformation") matrix.

Overrides:
printMatrix in class PGraphics

screenX

public float screenX(float x,
                     float y)
Description copied from class: PGraphics
Given an x and y coordinate, returns the x position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations.

Overrides:
screenX in class PGraphics

screenY

public float screenY(float x,
                     float y)
Description copied from class: PGraphics
Given an x and y coordinate, returns the y position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations.

Overrides:
screenY in class PGraphics