### Basic Video Capture and Display Setup Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/video/index.html This is a complete example demonstrating the basic setup for capturing video from a device and displaying it in the Processing window. It includes importing the library, initializing the Capture object, starting the capture, and displaying the video feed in draw(). ```Java // Step 1. Import the video library. import processing.video.* //Step 2. Declare a capture object. Capture video; // Step 5. Read from the camera when a new image is available! void captureEvent(Capture video) { video.read(); } void setup() { size(320, 240); // Step 3. Initialize Capture object. video = new Capture(this, 320, 240); // Step 4. Start the capturing process. video.start(); } // Step 6. Display the image. void draw() { image(video, 0, 0); } ``` -------------------------------- ### Complete Processing Sketch Example Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/eclipse/index.html A complete example demonstrating how to set screen size in settings(), fill color in setup(), and draw an ellipse in draw(). ```Java import processing.core.PApplet; public class UsingProcessing extends PApplet{ public static void main(String[] args) { PApplet.main("UsingProcessing"); } public void settings(){ size(300,300); } public void setup(){ fill(120,50,240); } public void draw(){ ellipse(width/2,height/2,second(),second()); } } ``` -------------------------------- ### Start Video Capture Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/video/index.html Start the video capture process after initializing the Capture object in setup(). ```Java void setup() { video = new Capture(this, 320, 240); video.start(); } ``` -------------------------------- ### Web Client Example Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/network/index.html Demonstrates how to create a simple web client to fetch content from a URL using HTTP GET requests. Ensure the Processing Net library is imported. ```processing import processing.net.* Client c; String data; void setup() { size(200, 200); background(50); fill(200); c = new Client(this, "www.ucla.edu", 80); // Connect to server on port 80 c.write("GET / HTTP/1.0\n"); // Use the HTTP "GET" command to ask for a webpage c.write("Host: www.ucla.edu\n\n"); // Tell the server for which domain you are making the request } void draw() { if (c.available() > 0) { // If there's incoming data from the client... data += c.readString(); // ...then grab it and print it println(data); } } ``` -------------------------------- ### Setup Function in Processing Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/anatomy/index.html The setup() function is called once when the sketch starts. It's used for initializations like setting the sketch size and background color. ```processing void setup() { size(300, 300); background(255); noFill(); polygon(3, 2 50, 2 75, 2 100, 2 100, 2 -PI / 2.0); // -90 degrees polygon(4, 2 170, 2 75, 2 50, 2 125, 2 -PI / 4.0); // -45 degrees fill(255, 204, 255); stroke(128, 0, 128); polygon(5, 2 50, 2 200, 2 75, 2 50, 2 -PI / 2.0); // -90 degrees noFill(); stroke(0); polygon(6, 2 170, 2 200, 2 50, 2 100, 2 0); stroke(128); // Draw enclosing ellipses to make sure we did it right ellipse(50, 75, 100, 100); ellipse(170, 75, 50, 125); ellipse(50, 200, 75, 50); ellipse(170, 200, 50, 100); } ``` -------------------------------- ### Using a Processing Library for Data Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/data/index.html This example demonstrates how to use a hypothetical Processing library to access and process data. Ensure the library is installed and imported correctly. ```Java import flowers.* void setup() { FlowerDatabase fdb = new FlowerDatabase(); Flower sunflower = fdb.findFlower("sunflower"); float h = sunflower.getAverageHeight(); } ``` -------------------------------- ### Setup Function in Processing Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/anatomy/index.html The setup() function is called once when the sketch starts. It's used for initial configuration like setting the sketch size and background color. ```processing void **setup**() {   size(300, 300);   background(255);   noFill();   polygon(3, 50, 75, 50);   polygon(4, 170, 75, 50);   fill(255, 204, 255);   stroke(128, 0, 128);   polygon(5, 50, 180, 50);   noFill();   stroke(0);   polygon(6, 170, 180, 50); } ``` -------------------------------- ### Launch a Function as a Thread Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/data/index-old.html Use the `thread()` function in `setup()` to launch a specified function to run as a separate thread. This is useful for starting background tasks when the sketch begins. ```processing void setup() { size(200,200); thread("someFunction"); } void draw() { } void someFunction() { // This function will run as a thread when called via // thread("someFunction") as it was in setup! } ``` -------------------------------- ### Basic Interactive Sketch with setup() and draw() Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/overview/index.html An interactive sketch using setup() for initialization and draw() for continuous rendering. The line follows the mouse cursor. ```processing void setup() { size(400, 400); stroke(255); background(192, 64, 0); } void draw() { line(150, 25, mouseX, mouseY); } ``` -------------------------------- ### Declare and Create an Array, then Assign (with setup()) Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/arrays/index.html This approach declares and creates an integer array in one step, then assigns values to its elements within the setup() function. It's useful when the array size is known upfront and values are populated later. ```processing int[] data = new int[5]; // Declare, create void setup() { size(100, 100); data[0] = 19; // Assign data[1] = 40; data[2] = 75; data[3] = 76; data[4] = 90; } ``` -------------------------------- ### Setup and Draw Functions in Processing Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/anatomy/index.html The `setup()` function runs once at the beginning of the sketch to initialize settings. The `draw()` function runs repeatedly, handling the animation and drawing logic. ```processing void **setup**() {   size(300, 300);   background(255);   frameRate(6);   rectMode(CENTER); } void **draw**() {   // Choose a random stroke color   int r = int(random(0, 255));   int g = int(random(0, 255));   int b = int(random(0, 255));   // Fill opacity   int opacity = int(random(100, 255));   int nSides = int(random(3, 9));   // Determine the center x and y coordinates   int cx = 25 + 50 * int(random(0, 6));   int cy = 25 + 50 * int(random(0, 6));   // If a random number (0 or 1) is 0, draw a polygon;   // otherwise, draw a star   boolean isPolygon = int(random(2)) == 0;   // For stars, you need the proportion of short to long radius   float proportion;   stroke(255); // erase any previous drawing in this area   fill(255);   rect(cx, cy, 50, 50);   stroke(r, g, b);   fill(r, g, b, opacity);   if (isPolygon) {     polygon(nSides, cx, cy, 24);   } else {     proportion = random(0.2, 0.8) * cos(PI / nSides);     star(nSides, cx, cy, 24, proportion);   } } ``` -------------------------------- ### Declare, Create, and Assign an Array (with setup()) Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/arrays/index.html This method declares an integer array, creates it with a specific size, and then assigns values to each element within the setup() function. Use this when the array size is known but values are assigned sequentially. ```processing int[] data; void setup() { size(100, 100); data = new int[5]; // Create data[0] = 19; // Assign data[1] = 40; data[2] = 75; data[3] = 76; data[4] = 90; } ``` -------------------------------- ### Declare, Create, and Assign Array Elements (without setup()) Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/arrays/index.html This demonstrates how to declare, create, and assign values to an array when not using setup() or draw(). It requires explicit steps for each operation. ```processing int[] data; // Declare data = new int[5]; // Create data[0] = 19; // Assign data[1] = 40; data[2] = 75; data[3] = 76; data[4] = 90; ``` -------------------------------- ### Declare, Create, and Assign Array (Literal, without setup()) Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/arrays/index.html This is the most concise method for initializing an array with known values when not using setup() or draw(). ```processing int[] data = { 19, 40, 75, 76, 90 }; // Declare, create, assign ``` -------------------------------- ### Basic DXF Export Example Source: https://github.com/processing/processing-docs/blob/master/content/api_en/LIB_dxf/index.html This example demonstrates how to use the DXF library to export a drawing to a DXF file. The export is triggered by pressing the 'r' key. Ensure the library is imported before use. ```processing import processing.dxf.*; boolean record; void setup() { size(500, 500, P3D); } void draw() { if (record) { beginRaw(DXF, "output.dxf"); } // Do all your drawing here if (record) { endRaw(); record = false; } } void keyPressed() { // Use a key press so that it doesn't make a million files if (key == 'r') { record = true; } } ``` -------------------------------- ### Declare and Create Array, then Assign (without setup()) Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/arrays/index.html This shows declaring and creating an array in one statement, followed by individual element assignments, outside of setup() or draw(). ```processing int[] data = new int[5]; // Declare, create data[0] = 19; // Assign data[1] = 40; data[2] = 75; data[3] = 76; data[4] = 90; ``` -------------------------------- ### Setup Function Source: https://github.com/processing/processing-docs/blob/master/exhibition/works/chronodraw/chronodraw.txt Initializes the sketch window size and prepares a blank image buffer for drawing. ```processing void setup(){ size(quadwidth * hquads, quadheight * vquads); blank.width = quadwidth; blank.height = quadheight; blank.pixels = new color[quadwidth*quadheight]; for (int j=0; jgetVersion(); ``` -------------------------------- ### Getting a Character at a Specific Index Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/text/index.html Uses the charAt() method to retrieve a single character from a String at a specified index. Remember that String indices start at 0. ```Java String message = "some text here."; char c = message.charAt(3); println(c); // Results in 'e' ``` -------------------------------- ### Displaying and Manipulating Video Feed with Tint and Transformations Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/video/index.html This example shows how to display a live video feed and apply transformations like tinting, translation, rotation, and resizing, similar to how you would manipulate a PImage. The video feed updates dynamically with these manipulations. ```Java import processing.video.* Capture video; void setup() { size(320, 240); video = new Capture(this, 320, 240); video.start(); } void captureEvent(Capture video) { video.read(); } void draw() { background(255); tint(mouseX, mouseY, 255); translate(width/2, height/2); imageMode(CENTER); rotate(PI/4); image(video, 0, 0, mouseX, mouseY); } ``` -------------------------------- ### Get Nodes by Node Value Source: https://github.com/processing/processing-docs/blob/master/generate/domit/docs/xml_domit_parser_docs.html Searches the document tree for nodes with a specific node value, starting from a given context node. This is useful for finding text or CDATA nodes. ```php //find all text nodes with a value of "Robbie Fulks" in cdlibrary $myTextNodeList = $cdCollection->getNodesByNodeValue("Robbie Fulks", $cdCollection); //get first match $firstItem = $myTextNodeList->item(0); //echo parent node to browser echo $firstItem->parentNode->toNormalizedString(true); ``` -------------------------------- ### Get Nodes by Node Type Source: https://github.com/processing/processing-docs/blob/master/generate/domit/docs/xml_domit_parser_docs.html Searches the document tree for nodes of a specific type, starting from a given context node. DOMIT! provides constants for various node types. ```php //find all text nodes in cdlibrary $myTextNodeList = $cdCollection->getNodesByNodeType(DOMIT_TEXT_NODE, $cdCollection); //echo to browser echo $myTextNodeList->toNormalizedString(true); ``` -------------------------------- ### Setup for Line Shader Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/pshader/index.html Initializes the Processing sketch, loads the line shader, and creates a cube shape. ```processing void **setup**() { size(640, 360, P3D); lineShader = loadShader("linefrag.glsl", "linevert.glsl"); cube = createShape(BOX, 150); cube.setFill(false); cube.setStroke(color(255)); cube.setStrokeWeight(weight); } ``` -------------------------------- ### Setup for Line Shader with Transparency Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/pshader/index.html Initializes the sketch, loads the line shader, sets its weight uniform, and creates a cube shape. Includes a hint to disable depth mask for transparency. ```processing PShape cube; PShader lineShader; float angle; float weight = 20; void **setup**() { size(640, 360, P3D); lineShader = loadShader("linefrag.glsl", "linevert.glsl"); lineShader.set("weight", weight); cube = createShape(BOX, 150); cube.setFill(false); cube.setStroke(color(255)); cube.setStrokeWeight(weight); hint(DISABLE_DEPTH_MASK); } ``` -------------------------------- ### Accessing the Next Sibling Node in DOMIT! Source: https://github.com/processing/processing-docs/blob/master/generate/domit/docs/xml_domit_parser_docs.html Retrieves a reference to the next sibling node in the DOM tree. Returns null if no next sibling exists. This example shows how to get the next sibling of the first child node. ```php /* @var $cdCollection DOMIT_Document */ if ($cdCollection->documentElement->hasChildNodes()) { //get reference to first cd node (the Robbie Fulks cd) $firstChildNode = &$cdCollection->documentElement->firstChild; //get a reference to the next sibling (the Richard Thompson cd) $nextSiblingNode = &$firstChildNode->nextSibling; //echo out the node to browser echo ("The contents of the next sibling are: \n
" . $nextSiblingNode->toNormalizedString(true)); } ``` -------------------------------- ### Accumulate Multiple Frames into One PDF Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/print/index.html This example saves multiple frames into a single PDF file. Press 'B' to start recording and 'E' to stop and exit. The background is cleared within the PDF for each new recording session. ```processing import processing.pdf.*; // Import PDF code void setup() { size(600, 600); background(255); } void draw() { stroke(0, 20); strokeWeight(20); line(mouseX, 0, width-mouseY, height); } void keyPressed() { if (key == 'B' || key == 'b') { // When 'B' or 'b' is pressed, beginRecord(PDF, "lines.pdf"); // start recording to the PDF background(255); // Set a white background } else if (key == 'E' || key == 'e') { // When 'E' or 'e' is pressed, endRecord(); // stop recording the PDF and exit(); // quit the program } } ``` -------------------------------- ### Processing Setup Function Source: https://github.com/processing/processing-docs/blob/master/exhibition/works/004/code.html Initializes the Processing sketch window, sets the background color, initializes rotation variables, enables lighting, and copies the first preset ('preset_a') to the current position array. ```processing void setup() { size(400, 400); background(255); rotX = 0; rotY = 0; lights(); //noStroke(); pos_preset = new float[POS_NUM]; pos_current = new float[POS_NUM]; for(int i=0; i width) { xpos = 0; } } } ``` -------------------------------- ### Advanced Java Mode Sketch Example Source: https://github.com/processing/processing-docs/blob/master/content/api_en/environment/index.html This is for advanced developers only and is not really recommended. Using this technique means that any additional tabs will no longer be inner classes, meaning you'll have to do extra work to make them communicate properly with the host PApplet. It is not necessary to use this technique just to get features of the Java language. ```Java public class MyDemo extends PApplet { ``` -------------------------------- ### Get Attribute Node Reference and Value Source: https://github.com/processing/processing-docs/blob/master/generate/domit/docs/xml_domit_parser_docs.html Use getAttributeNode() to get a reference to an attribute node itself, rather than just its value. The getValue() method can then be used on the returned node reference to get the attribute's value. This provides more control over attribute manipulation. ```PHP if ($cdCollection->documentElement->hasChildNodes()) { //get reference to first cd node (the Robbie Fulks cd) $firstChildNode =& $cdCollection->documentElement->firstChild; //determine whether it has an attribute named "discid" if ($firstChildNode->hasAttribute("discid")) { //obtain a reference to the discid attribute node (don't forget the ampersand!) $attrNode =& $firstChildNode->getAttributeNode("discid); //echo the value out to the browser echo ("The value of the discid attribute is: \n
" . $attrNode->getValue()); } else { echo ("I DO NOT have a discid attribute"); } } ``` -------------------------------- ### Comment Node Example Source: https://github.com/processing/processing-docs/blob/master/generate/domit/docs/xml_domit_parser_docs.html A Comment Node represents an XML comment. This example shows a comment and its corresponding node properties. ```xml ``` -------------------------------- ### Per-Vertex Lighting Shader Setup Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/pshader/index.html Sets up the Processing sketch to use a custom per-vertex lighting shader. Loads the vertex and fragment shader files. ```Java PShape can; float angle; PShader lightShader; void setup() { size(640, 360, P3D); can = createCan(100, 200, 32); lightShader = loadShader("lightfrag.glsl", "lightvert.glsl"); } void draw() { background(0); shader(lightShader); pointLight(255, 255, 255, width/2, height, 200); translate(width/2, height/2); rotateY(angle); shape(can); angle += 0.01; } ``` -------------------------------- ### Car Class Example Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/pvector/index.html A basic example illustrating the concept of object-oriented programming by defining a 'Car' class with data and functionality. ```processing Car c = new Car(red,big,fast); c.drive(); c.turn(); c.stop(); ``` -------------------------------- ### Declare and Initialize Array of Spot Objects with Constructor Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/arrays/index.html Declare a Spot array and initialize it within setup(). Each Spot object is created using a constructor that passes initial values for position, size, and speed. ```processing Spot[] spots; // Declare array void setup() { size(700, 100); int numSpots = 70; // Number of objects int dia = width/numSpots; // Calculate diameter spots = new Spot[numSpots]; // Create array for (int i = 0; i < spots.length; i++) { float x = dia/2 + i*dia; float rate = random(0.1, 2.0); // Create each object spots[i] = new Spot(x, 50, dia, rate); } noStroke(); } ``` -------------------------------- ### XML Data Structure Example Source: https://github.com/processing/processing-docs/blob/master/content/static/tutorials/data/index-old.html An example of an XML structure representing a list of students, demonstrating nested elements for addresses. ```xml 001 Daniel Shiffman 555-555-5555 daniel@shiffman.net
123 Processing Way Loops New York 01234
002 Zoog 555-555-5555 zoog@planetzoron.uni
45.3 Nebula 5 Boolean City 12358
``` -------------------------------- ### Element Node Example Source: https://github.com/processing/processing-docs/blob/master/generate/domit/docs/xml_domit_parser_docs.html An Element Node represents an XML Element. This example shows a element and its corresponding node properties. ```xml John Heinstein ``` -------------------------------- ### Processing Setup Function Source: https://github.com/processing/processing-docs/blob/master/exhibition/works/002/code.html Initializes the Processing sketch, setting the window size, background color, and stroke properties. Also initializes particle system. ```Java void setup() { size(300, 300); background(49, 81, 74); noStroke(); colorMode(RGB, 100); for (int i=0; i ```