|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
processing.core.PApplet
Base class for all sketches that use processing.core.
Note that you should not use AWT or Swing components inside a Processing applet. The surface is made to automatically update itself, and will cause problems with redraw of components drawn above it. If you'd like to integrate other Java components, see below. This class extends Applet instead of JApplet because 1) we will eventually be returning Java 1.1 support, which does not include Swing (without an additional, sizable, download), and 2) Swing is a bloated piece of crap. A Processing applet is a heavyweight AWT component, and can be used the same as any other AWT component, with or without Swing. Similarly, Processing runs in a Frame and not a JFrame. However, there's nothing to prevent you from embedding a PApplet into a JFrame, it's just that the base version uses a regular AWT frame because there's simply no need for swing in that context. If people want to use Swing, they can embed themselves as they wish. It is possible to use PApplet, along with core.jar in other projects. In addition to enabling you to use Java 1.5+ features with your sketch, this also allows you to embed a Processing drawing area into another Java application. This means you can use standard GUI controls with a Processing sketch. Because AWT and Swing GUI components cannot be used on top of a PApplet, you can instead embed the PApplet inside another GUI the wayyou would any other Component. Because the default animation thread will run at 60 frames per second, an embedded PApplet can make the parent sluggish. You can use frameRate() to make it update less often, or you can use noLoop() and loop() to disable and then re-enable looping. If you want to only update the sketch intermittently, use noLoop() inside setup(), and redraw() whenever the screen needs to be updated once (or loop() to re-enable the animation thread). The following example embeds a sketch and also uses the noLoop() and redraw() methods. You need not use noLoop() and redraw() when embedding if you want your application to animate continuously.
public class ExampleFrame extends Frame {
public ExampleFrame() {
super("Embedded PApplet");
setLayout(new BorderLayout());
PApplet embed = new Embedded();
add(embed, BorderLayout.CENTER);
// important to call this whenever embedding a PApplet.
// It ensures that the animation thread is started and
// that other internal variables are properly set.
embed.init();
}
}
public class Embedded extends PApplet {
public void setup() {
// original setup code here ...
size(400, 400);
// prevent thread from starving everything else
noLoop();
}
public void draw() {
// drawing code goes here
}
public void mousePressed() {
// do something based on mouse movement
// update the screen (run draw once)
redraw();
}
}
I was asked about Processing with multiple displays, and for lack of a better place to document it, things will go here.
You can address both screens by making a window the width of both, and the height of the maximum of both screens. In this case, do not use present mode, because that's exclusive to one screen. Basically it'll give you a PApplet that spans both screens. If using one half to control and the other half for graphics, you'd just have to put the 'live' stuff on one half of the canvas, the control stuff on the other. This works better in windows because on the mac we can't get rid of the menu bar unless it's running in present mode.
For more control, you need to write straight java code that uses p5. You can create two windows, that are shown on two separate screens, that have their own PApplet. this is just one of the tradeoffs of one of the things that we don't support in p5 from within the environment itself (we must draw the line somewhere), because of how messy it would get to start talking about multiple screens. It's also not that tough to do by hand w/ some Java code.
| Nested Class Summary | |
class |
PApplet.RegisteredMethods
|
| Field Summary | |
java.lang.String[] |
args
Command line options passed in from main(). |
static java.lang.String |
ARGS_BGCOLOR
|
static java.lang.String |
ARGS_DISPLAY
|
static java.lang.String |
ARGS_EDITOR_LOCATION
Position of the upper-lefthand corner of the editor window that launched this applet. |
static java.lang.String |
ARGS_EXTERNAL
Location for where to position the applet window on screen. |
static java.lang.String |
ARGS_HIDE_STOP
|
static java.lang.String |
ARGS_LOCATION
|
static java.lang.String |
ARGS_PRESENT
|
static java.lang.String |
ARGS_SKETCH_FOLDER
Allows the user or PdeEditor to set a specific sketch folder path. |
static java.lang.String |
ARGS_STOP_COLOR
|
static int |
DEFAULT_HEIGHT
|
static int |
DEFAULT_WIDTH
Default width and height for applet when not specified |
boolean |
defaultSize
true if no size() command has been executed. |
java.lang.Exception |
exception
Set to the an exception that occurs inside run() and is not caught. |
static java.lang.String |
EXTERNAL_MOVE
When run externally to a PdeEditor, this is sent by the applet whenever the window is moved. |
static java.lang.String |
EXTERNAL_QUIT
When run externally to a PdeEditor, this is sent by the applet when it quits. |
static char |
EXTERNAL_STOP
Message from parent editor (when run as external) to quit. |
boolean |
finished
true if this applet has had it. |
boolean |
firstMouse
Used to set pmouseX/Y to mouseX/Y the first time mouseX/Y are used, otherwise pmouseX/Y are always zero, causing a nasty jump. |
boolean |
focused
Gets set to true/false as the applet gains/loses focus. |
java.awt.Frame |
frame
The frame containing this applet (if any) |
int |
frameCount
How many frames have been displayed since the applet started. |
float |
frameRate
The current value of frames per second. |
PGraphics |
g
The PGraphics renderer associated with this PApplet |
int |
height
height of this applet's associated PGraphics |
static float |
javaVersion
Version of Java that's in use, whether 1.1 or 1.3 or whatever, stored as a float. |
static java.lang.String |
javaVersionName
Full name of the Java version (i.e. |
char |
key
Last key pressed. |
int |
keyCode
When "key" is set to CODED, this will contain a Java key code. |
java.awt.event.KeyEvent |
keyEvent
the last KeyEvent object passed into a mouse function. |
boolean |
keyPressed
true if the mouse is currently pressed. |
static java.lang.String |
LEECH_WAKEUP
|
java.io.PrintStream |
leechErr
|
static int |
MIN_WINDOW_HEIGHT
|
static int |
MIN_WINDOW_WIDTH
Minimum dimensions for the window holding an applet. |
int |
mouseButton
Last mouse button pressed, one of LEFT, CENTER, or RIGHT. |
java.awt.event.MouseEvent |
mouseEvent
|
boolean |
mousePressed
|
int |
mouseX
current x position of the mouse |
int |
mouseY
current y position of the mouse |
boolean |
online
true if the applet is online. |
int[] |
pixels
Pixel buffer from this applet's PGraphics. |
static int |
platform
Current platform in use, one of the PConstants WINDOWS, MACOSX, MACOS9, LINUX or OTHER. |
static java.lang.String |
platformName
Current platform in use. |
int |
pmouseX
Previous x/y position of the mouse. |
int |
pmouseY
Previous x/y position of the mouse. |
PGraphics |
recorder
A leech graphics object that is echoing all events. |
java.awt.Dimension |
screen
The screen size when the applet was started. |
java.lang.String |
sketchPath
Path to sketch folder |
int |
width
width of this applet's associated PGraphics |
| Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
PApplet()
|
|
| Method Summary | |
static float |
abs(float n)
|
static int |
abs(int n)
|
static float |
acos(float value)
|
void |
addListeners()
|
float |
alpha(int what)
|
void |
ambient(float gray)
|
void |
ambient(float x,
float y,
float z)
|
void |
ambient(int rgb)
|
void |
ambientLight(float red,
float green,
float blue)
|
void |
ambientLight(float red,
float green,
float blue,
float x,
float y,
float z)
|
static byte[] |
append(byte[] b,
byte value)
|
static char[] |
append(char[] b,
char value)
|
static float[] |
append(float[] b,
float value)
|
static int[] |
append(int[] b,
int value)
|
static java.lang.Object |
append(java.lang.Object b,
java.lang.Object value)
|
static java.lang.String[] |
append(java.lang.String[] b,
java.lang.String value)
|
void |
applyMatrix(float n00,
float n01,
float n02,
float n10,
float n11,
float n12)
|
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)
|
void |
arc(float a,
float b,
float c,
float d,
float start,
float stop)
|
static void |
arraycopy(java.lang.Object src,
int srcPosition,
java.lang.Object dst,
int dstPosition,
int length)
Calls System.arraycopy(), included here so that we can avoid people needing to learn about the System object before they can just copy an array. |
static void |
arraycopy(java.lang.Object src,
java.lang.Object dst)
Shortcut to copy the entire contents of the source into the destination array. |
static void |
arraycopy(java.lang.Object src,
java.lang.Object dst,
int length)
Convenience method for arraycopy(). |
static float |
asin(float value)
|
static float |
atan(float value)
|
static float |
atan2(float a,
float b)
|
void |
background(float gray)
|
void |
background(float gray,
float alpha)
|
void |
background(float x,
float y,
float z)
|
void |
background(float x,
float y,
float z,
float a)
|
void |
background(int rgb)
|
void |
background(int rgb,
float alpha)
|
void |
background(PImage image)
|
void |
beginCamera()
|
void |
beginRaw(PGraphics rawGraphics)
|
PGraphics |
beginRaw(java.lang.String renderer,
java.lang.String filename)
|
void |
beginRecord(PGraphics recorder)
|
PGraphics |
beginRecord(java.lang.String renderer,
java.lang.String filename)
|
void |
beginShape()
|
void |
beginShape(int kind)
|
void |
bezier(float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
float x4,
float y4)
|
void |
bezier(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float x3,
float y3,
float z3,
float x4,
float y4,
float z4)
|
void |
bezierDetail(int detail)
|
float |
bezierPoint(float a,
float b,
float c,
float d,
float t)
|
float |
bezierTangent(float a,
float b,
float c,
float d,
float t)
|
void |
bezierVertex(float x2,
float y2,
float x3,
float y3,
float x4,
float y4)
|
void |
bezierVertex(float x2,
float y2,
float z2,
float x3,
float y3,
float z3,
float x4,
float y4,
float z4)
|
static java.lang.String |
binary(byte what)
Returns a String that contains the binary value of a byte. |
static java.lang.String |
binary(char what)
Returns a String that contains the binary value of a char. |
static java.lang.String |
binary(int what)
Returns a String that contains the binary value of an int. |
static java.lang.String |
binary(int what,
int digits)
Returns a String that contains the binary value of an int. |
void |
blend(int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
|
void |
blend(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
|
static int |
blendColor(int c1,
int c2,
int mode)
|
float |
blue(int what)
|
void |
box(float size)
|
void |
box(float w,
float h,
float d)
|
void |
breakShape()
|
float |
brightness(int what)
|
void |
camera()
|
void |
camera(float eyeX,
float eyeY,
float eyeZ,
float centerX,
float centerY,
float centerZ,
float upX,
float upY,
float upZ)
|
static int |
ceil(float what)
|
int |
color(float fgray)
|
int |
color(float fgray,
float falpha)
|
int |
color(float x,
float y,
float z)
|
int |
color(float x,
float y,
float z,
float a)
|
int |
color(int gray)
|
int |
color(int gray,
int alpha)
As of 0116 this also takes color(#FF8800, alpha) |
int |
color(int x,
int y,
int z)
|
int |
color(int x,
int y,
int z,
int a)
|
void |
colorMode(int mode)
|
void |
colorMode(int mode,
float max)
|
void |
colorMode(int mode,
float maxX,
float maxY,
float maxZ)
|
void |
colorMode(int mode,
float maxX,
float maxY,
float maxZ,
float maxA)
|
static boolean[] |
concat(boolean[] a,
boolean[] b)
|
static byte[] |
concat(byte[] a,
byte[] b)
|
static char[] |
concat(char[] a,
char[] b)
|
static float[] |
concat(float[] a,
float[] b)
|
static int[] |
concat(int[] a,
int[] b)
|
static java.lang.Object |
concat(java.lang.Object a,
java.lang.Object b)
|
static java.lang.String[] |
concat(java.lang.String[] a,
java.lang.String[] b)
|
static float |
constrain(float amt,
float low,
float high)
|
static int |
constrain(int amt,
int low,
int high)
|
void |
copy(int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2)
|
void |
copy(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2)
|
static float |
cos(float angle)
|
PFont |
createFont(java.lang.String name,
float size)
|
PFont |
createFont(java.lang.String name,
float size,
boolean smooth)
|
PFont |
createFont(java.lang.String name,
float size,
boolean smooth,
char[] charset)
Create a .vlw font on the fly from either a font name that's installed on the system, or from a .ttf or .otf that's inside the data folder of this sketch. |
PGraphics |
createGraphics(int iwidth,
int iheight,
java.lang.String irenderer)
Create an offscreen PGraphics object for drawing. |
PGraphics |
createGraphics(int iwidth,
int iheight,
java.lang.String irenderer,
java.lang.String ipath)
Create an offscreen graphics surface for drawing, in this case for a renderer that writes to a file (such as PDF or DXF). |
PImage |
createImage(int wide,
int high,
int format)
Preferred method of creating new PImage objects, ensures that a reference to the parent PApplet is included, which makes save() work without needing an absolute path. |
static void |
createPath(java.lang.String filename)
Takes a path and creates any in-between folders if they don't already exist. |
static java.io.BufferedReader |
createReader(java.io.File file)
I want to read lines from a file. |
static java.io.BufferedReader |
createReader(java.io.InputStream input)
I want to read lines from a stream. |
java.io.BufferedReader |
createReader(java.lang.String filename)
I want to read lines from a file. |
static java.io.PrintWriter |
createWriter(java.io.File file)
I want to print lines to a file. |
static java.io.PrintWriter |
createWriter(java.io.OutputStream output)
I want to print lines to a file. |
java.io.PrintWriter |
createWriter(java.lang.String filename)
I want to print lines to a file. |
void |
cursor()
Show the cursor after noCursor() was called. |
void |
cursor(int _cursor_type)
Set the cursor type |
void |
cursor(PImage image)
Replace the cursor with the specified PImage. |
void |
cursor(PImage image,
int hotspotX,
int hotspotY)
Set a custom cursor to an image with a specific hotspot. |
void |
curve(float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
float x4,
float y4)
|
void |
curve(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float x3,
float y3,
float z3,
float x4,
float y4,
float z4)
|
void |
curveDetail(int detail)
|
float |
curvePoint(float a,
float b,
float c,
float d,
float t)
|
float |
curveTangent(float a,
float b,
float c,
float d,
float t)
|
void |
curveTightness(float tightness)
|
void |
curveVertex(float x,
float y)
|
void |
curveVertex(float x,
float y,
float z)
|
java.io.File |
dataFile(java.lang.String where)
Return a full path to an item in the data folder as a File object. |
java.lang.String |
dataPath(java.lang.String where)
Return a full path to an item in the data folder. |
static int |
day()
Get the current day of the month (1 through 31). |
static float |
degrees(float radians)
|
void |
delay(int napTime)
The delay() function causes the program to halt for a specified time. |
void |
destroy()
Called by the browser or applet viewer to inform this applet that it is being reclaimed and that it should destroy any resources that it has allocated. |
void |
die(java.lang.String what)
Function for an applet/application to kill itself and display an error. |
void |
die(java.lang.String what,
java.lang.Exception e)
Same as above but with an exception. |
void |
directionalLight(float red,
float green,
float blue,
float nx,
float ny,
float nz)
|
boolean |
displayable()
|
static float |
dist(float x1,
float y1,
float x2,
float y2)
|
static float |
dist(float x1,
float y1,
float z1,
float x2,
float y2,
float z2)
|
void |
draw()
|
void |
ellipse(float a,
float b,
float c,
float d)
|
void |
ellipseMode(int mode)
|
void |
emissive(float gray)
|
void |
emissive(float x,
float y,
float z)
|
void |
emissive(int rgb)
|
void |
endCamera()
|
void |
endRaw()
|
void |
endRecord()
|
void |
endShape()
|
void |
endShape(int mode)
|
static java.lang.Process |
exec(java.lang.String[] argv)
|
void |
exit()
Call to safely exit the sketch when finished. |
static float |
exp(float a)
|
static boolean[] |
expand(boolean[] list)
|
static boolean[] |
expand(boolean[] list,
int newSize)
|
static byte[] |
expand(byte[] list)
|
static byte[] |
expand(byte[] list,
int newSize)
|
static char[] |
expand(char[] list)
|
static char[] |
expand(char[] list,
int newSize)
|
static float[] |
expand(float[] list)
|
static float[] |
expand(float[] list,
int newSize)
|
static int[] |
expand(int[] list)
|
static int[] |
expand(int[] list,
int newSize)
|
static java.lang.Object |
expand(java.lang.Object array)
|
static java.lang.Object |
expand(java.lang.Object list,
int newSize)
|
static java.lang.String[] |
expand(java.lang.String[] list)
|
static java.lang.String[] |
expand(java.lang.String[] list,
int newSize)
|
void |
fill(float gray)
|
void |
fill(float gray,
float alpha)
|
void |
fill(float x,
float y,
float z)
|
void |
fill(float x,
float y,
float z,
float a)
|
void |
fill(int rgb)
|
void |
fill(int rgb,
float alpha)
|
void |
filter(int kind)
|
void |
filter(int kind,
float param)
|
static int |
floor(float what)
|
void |
focusGained()
|
void |
focusGained(java.awt.event.FocusEvent e)
|
void |
focusLost()
|
void |
focusLost(java.awt.event.FocusEvent e)
|
void |
frameRate(float newRateTarget)
Set a target frameRate. |
void |
frustum(float left,
float right,
float bottom,
float top,
float znear,
float zfar)
|
PImage |
get()
|
int |
get(int x,
int y)
|
PImage |
get(int x,
int y,
int w,
int h)
|
java.awt.Dimension |
getPreferredSize()
This returns the last width and height specified by the user via the size() command. |
float |
green(int what)
|
void |
handleDisplay()
|
static java.lang.String |
hex(byte what)
|
static java.lang.String |
hex(char what)
|
static java.lang.String |
hex(int what)
|
static java.lang.String |
hex(int what,
int digits)
|
void |
hint(int which)
|
static int |
hour()
Hour position of the current time in international format (0-23). |
float |
hue(int what)
|
void |
image(PImage image,
float x,
float y)
|
void |
image(PImage image,
float x,
float y,
float c,
float d)
|
void |
image(PImage image,
float a,
float b,
float c,
float d,
int u1,
int v1,
int u2,
int v2)
|
void |
imageMode(int mode)
|
void |
init()
|
java.io.File |
inputFile()
|
static java.io.File |
inputFile(java.awt.Frame parent)
|
java.io.File |
inputFile(java.lang.String prompt)
|
static java.io.File |
inputFile(java.lang.String prompt,
java.awt.Frame parentFrame)
static version of inputFile usable by external classes. |
java.lang.String |
insertFrame(java.lang.String what)
Check a string for #### signs to see if the frame number should be inserted. |
static java.lang.String |
join(java.lang.String[] str,
char separator)
Join an array of Strings together as a single String, separated by the whatever's passed in for the separator. |
static java.lang.String |
join(java.lang.String[] str,
java.lang.String separator)
Join an array of Strings together as a single String, separated by the whatever's passed in for the separator. |
void |
keyPressed()
Called each time a single key on the keyboard is pressed. |
void |
keyPressed(java.awt.event.KeyEvent e)
Overriding keyXxxxx(KeyEvent e) functions will cause the 'key', 'keyCode', and 'keyEvent' variables to no longer work; key events will no longer be queued until the end of draw(); and the keyPressed(), keyReleased() and keyTyped() methods will no longer be called. |
void |
keyReleased()
See keyPressed(). |
void |
keyReleased(java.awt.event.KeyEvent e)
|
void |
keyTyped()
Only called for "regular" keys like letters, see keyPressed() for full documentation. |
void |
keyTyped(java.awt.event.KeyEvent e)
|
static float |
lerp(float start,
float stop,
float amt)
|
int |
lerpColor(int c1,
int c2,
float amt)
|
static int |
lerpColor(int c1,
int c2,
float amt,
int mode)
|
void |
lightFalloff(float constant,
float linear,
float quadratic)
|
void |
lights()
|
void |
lightSpecular(float x,
float y,
float z)
|
void |
line(float x1,
float y1,
float x2,
float y2)
|
void |
line(float x1,
float y1,
float z1,
float x2,
float y2,
float z2)
|
void |
link(java.lang.String here)
|
void |
link(java.lang.String url,
java.lang.String frameTitle)
Link to an external page without all the muss. |
static byte[] |
loadBytes(java.io.InputStream input)
|
byte[] |
loadBytes(java.lang.String filename)
|
PFont |
loadFont(java.lang.String filename)
Set the font based on its filename. |
PImage |
loadImage(java.lang.String filename)
Load an image from the data folder or a local directory. |
PImage |
loadImage(java.lang.String filename,
java.lang.String extension)
Identical to loadImage, but allows you to specify the type of image by its extension. |
PImage |
loadImageSync(java.awt.Image awtImage)
Load an AWT image synchronously. |
void |
loadMatrix()
|
void |
loadPixels()
Override the g.pixels[] function to set the pixels[] array that's part of the PApplet object. |
static java.lang.String[] |
loadStrings(java.io.File file)
|
static java.lang.String[] |
loadStrings(java.io.InputStream input)
|
java.lang.String[] |
loadStrings(java.lang.String filename)
Load data from a file and shove it into a String array. |
static float |
log(float a)
|
void |
loop()
|
static float |
mag(float a,
float b)
|
static float |
mag(float a,
float b,
float c)
|
static void |
main(java.lang.String[] args)
main() method for running this class from the command line. |
static float |
map(float value,
float istart,
float istop,
float ostart,
float ostop)
Convenience function to map a variable from one coordinate space to another. |
void |
mask(int[] alpha)
|
void |
|