|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object processing.core.PImage processing.core.PGraphics processing.core.PGraphicsJava2D
public class PGraphicsJava2D
Subclass for PGraphics that implements the graphics API using Java2D.
Pixel operations too slow? As of release 0085 (the first beta), the default renderer uses Java2D. It's more accurate than the renderer used in alpha releases of Processing (it handles stroke caps and joins, and has better polygon tessellation), but it's super slow for handling pixels. At least until we get a chance to get the old 2D renderer (now called P2D) working in a similar fashion, you can use size(w, h, P3D) instead of size(w, h) which will be faster for general pixel flipping madness.
To get access to the Java 2D "Graphics2D" object for the default renderer, use:
Graphics2D g2 = ((PGraphicsJava2D)g).g2;This will let you do Java 2D stuff directly, but is not supported in any way shape or form. Which just means "have fun, but don't complain if it breaks."
Field Summary | |
---|---|
boolean |
fillGradient
|
java.awt.Paint |
fillGradientObject
|
java.awt.Graphics2D |
g2
|
boolean |
strokeGradient
|
java.awt.Paint |
strokeGradientObject
|
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 |
Constructor Summary | |
---|---|
PGraphicsJava2D()
|
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 |
backgroundImpl()
Actual implementation of clearing the background, now that the internal variables for background color have been set. |
void |
beginDraw()
Prepares the PGraphics for drawing. |
void |
beginRaw(PGraphics recorderRaw)
Record individual lines and triangles by echoing them to another renderer. |
void |
beginShape(int kind)
Start a new shape. |
void |
bezierDetail(int detail)
Ignored (not needed) in Java 2D. |
void |
bezierVertex(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
|
void |
bezierVertex(float x2,
float y2,
float z2,
float x3,
float y3,
float z3,
float x4,
float y4,
float z4)
|
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 |
copy(int sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh)
Copy things from one area of this image to another area in the same image. |
void |
curveDetail(int detail)
Ignored (not needed) in Java 2D. |
void |
curveVertex(float x,
float y,
float z)
|
void |
endDraw()
This will finalize rendering so that it can be shown on-screen. |
void |
endRaw()
|
void |
endShape(int mode)
|
PImage |
get()
Returns a copy of this PImage. |
int |
get(int x,
int y)
Returns an ARGB "color" type (a packed 32 bit int with the color. |
PImage |
getImpl(int x,
int y,
int w,
int h)
Internal function to actually handle getting a block of pixels that has already been properly cropped to a valid region. |
PMatrix |
getMatrix()
|
PMatrix2D |
getMatrix(PMatrix2D target)
Copy the current transformation matrix into the specified target. |
PMatrix3D |
getMatrix(PMatrix3D target)
Copy the current transformation matrix into the specified target. |
void |
line(float x1,
float y1,
float x2,
float y2)
|
void |
loadPixels()
Call this when you want to mess with the pixels[] array. |
void |
mask(int[] alpha)
Set alpha channel for an image. |
void |
mask(PImage alpha)
Set alpha channel for an image using another image as the source. |
void |
noSmooth()
Disable smoothing. |
void |
point(float x,
float y)
|
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 |
quad(float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
float x4,
float y4)
|
void |
resetMatrix()
Set the current transformation matrix to identity. |
void |
resize(int wide,
int high)
Resize this image to a new width and height. |
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 sx,
float sy,
float sz)
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 |
screenX(float x,
float y,
float z)
Maps a three dimensional point to its placement on-screen. |
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. |
float |
screenY(float x,
float y,
float z)
Maps a three dimensional point to its placement on-screen. |
float |
screenZ(float x,
float y,
float z)
Maps a three dimensional point to its placement on-screen. |
void |
set(int x,
int y,
int argb)
Set a single pixel to the specified color. |
void |
setMatrix(PMatrix2D source)
Set the current transformation to the contents of the specified source. |
void |
setMatrix(PMatrix3D source)
Set the current transformation to the contents of the specified source. |
void |
setSize(int iwidth,
int iheight)
Called in response to a resize event, handles setting the new width and height internally, as well as re-allocating the pixel buffer for the new size. |
void |
smooth()
If true in PImage, use bilinear interpolation for copy() operations. |
void |
sphere(float r)
Draw a sphere with radius r centered at coordinate 0, 0, 0. |
void |
strokeCap(int cap)
|
void |
strokeJoin(int join)
|
void |
strokeWeight(float weight)
|
float |
textAscent()
Returns the ascent of the current font at the current size. |
float |
textDescent()
Returns the descent of the current font at the current size. |
void |
textSize(float size)
Same as parent, but override for native version of the font. |
void |
texture(PImage image)
Set texture image for current shape. |
void |
translate(float tx,
float ty)
Translate in X and Y. |
void |
triangle(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
|
void |
updatePixels()
Update the pixels[] buffer to the PGraphics image. |
void |
updatePixels(int x,
int y,
int c,
int d)
Update the pixels[] buffer to the PGraphics image. |
void |
vertex(float x,
float y)
|
void |
vertex(float x,
float y,
float z)
|
void |
vertex(float x,
float y,
float u,
float v)
|
void |
vertex(float x,
float y,
float z,
float u,
float v)
|
Methods inherited from class processing.core.PImage |
---|
blend, blend, blendColor, clone, copy, filter, filter, get, getCache, getImage, init, isModified, removeCache, save, set, setCache, setModified, setModified |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public java.awt.Graphics2D g2
public boolean fillGradient
public java.awt.Paint fillGradientObject
public boolean strokeGradient
public java.awt.Paint strokeGradientObject
Constructor Detail |
---|
public PGraphicsJava2D()
Method Detail |
---|
public void setSize(int iwidth, int iheight)
setSize
in class PGraphics
public boolean canDraw()
PGraphics
canDraw
in class PGraphics
public void beginDraw()
PGraphics
beginDraw
in class PGraphics
public void endDraw()
PGraphics
endDraw
in class PGraphics
public void beginShape(int kind)
PGraphics
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.
beginShape
in class PGraphics
public void texture(PImage image)
PGraphics
texture
in class PGraphics
image
- reference to a PImage objectpublic void vertex(float x, float y)
vertex
in class PGraphics
public void vertex(float x, float y, float z)
vertex
in class PGraphics
public void vertex(float x, float y, float u, float v)
vertex
in class PGraphics
public void vertex(float x, float y, float z, float u, float v)
vertex
in class PGraphics
public void breakShape()
PGraphics
breakShape
in class PGraphics
public void endShape(int mode)
endShape
in class PGraphics
public void bezierVertex(float x1, float y1, float x2, float y2, float x3, float y3)
bezierVertex
in class PGraphics
public void bezierVertex(float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)
bezierVertex
in class PGraphics
public void curveVertex(float x, float y, float z)
curveVertex
in class PGraphics
public void point(float x, float y)
point
in class PGraphics
public void line(float x1, float y1, float x2, float y2)
line
in class PGraphics
public void triangle(float x1, float y1, float x2, float y2, float x3, float y3)
triangle
in class PGraphics
public void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
quad
in class PGraphics
public void box(float w, float h, float d)
box
in class PGraphics
public void sphere(float r)
PGraphics
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
sphere
in class PGraphics
public void bezierDetail(int detail)
bezierDetail
in class PGraphics
public void curveDetail(int detail)
curveDetail
in class PGraphics
public void smooth()
PGraphics
smooth
in class PGraphics
public void noSmooth()
PGraphics
noSmooth
in class PGraphics
public float textAscent()
PGraphics
textAscent
in class PGraphics
public float textDescent()
PGraphics
textDescent
in class PGraphics
public void textSize(float size)
textSize
in class PGraphics
public void pushMatrix()
PGraphics
pushMatrix
in class PGraphics
public void popMatrix()
PGraphics
popMatrix
in class PGraphics
public void translate(float tx, float ty)
PGraphics
translate
in class PGraphics
public void rotate(float angle)
PGraphics
rotate
in class PGraphics
public void rotateX(float angle)
PGraphics
rotateX
in class PGraphics
public void rotateY(float angle)
PGraphics
rotateY
in class PGraphics
public void rotateZ(float angle)
PGraphics
rotateZ
in class PGraphics
public void rotate(float angle, float vx, float vy, float vz)
PGraphics
rotate
in class PGraphics
public void scale(float s)
PGraphics
scale
in class PGraphics
public void scale(float sx, float sy)
PGraphics
scale
in class PGraphics
public void scale(float sx, float sy, float sz)
PGraphics
scale
in class PGraphics
public void resetMatrix()
PGraphics
resetMatrix
in class PGraphics
public void applyMatrix(float n00, float n01, float n02, float n10, float n11, float n12)
PGraphics
applyMatrix
in class PGraphics
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)
PGraphics
applyMatrix
in class PGraphics
public PMatrix getMatrix()
getMatrix
in class PGraphics
public PMatrix2D getMatrix(PMatrix2D target)
PGraphics
getMatrix
in class PGraphics
public PMatrix3D getMatrix(PMatrix3D target)
PGraphics
getMatrix
in class PGraphics
public void setMatrix(PMatrix2D source)
PGraphics
setMatrix
in class PGraphics
public void setMatrix(PMatrix3D source)
PGraphics
setMatrix
in class PGraphics
public void printMatrix()
PGraphics
printMatrix
in class PGraphics
public float screenX(float x, float y)
PGraphics
screenX
in class PGraphics
public float screenY(float x, float y)
PGraphics
screenY
in class PGraphics
public float screenX(float x, float y, float z)
PGraphics
Given an (x, y, z) coordinate, returns the x position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations.
screenX
in class PGraphics
public float screenY(float x, float y, float z)
PGraphics
Given an (x, y, z) coordinate, returns the y position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations.
screenY
in class PGraphics
public float screenZ(float x, float y, float z)
PGraphics
Given an (x, y, z) coordinate, returns its z value. This value can be used to determine if an (x, y, z) coordinate is in front or in back of another (x, y, z) coordinate. The units are based on how the zbuffer is set up, and don't relate to anything "real". They're only useful for in comparison to another value obtained from screenZ(), or directly out of the zbuffer[].
screenZ
in class PGraphics
public void strokeCap(int cap)
strokeCap
in class PGraphics
public void strokeJoin(int join)
strokeJoin
in class PGraphics
public void strokeWeight(float weight)
strokeWeight
in class PGraphics
public void backgroundImpl()
PGraphics
public void beginRaw(PGraphics recorderRaw)
PGraphics
beginRaw
in class PGraphics
public void endRaw()
endRaw
in class PGraphics
public void loadPixels()
PImage
loadPixels
in class PImage
public void updatePixels()
Unlike in PImage, where updatePixels() only requests that the update happens, in PGraphicsJava2D, this will happen immediately.
updatePixels
in class PImage
public void updatePixels(int x, int y, int c, int d)
Unlike in PImage, where updatePixels() only requests that the update happens, in PGraphicsJava2D, this will happen immediately.
updatePixels
in class PImage
public void resize(int wide, int high)
PImage
resize
in class PImage
public int get(int x, int y)
PImage
If the image is in RGB format (i.e. on a PVideo object), the value will get its high bits set, just to avoid cases where they haven't been set already.
If the image is in ALPHA format, this returns a white with its alpha value set.
This function is included primarily for beginners. It is quite slow because it has to check to see if the x, y that was provided is inside the bounds, and then has to check to see what image type it is. If you want things to be more efficient, access the pixels[] array directly.
get
in class PImage
public PImage getImpl(int x, int y, int w, int h)
PImage
public PImage get()
PImage
get
in class PImage
public void set(int x, int y, int argb)
PImage
set
in class PImage
public void mask(int[] alpha)
PImage
Strictly speaking the "blue" value from the source image is 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 performing a proper luminance-based conversion.
mask
in class PImage
public void mask(PImage alpha)
PImage
mask
in class PImage
public void copy(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
PImage
copy
in class PImage
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |