| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
* This is called when a sketch is shut down and this renderer was * specified using the size() command, or inside endRecord() and * endRaw(), in order to shut things off. */ public void dispose() { // ignore if (primaryGraphics && asyncImageSaver != null) { asyncImageSaver.dispose(); asyncImageSaver = null; } } public PSurface createSurface() { // ignore return surface = new PSurfaceNone(this); } ////////////////////////////////////////////////////////////// // IMAGE METADATA FOR THIS RENDERER /** * Store data of some kind for the renderer that requires extra metadata of * some kind. Usually this is a renderer-specific representation of the * image data, for instance a BufferedImage with tint() settings applied for * PGraphicsJava2D, or resized image data and OpenGL texture indices for * PGraphicsOpenGL. * @param image The image to be stored * @param storage The metadata required by the renderer */ public void setCache(PImage image, Object storage) { // ignore cacheMap.put(image, storage); } /** * Get cache storage data for the specified renderer. Because each renderer * will cache data in different formats, it's necessary to store cache data * keyed by the renderer object. Otherwise, attempting to draw the same * image to both a PGraphicsJava2D and a PGraphicsOpenGL will cause errors. * @return metadata stored for the specified renderer */ public Object getCache(PImage image) { // ignore return cacheMap.get(image); } /** * Remove information associated with this renderer from the cache, if any. * @param image The image whose cache data should be removed */ public void removeCache(PImage image) { // ignore cacheMap.remove(image); } ////////////////////////////////////////////////////////////// // FRAME // /** // * Some renderers have requirements re: when they are ready to draw. // */ // public boolean canDraw() { // ignore // return true; // } // removing because renderers will have their own animation threads and // can handle this however they wish // /** // * Try to draw, or put a draw request on the queue. // */ // public void requestDraw() { // ignore // parent.handleDraw(); // } /** * ( begin auto-generated from PGraphics_beginDraw.xml ) * * Sets the default properties for a PGraphics object. It should be called * before anything is drawn into the object. * * ( end auto-generated ) *
* 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 ** * @webref shape:3d_primitives * @param r the radius of the sphere * @see PGraphics#sphereDetail(int) */ public void sphere(float r) { if ((sphereDetailU < 3) || (sphereDetailV < 2)) { sphereDetail(30); } edge(false); // 1st ring from south pole beginShape(TRIANGLE_STRIP); for (int i = 0; i < sphereDetailU; i++) { normal(0, -1, 0); vertex(0, -r, 0); normal(sphereX[i], sphereY[i], sphereZ[i]); vertex(r * sphereX[i], r * sphereY[i], r * sphereZ[i]); } normal(0, -r, 0); vertex(0, -r, 0); normal(sphereX[0], sphereY[0], sphereZ[0]); vertex(r * sphereX[0], r * sphereY[0], r * sphereZ[0]); endShape(); int v1,v11,v2; // middle rings int voff = 0; for (int i = 2; i < sphereDetailV; i++) { v1 = v11 = voff; voff += sphereDetailU; v2 = voff; beginShape(TRIANGLE_STRIP); for (int j = 0; j < sphereDetailU; j++) { normal(sphereX[v1], sphereY[v1], sphereZ[v1]); vertex(r * sphereX[v1], r * sphereY[v1], r * sphereZ[v1++]); normal(sphereX[v2], sphereY[v2], sphereZ[v2]); vertex(r * sphereX[v2], r * sphereY[v2], r * sphereZ[v2++]); } // close each ring v1 = v11; v2 = voff; normal(sphereX[v1], sphereY[v1], sphereZ[v1]); vertex(r * sphereX[v1], r * sphereY[v1], r * sphereZ[v1]); normal(sphereX[v2], sphereY[v2], sphereZ[v2]); vertex(r * sphereX[v2], r * sphereY[v2], r * sphereZ[v2]); endShape(); } // add the northern cap beginShape(TRIANGLE_STRIP); for (int i = 0; i < sphereDetailU; i++) { v2 = voff + i; normal(sphereX[v2], sphereY[v2], sphereZ[v2]); vertex(r * sphereX[v2], r * sphereY[v2], r * sphereZ[v2]); normal(0, 1, 0); vertex(0, r, 0); } normal(sphereX[voff], sphereY[voff], sphereZ[voff]); vertex(r * sphereX[voff], r * sphereY[voff], r * sphereZ[voff]); normal(0, 1, 0); vertex(0, r, 0); endShape(); edge(true); } ////////////////////////////////////////////////////////////// // BEZIER /** * ( begin auto-generated from bezierPoint.xml ) * * Evaluates the Bezier at point t for points a, b, c, d. The parameter t * varies between 0 and 1, a and d are points on the curve, and b and c are * the control points. This can be done once with the x coordinates and a * second time with the y coordinates to get the location of a bezier curve * at t. * * ( end auto-generated ) * *
* stroke(255, 102, 0);
* line(85, 20, 10, 10);
* line(90, 90, 15, 80);
* stroke(0, 0, 0);
* bezier(85, 20, 10, 10, 90, 90, 15, 80);
*
* // draw it in gray, using 10 steps instead of the default 20
* // this is a slower way to do it, but useful if you need
* // to do things with the coordinates at each step
* stroke(128);
* beginShape(LINE_STRIP);
* for (int i = 0; i textBuffer.length) {
textBuffer = new char[length + 10];
}
str.getChars(0, length, textBuffer, 0);
text(textBuffer, 0, length, x, y);
}
/**
* Advanced
* Method to draw text from an array of chars. This method will usually be
* more efficient than drawing from a String object, because the String will
* not be converted to a char array before drawing.
* @param chars the alphanumberic symbols to be displayed
* @param start array index at which to start writing characters
* @param stop array index at which to stop writing characters
*/
public void text(char[] chars, int start, int stop, float x, float y) {
// If multiple lines, sum the height of the additional lines
float high = 0; //-textAscent();
for (int i = start; i < stop; i++) {
if (chars[i] == '\n') {
high += textLeading;
}
}
if (textAlignY == CENTER) {
// for a single line, this adds half the textAscent to y
// for multiple lines, subtract half the additional height
//y += (textAscent() - textDescent() - high)/2;
y += (textAscent() - high)/2;
} else if (textAlignY == TOP) {
// for a single line, need to add textAscent to y
// for multiple lines, no different
y += textAscent();
} else if (textAlignY == BOTTOM) {
// for a single line, this is just offset by the descent
// for multiple lines, subtract leading for each line
y -= textDescent() + high;
//} else if (textAlignY == BASELINE) {
// do nothing
}
// int start = 0;
int index = 0;
while (index < stop) { //length) {
if (chars[index] == '\n') {
textLineAlignImpl(chars, start, index, x, y);
start = index + 1;
y += textLeading;
}
index++;
}
if (start < stop) { //length) {
textLineAlignImpl(chars, start, index, x, y);
}
}
/**
* Same as above but with a z coordinate.
*/
public void text(String str, float x, float y, float z) {
if (z != 0) translate(0, 0, z); // slow!
text(str, x, y);
// textZ = z;
if (z != 0) translate(0, 0, -z); // inaccurate!
}
public void text(char[] chars, int start, int stop,
float x, float y, float z) {
if (z != 0) translate(0, 0, z); // slow!
text(chars, start, stop, x, y);
// textZ = z;
if (z != 0) translate(0, 0, -z); // inaccurate!
}
/**
* Advanced
* Draw text in a box that is constrained to a particular size.
* The current rectMode() determines what the coordinates mean
* (whether x1/y1/x2/y2 or x/y/w/h).
*
* Note that the x,y coords of the start of the box
* will align with the *ascent* of the text, not the baseline,
* as is the case for the other text() functions.
*
* Newlines that are \n (Unix newline or linefeed char, ascii 10)
* are honored, and \r (carriage return, Windows and Mac OS) are
* ignored.
*
* @param x1 by default, the x-coordinate of text, see rectMode() for more info
* @param y1 by default, the y-coordinate of text, see rectMode() for more info
* @param x2 by default, the width of the text box, see rectMode() for more info
* @param y2 by default, the height of the text box, see rectMode() for more info
*/
public void text(String str, float x1, float y1, float x2, float y2) {
if (textFont == null) {
defaultFontOrDeath("text");
}
float hradius, vradius;
switch (rectMode) {
case CORNER:
x2 += x1; y2 += y1;
break;
case RADIUS:
hradius = x2;
vradius = y2;
x2 = x1 + hradius;
y2 = y1 + vradius;
x1 -= hradius;
y1 -= vradius;
break;
case CENTER:
hradius = x2 / 2.0f;
vradius = y2 / 2.0f;
x2 = x1 + hradius;
y2 = y1 + vradius;
x1 -= hradius;
y1 -= vradius;
}
if (x2 < x1) {
float temp = x1; x1 = x2; x2 = temp;
}
if (y2 < y1) {
float temp = y1; y1 = y2; y2 = temp;
}
// float currentY = y1;
float boxWidth = x2 - x1;
// // ala illustrator, the text itself must fit inside the box
// currentY += textAscent(); //ascent() * textSize;
// // if the box is already too small, tell em to f off
// if (currentY > y2) return;
float spaceWidth = textWidth(' ');
if (textBreakStart == null) {
textBreakStart = new int[20];
textBreakStop = new int[20];
}
textBreakCount = 0;
int length = str.length();
if (length + 1 > textBuffer.length) {
textBuffer = new char[length + 1];
}
str.getChars(0, length, textBuffer, 0);
// add a fake newline to simplify calculations
textBuffer[length++] = '\n';
int sentenceStart = 0;
for (int i = 0; i < length; i++) {
if (textBuffer[i] == '\n') {
// currentY = textSentence(textBuffer, sentenceStart, i,
// lineX, boxWidth, currentY, y2, spaceWidth);
boolean legit =
textSentence(textBuffer, sentenceStart, i, boxWidth, spaceWidth);
if (!legit) break;
// if (Float.isNaN(currentY)) break; // word too big (or error)
// if (currentY > y2) break; // past the box
sentenceStart = i + 1;
}
}
// lineX is the position where the text starts, which is adjusted
// to left/center/right based on the current textAlign
float lineX = x1; //boxX1;
if (textAlign == CENTER) {
lineX = lineX + boxWidth/2f;
} else if (textAlign == RIGHT) {
lineX = x2; //boxX2;
}
float boxHeight = y2 - y1;
//int lineFitCount = 1 + PApplet.floor((boxHeight - textAscent()) / textLeading);
// incorporate textAscent() for the top (baseline will be y1 + ascent)
// and textDescent() for the bottom, so that lower parts of letters aren't
// outside the box. [0151]
float topAndBottom = textAscent() + textDescent();
int lineFitCount = 1 + PApplet.floor((boxHeight - topAndBottom) / textLeading);
int lineCount = Math.min(textBreakCount, lineFitCount);
if (textAlignY == CENTER) {
float lineHigh = textAscent() + textLeading * (lineCount - 1);
float y = y1 + textAscent() + (boxHeight - lineHigh) / 2;
for (int i = 0; i < lineCount; i++) {
textLineAlignImpl(textBuffer, textBreakStart[i], textBreakStop[i], lineX, y);
y += textLeading;
}
} else if (textAlignY == BOTTOM) {
float y = y2 - textDescent() - textLeading * (lineCount - 1);
for (int i = 0; i < lineCount; i++) {
textLineAlignImpl(textBuffer, textBreakStart[i], textBreakStop[i], lineX, y);
y += textLeading;
}
} else { // TOP or BASELINE just go to the default
float y = y1 + textAscent();
for (int i = 0; i < lineCount; i++) {
textLineAlignImpl(textBuffer, textBreakStart[i], textBreakStop[i], lineX, y);
y += textLeading;
}
}
}
/**
* Emit a sentence of text, defined as a chunk of text without any newlines.
* @param stop non-inclusive, the end of the text in question
* @return false if cannot fit
*/
protected boolean textSentence(char[] buffer, int start, int stop,
float boxWidth, float spaceWidth) {
float runningX = 0;
// Keep track of this separately from index, since we'll need to back up
// from index when breaking words that are too long to fit.
int lineStart = start;
int wordStart = start;
int index = start;
while (index wordStart) {
// we have a non-empty word, measure it
wordWidth = textWidthImpl(buffer, wordStart, index);
}
if (runningX + wordWidth >= boxWidth) {
if (runningX != 0) {
// Next word is too big, output the current line and advance
index = wordStart;
textSentenceBreak(lineStart, index);
// Eat whitespace before the first word on the next line.
while ((index < stop) && (buffer[index] == ' ')) {
index++;
}
} else { // (runningX == 0)
// If this is the first word on the line, and its width is greater
// than the width of the text box, then break the word where at the
// max width, and send the rest of the word to the next line.
if (index - wordStart < 25) {
do {
index--;
if (index == wordStart) {
// Not a single char will fit on this line. screw 'em.
return false;
}
wordWidth = textWidthImpl(buffer, wordStart, index);
} while (wordWidth > boxWidth);
} else {
// This word is more than 25 characters long, might be faster to
// start from the beginning of the text rather than shaving from
// the end of it, which is super slow if it's 1000s of letters.
// https://github.com/processing/processing/issues/211
int lastIndex = index;
index = wordStart + 1;
// walk to the right while things fit
while ((wordWidth = textWidthImpl(buffer, wordStart, index)) < boxWidth) {
index++;
if (index > lastIndex) { // Unreachable?
break;
}
}
index--;
if (index == wordStart) {
return false; // nothing fits
}
}
//textLineImpl(buffer, lineStart, index, x, y);
textSentenceBreak(lineStart, index);
}
lineStart = index;
wordStart = index;
runningX = 0;
} else if (index == stop) {
// last line in the block, time to unload
//textLineImpl(buffer, lineStart, index, x, y);
textSentenceBreak(lineStart, index);
// y += textLeading;
index++;
} else { // this word will fit, just add it to the line
runningX += wordWidth;
wordStart = index ; // move on to the next word including the space before the word
index++;
}
} else { // not a space or the last character
index++; // this is just another letter
}
}
// return y;
return true;
}
protected void textSentenceBreak(int start, int stop) {
if (textBreakCount == textBreakStart.length) {
textBreakStart = PApplet.expand(textBreakStart);
textBreakStop = PApplet.expand(textBreakStop);
}
textBreakStart[textBreakCount] = start;
textBreakStop[textBreakCount] = stop;
textBreakCount++;
}
// public void text(String s, float a, float b, float c, float d, float z) {
// if (z != 0) translate(0, 0, z); // slowness, badness
//
// text(s, a, b, c, d);
// textZ = z;
//
// if (z != 0) translate(0, 0, -z); // TEMPORARY HACK! SLOW!
// }
public void text(int num, float x, float y) {
text(String.valueOf(num), x, y);
}
public void text(int num, float x, float y, float z) {
text(String.valueOf(num), x, y, z);
}
/**
* This does a basic number formatting, to avoid the
* generally ugly appearance of printing floats.
* Users who want more control should use their own nf() cmmand,
* or if they want the long, ugly version of float,
* use String.valueOf() to convert the float to a String first.
*
* @param num the numeric value to be displayed
*/
public void text(float num, float x, float y) {
text(PApplet.nfs(num, 0, 3), x, y);
}
public void text(float num, float x, float y, float z) {
text(PApplet.nfs(num, 0, 3), x, y, z);
}
//////////////////////////////////////////////////////////////
// TEXT IMPL
// These are most likely to be overridden by subclasses, since the other
// (public) functions handle generic features like setting alignment.
/**
* Handles placement of a text line, then calls textLineImpl
* to actually render at the specific point.
*/
protected void textLineAlignImpl(char buffer[], int start, int stop,
float x, float y) {
if (textAlign == CENTER) {
x -= textWidthImpl(buffer, start, stop) / 2f;
} else if (textAlign == RIGHT) {
x -= textWidthImpl(buffer, start, stop);
}
textLineImpl(buffer, start, stop, x, y);
}
/**
* Implementation of actual drawing for a line of text.
*/
protected void textLineImpl(char buffer[], int start, int stop,
float x, float y) {
for (int index = start; index < stop; index++) {
textCharImpl(buffer[index], x, y);
// this doesn't account for kerning
x += textWidth(buffer[index]);
}
// textX = x;
// textY = y;
// textZ = 0; // this will get set by the caller if non-zero
}
protected void textCharImpl(char ch, float x, float y) { //, float z) {
PFont.Glyph glyph = textFont.getGlyph(ch);
if (glyph != null) {
if (textMode == MODEL) {
float high = glyph.height / (float) textFont.getSize();
float bwidth = glyph.width / (float) textFont.getSize();
float lextent = glyph.leftExtent / (float) textFont.getSize();
float textent = glyph.topExtent / (float) textFont.getSize();
float x1 = x + lextent * textSize;
float y1 = y - textent * textSize;
float x2 = x1 + bwidth * textSize;
float y2 = y1 + high * textSize;
textCharModelImpl(glyph.image,
x1, y1, x2, y2,
glyph.width, glyph.height);
}
} else if (ch != ' ' && ch != 127) {
showWarning("No glyph found for the " + ch + " (\\u" + PApplet.hex(ch, 4) + ") character");
}
}
protected void textCharModelImpl(PImage glyph,
float x1, float y1, //float z1,
float x2, float y2, //float z2,
int u2, int v2) {
boolean savedTint = tint;
int savedTintColor = tintColor;
float savedTintR = tintR;
float savedTintG = tintG;
float savedTintB = tintB;
float savedTintA = tintA;
boolean savedTintAlpha = tintAlpha;
tint = true;
tintColor = fillColor;
tintR = fillR;
tintG = fillG;
tintB = fillB;
tintA = fillA;
tintAlpha = fillAlpha;
imageImpl(glyph, x1, y1, x2, y2, 0, 0, u2, v2);
tint = savedTint;
tintColor = savedTintColor;
tintR = savedTintR;
tintG = savedTintG;
tintB = savedTintB;
tintA = savedTintA;
tintAlpha = savedTintAlpha;
}
/*
protected void textCharScreenImpl(PImage glyph,
int xx, int yy,
int w0, int h0) {
int x0 = 0;
int y0 = 0;
if ((xx >= width) || (yy >= height) ||
(xx + w0 < 0) || (yy + h0 < 0)) return;
if (xx < 0) {
x0 -= xx;
w0 += xx;
xx = 0;
}
if (yy < 0) {
y0 -= yy;
h0 += yy;
yy = 0;
}
if (xx + w0 > width) {
w0 -= ((xx + w0) - width);
}
if (yy + h0 > height) {
h0 -= ((yy + h0) - height);
}
int fr = fillRi;
int fg = fillGi;
int fb = fillBi;
int fa = fillAi;
int pixels1[] = glyph.pixels; //images[glyph].pixels;
// TODO this can be optimized a bit
for (int row = y0; row < y0 + h0; row++) {
for (int col = x0; col < x0 + w0; col++) {
//int a1 = (fa * pixels1[row * textFont.twidth + col]) >> 8;
int a1 = (fa * pixels1[row * glyph.width + col]) >> 8;
int a2 = a1 ^ 0xff;
//int p1 = pixels1[row * glyph.width + col];
int p2 = pixels[(yy + row-y0)*width + (xx+col-x0)];
pixels[(yy + row-y0)*width + xx+col-x0] =
(0xff000000 |
(((a1 * fr + a2 * ((p2 >> 16) & 0xff)) & 0xff00) > 8) & 0xff)) & 0xff00) |
(( a1 * fb + a2 * ( p2 & 0xff)) >> 8));
}
}
}
*/
// /**
// * Convenience method to get a legit FontMetrics object. Where possible,
// * override this any renderer subclass so that you're not using what's
// * returned by getDefaultToolkit() to get your metrics.
// */
// @SuppressWarnings("deprecation")
// public FontMetrics getFontMetrics(Font font) { // ignore
// Frame frame = parent.frame;
// if (frame != null) {
// return frame.getToolkit().getFontMetrics(font);
// }
// return Toolkit.getDefaultToolkit().getFontMetrics(font);
// }
//
//
// /**
// * Convenience method to jump through some Java2D hoops and get an FRC.
// */
// public FontRenderContext getFontRenderContext(Font font) { // ignore
// return getFontMetrics(font).getFontRenderContext();
// }
//////////////////////////////////////////////////////////////
// MATRIX STACK
/**
* ( begin auto-generated from pushMatrix.xml )
*
* Pushes the current transformation matrix onto the matrix stack.
* Understanding pushMatrix() and popMatrix() requires
* understanding the concept of a matrix stack. The pushMatrix()
* function saves the current coordinate system to the stack and
* popMatrix() restores the prior coordinate system.
* pushMatrix() and popMatrix() are used in conjuction with
* the other transformation functions and may be embedded to control the
* scope of the transformations.
*
* ( end auto-generated )
*
* @webref transform
* @see PGraphics#popMatrix()
* @see PGraphics#translate(float, float, float)
* @see PGraphics#scale(float)
* @see PGraphics#rotate(float)
* @see PGraphics#rotateX(float)
* @see PGraphics#rotateY(float)
* @see PGraphics#rotateZ(float)
*/
public void pushMatrix() {
showMethodWarning("pushMatrix");
}
/**
* ( begin auto-generated from popMatrix.xml )
*
* Pops the current transformation matrix off the matrix stack.
* Understanding pushing and popping requires understanding the concept of
* a matrix stack. The pushMatrix() function saves the current
* coordinate system to the stack and popMatrix() restores the prior
* coordinate system. pushMatrix() and popMatrix() are used
* in conjuction with the other transformation functions and may be
* embedded to control the scope of the transformations.
*
* ( end auto-generated )
*
* @webref transform
* @see PGraphics#pushMatrix()
*/
public void popMatrix() {
showMethodWarning("popMatrix");
}
//////////////////////////////////////////////////////////////
// MATRIX TRANSFORMATIONS
/**
* ( begin auto-generated from translate.xml )
*
* Specifies an amount to displace objects within the display window. The
* x parameter specifies left/right translation, the y
* parameter specifies up/down translation, and the z parameter
* specifies translations toward/away from the screen. Using this function
* with the z parameter requires using P3D as a parameter in
* combination with size as shown in the above example. 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. This function can be
* further controlled by the pushMatrix() and popMatrix().
*
* ( end auto-generated )
*
* @webref transform
* @param x left/right translation
* @param y up/down translation
* @see PGraphics#popMatrix()
* @see PGraphics#pushMatrix()
* @see PGraphics#rotate(float)
* @see PGraphics#rotateX(float)
* @see PGraphics#rotateY(float)
* @see PGraphics#rotateZ(float)
* @see PGraphics#scale(float, float, float)
*/
public void translate(float x, float y) {
showMissingWarning("translate");
}
/**
* @param z forward/backward translation
*/
public void translate(float x, float y, float z) {
showMissingWarning("translate");
}
/**
* ( begin auto-generated from rotate.xml )
*
* Rotates a shape the amount specified by the angle parameter.
* Angles should be specified in radians (values from 0 to TWO_PI) or
* converted to radians with the radians() function.
*
* 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(HALF_PI) and then rotate(HALF_PI) is the same as
* rotate(PI). All tranformations are reset when draw()
* begins again.
*
* Technically, rotate() multiplies the current transformation
* matrix by a rotation matrix. This function can be further controlled by
* the pushMatrix() and popMatrix().
*
* ( end auto-generated )
*
* @webref transform
* @param angle angle of rotation specified in radians
* @see PGraphics#popMatrix()
* @see PGraphics#pushMatrix()
* @see PGraphics#rotateX(float)
* @see PGraphics#rotateY(float)
* @see PGraphics#rotateZ(float)
* @see PGraphics#scale(float, float, float)
* @see PApplet#radians(float)
*/
public void rotate(float angle) {
showMissingWarning("rotate");
}
/**
* ( begin auto-generated from rotateX.xml )
*
* Rotates a shape around the x-axis the amount specified by the
* angle parameter. Angles should be specified in radians (values
* from 0 to PI*2) or converted to radians with the radians()
* function. Objects are always rotated around their relative position to
* the origin and positive numbers rotate objects in a counterclockwise
* direction. Transformations apply to everything that happens after and
* subsequent calls to the function accumulates the effect. For example,
* calling rotateX(PI/2) and then rotateX(PI/2) is the same
* as rotateX(PI). If rotateX() is called within the
* draw(), the transformation is reset when the loop begins again.
* This function requires using P3D as a third parameter to size()
* as shown in the example above.
*
* ( end auto-generated )
*
* @webref transform
* @param angle angle of rotation specified in radians
* @see PGraphics#popMatrix()
* @see PGraphics#pushMatrix()
* @see PGraphics#rotate(float)
* @see PGraphics#rotateY(float)
* @see PGraphics#rotateZ(float)
* @see PGraphics#scale(float, float, float)
* @see PGraphics#translate(float, float, float)
*/
public void rotateX(float angle) {
showMethodWarning("rotateX");
}
/**
* ( begin auto-generated from rotateY.xml )
*
* Rotates a shape around the y-axis the amount specified by the
* angle parameter. Angles should be specified in radians (values
* from 0 to PI*2) or converted to radians with the radians()
* function. Objects are always rotated around their relative position to
* the origin and positive numbers rotate objects in a counterclockwise
* direction. Transformations apply to everything that happens after and
* subsequent calls to the function accumulates the effect. For example,
* calling rotateY(PI/2) and then rotateY(PI/2) is the same
* as rotateY(PI). If rotateY() is called within the
* draw(), the transformation is reset when the loop begins again.
* This function requires using P3D as a third parameter to size()
* as shown in the examples above.
*
* ( end auto-generated )
*
* @webref transform
* @param angle angle of rotation specified in radians
* @see PGraphics#popMatrix()
* @see PGraphics#pushMatrix()
* @see PGraphics#rotate(float)
* @see PGraphics#rotateX(float)
* @see PGraphics#rotateZ(float)
* @see PGraphics#scale(float, float, float)
* @see PGraphics#translate(float, float, float)
*/
public void rotateY(float angle) {
showMethodWarning("rotateY");
}
/**
* ( begin auto-generated from rotateZ.xml )
*
* Rotates a shape around the z-axis the amount specified by the
* angle parameter. Angles should be specified in radians (values
* from 0 to PI*2) or converted to radians with the radians()
* function. Objects are always rotated around their relative position to
* the origin and positive numbers rotate objects in a counterclockwise
* direction. Transformations apply to everything that happens after and
* subsequent calls to the function accumulates the effect. For example,
* calling rotateZ(PI/2) and then rotateZ(PI/2) is the same
* as rotateZ(PI). If rotateZ() is called within the
* draw(), the transformation is reset when the loop begins again.
* This function requires using P3D as a third parameter to size()
* as shown in the examples above.
*
* ( end auto-generated )
*
* @webref transform
* @param angle angle of rotation specified in radians
* @see PGraphics#popMatrix()
* @see PGraphics#pushMatrix()
* @see PGraphics#rotate(float)
* @see PGraphics#rotateX(float)
* @see PGraphics#rotateY(float)
* @see PGraphics#scale(float, float, float)
* @see PGraphics#translate(float, float, float)
*/
public void rotateZ(float angle) {
showMethodWarning("rotateZ");
}
/**
* Advanced
* Rotate about a vector in space. Same as the glRotatef() function.
* @nowebref
* @param x
* @param y
* @param z
*/
public void rotate(float angle, float x, float y, float z) {
showMissingWarning("rotate");
}
/**
* ( begin auto-generated from scale.xml )
*
* Increases or decreases the size of a shape by expanding and contracting
* vertices. Objects always scale from their relative origin to the
* coordinate system. Scale values are specified as decimal percentages.
* For example, the function call scale(2.0) increases the dimension
* of a shape by 200%. 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.
* Using this fuction with the z parameter requires using P3D as a
* parameter for size() as shown in the example above. This function
* can be further controlled by pushMatrix() and popMatrix().
*
* ( end auto-generated )
*
* @webref transform
* @param s percentage to scale the object
* @see PGraphics#pushMatrix()
* @see PGraphics#popMatrix()
* @see PGraphics#translate(float, float, float)
* @see PGraphics#rotate(float)
* @see PGraphics#rotateX(float)
* @see PGraphics#rotateY(float)
* @see PGraphics#rotateZ(float)
*/
public void scale(float s) {
showMissingWarning("scale");
}
/**
* Advanced
* 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.
*
* @param x percentage to scale the object in the x-axis
* @param y percentage to scale the object in the y-axis
*/
public void scale(float x, float y) {
showMissingWarning("scale");
}
/**
* @param z percentage to scale the object in the z-axis
*/
public void scale(float x, float y, float z) {
showMissingWarning("scale");
}
/**
* ( begin auto-generated from shearX.xml )
*
* Shears a shape around the x-axis the amount specified by the
* angle parameter. Angles should be specified in radians (values
* from 0 to PI*2) or converted to radians with the radians()
* function. Objects are always sheared around their relative position to
* the origin and positive numbers shear objects in a clockwise direction.
* Transformations apply to everything that happens after and subsequent
* calls to the function accumulates the effect. For example, calling
* shearX(PI/2) and then shearX(PI/2) is the same as
* shearX(PI). If shearX() is called within the
* draw(), the transformation is reset when the loop begins again.
*
* Technically, shearX() multiplies the current transformation
* matrix by a rotation matrix. This function can be further controlled by
* the pushMatrix() and popMatrix() functions.
*
* ( end auto-generated )
*
* @webref transform
* @param angle angle of shear specified in radians
* @see PGraphics#popMatrix()
* @see PGraphics#pushMatrix()
* @see PGraphics#shearY(float)
* @see PGraphics#scale(float, float, float)
* @see PGraphics#translate(float, float, float)
* @see PApplet#radians(float)
*/
public void shearX(float angle) {
showMissingWarning("shearX");
}
/**
* ( begin auto-generated from shearY.xml )
*
* Shears a shape around the y-axis the amount specified by the
* angle parameter. Angles should be specified in radians (values
* from 0 to PI*2) or converted to radians with the radians()
* function. Objects are always sheared around their relative position to
* the origin and positive numbers shear objects in a clockwise direction.
* Transformations apply to everything that happens after and subsequent
* calls to the function accumulates the effect. For example, calling
* shearY(PI/2) and then shearY(PI/2) is the same as
* shearY(PI). If shearY() is called within the
* draw(), the transformation is reset when the loop begins again.
*
* Technically, shearY() multiplies the current transformation
* matrix by a rotation matrix. This function can be further controlled by
* the pushMatrix() and popMatrix() functions.
*
* ( end auto-generated )
*
* @webref transform
* @param angle angle of shear specified in radians
* @see PGraphics#popMatrix()
* @see PGraphics#pushMatrix()
* @see PGraphics#shearX(float)
* @see PGraphics#scale(float, float, float)
* @see PGraphics#translate(float, float, float)
* @see PApplet#radians(float)
*/
public void shearY(float angle) {
showMissingWarning("shearY");
}
//////////////////////////////////////////////////////////////
// MATRIX FULL MONTY
/**
* ( begin auto-generated from resetMatrix.xml )
*
* Replaces the current matrix with the identity matrix. The equivalent
* function in OpenGL is glLoadIdentity().
*
* ( end auto-generated )
*
* @webref transform
* @see PGraphics#pushMatrix()
* @see PGraphics#popMatrix()
* @see PGraphics#applyMatrix(PMatrix)
* @see PGraphics#printMatrix()
*/
public void resetMatrix() {
showMethodWarning("resetMatrix");
}
/**
* ( begin auto-generated from applyMatrix.xml )
*
* Multiplies the current matrix by the one specified through the
* parameters. This is very slow because it will try to calculate the
* inverse of the transform, so avoid it whenever possible. The equivalent
* function in OpenGL is glMultMatrix().
*
* ( end auto-generated )
*
* @webref transform
* @source
* @see PGraphics#pushMatrix()
* @see PGraphics#popMatrix()
* @see PGraphics#resetMatrix()
* @see PGraphics#printMatrix()
*/
public void applyMatrix(PMatrix source) {
if (source instanceof PMatrix2D) {
applyMatrix((PMatrix2D) source);
} else if (source instanceof PMatrix3D) {
applyMatrix((PMatrix3D) source);
}
}
public void applyMatrix(PMatrix2D source) {
applyMatrix(source.m00, source.m01, source.m02,
source.m10, source.m11, source.m12);
}
/**
* @param n00 numbers which define the 4x4 matrix to be multiplied
* @param n01 numbers which define the 4x4 matrix to be multiplied
* @param n02 numbers which define the 4x4 matrix to be multiplied
* @param n10 numbers which define the 4x4 matrix to be multiplied
* @param n11 numbers which define the 4x4 matrix to be multiplied
* @param n12 numbers which define the 4x4 matrix to be multiplied
*/
public void applyMatrix(float n00, float n01, float n02,
float n10, float n11, float n12) {
showMissingWarning("applyMatrix");
}
public void applyMatrix(PMatrix3D source) {
applyMatrix(source.m00, source.m01, source.m02, source.m03,
source.m10, source.m11, source.m12, source.m13,
source.m20, source.m21, source.m22, source.m23,
source.m30, source.m31, source.m32, source.m33);
}
/**
* @param n03 numbers which define the 4x4 matrix to be multiplied
* @param n13 numbers which define the 4x4 matrix to be multiplied
* @param n20 numbers which define the 4x4 matrix to be multiplied
* @param n21 numbers which define the 4x4 matrix to be multiplied
* @param n22 numbers which define the 4x4 matrix to be multiplied
* @param n23 numbers which define the 4x4 matrix to be multiplied
* @param n30 numbers which define the 4x4 matrix to be multiplied
* @param n31 numbers which define the 4x4 matrix to be multiplied
* @param n32 numbers which define the 4x4 matrix to be multiplied
* @param n33 numbers which define the 4x4 matrix to be multiplied
*/
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) {
showMissingWarning("applyMatrix");
}
//////////////////////////////////////////////////////////////
// MATRIX GET/SET/PRINT
public PMatrix getMatrix() {
showMissingWarning("getMatrix");
return null;
}
/**
* Copy the current transformation matrix into the specified target.
* Pass in null to create a new matrix.
*/
public PMatrix2D getMatrix(PMatrix2D target) {
showMissingWarning("getMatrix");
return null;
}
/**
* Copy the current transformation matrix into the specified target.
* Pass in null to create a new matrix.
*/
public PMatrix3D getMatrix(PMatrix3D target) {
showMissingWarning("getMatrix");
return null;
}
/**
* Set the current transformation matrix to the contents of another.
*/
public void setMatrix(PMatrix source) {
if (source instanceof PMatrix2D) {
setMatrix((PMatrix2D) source);
} else if (source instanceof PMatrix3D) {
setMatrix((PMatrix3D) source);
}
}
/**
* Set the current transformation to the contents of the specified source.
*/
public void setMatrix(PMatrix2D source) {
showMissingWarning("setMatrix");
}
/**
* Set the current transformation to the contents of the specified source.
*/
public void setMatrix(PMatrix3D source) {
showMissingWarning("setMatrix");
}
/**
* ( begin auto-generated from printMatrix.xml )
*
* Prints the current matrix to the Console (the text window at the bottom
* of Processing).
*
* ( end auto-generated )
*
* @webref transform
* @see PGraphics#pushMatrix()
* @see PGraphics#popMatrix()
* @see PGraphics#resetMatrix()
* @see PGraphics#applyMatrix(PMatrix)
*/
public void printMatrix() {
showMethodWarning("printMatrix");
}
//////////////////////////////////////////////////////////////
// CAMERA
/**
* ( begin auto-generated from beginCamera.xml )
*
* The beginCamera() and endCamera() functions enable
* advanced customization of the camera space. The functions are useful if
* you want to more control over camera movement, however for most users,
* the camera() function will be sufficient.
The camera
* functions will replace any transformations (such as rotate() or
* translate()) that occur before them in draw(), but they
* will not automatically replace the camera transform itself. For this
* reason, camera functions should be placed at the beginning of
* draw() (so that transformations happen afterwards), and the
* camera() function can be used after beginCamera() if you
* want to reset the camera before applying transformations.
This function sets the matrix mode to the camera matrix so calls such
* as translate(), rotate(), applyMatrix() and resetMatrix()
* affect the camera. beginCamera() should always be used with a
* following endCamera() and pairs of beginCamera() and
* endCamera() cannot be nested.
*
* ( end auto-generated )
*
* @webref lights_camera:camera
* @see PGraphics#camera()
* @see PGraphics#endCamera()
* @see PGraphics#applyMatrix(PMatrix)
* @see PGraphics#resetMatrix()
* @see PGraphics#translate(float, float, float)
* @see PGraphics#scale(float, float, float)
*/
public void beginCamera() {
showMethodWarning("beginCamera");
}
/**
* ( begin auto-generated from endCamera.xml )
*
* The beginCamera() and endCamera() functions enable
* advanced customization of the camera space. Please see the reference for
* beginCamera() for a description of how the functions are used.
*
* ( end auto-generated )
*
* @webref lights_camera:camera
* @see PGraphics#beginCamera()
* @see PGraphics#camera(float, float, float, float, float, float, float, float, float)
*/
public void endCamera() {
showMethodWarning("endCamera");
}
/**
* ( begin auto-generated from camera.xml )
*
* Sets the position of the camera through setting the eye position, the
* center of the scene, and which axis is facing upward. Moving the eye
* position and the direction it is pointing (the center of the scene)
* allows the images to be seen from different angles. The version without
* any parameters sets the camera to the default position, pointing to the
* center of the display window with the Y axis as up. The default values
* are camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 /
* 180.0), width/2.0, height/2.0, 0, 0, 1, 0). This function is similar
* to gluLookAt() in OpenGL, but it first clears the current camera settings.
*
* ( end auto-generated )
*
* @webref lights_camera:camera
* @see PGraphics#beginCamera()
* @see PGraphics#endCamera()
* @see PGraphics#frustum(float, float, float, float, float, float)
*/
public void camera() {
showMissingWarning("camera");
}
/**
* @param eyeX x-coordinate for the eye
* @param eyeY y-coordinate for the eye
* @param eyeZ z-coordinate for the eye
* @param centerX x-coordinate for the center of the scene
* @param centerY y-coordinate for the center of the scene
* @param centerZ z-coordinate for the center of the scene
* @param upX usually 0.0, 1.0, or -1.0
* @param upY usually 0.0, 1.0, or -1.0
* @param upZ usually 0.0, 1.0, or -1.0
*/
public void camera(float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ,
float upX, float upY, float upZ) {
showMissingWarning("camera");
}
/**
* ( begin auto-generated from printCamera.xml )
*
* Prints the current camera matrix to the Console (the text window at the
* bottom of Processing).
*
* ( end auto-generated )
* @webref lights_camera:camera
* @see PGraphics#camera(float, float, float, float, float, float, float, float, float)
*/
public void printCamera() {
showMethodWarning("printCamera");
}
//////////////////////////////////////////////////////////////
// PROJECTION
/**
* ( begin auto-generated from ortho.xml )
*
* Sets an orthographic projection and defines a parallel clipping volume.
* All objects with the same dimension appear the same size, regardless of
* whether they are near or far from the camera. The parameters to this
* function specify the clipping volume where left and right are the
* minimum and maximum x values, top and bottom are the minimum and maximum
* y values, and near and far are the minimum and maximum z values. If no
* parameters are given, the default is used: ortho(0, width, 0, height,
* -10, 10).
*
* ( end auto-generated )
*
* @webref lights_camera:camera
*/
public void ortho() {
showMissingWarning("ortho");
}
/**
* @param left left plane of the clipping volume
* @param right right plane of the clipping volume
* @param bottom bottom plane of the clipping volume
* @param top top plane of the clipping volume
*/
public void ortho(float left, float right,
float bottom, float top) {
showMissingWarning("ortho");
}
/**
* @param near maximum distance from the origin to the viewer
* @param far maximum distance from the origin away from the viewer
*/
public void ortho(float left, float right,
float bottom, float top,
float near, float far) {
showMissingWarning("ortho");
}
/**
* ( begin auto-generated from perspective.xml )
*
* Sets a perspective projection applying foreshortening, making distant
* objects appear smaller than closer ones. The parameters define a viewing
* volume with the shape of truncated pyramid. Objects near to the front of
* the volume appear their actual size, while farther objects appear
* smaller. This projection simulates the perspective of the world more
* accurately than orthographic projection. The version of perspective
* without parameters sets the default perspective and the version with
* four parameters allows the programmer to set the area precisely. The
* default values are: perspective(PI/3.0, width/height, cameraZ/10.0,
* cameraZ*10.0) where cameraZ is ((height/2.0) / tan(PI*60.0/360.0));
*
* ( end auto-generated )
*
* @webref lights_camera:camera
*/
public void perspective() {
showMissingWarning("perspective");
}
/**
* @param fovy field-of-view angle (in radians) for vertical direction
* @param aspect ratio of width to height
* @param zNear z-position of nearest clipping plane
* @param zFar z-position of farthest clipping plane
*/
public void perspective(float fovy, float aspect, float zNear, float zFar) {
showMissingWarning("perspective");
}
/**
* ( begin auto-generated from frustum.xml )
*
* Sets a perspective matrix defined through the parameters. Works like
* glFrustum, except it wipes out the current perspective matrix rather
* than muliplying itself with it.
*
* ( end auto-generated )
*
* @webref lights_camera:camera
* @param left left coordinate of the clipping plane
* @param right right coordinate of the clipping plane
* @param bottom bottom coordinate of the clipping plane
* @param top top coordinate of the clipping plane
* @param near near component of the clipping plane; must be greater than zero
* @param far far component of the clipping plane; must be greater than the near value
* @see PGraphics#camera(float, float, float, float, float, float, float, float, float)
* @see PGraphics#beginCamera()
* @see PGraphics#endCamera()
* @see PGraphics#perspective(float, float, float, float)
*/
public void frustum(float left, float right,
float bottom, float top,
float near, float far) {
showMethodWarning("frustum");
}
/**
* ( begin auto-generated from printProjection.xml )
*
* Prints the current projection matrix to the Console (the text window at
* the bottom of Processing).
*
* ( end auto-generated )
*
* @webref lights_camera:camera
* @see PGraphics#camera(float, float, float, float, float, float, float, float, float)
*/
public void printProjection() {
showMethodWarning("printProjection");
}
//////////////////////////////////////////////////////////////
// SCREEN TRANSFORMS
/**
* ( begin auto-generated from screenX.xml )
*
* Takes a three-dimensional X, Y, Z position and returns the X value for
* where it will appear on a (two-dimensional) screen.
*
* ( end auto-generated )
*
* @webref lights_camera:coordinates
* @param x 3D x-coordinate to be mapped
* @param y 3D y-coordinate to be mapped
* @see PGraphics#screenY(float, float, float)
* @see PGraphics#screenZ(float, float, float)
*/
public float screenX(float x, float y) {
showMissingWarning("screenX");
return 0;
}
/**
* ( begin auto-generated from screenY.xml )
*
* Takes a three-dimensional X, Y, Z position and returns the Y value for
* where it will appear on a (two-dimensional) screen.
*
* ( end auto-generated )
*
* @webref lights_camera:coordinates
* @param x 3D x-coordinate to be mapped
* @param y 3D y-coordinate to be mapped
* @see PGraphics#screenX(float, float, float)
* @see PGraphics#screenZ(float, float, float)
*/
public float screenY(float x, float y) {
showMissingWarning("screenY");
return 0;
}
/**
* @param z 3D z-coordinate to be mapped
*/
public float screenX(float x, float y, float z) {
showMissingWarning("screenX");
return 0;
}
/**
* @param z 3D z-coordinate to be mapped
*/
public float screenY(float x, float y, float z) {
showMissingWarning("screenY");
return 0;
}
/**
* ( begin auto-generated from screenZ.xml )
*
* Takes a three-dimensional X, Y, Z position and returns the Z value for
* where it will appear on a (two-dimensional) screen.
*
* ( end auto-generated )
*
* @webref lights_camera:coordinates
* @param x 3D x-coordinate to be mapped
* @param y 3D y-coordinate to be mapped
* @param z 3D z-coordinate to be mapped
* @see PGraphics#screenX(float, float, float)
* @see PGraphics#screenY(float, float, float)
*/
public float screenZ(float x, float y, float z) {
showMissingWarning("screenZ");
return 0;
}
/**
* ( begin auto-generated from modelX.xml )
*
* Returns the three-dimensional X, Y, Z position in model space. This
* returns the X value for a given coordinate based on the current set of
* transformations (scale, rotate, translate, etc.) The X value can be used
* to place an object in space relative to the location of the original
* point once the transformations are no longer in use.
*
* In the example, the modelX(), modelY(), and
* modelZ() functions record the location of a box in space after
* being placed using a series of translate and rotate commands. After
* popMatrix() is called, those transformations no longer apply, but the
* (x, y, z) coordinate returned by the model functions is used to place
* another box in the same location.
*
* ( end auto-generated )
*
* @webref lights_camera:coordinates
* @param x 3D x-coordinate to be mapped
* @param y 3D y-coordinate to be mapped
* @param z 3D z-coordinate to be mapped
* @see PGraphics#modelY(float, float, float)
* @see PGraphics#modelZ(float, float, float)
*/
public float modelX(float x, float y, float z) {
showMissingWarning("modelX");
return 0;
}
/**
* ( begin auto-generated from modelY.xml )
*
* Returns the three-dimensional X, Y, Z position in model space. This
* returns the Y value for a given coordinate based on the current set of
* transformations (scale, rotate, translate, etc.) The Y value can be used
* to place an object in space relative to the location of the original
* point once the transformations are no longer in use.
*
* In the example, the modelX(), modelY(), and
* modelZ() functions record the location of a box in space after
* being placed using a series of translate and rotate commands. After
* popMatrix() is called, those transformations no longer apply, but the
* (x, y, z) coordinate returned by the model functions is used to place
* another box in the same location.
*
* ( end auto-generated )
*
* @webref lights_camera:coordinates
* @param x 3D x-coordinate to be mapped
* @param y 3D y-coordinate to be mapped
* @param z 3D z-coordinate to be mapped
* @see PGraphics#modelX(float, float, float)
* @see PGraphics#modelZ(float, float, float)
*/
public float modelY(float x, float y, float z) {
showMissingWarning("modelY");
return 0;
}
/**
* ( begin auto-generated from modelZ.xml )
*
* Returns the three-dimensional X, Y, Z position in model space. This
* returns the Z value for a given coordinate based on the current set of
* transformations (scale, rotate, translate, etc.) The Z value can be used
* to place an object in space relative to the location of the original
* point once the transformations are no longer in use.
*
* In the example, the modelX(), modelY(), and
* modelZ() functions record the location of a box in space after
* being placed using a series of translate and rotate commands. After
* popMatrix() is called, those transformations no longer apply, but the
* (x, y, z) coordinate returned by the model functions is used to place
* another box in the same location.
*
* ( end auto-generated )
*
* @webref lights_camera:coordinates
* @param x 3D x-coordinate to be mapped
* @param y 3D y-coordinate to be mapped
* @param z 3D z-coordinate to be mapped
* @see PGraphics#modelX(float, float, float)
* @see PGraphics#modelY(float, float, float)
*/
public float modelZ(float x, float y, float z) {
showMissingWarning("modelZ");
return 0;
}
//////////////////////////////////////////////////////////////
// STYLE
/**
* ( begin auto-generated from pushStyle.xml )
*
* The pushStyle() function saves the current style settings and
* popStyle() restores the prior settings. Note that these functions
* are always used together. They allow you to change the style settings
* and later return to what you had. When a new style is started with
* pushStyle(), it builds on the current style information. The
* pushStyle() and popStyle() functions can be embedded to
* provide more control (see the second example above for a demonstration.)
*
* The style information controlled by the following functions are included
* in the style:
* fill(), stroke(), tint(), strokeWeight(), strokeCap(), strokeJoin(),
* imageMode(), rectMode(), ellipseMode(), shapeMode(), colorMode(),
* textAlign(), textFont(), textMode(), textSize(), textLeading(),
* emissive(), specular(), shininess(), ambient()
*
* ( end auto-generated )
*
* @webref structure
* @see PGraphics#popStyle()
*/
public void pushStyle() {
if (styleStackDepth == styleStack.length) {
styleStack = (PStyle[]) PApplet.expand(styleStack);
}
if (styleStack[styleStackDepth] == null) {
styleStack[styleStackDepth] = new PStyle();
}
PStyle s = styleStack[styleStackDepth++];
getStyle(s);
}
/**
* ( begin auto-generated from popStyle.xml )
*
* The pushStyle() function saves the current style settings and
* popStyle() restores the prior settings; these functions are
* always used together. They allow you to change the style settings and
* later return to what you had. When a new style is started with
* pushStyle(), it builds on the current style information. The
* pushStyle() and popStyle() functions can be embedded to
* provide more control (see the second example above for a demonstration.)
*
* ( end auto-generated )
*
* @webref structure
* @see PGraphics#pushStyle()
*/
public void popStyle() {
if (styleStackDepth == 0) {
throw new RuntimeException("Too many popStyle() without enough pushStyle()");
}
styleStackDepth--;
style(styleStack[styleStackDepth]);
}
public void style(PStyle s) {
// if (s.smooth) {
// smooth();
// } else {
// noSmooth();
// }
imageMode(s.imageMode);
rectMode(s.rectMode);
ellipseMode(s.ellipseMode);
shapeMode(s.shapeMode);
blendMode(s.blendMode);
if (s.tint) {
tint(s.tintColor);
} else {
noTint();
}
if (s.fill) {
fill(s.fillColor);
} else {
noFill();
}
if (s.stroke) {
stroke(s.strokeColor);
} else {
noStroke();
}
strokeWeight(s.strokeWeight);
strokeCap(s.strokeCap);
strokeJoin(s.strokeJoin);
// Set the colorMode() for the material properties.
// TODO this is really inefficient, need to just have a material() method,
// but this has the least impact to the API.
colorMode(RGB, 1);
ambient(s.ambientR, s.ambientG, s.ambientB);
emissive(s.emissiveR, s.emissiveG, s.emissiveB);
specular(s.specularR, s.specularG, s.specularB);
shininess(s.shininess);
/*
s.ambientR = ambientR;
s.ambientG = ambientG;
s.ambientB = ambientB;
s.specularR = specularR;
s.specularG = specularG;
s.specularB = specularB;
s.emissiveR = emissiveR;
s.emissiveG = emissiveG;
s.emissiveB = emissiveB;
s.shininess = shininess;
*/
// material(s.ambientR, s.ambientG, s.ambientB,
// s.emissiveR, s.emissiveG, s.emissiveB,
// s.specularR, s.specularG, s.specularB,
// s.shininess);
// Set this after the material properties.
colorMode(s.colorMode,
s.colorModeX, s.colorModeY, s.colorModeZ, s.colorModeA);
// This is a bit asymmetric, since there's no way to do "noFont()",
// and a null textFont will produce an error (since usually that means that
// the font couldn't load properly). So in some cases, the font won't be
// 'cleared' to null, even though that's technically correct.
if (s.textFont != null) {
textFont(s.textFont, s.textSize);
textLeading(s.textLeading);
}
// These don't require a font to be set.
textAlign(s.textAlign, s.textAlignY);
textMode(s.textMode);
}
public PStyle getStyle() { // ignore
return getStyle(null);
}
public PStyle getStyle(PStyle s) { // ignore
if (s == null) {
s = new PStyle();
}
s.imageMode = imageMode;
s.rectMode = rectMode;
s.ellipseMode = ellipseMode;
s.shapeMode = shapeMode;
s.blendMode = blendMode;
s.colorMode = colorMode;
s.colorModeX = colorModeX;
s.colorModeY = colorModeY;
s.colorModeZ = colorModeZ;
s.colorModeA = colorModeA;
s.tint = tint;
s.tintColor = tintColor;
s.fill = fill;
s.fillColor = fillColor;
s.stroke = stroke;
s.strokeColor = strokeColor;
s.strokeWeight = strokeWeight;
s.strokeCap = strokeCap;
s.strokeJoin = strokeJoin;
s.ambientR = ambientR;
s.ambientG = ambientG;
s.ambientB = ambientB;
s.specularR = specularR;
s.specularG = specularG;
s.specularB = specularB;
s.emissiveR = emissiveR;
s.emissiveG = emissiveG;
s.emissiveB = emissiveB;
s.shininess = shininess;
s.textFont = textFont;
s.textAlign = textAlign;
s.textAlignY = textAlignY;
s.textMode = textMode;
s.textSize = textSize;
s.textLeading = textLeading;
return s;
}
//////////////////////////////////////////////////////////////
// STROKE CAP/JOIN/WEIGHT
/**
* ( begin auto-generated from strokeWeight.xml )
*
* Sets the width of the stroke used for lines, points, and the border
* around shapes. All widths are set in units of pixels.
*
* When drawing with P3D, series of connected lines (such as the stroke
* around a polygon, triangle, or ellipse) produce unattractive results
* when a thick stroke weight is set (see
* Issue 123). With P3D, the minimum and maximum values for
* strokeWeight() are controlled by the graphics card and the
* operating system's OpenGL implementation. For instance, the thickness
* may not go higher than 10 pixels.
*
* ( end auto-generated )
*
* @webref shape:attributes
* @param weight the weight (in pixels) of the stroke
* @see PGraphics#stroke(int, float)
* @see PGraphics#strokeJoin(int)
* @see PGraphics#strokeCap(int)
*/
public void strokeWeight(float weight) {
strokeWeight = weight;
}
/**
* ( begin auto-generated from strokeJoin.xml )
*
* Sets the style of the joints which connect line segments. These joints
* are either mitered, beveled, or rounded and specified with the
* corresponding parameters MITER, BEVEL, and ROUND. The default joint is
* MITER.
*
* This function is not available with the P3D renderer, (see
* Issue 123). More information about the renderers can be found in the
* size() reference.
*
* ( end auto-generated )
*
* @webref shape:attributes
* @param join either MITER, BEVEL, ROUND
* @see PGraphics#stroke(int, float)
* @see PGraphics#strokeWeight(float)
* @see PGraphics#strokeCap(int)
*/
public void strokeJoin(int join) {
strokeJoin = join;
}
/**
* ( begin auto-generated from strokeCap.xml )
*
* Sets the style for rendering line endings. These ends are either
* squared, extended, or rounded and specified with the corresponding
* parameters SQUARE, PROJECT, and ROUND. The default cap is ROUND.
*
* This function is not available with the P3D renderer (see
* Issue 123). More information about the renderers can be found in the
* size() reference.
*
* ( end auto-generated )
*
* @webref shape:attributes
* @param cap either SQUARE, PROJECT, or ROUND
* @see PGraphics#stroke(int, float)
* @see PGraphics#strokeWeight(float)
* @see PGraphics#strokeJoin(int)
* @see PApplet#size(int, int, String, String)
*/
public void strokeCap(int cap) {
strokeCap = cap;
}
//////////////////////////////////////////////////////////////
// STROKE COLOR
/**
* ( begin auto-generated from noStroke.xml )
*
* Disables drawing the stroke (outline). If both noStroke() and
* noFill() are called, nothing will be drawn to the screen.
*
* ( end auto-generated )
*
* @webref color:setting
* @see PGraphics#stroke(int, float)
* @see PGraphics#fill(float, float, float, float)
* @see PGraphics#noFill()
*/
public void noStroke() {
stroke = false;
}
/**
* ( begin auto-generated from stroke.xml )
*
* Sets the color used to draw lines and borders around shapes. This color
* is either specified in terms of the RGB or HSB color depending on the
* current colorMode() (the default color space is RGB, with each
* value in the range from 0 to 255).
*
* When using hexadecimal notation to specify a color, use "#" or "0x"
* before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six
* digits to specify a color (the way colors are specified in HTML and
* CSS). When using the hexadecimal notation starting with "0x", the
* hexadecimal value must be specified with eight characters; the first two
* characters define the alpha component and the remainder the red, green,
* and blue components.
*
* The value for the parameter "gray" must be less than or equal to the
* current maximum value as specified by colorMode(). The default
* maximum value is 255.
*
* ( end auto-generated )
*
* @param rgb color value in hexadecimal notation
* @see PGraphics#noStroke()
* @see PGraphics#strokeWeight(float)
* @see PGraphics#strokeJoin(int)
* @see PGraphics#strokeCap(int)
* @see PGraphics#fill(int, float)
* @see PGraphics#noFill()
* @see PGraphics#tint(int, float)
* @see PGraphics#background(float, float, float, float)
* @see PGraphics#colorMode(int, float, float, float, float)
*/
public void stroke(int rgb) {
colorCalc(rgb);
strokeFromCalc();
}
/**
* @param alpha opacity of the stroke
*/
public void stroke(int rgb, float alpha) {
colorCalc(rgb, alpha);
strokeFromCalc();
}
/**
* @param gray specifies a value between white and black
*/
public void stroke(float gray) {
colorCalc(gray);
strokeFromCalc();
}
public void stroke(float gray, float alpha) {
colorCalc(gray, alpha);
strokeFromCalc();
}
/**
* @param v1 red or hue value (depending on current color mode)
* @param v2 green or saturation value (depending on current color mode)
* @param v3 blue or brightness value (depending on current color mode)
* @webref color:setting
*/
public void stroke(float v1, float v2, float v3) {
colorCalc(v1, v2, v3);
strokeFromCalc();
}
public void stroke(float v1, float v2, float v3, float alpha) {
colorCalc(v1, v2, v3, alpha);
strokeFromCalc();
}
protected void strokeFromCalc() {
stroke = true;
strokeR = calcR;
strokeG = calcG;
strokeB = calcB;
strokeA = calcA;
strokeRi = calcRi;
strokeGi = calcGi;
strokeBi = calcBi;
strokeAi = calcAi;
strokeColor = calcColor;
strokeAlpha = calcAlpha;
}
//////////////////////////////////////////////////////////////
// TINT COLOR
/**
* ( begin auto-generated from noTint.xml )
*
* Removes the current fill value for displaying images and reverts to
* displaying images with their original hues.
*
* ( end auto-generated )
*
* @webref image:loading_displaying
* @usage web_application
* @see PGraphics#tint(float, float, float, float)
* @see PGraphics#image(PImage, float, float, float, float)
*/
public void noTint() {
tint = false;
}
/**
* ( begin auto-generated from tint.xml )
*
* Sets the fill value for displaying images. Images can be tinted to
* specified colors or made transparent by setting the alpha.
*
* To make an image transparent, but not change it's color, use white as
* the tint color and specify an alpha value. For instance, tint(255, 128)
* will make an image 50% transparent (unless colorMode() has been
* used).
*
* When using hexadecimal notation to specify a color, use "#" or "0x"
* before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six
* digits to specify a color (the way colors are specified in HTML and
* CSS). When using the hexadecimal notation starting with "0x", the
* hexadecimal value must be specified with eight characters; the first two
* characters define the alpha component and the remainder the red, green,
* and blue components.
*
* The value for the parameter "gray" must be less than or equal to the
* current maximum value as specified by colorMode(). The default
* maximum value is 255.
*
* The tint() function is also used to control the coloring of
* textures in 3D.
*
* ( end auto-generated )
*
* @webref image:loading_displaying
* @usage web_application
* @param rgb color value in hexadecimal notation
* @see PGraphics#noTint()
* @see PGraphics#image(PImage, float, float, float, float)
*/
public void tint(int rgb) {
colorCalc(rgb);
tintFromCalc();
}
/**
* @param alpha opacity of the image
*/
public void tint(int rgb, float alpha) {
colorCalc(rgb, alpha);
tintFromCalc();
}
/**
* @param gray specifies a value between white and black
*/
public void tint(float gray) {
colorCalc(gray);
tintFromCalc();
}
public void tint(float gray, float alpha) {
colorCalc(gray, alpha);
tintFromCalc();
}
/**
* @param v1 red or hue value (depending on current color mode)
* @param v2 green or saturation value (depending on current color mode)
* @param v3 blue or brightness value (depending on current color mode)
*/
public void tint(float v1, float v2, float v3) {
colorCalc(v1, v2, v3);
tintFromCalc();
}
public void tint(float v1, float v2, float v3, float alpha) {
colorCalc(v1, v2, v3, alpha);
tintFromCalc();
}
protected void tintFromCalc() {
tint = true;
tintR = calcR;
tintG = calcG;
tintB = calcB;
tintA = calcA;
tintRi = calcRi;
tintGi = calcGi;
tintBi = calcBi;
tintAi = calcAi;
tintColor = calcColor;
tintAlpha = calcAlpha;
}
//////////////////////////////////////////////////////////////
// FILL COLOR
/**
* ( begin auto-generated from noFill.xml )
*
* Disables filling geometry. If both noStroke() and noFill()
* are called, nothing will be drawn to the screen.
*
* ( end auto-generated )
*
* @webref color:setting
* @usage web_application
* @see PGraphics#fill(float, float, float, float)
* @see PGraphics#stroke(int, float)
* @see PGraphics#noStroke()
*/
public void noFill() {
fill = false;
}
/**
* ( begin auto-generated from fill.xml )
*
* Sets the color used to fill shapes. For example, if you run fill(204,
* 102, 0), all subsequent shapes will be filled with orange. This
* color is either specified in terms of the RGB or HSB color depending on
* the current colorMode() (the default color space is RGB, with
* each value in the range from 0 to 255).
*
* When using hexadecimal notation to specify a color, use "#" or "0x"
* before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six
* digits to specify a color (the way colors are specified in HTML and
* CSS). When using the hexadecimal notation starting with "0x", the
* hexadecimal value must be specified with eight characters; the first two
* characters define the alpha component and the remainder the red, green,
* and blue components.
*
* The value for the parameter "gray" must be less than or equal to the
* current maximum value as specified by colorMode(). The default
* maximum value is 255.
*
* To change the color of an image (or a texture), use tint().
*
* ( end auto-generated )
*
* @webref color:setting
* @usage web_application
* @param rgb color variable or hex value
* @see PGraphics#noFill()
* @see PGraphics#stroke(int, float)
* @see PGraphics#noStroke()
* @see PGraphics#tint(int, float)
* @see PGraphics#background(float, float, float, float)
* @see PGraphics#colorMode(int, float, float, float, float)
*/
public void fill(int rgb) {
colorCalc(rgb);
fillFromCalc();
}
/**
* @param alpha opacity of the fill
*/
public void fill(int rgb, float alpha) {
colorCalc(rgb, alpha);
fillFromCalc();
}
/**
* @param gray number specifying value between white and black
*/
public void fill(float gray) {
colorCalc(gray);
fillFromCalc();
}
public void fill(float gray, float alpha) {
colorCalc(gray, alpha);
fillFromCalc();
}
/**
* @param v1 red or hue value (depending on current color mode)
* @param v2 green or saturation value (depending on current color mode)
* @param v3 blue or brightness value (depending on current color mode)
*/
public void fill(float v1, float v2, float v3) {
colorCalc(v1, v2, v3);
fillFromCalc();
}
public void fill(float v1, float v2, float v3, float alpha) {
colorCalc(v1, v2, v3, alpha);
fillFromCalc();
}
protected void fillFromCalc() {
fill = true;
fillR = calcR;
fillG = calcG;
fillB = calcB;
fillA = calcA;
fillRi = calcRi;
fillGi = calcGi;
fillBi = calcBi;
fillAi = calcAi;
fillColor = calcColor;
fillAlpha = calcAlpha;
}
//////////////////////////////////////////////////////////////
// MATERIAL PROPERTIES
/**
* ( begin auto-generated from ambient.xml )
*
* Sets the ambient reflectance for shapes drawn to the screen. This is
* combined with the ambient light component of environment. The color
* components set through the parameters define the reflectance. For
* example in the default color mode, setting v1=255, v2=126, v3=0, would
* cause all the red light to reflect and half of the green light to
* reflect. Used in combination with emissive(), specular(),
* and shininess() in setting the material properties of shapes.
*
* ( end auto-generated )
*
* @webref lights_camera:material_properties
* @usage web_application
* @param rgb any value of the color datatype
* @see PGraphics#emissive(float, float, float)
* @see PGraphics#specular(float, float, float)
* @see PGraphics#shininess(float)
*/
public void ambient(int rgb) {
// if (((rgb & 0xff000000) == 0) && (rgb > 24) & 0xff;
calcColor = argb;
} else {
calcAi = (int) (((argb >> 24) & 0xff) * PApplet.constrain((alpha / colorModeA), 0, 1));
calcColor = (calcAi > 16) & 0xff;
calcGi = (argb >> 8) & 0xff;
calcBi = argb & 0xff;
calcA = calcAi / 255.0f;
calcR = calcRi / 255.0f;
calcG = calcGi / 255.0f;
calcB = calcBi / 255.0f;
calcAlpha = (calcAi != 255);
}
//////////////////////////////////////////////////////////////
// COLOR DATATYPE STUFFING
// The 'color' primitive type in Processing syntax is in fact a 32-bit int.
// These functions handle stuffing color values into a 32-bit cage based
// on the current colorMode settings.
// These functions are really slow (because they take the current colorMode
// into account), but they're easy to use. Advanced users can write their
// own bit shifting operations to setup 'color' data types.
public final int color(int c) { // ignore
// if (((c & 0xff000000) == 0) && (c 255) c = 255; else if (c < 0) c = 0;
// if (alpha > 255) alpha = 255; else if (alpha < 0) alpha = 0;
//
// return ((alpha & 0xff) 16) & 0xff;
if (colorModeDefault) return c;
return (c / 255.0f) * colorModeX;
}
/**
* ( begin auto-generated from green.xml )
*
* Extracts the green value from a color, scaled to match current
* colorMode(). This value is always returned as a float so be
* careful not to assign it to an int value.
The green()
* function is easy to use and undestand, but is slower than another
* technique. To achieve the same results when working in colorMode(RGB,
* 255), but with greater speed, use the >> (right shift)
* operator with a bit mask. For example, the following two lines of code
* are equivalent:
float r1 = green(myColor);
float r2 =
* myColor >> 8 & 0xFF;
*
* ( end auto-generated )
*
* @webref color:creating_reading
* @usage web_application
* @param rgb any value of the color datatype
* @see PGraphics#red(int)
* @see PGraphics#blue(int)
* @see PGraphics#alpha(int)
* @see PGraphics#hue(int)
* @see PGraphics#saturation(int)
* @see PGraphics#brightness(int)
* @see_external rightshift
*/
public final float green(int rgb) {
float c = (rgb >> 8) & 0xff;
if (colorModeDefault) return c;
return (c / 255.0f) * colorModeY;
}
/**
* ( begin auto-generated from blue.xml )
*
* Extracts the blue value from a color, scaled to match current
* colorMode(). This value is always returned as a float so be
* careful not to assign it to an int value.
The blue()
* function is easy to use and undestand, but is slower than another
* technique. To achieve the same results when working in colorMode(RGB,
* 255), but with greater speed, use a bit mask to remove the other
* color components. For example, the following two lines of code are
* equivalent:
float r1 = blue(myColor);
float r2 = myColor
* & 0xFF;
*
* ( end auto-generated )
*
* @webref color:creating_reading
* @usage web_application
* @param rgb any value of the color datatype
* @see PGraphics#red(int)
* @see PGraphics#green(int)
* @see PGraphics#alpha(int)
* @see PGraphics#hue(int)
* @see PGraphics#saturation(int)
* @see PGraphics#brightness(int)
* @see_external rightshift
*/
public final float blue(int rgb) {
float c = (rgb) & 0xff;
if (colorModeDefault) return c;
return (c / 255.0f) * colorModeZ;
}
/**
* ( begin auto-generated from hue.xml )
*
* Extracts the hue value from a color.
*
* ( end auto-generated )
* @webref color:creating_reading
* @usage web_application
* @param rgb any value of the color datatype
* @see PGraphics#red(int)
* @see PGraphics#green(int)
* @see PGraphics#blue(int)
* @see PGraphics#alpha(int)
* @see PGraphics#saturation(int)
* @see PGraphics#brightness(int)
*/
public final float hue(int rgb) {
if (rgb != cacheHsbKey) {
Color.RGBtoHSB((rgb >> 16) & 0xff, (rgb >> 8) & 0xff,
rgb & 0xff, cacheHsbValue);
cacheHsbKey = rgb;
}
return cacheHsbValue[0] * colorModeX;
}
/**
* ( begin auto-generated from saturation.xml )
*
* Extracts the saturation value from a color.
*
* ( end auto-generated )
* @webref color:creating_reading
* @usage web_application
* @param rgb any value of the color datatype
* @see PGraphics#red(int)
* @see PGraphics#green(int)
* @see PGraphics#blue(int)
* @see PGraphics#alpha(int)
* @see PGraphics#hue(int)
* @see PGraphics#brightness(int)
*/
public final float saturation(int rgb) {
if (rgb != cacheHsbKey) {
Color.RGBtoHSB((rgb >> 16) & 0xff, (rgb >> 8) & 0xff,
rgb & 0xff, cacheHsbValue);
cacheHsbKey = rgb;
}
return cacheHsbValue[1] * colorModeY;
}
/**
* ( begin auto-generated from brightness.xml )
*
* Extracts the brightness value from a color.
*
* ( end auto-generated )
*
* @webref color:creating_reading
* @usage web_application
* @param rgb any value of the color datatype
* @see PGraphics#red(int)
* @see PGraphics#green(int)
* @see PGraphics#blue(int)
* @see PGraphics#alpha(int)
* @see PGraphics#hue(int)
* @see PGraphics#saturation(int)
*/
public final float brightness(int rgb) {
if (rgb != cacheHsbKey) {
Color.RGBtoHSB((rgb >> 16) & 0xff, (rgb >> 8) & 0xff,
rgb & 0xff, cacheHsbValue);
cacheHsbKey = rgb;
}
return cacheHsbValue[2] * colorModeZ;
}
//////////////////////////////////////////////////////////////
// COLOR DATATYPE INTERPOLATION
// Against our better judgement.
/**
* ( begin auto-generated from lerpColor.xml )
*
* 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.
*
* ( end auto-generated )
*
* @webref color:creating_reading
* @usage web_application
* @param c1 interpolate from this color
* @param c2 interpolate to this color
* @param amt between 0.0 and 1.0
* @see PImage#blendColor(int, int, int)
* @see PGraphics#color(float, float, float, float)
* @see PApplet#lerp(float, float, float)
*/
public int lerpColor(int c1, int c2, float amt) { // ignore
return lerpColor(c1, c2, amt, colorMode);
}
static float[] lerpColorHSB1;
static float[] lerpColorHSB2;
/**
* @nowebref
* Interpolate between two colors. Like lerp(), but for the
* individual color components of a color supplied as an int value.
*/
static public int lerpColor(int c1, int c2, float amt, int mode) {
if (amt < 0) amt = 0;
if (amt > 1) amt = 1;
if (mode == RGB) {
float a1 = ((c1 >> 24) & 0xff);
float r1 = (c1 >> 16) & 0xff;
float g1 = (c1 >> 8) & 0xff;
float b1 = c1 & 0xff;
float a2 = (c2 >> 24) & 0xff;
float r2 = (c2 >> 16) & 0xff;
float g2 = (c2 >> 8) & 0xff;
float b2 = c2 & 0xff;
return ((PApplet.round(a1 + (a2-a1)*amt) > 24) & 0xff;
int alfa = (PApplet.round(a1 + (a2-a1)*amt)) > 16) & 0xff, (c1 >> 8) & 0xff, c1 & 0xff,
lerpColorHSB1);
Color.RGBtoHSB((c2 >> 16) & 0xff, (c2 >> 8) & 0xff, c2 & 0xff,
lerpColorHSB2);
/* If mode is HSB, this will take the shortest path around the
* color wheel to find the new color. For instance, red to blue
* will go red violet blue (backwards in hue space) rather than
* cycling through ROYGBIV.
*/
// Disabling rollover (wasn't working anyway) for 0126.
// Otherwise it makes full spectrum scale impossible for
// those who might want it...in spite of how despicable
// a full spectrum scale might be.
// roll around when 0.9 to 0.1
// more than 0.5 away means that it should roll in the other direction
/*
float h1 = lerpColorHSB1[0];
float h2 = lerpColorHSB2[0];
if (Math.abs(h1 - h2) > 0.5f) {
if (h1 > h2) {
// i.e. h1 is 0.7, h2 is 0.1
h2 += 1;
} else {
// i.e. h1 is 0.1, h2 is 0.7
h1 += 1;
}
}
float ho = (PApplet.lerp(lerpColorHSB1[0], lerpColorHSB2[0], amt)) % 1.0f;
*/
float ho = PApplet.lerp(lerpColorHSB1[0], lerpColorHSB2[0], amt);
float so = PApplet.lerp(lerpColorHSB1[1], lerpColorHSB2[1], amt);
float bo = PApplet.lerp(lerpColorHSB1[2], lerpColorHSB2[2], amt);
return alfa | (Color.HSBtoRGB(ho, so, bo) & 0xFFFFFF);
}
return 0;
}
//////////////////////////////////////////////////////////////
// BEGINRAW/ENDRAW
/**
* Record individual lines and triangles by echoing them to another renderer.
*/
public void beginRaw(PGraphics rawGraphics) { // ignore
this.raw = rawGraphics;
rawGraphics.beginDraw();
}
public void endRaw() { // ignore
if (raw != null) {
// for 3D, need to flush any geometry that's been stored for sorting
// (particularly if the ENABLE_DEPTH_SORT hint is set)
flush();
// just like beginDraw, this will have to be called because
// endDraw() will be happening outside of draw()
raw.endDraw();
raw.dispose();
raw = null;
}
}
public boolean haveRaw() { // ignore
return raw != null;
}
public PGraphics getRaw() { // ignore
return raw;
}
//////////////////////////////////////////////////////////////
// WARNINGS and EXCEPTIONS
static protected Map warnings;
/**
* Show a renderer error, and keep track of it so that it's only shown once.
* @param msg the error message (which will be stored for later comparison)
*/
static public void showWarning(String msg) { // ignore
if (warnings == null) {
warnings = new HashMap();
}
if (!warnings.containsKey(msg)) {
System.err.println(msg);
warnings.put(msg, new Object());
}
}
/**
* Version of showWarning() that takes a parsed String.
*/
static public void showWarning(String msg, Object... args) { // ignore
showWarning(String.format(msg, args));
}
/**
* Display a warning that the specified method is only available with 3D.
* @param method The method name (no parentheses)
*/
static public void showDepthWarning(String method) {
showWarning(method + "() can only be used with a renderer that " +
"supports 3D, such as P3D.");
}
/**
* Display a warning that the specified method that takes x, y, z parameters
* can only be used with x and y parameters in this renderer.
* @param method The method name (no parentheses)
*/
static public void showDepthWarningXYZ(String method) {
showWarning(method + "() with x, y, and z coordinates " +
"can only be used with a renderer that " +
"supports 3D, such as P3D. " +
"Use a version without a z-coordinate instead.");
}
/**
* Display a warning that the specified method is simply unavailable.
*/
static public void showMethodWarning(String method) {
showWarning(method + "() is not available with this renderer.");
}
/**
* Error that a particular variation of a method is unavailable (even though
* other variations are). For instance, if vertex(x, y, u, v) is not
* available, but vertex(x, y) is just fine.
*/
static public void showVariationWarning(String str) {
showWarning(str + " is not available with this renderer.");
}
/**
* Display a warning that the specified method is not implemented, meaning
* that it could be either a completely missing function, although other
* variations of it may still work properly.
*/
static public void showMissingWarning(String method) {
showWarning(method + "(), or this particular variation of it, " +
"is not available with this renderer.");
}
/**
* Show an renderer-related exception that halts the program. Currently just
* wraps the message as a RuntimeException and throws it, but might do
* something more specific might be used in the future.
*/
static public void showException(String msg) { // ignore
throw new RuntimeException(msg);
}
/**
* Same as below, but defaults to a 12 point font, just as MacWrite intended.
*/
protected void defaultFontOrDeath(String method) {
defaultFontOrDeath(method, 12);
}
/**
* First try to create a default font, but if that's not possible, throw
* an exception that halts the program because textFont() has not been used
* prior to the specified method.
*/
protected void defaultFontOrDeath(String method, float size) {
if (parent != null) {
textFont = parent.createDefaultFont(size);
} else {
throw new RuntimeException("Use textFont() before " + method + "()");
}
}
//////////////////////////////////////////////////////////////
// RENDERER SUPPORT QUERIES
/**
* Return true if this renderer should be drawn to the screen. Defaults to
* returning true, since nearly all renderers are on-screen beasts. But can
* be overridden for subclasses like PDF so that a window doesn't open up.
*
* A better name? showFrame, displayable, isVisible, visible, shouldDisplay,
* what to call this?
*/
public boolean displayable() { // ignore
return true;
}
/**
* Return true if this renderer supports 2D drawing. Defaults to true.
*/
public boolean is2D() { // ignore
return true;
}
/**
* Return true if this renderer supports 3D drawing. Defaults to false.
*/
public boolean is3D() { // ignore
return false;
}
/**
* Return true if this renderer does rendering through OpenGL. Defaults to false.
*/
public boolean isGL() { // ignore
return false;
}
public boolean is2X() {
return pixelDensity == 2;
}
//////////////////////////////////////////////////////////////
// ASYNC IMAGE SAVING
@Override
public boolean save(String filename) { // ignore
if (hints[DISABLE_ASYNC_SAVEFRAME]) {
return super.save(filename);
}
if (asyncImageSaver == null) {
asyncImageSaver = new AsyncImageSaver();
}
if (!loaded) loadPixels();
PImage target = asyncImageSaver.getAvailableTarget(pixelWidth, pixelHeight,
format);
if (target == null) return false;
int count = PApplet.min(pixels.length, target.pixels.length);
System.arraycopy(pixels, 0, target.pixels, 0, count);
asyncImageSaver.saveTargetAsync(this, target, parent.sketchFile(filename));
return true;
}
protected void processImageBeforeAsyncSave(PImage image) { }
/**
* If there is running async save task for this file, blocks until it completes.
* Has to be called on main thread because OpenGL overrides this and calls GL.
* @param filename
*/
protected void awaitAsyncSaveCompletion(String filename) {
if (asyncImageSaver != null) {
asyncImageSaver.awaitAsyncSaveCompletion(parent.sketchFile(filename));
}
}
protected static AsyncImageSaver asyncImageSaver;
protected static class AsyncImageSaver {
static final int TARGET_COUNT =
Math.max(1, Runtime.getRuntime().availableProcessors() - 1);
BlockingQueue targetPool = new ArrayBlockingQueue(TARGET_COUNT);
ExecutorService saveExecutor = Executors.newFixedThreadPool(TARGET_COUNT);
int targetsCreated = 0;
Map | Back | FazBrowse Home | New Git URL |