diff --git a/android/examples/Basics/Arrays/Array/Array.pde b/android/examples/Basics/Arrays/Array/Array.pde new file mode 100644 index 000000000..a981fa470 --- /dev/null +++ b/android/examples/Basics/Arrays/Array/Array.pde @@ -0,0 +1,35 @@ +/** + * Array. + * + * An array is a list of data. Each piece of data in an array + * is identified by an index number representing its position in + * the array. Arrays are zero based, which means that the first + * element in the array is [0], the second element is [1], and so on. + * In this example, an array named "coswav" is created and + * filled with the cosine values. This data is displayed three + * separate ways on the screen. + */ + +size(200, 200); + +float[] coswave = new float[width]; + +for (int i = 0; i < width; i++) { + float amount = map(i, 0, width, 0, PI); + coswave[i] = abs(cos(amount)); +} + +for (int i = 0; i < width; i++) { + stroke(coswave[i]*255); + line(i, 0, i, height/3); +} + +for (int i = 0; i < width; i++) { + stroke(coswave[i]*255 / 4); + line(i, height/3, i, height/3*2); +} + +for (int i = 0; i < width; i++) { + stroke(255 - coswave[i]*255); + line(i, height/3*2, i, height); +} diff --git a/android/examples/Basics/Arrays/Array/applet/Array.java b/android/examples/Basics/Arrays/Array/applet/Array.java new file mode 100644 index 000000000..3beda6698 --- /dev/null +++ b/android/examples/Basics/Arrays/Array/applet/Array.java @@ -0,0 +1,56 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Array extends PApplet { + public void setup() {/** + * Array. + * + * An array is a list of data. Each piece of data in an array + * is identified by an index number representing its position in + * the array. Arrays are zero based, which means that the first + * element in the array is [0], the second element is [1], and so on. + * In this example, an array named "coswav" is created and + * filled with the cosine values. This data is displayed three + * separate ways on the screen. + */ + +size(200, 200); + +float[] coswave = new float[width]; + +for (int i = 0; i < width; i++) { + float amount = map(i, 0, width, 0, PI); + coswave[i] = abs(cos(amount)); +} + +for (int i = 0; i < width; i++) { + stroke(coswave[i]*255); + line(i, 0, i, height/3); +} + +for (int i = 0; i < width; i++) { + stroke(coswave[i]*255 / 4); + line(i, height/3, i, height/3*2); +} + +for (int i = 0; i < width; i++) { + stroke(255 - coswave[i]*255); + line(i, height/3*2, i, height); +} + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "Array" }); + } +} diff --git a/android/examples/Basics/Arrays/Array/applet/Array.pde b/android/examples/Basics/Arrays/Array/applet/Array.pde new file mode 100644 index 000000000..a981fa470 --- /dev/null +++ b/android/examples/Basics/Arrays/Array/applet/Array.pde @@ -0,0 +1,35 @@ +/** + * Array. + * + * An array is a list of data. Each piece of data in an array + * is identified by an index number representing its position in + * the array. Arrays are zero based, which means that the first + * element in the array is [0], the second element is [1], and so on. + * In this example, an array named "coswav" is created and + * filled with the cosine values. This data is displayed three + * separate ways on the screen. + */ + +size(200, 200); + +float[] coswave = new float[width]; + +for (int i = 0; i < width; i++) { + float amount = map(i, 0, width, 0, PI); + coswave[i] = abs(cos(amount)); +} + +for (int i = 0; i < width; i++) { + stroke(coswave[i]*255); + line(i, 0, i, height/3); +} + +for (int i = 0; i < width; i++) { + stroke(coswave[i]*255 / 4); + line(i, height/3, i, height/3*2); +} + +for (int i = 0; i < width; i++) { + stroke(255 - coswave[i]*255); + line(i, height/3*2, i, height); +} diff --git a/android/examples/Basics/Arrays/Array/applet/loading.gif b/android/examples/Basics/Arrays/Array/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Arrays/Array/applet/loading.gif differ diff --git a/android/examples/Basics/Arrays/Array2D/Array2D.pde b/android/examples/Basics/Arrays/Array2D/Array2D.pde new file mode 100644 index 000000000..3a97587e7 --- /dev/null +++ b/android/examples/Basics/Arrays/Array2D/Array2D.pde @@ -0,0 +1,32 @@ +/** + * Array 2D. + * + * Demonstrates the syntax for creating a two-dimensional (2D) array. + * Values in a 2D array are accessed through two index values. + * 2D arrays are useful for storing images. In this example, each dot + * is colored in relation to its distance from the center of the image. + */ + +float[][] distances; +float maxDistance; + +size(200, 200); +background(0); +maxDistance = dist(width/2, height/2, width, height); +distances = new float[width][height]; +for(int i=0; i= big || x <= 0) { + xdir *= -1; + x = x + (1 * xdir); + y = y + (1 * ydir); + } + if (y >= big || y <= 0) { + ydir *= -1; + y = y + (1 * ydir); + } + } + + // Custom method for drawing the object + void draw() { + stroke(second() * 4); + point(mx+x-1, my+y-1); + } +} diff --git a/android/examples/Basics/Arrays/ArrayObjects/applet/ArrayObjects.java b/android/examples/Basics/Arrays/ArrayObjects/applet/ArrayObjects.java new file mode 100644 index 000000000..3ce1aa1a9 --- /dev/null +++ b/android/examples/Basics/Arrays/ArrayObjects/applet/ArrayObjects.java @@ -0,0 +1,94 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class ArrayObjects extends PApplet { + +/** + * Array Objects. + * + * Demonstrates the syntax for creating an array of custom objects. + */ + +int unit = 40; +int num; +Module[] mods; + +public void setup() +{ + size(200, 200); + background(176); + noStroke(); + + num = width/unit * width/unit; + mods = new Module[num]; + + for (int i=0; i= size || x <= 0) { + xdir *= -1; + x = x + (1 * xdir); + y = y + (1 * ydir); + } + if (y >= size || y <= 0) { + ydir *= -1; + y = y + (1 * ydir); + } + } + + // Custom method for drawing the object + public void draw() { + stroke(second()*4); + point(mx+x-1, my+y-1); + } +} + + + + static public void main(String args[]) { + PApplet.main(new String[] { "ArrayObjects" }); + } +} diff --git a/android/examples/Basics/Arrays/ArrayObjects/applet/ArrayObjects.pde b/android/examples/Basics/Arrays/ArrayObjects/applet/ArrayObjects.pde new file mode 100644 index 000000000..c2ea3b4a2 --- /dev/null +++ b/android/examples/Basics/Arrays/ArrayObjects/applet/ArrayObjects.pde @@ -0,0 +1,74 @@ +/** + * Array Objects. + * + * Demonstrates the syntax for creating an array of custom objects. + */ + +int unit = 40; +int num; +Module[] mods; + +void setup() +{ + size(200, 200); + background(176); + noStroke(); + + num = width/unit * width/unit; + mods = new Module[num]; + + for (int i=0; i= size || x <= 0) { + xdir *= -1; + x = x + (1 * xdir); + y = y + (1 * ydir); + } + if (y >= size || y <= 0) { + ydir *= -1; + y = y + (1 * ydir); + } + } + + // Custom method for drawing the object + void draw() { + stroke(second()*4); + point(mx+x-1, my+y-1); + } +} + + diff --git a/android/examples/Basics/Arrays/ArrayObjects/applet/loading.gif b/android/examples/Basics/Arrays/ArrayObjects/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Arrays/ArrayObjects/applet/loading.gif differ diff --git a/android/examples/Basics/Color/Brightness/Brightness.pde b/android/examples/Basics/Color/Brightness/Brightness.pde new file mode 100644 index 000000000..a91331e30 --- /dev/null +++ b/android/examples/Basics/Color/Brightness/Brightness.pde @@ -0,0 +1,29 @@ +/** + * Brightness + * by Rusty Robison. + * + * Brightness is the relative lightness or darkness of a color. + * Move the cursor vertically over each bar to alter its brightness. + * + * Updated 28 February 2010. + */ + +int barWidth = 5; +int lastBar = -1; + +void setup() { + size(200, 200); + colorMode(HSB, 360, 100, height); + noStroke(); + background(0); +} + +void draw() { + int whichBar = mouseX / barWidth; + if (whichBar != lastBar) { + int barX = whichBar * barWidth; + fill(barX, 100, mouseY); + rect(barX, 0, barWidth, height); + lastBar = whichBar; + } +} diff --git a/android/examples/Basics/Color/Brightness/applet/Brightness.java b/android/examples/Basics/Color/Brightness/applet/Brightness.java new file mode 100644 index 000000000..03e7c208c --- /dev/null +++ b/android/examples/Basics/Color/Brightness/applet/Brightness.java @@ -0,0 +1,51 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Brightness extends PApplet { + +/** + * Brightness + * by Rusty Robison. + * + * Brightness is the relative lightness or darkness of a color. + * Move the cursor vertically over each bar to alter its brightness. + */ + +int barWidth = 5; +int[] brightness; + +public void setup() +{ + size(200, 200); + colorMode(HSB, 360, height, height); + brightness = new int[width/barWidth]; +} + +public void draw() +{ + int j = 0; + for (int i = 0; i <= (width-barWidth); i += barWidth) { + noStroke(); + if ((mouseX > i) && (mouseX < i+barWidth)) { + brightness[j] = mouseY; + } + fill(i, height, brightness[j]); + rect(i, 0, barWidth, height); + j++; + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Brightness" }); + } +} diff --git a/android/examples/Basics/Color/Brightness/applet/Brightness.pde b/android/examples/Basics/Color/Brightness/applet/Brightness.pde new file mode 100644 index 000000000..c9dba6d28 --- /dev/null +++ b/android/examples/Basics/Color/Brightness/applet/Brightness.pde @@ -0,0 +1,31 @@ +/** + * Brightness + * by Rusty Robison. + * + * Brightness is the relative lightness or darkness of a color. + * Move the cursor vertically over each bar to alter its brightness. + */ + +int barWidth = 5; +int[] brightness; + +void setup() +{ + size(200, 200); + colorMode(HSB, 360, height, height); + brightness = new int[width/barWidth]; +} + +void draw() +{ + int j = 0; + for (int i = 0; i <= (width-barWidth); i += barWidth) { + noStroke(); + if ((mouseX > i) && (mouseX < i+barWidth)) { + brightness[j] = mouseY; + } + fill(i, height, brightness[j]); + rect(i, 0, barWidth, height); + j++; + } +} diff --git a/android/examples/Basics/Color/Brightness/applet/loading.gif b/android/examples/Basics/Color/Brightness/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Color/Brightness/applet/loading.gif differ diff --git a/android/examples/Basics/Color/ColorWheel/ColorWheel.pde b/android/examples/Basics/Color/ColorWheel/ColorWheel.pde new file mode 100644 index 000000000..69c34602a --- /dev/null +++ b/android/examples/Basics/Color/ColorWheel/ColorWheel.pde @@ -0,0 +1,88 @@ +/** + * Subtractive Color Wheel + * by Ira Greenberg. + * + * The primaries are red, yellow, and blue. The secondaries are green, + * purple, and orange. The tertiaries are yellow-orange, red-orange, + * red-purple, blue-purple, blue-green, and yellow-green. + * + * Create a shade or tint of the subtractive color wheel using + * SHADE or TINT parameters. + * + * Updated 26 February 2010. + */ + +int segs = 12; +int steps = 6; +float rotAdjust = TWO_PI / segs / 2; +float radius; +float segWidth; +float interval = TWO_PI / segs; + + +void setup() { + size(200, 200); + background(127); + smooth(); + ellipseMode(RADIUS); + noStroke(); + // make the diameter 90% of the sketch area + radius = min(width, height) * 0.45; + segWidth = radius / steps; + + // swap which line is commented out to draw the other version + //drawTintWheel(); + drawShadeWheel(); +} + + +void drawShadeWheel() { + for (int j = 0; j < steps; j++) { + color[] cols = { + color(255-(255/steps)*j, 255-(255/steps)*j, 0), + color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0), + color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0), + color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0), + color(255-(255/steps)*j, 0, 0), + color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j), + color(255-(255/steps)*j, 0, 255-(255/steps)*j), + color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j), + color(0, 0, 255-(255/steps)*j), + color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j), + color(0, 255-(255/steps)*j, 0), + color((255/2)-((255/2)/steps)*j, 255-(255/steps)*j, 0) + }; + for (int i = 0; i < segs; i++) { + fill(cols[i]); + arc(width/2, height/2, radius, radius, + interval*i+rotAdjust, interval*(i+1)+rotAdjust); + } + radius -= segWidth; + } +} + + +void drawTintWheel() { + for (int j = 0; j < steps; j++) { + color[] cols = { + color((255/steps)*j, (255/steps)*j, 0), + color((255/steps)*j, ((255/1.5)/steps)*j, 0), + color((255/steps)*j, ((255/2)/steps)*j, 0), + color((255/steps)*j, ((255/2.5)/steps)*j, 0), + color((255/steps)*j, 0, 0), + color((255/steps)*j, 0, ((255/2)/steps)*j), + color((255/steps)*j, 0, (255/steps)*j), + color(((255/2)/steps)*j, 0, (255/steps)*j), + color(0, 0, (255/steps)*j), + color(0, (255/steps)*j, ((255/2.5)/steps)*j), + color(0, (255/steps)*j, 0), + color(((255/2)/steps)*j, (255/steps)*j, 0) + }; + for (int i = 0; i < segs; i++) { + fill(cols[i]); + arc(width/2, height/2, radius, radius, + interval*i+rotAdjust, interval*(i+1)+rotAdjust); + } + radius -= segWidth; + } +} diff --git a/android/examples/Basics/Color/ColorWheel/applet/ColorWheel.java b/android/examples/Basics/Color/ColorWheel/applet/ColorWheel.java new file mode 100644 index 000000000..c9ecabb74 --- /dev/null +++ b/android/examples/Basics/Color/ColorWheel/applet/ColorWheel.java @@ -0,0 +1,99 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class ColorWheel extends PApplet { + +/** + * Subtractive Color Wheel + * by Ira Greenberg. + * + * The primaries are red, yellow, and blue. The + * secondaries are green, purple, and orange. The + * tertiaries are yellow-orange, red-orange, red-purple, + * blue-purple, blue-green, and yellow-green. + * + * Create a shade or tint of the + * subtractive color wheel using + * SHADE or TINT parameters. + */ + +int segs = 12; +int steps = 6; +float rotAdjust = radians(360.0f/segs/2.0f); +float radius = 95.0f; +float segWidth = radius/steps; +float interval = TWO_PI/segs; +int SHADE = 0; +int TINT = 1; + +public void setup(){ + size(200, 200); + background(127); + smooth(); + ellipseMode(CENTER_RADIUS); + noStroke(); + // you can substitue TINT for SHADE argument + createWheel(width/2, height/2, SHADE); +} + +public void createWheel(int x, int y, int valueShift){ + if (valueShift == SHADE){ + for (int j=0; j i) && (mouseX < i+barWidth)) { + hue[j] = mouseY; + } + fill(hue[j], height/1.2, height/1.2); + rect(i, 0, barWidth, height); + j++; + } +} diff --git a/android/examples/Basics/Color/Hue/applet/Hue.java b/android/examples/Basics/Color/Hue/applet/Hue.java new file mode 100644 index 000000000..e75799f52 --- /dev/null +++ b/android/examples/Basics/Color/Hue/applet/Hue.java @@ -0,0 +1,51 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Hue extends PApplet { + +/** + * Hue. + * + * Hue is the color reflected from or transmitted through an object + * and is typically referred to as the name of the color (red, blue, yellow, etc.) + * Move the cursor vertically over each bar to alter its hue. + */ + +int barWidth = 5; +int[] hue; + +public void setup() +{ + size(200, 200); + colorMode(HSB, 360, height, height); + hue = new int[width/barWidth]; + noStroke(); +} + +public void draw() +{ + int j = 0; + for (int i=0; i<=(width-barWidth); i+=barWidth) { + if ((mouseX > i) && (mouseX < i+barWidth)) { + hue[j] = mouseY; + } + fill(hue[j], height/1.2f, height/1.2f); + rect(i, 0, barWidth, height); + j++; + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Hue" }); + } +} diff --git a/android/examples/Basics/Color/Hue/applet/Hue.pde b/android/examples/Basics/Color/Hue/applet/Hue.pde new file mode 100644 index 000000000..b22ffb535 --- /dev/null +++ b/android/examples/Basics/Color/Hue/applet/Hue.pde @@ -0,0 +1,31 @@ +/** + * Hue. + * + * Hue is the color reflected from or transmitted through an object + * and is typically referred to as the name of the color (red, blue, yellow, etc.) + * Move the cursor vertically over each bar to alter its hue. + */ + +int barWidth = 5; +int[] hue; + +void setup() +{ + size(200, 200); + colorMode(HSB, 360, height, height); + hue = new int[width/barWidth]; + noStroke(); +} + +void draw() +{ + int j = 0; + for (int i=0; i<=(width-barWidth); i+=barWidth) { + if ((mouseX > i) && (mouseX < i+barWidth)) { + hue[j] = mouseY; + } + fill(hue[j], height/1.2, height/1.2); + rect(i, 0, barWidth, height); + j++; + } +} diff --git a/android/examples/Basics/Color/Hue/applet/loading.gif b/android/examples/Basics/Color/Hue/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Color/Hue/applet/loading.gif differ diff --git a/android/examples/Basics/Color/LinearGradient/LinearGradient.pde b/android/examples/Basics/Color/LinearGradient/LinearGradient.pde new file mode 100644 index 000000000..f41fc2b66 --- /dev/null +++ b/android/examples/Basics/Color/LinearGradient/LinearGradient.pde @@ -0,0 +1,73 @@ +/** + * Simple Linear Gradient + * by Ira Greenberg. + * + * Using the convenient red(), green() + * and blue() component functions, + * generate some linear gradients. + */ + +// constants +int Y_AXIS = 1; +int X_AXIS = 2; + +void setup(){ + size(200, 200); + + // create some gradients + // background + color b1 = color(190, 190, 190); + color b2 = color(20, 20, 20); + setGradient(0, 0, width, height, b1, b2, Y_AXIS); + //center squares + color c1 = color(255, 120, 0); + color c2 = color(10, 45, 255); + color c3 = color(10, 255, 15); + color c4 = color(125, 2, 140); + color c5 = color(255, 255, 0); + color c6 = color(25, 255, 200); + setGradient(25, 25, 75, 75, c1, c2, Y_AXIS); + setGradient(100, 25, 75, 75, c3, c4, X_AXIS); + setGradient(25, 100, 75, 75, c2, c5, X_AXIS); + setGradient(100, 100, 75, 75, c4, c6, Y_AXIS); +} + +void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ){ + // calculate differences between color components + float deltaR = red(c2)-red(c1); + float deltaG = green(c2)-green(c1); + float deltaB = blue(c2)-blue(c1); + + // choose axis + if(axis == Y_AXIS){ + /*nested for loops set pixels + in a basic table structure */ + // column + for (int i=x; i<=(x+w); i++){ + // row + for (int j = y; j<=(y+h); j++){ + color c = color( + (red(c1)+(j-y)*(deltaR/h)), + (green(c1)+(j-y)*(deltaG/h)), + (blue(c1)+(j-y)*(deltaB/h)) + ); + set(i, j, c); + } + } + } + else if(axis == X_AXIS){ + // column + for (int i=y; i<=(y+h); i++){ + // row + for (int j = x; j<=(x+w); j++){ + color c = color( + (red(c1)+(j-x)*(deltaR/h)), + (green(c1)+(j-x)*(deltaG/h)), + (blue(c1)+(j-x)*(deltaB/h)) + ); + set(j, i, c); + } + } + } +} + diff --git a/android/examples/Basics/Color/LinearGradient/applet/LinearGradient.java b/android/examples/Basics/Color/LinearGradient/applet/LinearGradient.java new file mode 100644 index 000000000..6fbbc5c2e --- /dev/null +++ b/android/examples/Basics/Color/LinearGradient/applet/LinearGradient.java @@ -0,0 +1,93 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class LinearGradient extends PApplet { + +/** + * Simple Linear Gradient + * by Ira Greenberg. + * + * Using the convenient red(), green() + * and blue() component functions, + * generate some linear gradients. + */ + +// constants +int Y_AXIS = 1; +int X_AXIS = 2; + +public void setup(){ + size(200, 200); + + // create some gradients + // background + int b1 = color(190, 190, 190); + int b2 = color(20, 20, 20); + setGradient(0, 0, width, height, b1, b2, Y_AXIS); + //center squares + int c1 = color(255, 120, 0); + int c2 = color(10, 45, 255); + int c3 = color(10, 255, 15); + int c4 = color(125, 2, 140); + int c5 = color(255, 255, 0); + int c6 = color(25, 255, 200); + setGradient(25, 25, 75, 75, c1, c2, Y_AXIS); + setGradient(100, 25, 75, 75, c3, c4, X_AXIS); + setGradient(25, 100, 75, 75, c2, c5, X_AXIS); + setGradient(100, 100, 75, 75, c4, c6, Y_AXIS); +} + +public void setGradient(int x, int y, float w, float h, int c1, int c2, int axis ){ + // calculate differences between color components + float deltaR = red(c2)-red(c1); + float deltaG = green(c2)-green(c1); + float deltaB = blue(c2)-blue(c1); + + // choose axis + if(axis == Y_AXIS){ + /*nested for loops set pixels + in a basic table structure */ + // column + for (int i=x; i<=(x+w); i++){ + // row + for (int j = y; j<=(y+h); j++){ + int c = color( + (red(c1)+(j-y)*(deltaR/h)), + (green(c1)+(j-y)*(deltaG/h)), + (blue(c1)+(j-y)*(deltaB/h)) + ); + set(i, j, c); + } + } + } + else if(axis == X_AXIS){ + // column + for (int i=y; i<=(y+h); i++){ + // row + for (int j = x; j<=(x+w); j++){ + int c = color( + (red(c1)+(j-x)*(deltaR/h)), + (green(c1)+(j-x)*(deltaG/h)), + (blue(c1)+(j-x)*(deltaB/h)) + ); + set(j, i, c); + } + } + } +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "LinearGradient" }); + } +} diff --git a/android/examples/Basics/Color/LinearGradient/applet/LinearGradient.pde b/android/examples/Basics/Color/LinearGradient/applet/LinearGradient.pde new file mode 100644 index 000000000..f41fc2b66 --- /dev/null +++ b/android/examples/Basics/Color/LinearGradient/applet/LinearGradient.pde @@ -0,0 +1,73 @@ +/** + * Simple Linear Gradient + * by Ira Greenberg. + * + * Using the convenient red(), green() + * and blue() component functions, + * generate some linear gradients. + */ + +// constants +int Y_AXIS = 1; +int X_AXIS = 2; + +void setup(){ + size(200, 200); + + // create some gradients + // background + color b1 = color(190, 190, 190); + color b2 = color(20, 20, 20); + setGradient(0, 0, width, height, b1, b2, Y_AXIS); + //center squares + color c1 = color(255, 120, 0); + color c2 = color(10, 45, 255); + color c3 = color(10, 255, 15); + color c4 = color(125, 2, 140); + color c5 = color(255, 255, 0); + color c6 = color(25, 255, 200); + setGradient(25, 25, 75, 75, c1, c2, Y_AXIS); + setGradient(100, 25, 75, 75, c3, c4, X_AXIS); + setGradient(25, 100, 75, 75, c2, c5, X_AXIS); + setGradient(100, 100, 75, 75, c4, c6, Y_AXIS); +} + +void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ){ + // calculate differences between color components + float deltaR = red(c2)-red(c1); + float deltaG = green(c2)-green(c1); + float deltaB = blue(c2)-blue(c1); + + // choose axis + if(axis == Y_AXIS){ + /*nested for loops set pixels + in a basic table structure */ + // column + for (int i=x; i<=(x+w); i++){ + // row + for (int j = y; j<=(y+h); j++){ + color c = color( + (red(c1)+(j-y)*(deltaR/h)), + (green(c1)+(j-y)*(deltaG/h)), + (blue(c1)+(j-y)*(deltaB/h)) + ); + set(i, j, c); + } + } + } + else if(axis == X_AXIS){ + // column + for (int i=y; i<=(y+h); i++){ + // row + for (int j = x; j<=(x+w); j++){ + color c = color( + (red(c1)+(j-x)*(deltaR/h)), + (green(c1)+(j-x)*(deltaG/h)), + (blue(c1)+(j-x)*(deltaB/h)) + ); + set(j, i, c); + } + } + } +} + diff --git a/android/examples/Basics/Color/LinearGradient/applet/loading.gif b/android/examples/Basics/Color/LinearGradient/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Color/LinearGradient/applet/loading.gif differ diff --git a/android/examples/Basics/Color/RadialGradient/RadialGradient.pde b/android/examples/Basics/Color/RadialGradient/RadialGradient.pde new file mode 100644 index 000000000..f5ba2b3fe --- /dev/null +++ b/android/examples/Basics/Color/RadialGradient/RadialGradient.pde @@ -0,0 +1,58 @@ +/** + * Simple Radial Gradient + * by Ira Greenberg. + * + * Using the convenient red(), green() + * and blue() component functions, + * generate an array of radial gradients. + */ + +void setup(){ + size(200, 200); + background(0); + smooth(); + + // create a simple table of gradients + int columns = 4; + int radius = (width/columns)/2; + // create some gradients + for (int i=radius; i< width; i+=radius*2){ + for (int j =radius; j< height; j+=radius*2){ + createGradient(i, j, radius, + color(int(random(255)), int(random(255)), int(random(255))), + color(int(random(255)), int(random(255)), int(random(255)))); + } + } +} + +void createGradient (float x, float y, float radius, color c1, color c2){ + float px = 0, py = 0, angle = 0; + + // calculate differences between color components + float deltaR = red(c2)-red(c1); + float deltaG = green(c2)-green(c1); + float deltaB = blue(c2)-blue(c1); + // hack to ensure there are no holes in gradient + // needs to be increased, as radius increases + float gapFiller = 8.0; + + for (int i=0; i< radius; i++){ + for (float j=0; j<360; j+=1.0/gapFiller){ + px = x+cos(radians(angle))*i; + py = y+sin(radians(angle))*i; + angle+=1.0/gapFiller; + color c = color( + (red(c1)+(i)*(deltaR/radius)), + (green(c1)+(i)*(deltaG/radius)), + (blue(c1)+(i)*(deltaB/radius)) + ); + set(int(px), int(py), c); + } + } + // adds smooth edge + // hack anti-aliasing + noFill(); + strokeWeight(3); + ellipse(x, y, radius*2, radius*2); +} + diff --git a/android/examples/Basics/Color/RadialGradient/applet/RadialGradient.java b/android/examples/Basics/Color/RadialGradient/applet/RadialGradient.java new file mode 100644 index 000000000..1ba6eaa19 --- /dev/null +++ b/android/examples/Basics/Color/RadialGradient/applet/RadialGradient.java @@ -0,0 +1,78 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class RadialGradient extends PApplet { + +/** + * Simple Radial Gradient + * by Ira Greenberg. + * + * Using the convenient red(), green() + * and blue() component functions, + * generate an array of radial gradients. + */ + +public void setup(){ + size(200, 200); + background(0); + smooth(); + + // create a simple table of gradients + int columns = 4; + int radius = (width/columns)/2; + // create some gradients + for (int i=radius; i< width; i+=radius*2){ + for (int j =radius; j< height; j+=radius*2){ + createGradient(i, j, radius, + color(PApplet.parseInt(random(255)), PApplet.parseInt(random(255)), PApplet.parseInt(random(255))), + color(PApplet.parseInt(random(255)), PApplet.parseInt(random(255)), PApplet.parseInt(random(255)))); + } + } +} + +public void createGradient (float x, float y, float radius, int c1, int c2){ + float px = 0, py = 0, angle = 0; + + // calculate differences between color components + float deltaR = red(c2)-red(c1); + float deltaG = green(c2)-green(c1); + float deltaB = blue(c2)-blue(c1); + // hack to ensure there are no holes in gradient + // needs to be increased, as radius increases + float gapFiller = 8.0f; + + for (int i=0; i< radius; i++){ + for (float j=0; j<360; j+=1.0f/gapFiller){ + px = x+cos(radians(angle))*i; + py = y+sin(radians(angle))*i; + angle+=1.0f/gapFiller; + int c = color( + (red(c1)+(i)*(deltaR/radius)), + (green(c1)+(i)*(deltaG/radius)), + (blue(c1)+(i)*(deltaB/radius)) + ); + set(PApplet.parseInt(px), PApplet.parseInt(py), c); + } + } + // adds smooth edge + // hack anti-aliasing + noFill(); + strokeWeight(3); + ellipse(x, y, radius*2, radius*2); +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "RadialGradient" }); + } +} diff --git a/android/examples/Basics/Color/RadialGradient/applet/RadialGradient.pde b/android/examples/Basics/Color/RadialGradient/applet/RadialGradient.pde new file mode 100644 index 000000000..f5ba2b3fe --- /dev/null +++ b/android/examples/Basics/Color/RadialGradient/applet/RadialGradient.pde @@ -0,0 +1,58 @@ +/** + * Simple Radial Gradient + * by Ira Greenberg. + * + * Using the convenient red(), green() + * and blue() component functions, + * generate an array of radial gradients. + */ + +void setup(){ + size(200, 200); + background(0); + smooth(); + + // create a simple table of gradients + int columns = 4; + int radius = (width/columns)/2; + // create some gradients + for (int i=radius; i< width; i+=radius*2){ + for (int j =radius; j< height; j+=radius*2){ + createGradient(i, j, radius, + color(int(random(255)), int(random(255)), int(random(255))), + color(int(random(255)), int(random(255)), int(random(255)))); + } + } +} + +void createGradient (float x, float y, float radius, color c1, color c2){ + float px = 0, py = 0, angle = 0; + + // calculate differences between color components + float deltaR = red(c2)-red(c1); + float deltaG = green(c2)-green(c1); + float deltaB = blue(c2)-blue(c1); + // hack to ensure there are no holes in gradient + // needs to be increased, as radius increases + float gapFiller = 8.0; + + for (int i=0; i< radius; i++){ + for (float j=0; j<360; j+=1.0/gapFiller){ + px = x+cos(radians(angle))*i; + py = y+sin(radians(angle))*i; + angle+=1.0/gapFiller; + color c = color( + (red(c1)+(i)*(deltaR/radius)), + (green(c1)+(i)*(deltaG/radius)), + (blue(c1)+(i)*(deltaB/radius)) + ); + set(int(px), int(py), c); + } + } + // adds smooth edge + // hack anti-aliasing + noFill(); + strokeWeight(3); + ellipse(x, y, radius*2, radius*2); +} + diff --git a/android/examples/Basics/Color/RadialGradient/applet/loading.gif b/android/examples/Basics/Color/RadialGradient/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Color/RadialGradient/applet/loading.gif differ diff --git a/android/examples/Basics/Color/RadialGradient2/RadialGradient2.pde b/android/examples/Basics/Color/RadialGradient2/RadialGradient2.pde new file mode 100644 index 000000000..ad571fcc0 --- /dev/null +++ b/android/examples/Basics/Color/RadialGradient2/RadialGradient2.pde @@ -0,0 +1,43 @@ +/** + * Inspired by Ira Greenberg's RadialGradient sketch, + * but uses a different method for the gradients. + */ + +int dim = 40; + +void setup() { + size(200, 200); + background(0); + smooth(); + noStroke(); + ellipseMode(RADIUS); + + // create a simple table of gradients + int rows = height / dim; + int cols = width / dim; + + for (int row = 0; row < rows; row++) { + for (int col = 0; col < cols; col++) { + drawGradient(col*dim + dim/2, row*dim + dim/2); + } + } +} + +void drawGradient(float x, float y) { + int radius = dim/2 - 2; + float r1 = random(255); + float g1 = random(255); + float b1 = random(255); + float dr = (random(255) - r1) / radius; + float dg = (random(255) - g1) / radius; + float db = (random(255) - b1) / radius; + + for (int r = radius; r > 0; --r) { + fill(r1, g1, b1); + ellipse(x, y, r, r); + r1 += dr; + g1 += dg; + b1 += db; + } +} + diff --git a/android/examples/Basics/Color/Reading/Reading.pde b/android/examples/Basics/Color/Reading/Reading.pde new file mode 100644 index 000000000..d142aff88 --- /dev/null +++ b/android/examples/Basics/Color/Reading/Reading.pde @@ -0,0 +1,46 @@ +/** + * Reading. + * + * An image is recreated from its individual component colors. + * The many colors of the image are created through modulating the + * red, green, and blue values. This is an exageration of an LCD display. + */ + +size(200, 200); +noStroke(); +background(0); + +// Load an image from the data directory +PImage img = loadImage("cait.jpg"); +img.loadPixels(); + +// figure out how big to make each block based on +// the sketch area and the size of the input image +int eachW = width / img.width; +int eachH = height / img.height; +int each = min(eachW, eachH); +// vertical stripes will be a third as wide +int stripeW = each / 3; +// make sure the block size is a multiple of 3 +each = 3 * stripeW; + +int left = (width - (img.width * each)) / 2; +int top = (height - (img.height * each)) / 2; + +for (int y = 0; y < img.height; y++) { + int y1 = top + y*each; + + for (int x = 0; x < img.width; x++) { + int pixel = img.get(x, y); + int x1 = left + x*each; + + fill(red(pixel), 0, 0); + rect(x1 + stripeW*0, y1, stripeW, each); + + fill(0, green(pixel), 0); + rect(x1 + stripeW*1, y1, stripeW, each); + + fill(0, 0, blue(pixel)); + rect(x1 + stripeW*2, y1, stripeW, each); + } +} diff --git a/android/examples/Basics/Color/Reading/applet/Reading.java b/android/examples/Basics/Color/Reading/applet/Reading.java new file mode 100644 index 000000000..5ce02d462 --- /dev/null +++ b/android/examples/Basics/Color/Reading/applet/Reading.java @@ -0,0 +1,63 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Reading extends PApplet { + public void setup() {/** + * Reading. + * + * An image is recreated from its individual component colors. + * The many colors of the image are created through modulating the + * red, green, and blue values. This is an exageration of an LCD display. + */ + +size(200, 200); +noStroke(); +background(0); + +// Load an image from the data directory +PImage c; +c = loadImage("cait.jpg"); + +int xoff = 0; +int yoff = 0; +int p = 2; +int pix = p*3; + + +for(int i = 0; i < c.width*c.height; i += 1) +{ + int here = c.pixels[i]; + + fill(red(here), 0, 0); + rect(xoff, yoff, p, pix); + + fill(0, green(here), 0); + rect(xoff+p, yoff, p, pix); + + fill(0, 0, blue(here)); + rect(xoff+p*2, yoff, p, pix); + + xoff+=pix; + if(xoff >= width-pix) { + xoff = 0; + yoff += pix; + } +} + + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "Reading" }); + } +} diff --git a/android/examples/Basics/Color/Reading/applet/Reading.pde b/android/examples/Basics/Color/Reading/applet/Reading.pde new file mode 100644 index 000000000..6f1ec2042 --- /dev/null +++ b/android/examples/Basics/Color/Reading/applet/Reading.pde @@ -0,0 +1,42 @@ +/** + * Reading. + * + * An image is recreated from its individual component colors. + * The many colors of the image are created through modulating the + * red, green, and blue values. This is an exageration of an LCD display. + */ + +size(200, 200); +noStroke(); +background(0); + +// Load an image from the data directory +PImage c; +c = loadImage("cait.jpg"); + +int xoff = 0; +int yoff = 0; +int p = 2; +int pix = p*3; + + +for(int i = 0; i < c.width*c.height; i += 1) +{ + int here = c.pixels[i]; + + fill(red(here), 0, 0); + rect(xoff, yoff, p, pix); + + fill(0, green(here), 0); + rect(xoff+p, yoff, p, pix); + + fill(0, 0, blue(here)); + rect(xoff+p*2, yoff, p, pix); + + xoff+=pix; + if(xoff >= width-pix) { + xoff = 0; + yoff += pix; + } +} + diff --git a/android/examples/Basics/Color/Reading/applet/loading.gif b/android/examples/Basics/Color/Reading/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Color/Reading/applet/loading.gif differ diff --git a/android/examples/Basics/Color/Relativity/Relativity.pde b/android/examples/Basics/Color/Relativity/Relativity.pde new file mode 100644 index 000000000..9332e9baf --- /dev/null +++ b/android/examples/Basics/Color/Relativity/Relativity.pde @@ -0,0 +1,42 @@ +/** + * Relativity. + * + * Each color is perceived in relation to other colors. + * The top and bottom bars each contain the same component colors, + * but a different display order causes individual colors to appear differently. + */ + +color a, b, c, d, e; + +void setup() { + size(200, 200); + noStroke(); + a = color(165, 167, 20); + b = color(77, 86, 59); + c = color(42, 106, 105); + d = color(165, 89, 20); + e = color(146, 150, 127); + noLoop(); +} + +void draw() { + drawBand(a, b, c, d, e, 0, width/50); + drawBand(c, a, d, b, e, height/2, width/50); +} + +void drawBand(color v, color w, color x, color y, color z, int ypos, int barWidth) { + int num = 5; + color[] colorOrder = { v, w, x, y, z }; + for(int i = 0; i < width; i += barWidth*num) { + for(int j = 0; j < num; j++) { + fill(colorOrder[j]); + rect(i+j*barWidth, ypos, barWidth, height/2); + } + } +} + + + + + + diff --git a/android/examples/Basics/Color/Relativity/applet/Relativity.java b/android/examples/Basics/Color/Relativity/applet/Relativity.java new file mode 100644 index 000000000..3612db49e --- /dev/null +++ b/android/examples/Basics/Color/Relativity/applet/Relativity.java @@ -0,0 +1,62 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Relativity extends PApplet { + +/** + * Relativity. + * + * Each color is perceived in relation to other colors. + * The top and bottom bars each contain the same component colors, + * but a different display order causes individual colors to appear differently. + */ + +int a, b, c, d, e; + +public void setup() { + size(200, 200); + noStroke(); + a = color(165, 167, 20); + b = color(77, 86, 59); + c = color(42, 106, 105); + d = color(165, 89, 20); + e = color(146, 150, 127); + noLoop(); +} + +public void draw() { + drawBand(a, b, c, d, e, 0, 4); + drawBand(c, a, d, b, e, height/2, 4); +} + +public void drawBand(int v, int w, int x, int y, int z, int ypos, int barWidth) { + int num = 5; + int[] colorOrder = { v, w, x, y, z }; + for(int i = 0; i < width; i += barWidth*num) { + for(int j = 0; j < num; j++) { + fill(colorOrder[j]); + rect(i+j*barWidth, ypos, barWidth, height/2); + } + } +} + + + + + + + + static public void main(String args[]) { + PApplet.main(new String[] { "Relativity" }); + } +} diff --git a/android/examples/Basics/Color/Relativity/applet/Relativity.pde b/android/examples/Basics/Color/Relativity/applet/Relativity.pde new file mode 100644 index 000000000..59a3365a6 --- /dev/null +++ b/android/examples/Basics/Color/Relativity/applet/Relativity.pde @@ -0,0 +1,42 @@ +/** + * Relativity. + * + * Each color is perceived in relation to other colors. + * The top and bottom bars each contain the same component colors, + * but a different display order causes individual colors to appear differently. + */ + +color a, b, c, d, e; + +void setup() { + size(200, 200); + noStroke(); + a = color(165, 167, 20); + b = color(77, 86, 59); + c = color(42, 106, 105); + d = color(165, 89, 20); + e = color(146, 150, 127); + noLoop(); +} + +void draw() { + drawBand(a, b, c, d, e, 0, 4); + drawBand(c, a, d, b, e, height/2, 4); +} + +void drawBand(color v, color w, color x, color y, color z, int ypos, int barWidth) { + int num = 5; + color[] colorOrder = { v, w, x, y, z }; + for(int i = 0; i < width; i += barWidth*num) { + for(int j = 0; j < num; j++) { + fill(colorOrder[j]); + rect(i+j*barWidth, ypos, barWidth, height/2); + } + } +} + + + + + + diff --git a/android/examples/Basics/Color/Relativity/applet/loading.gif b/android/examples/Basics/Color/Relativity/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Color/Relativity/applet/loading.gif differ diff --git a/android/examples/Basics/Color/Saturation/Saturation.pde b/android/examples/Basics/Color/Saturation/Saturation.pde new file mode 100644 index 000000000..84137147e --- /dev/null +++ b/android/examples/Basics/Color/Saturation/Saturation.pde @@ -0,0 +1,29 @@ +/** + * Saturation. + * + * Saturation is the strength or purity of the color and represents the + * amount of gray in proportion to the hue. A "saturated" color is pure + * and an "unsaturated" color has a large percentage of gray. + * Move the cursor vertically over each bar to alter its saturation. + */ + +int barWidth = 5; +int lastBar = -1; + + +void setup() { + size(200, 200); + colorMode(HSB, width, height, 100); + noStroke(); +} + + +void draw() { + int whichBar = mouseX / barWidth; + if (whichBar != lastBar) { + int barX = whichBar * barWidth; + fill(barX, mouseY, 66); + rect(barX, 0, barWidth, height); + lastBar = whichBar; + } +} diff --git a/android/examples/Basics/Color/Saturation/applet/Saturation.java b/android/examples/Basics/Color/Saturation/applet/Saturation.java new file mode 100644 index 000000000..62ac4f2f0 --- /dev/null +++ b/android/examples/Basics/Color/Saturation/applet/Saturation.java @@ -0,0 +1,52 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Saturation extends PApplet { + +/** + * Saturation. + * + * Saturation is the strength or purity of the color and represents the + * amount of gray in proportion to the hue. A "saturated" color is pure + * and an "unsaturated" color has a large percentage of gray. + * Move the cursor vertically over each bar to alter its saturation. + */ + +int barWidth = 5; +int[] saturation; + +public void setup() +{ + size(200, 200); + colorMode(HSB, 360, height, height); + saturation = new int[width/barWidth]; +} + +public void draw() +{ + int j = 0; + for (int i=0; i<=(width-barWidth); i+=barWidth) { + noStroke(); + if ((mouseX > i) && (mouseX < i+barWidth)) { + saturation[j] = mouseY; + } + fill(i, saturation[j], height/1.5f); + rect(i, 0, barWidth, height); + j++; + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Saturation" }); + } +} diff --git a/android/examples/Basics/Color/Saturation/applet/Saturation.pde b/android/examples/Basics/Color/Saturation/applet/Saturation.pde new file mode 100644 index 000000000..0902ead92 --- /dev/null +++ b/android/examples/Basics/Color/Saturation/applet/Saturation.pde @@ -0,0 +1,32 @@ +/** + * Saturation. + * + * Saturation is the strength or purity of the color and represents the + * amount of gray in proportion to the hue. A "saturated" color is pure + * and an "unsaturated" color has a large percentage of gray. + * Move the cursor vertically over each bar to alter its saturation. + */ + +int barWidth = 5; +int[] saturation; + +void setup() +{ + size(200, 200); + colorMode(HSB, 360, height, height); + saturation = new int[width/barWidth]; +} + +void draw() +{ + int j = 0; + for (int i=0; i<=(width-barWidth); i+=barWidth) { + noStroke(); + if ((mouseX > i) && (mouseX < i+barWidth)) { + saturation[j] = mouseY; + } + fill(i, saturation[j], height/1.5); + rect(i, 0, barWidth, height); + j++; + } +} diff --git a/android/examples/Basics/Color/Saturation/applet/loading.gif b/android/examples/Basics/Color/Saturation/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Color/Saturation/applet/loading.gif differ diff --git a/android/examples/Basics/Color/WaveGradient/WaveGradient.pde b/android/examples/Basics/Color/WaveGradient/WaveGradient.pde new file mode 100644 index 000000000..eac305093 --- /dev/null +++ b/android/examples/Basics/Color/WaveGradient/WaveGradient.pde @@ -0,0 +1,39 @@ +/** + * Wave Gradient + * by Ira Greenberg. + * + * Generate a gradient along a sin() wave. + */ + +float angle = 0; +float px = 0, py = 0; +float amplitude = 30; +float frequency = 0; +float fillGap = 2.5; +color c; + +void setup() { + size(200, 200); + background(200,200,200); + noLoop(); +} + +void draw() { + for (int i =- 75; i < height+75; i++){ + // Reset angle to 0, so waves stack properly + angle = 0; + // Increasing frequency causes more gaps + frequency+=.006; + for (float j=0; j 0){ + for(int j = margin; j < width-margin; j+= box_space){ + fill(255-box_size*10); + rect(j, i, box_size, box_size); + } + box_size = box_size - 0.6; + } +} + + diff --git a/android/examples/Basics/Control/EmbeddedIteration/applet/EmbeddedIteration.java b/android/examples/Basics/Control/EmbeddedIteration/applet/EmbeddedIteration.java new file mode 100644 index 000000000..8c0056bbf --- /dev/null +++ b/android/examples/Basics/Control/EmbeddedIteration/applet/EmbeddedIteration.java @@ -0,0 +1,48 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class EmbeddedIteration extends PApplet { + public void setup() {/** + * Embedding Iteration. + * + * Embedding "for" structures allows repetition in two dimensions. + */ + +float box_size = 11; +float box_space = 12; +int margin = 7; + +size(200, 200); +background(0); +noStroke(); + +// Draw gray boxes + +for (int i = margin; i < height-margin; i += box_space){ + if(box_size > 0){ + for(int j = margin; j < width-margin; j+= box_space){ + fill(255-box_size*10); + rect(j, i, box_size, box_size); + } + box_size = box_size - 0.6f; + } +} + + + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "EmbeddedIteration" }); + } +} diff --git a/android/examples/Basics/Control/EmbeddedIteration/applet/EmbeddedIteration.pde b/android/examples/Basics/Control/EmbeddedIteration/applet/EmbeddedIteration.pde new file mode 100644 index 000000000..3473aca2e --- /dev/null +++ b/android/examples/Basics/Control/EmbeddedIteration/applet/EmbeddedIteration.pde @@ -0,0 +1,27 @@ +/** + * Embedding Iteration. + * + * Embedding "for" structures allows repetition in two dimensions. + */ + +float box_size = 11; +float box_space = 12; +int margin = 7; + +size(200, 200); +background(0); +noStroke(); + +// Draw gray boxes + +for (int i = margin; i < height-margin; i += box_space){ + if(box_size > 0){ + for(int j = margin; j < width-margin; j+= box_space){ + fill(255-box_size*10); + rect(j, i, box_size, box_size); + } + box_size = box_size - 0.6; + } +} + + diff --git a/android/examples/Basics/Control/EmbeddedIteration/applet/loading.gif b/android/examples/Basics/Control/EmbeddedIteration/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Control/EmbeddedIteration/applet/loading.gif differ diff --git a/android/examples/Basics/Control/Iteration/Iteration.pde b/android/examples/Basics/Control/Iteration/Iteration.pde new file mode 100644 index 000000000..722806122 --- /dev/null +++ b/android/examples/Basics/Control/Iteration/Iteration.pde @@ -0,0 +1,45 @@ +/** + * Iteration. + * + * Iteration with a "for" structure constructs repetitive forms. + */ + +int k; +int xpos1 = 100; +int xpos2 = 118; +int count = 0; +int timey = 0; +int num = 12; + +size(200, 200); +background(102); +noStroke(); + +// Draw gray bars +fill(255); +k=60; +for(int i=0; i < num/3; i++) { + rect(25, k, 155, 5); + k+=10; +} + +// Black bars +fill(51); +k = 40; +for(int i=0; i < num; i++) { + rect(105, k, 30, 5); + k += 10; +} +k = 15; +for(int i = 0; i < num; i++) { + rect(125, k, 30, 5); + k +=10; +} + +// Thin lines +k = 42; +fill(0); +for(int i=0; i < num-1; i++) { + rect(36, k, 20, 1); + k+=10; +} diff --git a/android/examples/Basics/Control/Iteration/applet/Iteration.java b/android/examples/Basics/Control/Iteration/applet/Iteration.java new file mode 100644 index 000000000..56274253b --- /dev/null +++ b/android/examples/Basics/Control/Iteration/applet/Iteration.java @@ -0,0 +1,66 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Iteration extends PApplet { + public void setup() {/** + * Iteration. + * + * Iteration with a "for" structure constructs repetitive forms. + */ + +int k; +int xpos1 = 100; +int xpos2 = 118; +int count = 0; +int timey = 0; +int num = 12; + +size(200, 200); +background(102); +noStroke(); + +// Draw gray bars +fill(255); +k=60; +for(int i=0; i < num/3; i++) { + rect(25, k, 155, 5); + k+=10; +} + +// Black bars +fill(51); +k = 40; +for(int i=0; i < num; i++) { + rect(105, k, 30, 5); + k += 10; +} +k = 15; +for(int i = 0; i < num; i++) { + rect(125, k, 30, 5); + k +=10; +} + +// Thin lines +k = 42; +fill(0); +for(int i=0; i < num-1; i++) { + rect(36, k, 20, 1); + k+=10; +} + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "Iteration" }); + } +} diff --git a/android/examples/Basics/Control/Iteration/applet/Iteration.pde b/android/examples/Basics/Control/Iteration/applet/Iteration.pde new file mode 100644 index 000000000..722806122 --- /dev/null +++ b/android/examples/Basics/Control/Iteration/applet/Iteration.pde @@ -0,0 +1,45 @@ +/** + * Iteration. + * + * Iteration with a "for" structure constructs repetitive forms. + */ + +int k; +int xpos1 = 100; +int xpos2 = 118; +int count = 0; +int timey = 0; +int num = 12; + +size(200, 200); +background(102); +noStroke(); + +// Draw gray bars +fill(255); +k=60; +for(int i=0; i < num/3; i++) { + rect(25, k, 155, 5); + k+=10; +} + +// Black bars +fill(51); +k = 40; +for(int i=0; i < num; i++) { + rect(105, k, 30, 5); + k += 10; +} +k = 15; +for(int i = 0; i < num; i++) { + rect(125, k, 30, 5); + k +=10; +} + +// Thin lines +k = 42; +fill(0); +for(int i=0; i < num-1; i++) { + rect(36, k, 20, 1); + k+=10; +} diff --git a/android/examples/Basics/Control/Iteration/applet/loading.gif b/android/examples/Basics/Control/Iteration/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Control/Iteration/applet/loading.gif differ diff --git a/android/examples/Basics/Control/LogicalOperators/LogicalOperators.pde b/android/examples/Basics/Control/LogicalOperators/LogicalOperators.pde new file mode 100644 index 000000000..d9329c004 --- /dev/null +++ b/android/examples/Basics/Control/LogicalOperators/LogicalOperators.pde @@ -0,0 +1,45 @@ +/** + * Logical Operators. + * + * The logical operators for AND (&&) and OR (||) are used to + * combine simple relational statements into more complex expressions. + * The NOT (!) operator is used to negate a boolean statement. + */ + +size(200, 200); +background(126); + +boolean op = false; + +for(int i=5; i<=195; i+=5) { + // Logical AND + stroke(0); + if((i > 35) && (i < 100)) { + line(5, i, 95, i); + op = false; + } + + // Logical OR + stroke(76); + if((i <= 35) || (i >= 100)) { + line(105, i, 195, i); + op = true; + } + + // Testing if a boolean value is "true" + // The expression "if(op)" is equivalent to "if(op == true)" + if(op) { + stroke(0); + point(width/2, i); + } + + // Testing if a boolean value is "false" + // The expression "if(!op)" is equivalent to "if(op == false)" + if(!op) { + stroke(255); + point(width/4, i); + } +} + + + diff --git a/android/examples/Basics/Control/LogicalOperators/applet/LogicalOperators.java b/android/examples/Basics/Control/LogicalOperators/applet/LogicalOperators.java new file mode 100644 index 000000000..bf9354786 --- /dev/null +++ b/android/examples/Basics/Control/LogicalOperators/applet/LogicalOperators.java @@ -0,0 +1,66 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class LogicalOperators extends PApplet { + public void setup() {/** + * Logical Operators. + * + * The logical operators for AND (&&) and OR (||) are used to + * combine simple relational statements into more complex expressions. + * The NOT (!) operator is used to negate a boolean statement. + */ + +size(200, 200); +background(126); + +boolean op = false; + +for(int i=5; i<=195; i+=5) { + // Logical AND + stroke(0); + if((i > 35) && (i < 100)) { + line(5, i, 95, i); + op = false; + } + + // Logical OR + stroke(76); + if((i <= 35) || (i >= 100)) { + line(105, i, 195, i); + op = true; + } + + // Testing if a boolean value is "true" + // The expression "if(op)" is equivalent to "if(op == true)" + if(op) { + stroke(0); + point(width/2, i); + } + + // Testing if a boolean value is "false" + // The expression "if(!op)" is equivalent to "if(op == false)" + if(!op) { + stroke(255); + point(width/4, i); + } +} + + + + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "LogicalOperators" }); + } +} diff --git a/android/examples/Basics/Control/LogicalOperators/applet/LogicalOperators.pde b/android/examples/Basics/Control/LogicalOperators/applet/LogicalOperators.pde new file mode 100644 index 000000000..d9329c004 --- /dev/null +++ b/android/examples/Basics/Control/LogicalOperators/applet/LogicalOperators.pde @@ -0,0 +1,45 @@ +/** + * Logical Operators. + * + * The logical operators for AND (&&) and OR (||) are used to + * combine simple relational statements into more complex expressions. + * The NOT (!) operator is used to negate a boolean statement. + */ + +size(200, 200); +background(126); + +boolean op = false; + +for(int i=5; i<=195; i+=5) { + // Logical AND + stroke(0); + if((i > 35) && (i < 100)) { + line(5, i, 95, i); + op = false; + } + + // Logical OR + stroke(76); + if((i <= 35) || (i >= 100)) { + line(105, i, 195, i); + op = true; + } + + // Testing if a boolean value is "true" + // The expression "if(op)" is equivalent to "if(op == true)" + if(op) { + stroke(0); + point(width/2, i); + } + + // Testing if a boolean value is "false" + // The expression "if(!op)" is equivalent to "if(op == false)" + if(!op) { + stroke(255); + point(width/4, i); + } +} + + + diff --git a/android/examples/Basics/Control/LogicalOperators/applet/loading.gif b/android/examples/Basics/Control/LogicalOperators/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Control/LogicalOperators/applet/loading.gif differ diff --git a/android/examples/Basics/Data/CharactersStrings/CharactersStrings.pde b/android/examples/Basics/Data/CharactersStrings/CharactersStrings.pde new file mode 100644 index 000000000..c5b528562 --- /dev/null +++ b/android/examples/Basics/Data/CharactersStrings/CharactersStrings.pde @@ -0,0 +1,82 @@ +/** + * Characters Strings. + * + * Click on the image to give it focus and then type letters to + * shift the location of the image. + * Characters are typographic symbols such as A, d, and %. + * The character datatype, abbreviated as char, stores letters and + * symbols in the Unicode format, a coding system developed to support + * a variety of world languages. Characters are distinguished from other + * symbols by putting them between single quotes ('P'). + * A string is a sequence of characters. A string is noted by surrounding + * a group of letters with double quotes ("Processing"). + * Chars and strings are most often used with the keyboard methods, + * to display text to the screen, and to load images or files. + */ + +PImage frog; +PFont font; +int xoffset; +char letter; + +void setup() +{ + size(200, 200, P2D); + + font = loadFont("Eureka-90.vlw"); + textFont(font); + // Draw text more accurately and efficiently. + textMode(SCREEN); + textAlign(CENTER); + + // The String datatype must be capitalized because it is a complex datatype. + // A String is actually a class with its own methods, some of which are + // featured below. + String name = "rathausFrog"; + String extension = ".jpg"; + int nameLength = name.length(); + println("The length of " + name + " is " + nameLength + "."); + name = name.concat(extension); + nameLength = name.length(); + println("The length of " + name + " is " + nameLength + "."); + + // The parameter for the loadImage() method must be a string + // This line could also be written "frog = loadImage("rathausFrog.jpg"); + frog = loadImage(name); +} + +void draw() +{ + background(51); // Set background to dark gray + + // Same as image(frog, xoffset, 0), but more efficient + // because no transformations or tint() or smooth() are used. + set(xoffset, 0, frog); + + // Draw an X + line(0, 0, width, height); + line(0, height, width, 0); + +// // Get the width of the letter +// float letterWidth = textWidth(letter); +// + // Draw the letter to the center of the screen + text(letter, width/2, height/2); +} + +void keyPressed() +{ + // The variable "key" always contains the value of the most recent key pressed. + // If the key is an upper or lowercase letter between 'A' and 'z' + // the image is shifted to the corresponding value of that key + if (key >= 'A' && key <= 'z') { + // Map the index of the key pressed from the range between 'A' and 'z', + // into a position for the left edge of the image. The maximum xoffset + // is the width of the drawing area minus the size of the image. + xoffset = int(map(key, 'A', 'z', 0, width - frog.width)); + // Update the letter shown to the screen + letter = key; + // Write the letter to the console + println(key); + } +} diff --git a/android/examples/Basics/Data/CharactersStrings/applet/CharactersStrings.java b/android/examples/Basics/Data/CharactersStrings/applet/CharactersStrings.java new file mode 100644 index 000000000..6d3433d02 --- /dev/null +++ b/android/examples/Basics/Data/CharactersStrings/applet/CharactersStrings.java @@ -0,0 +1,101 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class CharactersStrings extends PApplet { + +/** + * Characters Strings. + * + * Click on the image to give it focus and then type letters to + * shift the location of the image. + * Characters are typographic symbols such as A, d, and %. + * The character datatype, abbreviated as char, stores letters and + * symbols in the Unicode format, a coding system developed to support + * a variety of world languages. Characters are distinguished from other + * symbols by putting them between single quotes ('P'). + * A string is a sequence of characters. A string is noted by surrounding + * a group of letters with double quotes ("Processing"). + * Chars and strings are most often used with the keyboard methods, + * to display text to the screen, and to load images or files. + */ + +PImage frog; +PFont fontA; +int lettersize = 90; +int xoffset; +char letter; + +public void setup() +{ + size(200, 200); + fontA = loadFont("Eureka90.vlw"); + textFont(fontA); + textSize(lettersize); + + // The String datatype must be capitalized because it is a complex datatype. + // A String is actually a class with its own methods, some of which are + // featured below. + String name= "rathausFrog"; + String extension = ".jpg"; + int nameLength = name.length(); + println("The length of " + name + " is " + nameLength + "."); + name = name.concat(extension); + nameLength = name.length(); + println("The length of " + name + " is " + nameLength + "."); + + // The parameter for the loadImage() method must be a string + // This line could also be written "frog = loadImage("rathausFrog.jpg"); + frog = loadImage(name); +} + +public void draw() +{ + background(51); // Set background to dark gray + + image(frog, xoffset, 0); + + // Draw an X + line(0, 0, width, height); + line(0, height, width, 0); + + // Get the width of the letter + int letterWidth = PApplet.parseInt(fontA.width(letter) * lettersize); + + // Draw the letter to the center of the screen + text(letter, width/2-letterWidth/2, height/2); +} + +public void keyPressed() +{ + // The variable "key" always contains the value of the most recent key pressed. + // If the key is an upper or lowercase letter between 'A' and 'z' + // the image is shifted to the corresponding value of that key + if(key >= 'A' && key <= 'z') { + letter = PApplet.parseChar(key); + // Scale the values to numbers between 0 and 100 + float scale = 100.0f/57.0f; + int temp = PApplet.parseInt((key - 'A') * scale); + // Set the offset for the image + xoffset = temp; + println(key); + } +} + + + + + + static public void main(String args[]) { + PApplet.main(new String[] { "CharactersStrings" }); + } +} diff --git a/android/examples/Basics/Data/CharactersStrings/applet/CharactersStrings.pde b/android/examples/Basics/Data/CharactersStrings/applet/CharactersStrings.pde new file mode 100644 index 000000000..868037671 --- /dev/null +++ b/android/examples/Basics/Data/CharactersStrings/applet/CharactersStrings.pde @@ -0,0 +1,81 @@ +/** + * Characters Strings. + * + * Click on the image to give it focus and then type letters to + * shift the location of the image. + * Characters are typographic symbols such as A, d, and %. + * The character datatype, abbreviated as char, stores letters and + * symbols in the Unicode format, a coding system developed to support + * a variety of world languages. Characters are distinguished from other + * symbols by putting them between single quotes ('P'). + * A string is a sequence of characters. A string is noted by surrounding + * a group of letters with double quotes ("Processing"). + * Chars and strings are most often used with the keyboard methods, + * to display text to the screen, and to load images or files. + */ + +PImage frog; +PFont fontA; +int lettersize = 90; +int xoffset; +char letter; + +void setup() +{ + size(200, 200); + fontA = loadFont("Eureka90.vlw"); + textFont(fontA); + textSize(lettersize); + + // The String datatype must be capitalized because it is a complex datatype. + // A String is actually a class with its own methods, some of which are + // featured below. + String name= "rathausFrog"; + String extension = ".jpg"; + int nameLength = name.length(); + println("The length of " + name + " is " + nameLength + "."); + name = name.concat(extension); + nameLength = name.length(); + println("The length of " + name + " is " + nameLength + "."); + + // The parameter for the loadImage() method must be a string + // This line could also be written "frog = loadImage("rathausFrog.jpg"); + frog = loadImage(name); +} + +void draw() +{ + background(51); // Set background to dark gray + + image(frog, xoffset, 0); + + // Draw an X + line(0, 0, width, height); + line(0, height, width, 0); + + // Get the width of the letter + int letterWidth = int(fontA.width(letter) * lettersize); + + // Draw the letter to the center of the screen + text(letter, width/2-letterWidth/2, height/2); +} + +void keyPressed() +{ + // The variable "key" always contains the value of the most recent key pressed. + // If the key is an upper or lowercase letter between 'A' and 'z' + // the image is shifted to the corresponding value of that key + if(key >= 'A' && key <= 'z') { + letter = char(key); + // Scale the values to numbers between 0 and 100 + float scale = 100.0/57.0; + int temp = int((key - 'A') * scale); + // Set the offset for the image + xoffset = temp; + println(key); + } +} + + + + diff --git a/android/examples/Basics/Data/CharactersStrings/applet/loading.gif b/android/examples/Basics/Data/CharactersStrings/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Data/CharactersStrings/applet/loading.gif differ diff --git a/android/examples/Basics/Data/CharactersStrings/data/Eureka-90.vlw b/android/examples/Basics/Data/CharactersStrings/data/Eureka-90.vlw new file mode 100644 index 000000000..d78d18272 Binary files /dev/null and b/android/examples/Basics/Data/CharactersStrings/data/Eureka-90.vlw differ diff --git a/android/examples/Basics/Data/DatatypeConversion/DatatypeConversion.pde b/android/examples/Basics/Data/DatatypeConversion/DatatypeConversion.pde new file mode 100644 index 000000000..381afd181 --- /dev/null +++ b/android/examples/Basics/Data/DatatypeConversion/DatatypeConversion.pde @@ -0,0 +1,28 @@ +/** + * Datatype Conversion. + * + * It is sometimes beneficial to convert a value from one type of + * data to another. Each of the conversion functions converts its parameter + * to an equivalent representation within its datatype. + * The conversion functions include int(), float(), char(), byte(), and others. + */ + +size(200, 200); +background(51); +noStroke(); + +char c; // Chars are used for storing typographic symbols +float f; // Floats are decimal numbers +int i; // Ints are values between 2,147,483,647 and -2147483648 +byte b; // Bytes are values between -128 and 128 + +c = 'A'; +f = float(c); // Sets f = 65.0 +i = int(f * 1.4); // Sets i to 91 +b = byte(c / 2); // Sets b to 32 + +rect(f, 0, 40, 66); +fill(204); +rect(i, 67, 40, 66); +fill(255); +rect(b, 134, 40, 66); diff --git a/android/examples/Basics/Data/DatatypeConversion/applet/DatatypeConversion.java b/android/examples/Basics/Data/DatatypeConversion/applet/DatatypeConversion.java new file mode 100644 index 000000000..d9b5077a0 --- /dev/null +++ b/android/examples/Basics/Data/DatatypeConversion/applet/DatatypeConversion.java @@ -0,0 +1,49 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class DatatypeConversion extends PApplet { + public void setup() {/** + * Datatype Conversion. + * + * It is sometimes beneficial to convert a value from one type of + * data to another. Each of the conversion functions converts its parameter + * to an equivalent representation within its datatype. + * The conversion functions include int(), float(), char(), byte(), and others. + */ + +size(200, 200); +background(51); +noStroke(); + +char c; // Chars are used for storing typographic symbols +float f; // Floats are decimal numbers +int i; // Ints are values between 2,147,483,647 and -2147483648 +byte b; // Bytes are values between -128 and 128 + +c = 'A'; +f = PApplet.parseFloat(c); // Sets f = 65.0 +i = PApplet.parseInt(f * 1.4f); // Sets i to 91 +b = PApplet.parseByte(c / 2); // Sets b to 32 + +rect(f, 0, 40, 66); +fill(204); +rect(i, 67, 40, 66); +fill(255); +rect(b, 134, 40, 66); + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "DatatypeConversion" }); + } +} diff --git a/android/examples/Basics/Data/DatatypeConversion/applet/DatatypeConversion.pde b/android/examples/Basics/Data/DatatypeConversion/applet/DatatypeConversion.pde new file mode 100644 index 000000000..381afd181 --- /dev/null +++ b/android/examples/Basics/Data/DatatypeConversion/applet/DatatypeConversion.pde @@ -0,0 +1,28 @@ +/** + * Datatype Conversion. + * + * It is sometimes beneficial to convert a value from one type of + * data to another. Each of the conversion functions converts its parameter + * to an equivalent representation within its datatype. + * The conversion functions include int(), float(), char(), byte(), and others. + */ + +size(200, 200); +background(51); +noStroke(); + +char c; // Chars are used for storing typographic symbols +float f; // Floats are decimal numbers +int i; // Ints are values between 2,147,483,647 and -2147483648 +byte b; // Bytes are values between -128 and 128 + +c = 'A'; +f = float(c); // Sets f = 65.0 +i = int(f * 1.4); // Sets i to 91 +b = byte(c / 2); // Sets b to 32 + +rect(f, 0, 40, 66); +fill(204); +rect(i, 67, 40, 66); +fill(255); +rect(b, 134, 40, 66); diff --git a/android/examples/Basics/Data/DatatypeConversion/applet/loading.gif b/android/examples/Basics/Data/DatatypeConversion/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Data/DatatypeConversion/applet/loading.gif differ diff --git a/android/examples/Basics/Data/IntegersFloats/IntegersFloats.pde b/android/examples/Basics/Data/IntegersFloats/IntegersFloats.pde new file mode 100644 index 000000000..87bf67f19 --- /dev/null +++ b/android/examples/Basics/Data/IntegersFloats/IntegersFloats.pde @@ -0,0 +1,36 @@ +/** + * Integers Floats. + * + * Integers and floats are two different kinds of numerical data. + * An integer (more commonly called an int) is a number without + * a decimal point. A float is a floating-point number, which means + * it is a number that has a decimal place. Floats are used when + * more precision is needed. + */ + +int a = 0; // Create a variable "a" of the datatype "int" +float b = 0.0; // Create a variable "b" of the datatype "float" + +void setup() +{ + size(200, 200); + stroke(255); + frameRate(30); +} + +void draw() +{ + background(51); + + a = a + 1; + b = b + 0.2; + line(a, 0, a, height/2); + line(b, height/2, b, height); + + if(a > width) { + a = 0; + } + if(b > width) { + b = 0; + } +} diff --git a/android/examples/Basics/Data/IntegersFloats/applet/IntegersFloats.java b/android/examples/Basics/Data/IntegersFloats/applet/IntegersFloats.java new file mode 100644 index 000000000..e705fde4c --- /dev/null +++ b/android/examples/Basics/Data/IntegersFloats/applet/IntegersFloats.java @@ -0,0 +1,56 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class IntegersFloats extends PApplet { + +/** + * Integers Floats. + * + * Integers and floats are two different kinds of numerical data. + * An integer (more commonly called an int) is a number without + * a decimal point. A float is a floating-point number, which means + * it is a number that has a decimal place. Floats are used when + * more precision is needed. + */ + +int a = 0; // Create a variable "a" of the datatype "int" +float b = 0.0f; // Create a variable "b" of the datatype "float" + +public void setup() +{ + size(200, 200); + stroke(255); + frameRate(30); +} + +public void draw() +{ + background(51); + + a = a + 1; + b = b + 0.2f; + line(a, 0, a, height/2); + line(b, height/2, b, height); + + if(a > width) { + a = 0; + } + if(b > width) { + b = 0; + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "IntegersFloats" }); + } +} diff --git a/android/examples/Basics/Data/IntegersFloats/applet/IntegersFloats.pde b/android/examples/Basics/Data/IntegersFloats/applet/IntegersFloats.pde new file mode 100644 index 000000000..87bf67f19 --- /dev/null +++ b/android/examples/Basics/Data/IntegersFloats/applet/IntegersFloats.pde @@ -0,0 +1,36 @@ +/** + * Integers Floats. + * + * Integers and floats are two different kinds of numerical data. + * An integer (more commonly called an int) is a number without + * a decimal point. A float is a floating-point number, which means + * it is a number that has a decimal place. Floats are used when + * more precision is needed. + */ + +int a = 0; // Create a variable "a" of the datatype "int" +float b = 0.0; // Create a variable "b" of the datatype "float" + +void setup() +{ + size(200, 200); + stroke(255); + frameRate(30); +} + +void draw() +{ + background(51); + + a = a + 1; + b = b + 0.2; + line(a, 0, a, height/2); + line(b, height/2, b, height); + + if(a > width) { + a = 0; + } + if(b > width) { + b = 0; + } +} diff --git a/android/examples/Basics/Data/IntegersFloats/applet/loading.gif b/android/examples/Basics/Data/IntegersFloats/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Data/IntegersFloats/applet/loading.gif differ diff --git a/android/examples/Basics/Data/TrueFalse/TrueFalse.pde b/android/examples/Basics/Data/TrueFalse/TrueFalse.pde new file mode 100644 index 000000000..c4bb0531f --- /dev/null +++ b/android/examples/Basics/Data/TrueFalse/TrueFalse.pde @@ -0,0 +1,34 @@ +/** + * True/False. + * + * Boolean data is one bit of information. True or false. + * It is common to use Booleans with control statements to + * determine the flow of a program. In this example, when the + * boolean value "x" is true, vertical black lines are drawn and when + * the boolean value "x" is false, horizontal gray lines are drawn. + */ + +boolean x = false; + +size(200, 200); +background(0); +stroke(0); + +for (int i = 1; i < width; i += 2) +{ + if (i < width/2) { + x = true; + } else { + x = false; + } + + if (x) { + stroke(255); + line(i, 1, i, height-1); + } + + if (!x) { + stroke(126); + line(width/2 , i, width-2, i); + } +} diff --git a/android/examples/Basics/Data/TrueFalse/applet/TrueFalse.java b/android/examples/Basics/Data/TrueFalse/applet/TrueFalse.java new file mode 100644 index 000000000..0d30054b6 --- /dev/null +++ b/android/examples/Basics/Data/TrueFalse/applet/TrueFalse.java @@ -0,0 +1,55 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class TrueFalse extends PApplet { + public void setup() {/** + * True/False. + * + * Boolean data is one bit of information. True or false. + * It is common to use Booleans with control statements to + * determine the flow of a program. In this example, when the + * boolean value "x" is true, vertical black lines are drawn and when + * the boolean value "x" is false, horizontal gray lines are drawn. + */ + +boolean x = false; + +size(200, 200); +background(0); +stroke(0); + +for (int i = 1; i < width; i += 2) +{ + if (i < width/2) { + x = true; + } else { + x = false; + } + + if (x) { + stroke(255); + line(i, 1, i, height-1); + } + + if (!x) { + stroke(126); + line(width/2 , i, width-2, i); + } +} + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "TrueFalse" }); + } +} diff --git a/android/examples/Basics/Data/TrueFalse/applet/TrueFalse.pde b/android/examples/Basics/Data/TrueFalse/applet/TrueFalse.pde new file mode 100644 index 000000000..c4bb0531f --- /dev/null +++ b/android/examples/Basics/Data/TrueFalse/applet/TrueFalse.pde @@ -0,0 +1,34 @@ +/** + * True/False. + * + * Boolean data is one bit of information. True or false. + * It is common to use Booleans with control statements to + * determine the flow of a program. In this example, when the + * boolean value "x" is true, vertical black lines are drawn and when + * the boolean value "x" is false, horizontal gray lines are drawn. + */ + +boolean x = false; + +size(200, 200); +background(0); +stroke(0); + +for (int i = 1; i < width; i += 2) +{ + if (i < width/2) { + x = true; + } else { + x = false; + } + + if (x) { + stroke(255); + line(i, 1, i, height-1); + } + + if (!x) { + stroke(126); + line(width/2 , i, width-2, i); + } +} diff --git a/android/examples/Basics/Data/TrueFalse/applet/loading.gif b/android/examples/Basics/Data/TrueFalse/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Data/TrueFalse/applet/loading.gif differ diff --git a/android/examples/Basics/Data/VariableScope/VariableScope.pde b/android/examples/Basics/Data/VariableScope/VariableScope.pde new file mode 100644 index 000000000..8c2ae3559 --- /dev/null +++ b/android/examples/Basics/Data/VariableScope/VariableScope.pde @@ -0,0 +1,61 @@ +/** + * Variable Scope. + * + * Variables may either have a global or local "scope". + * For example, variables declared within either the + * setup() or loop() functions may be only used in these + * functions. Global variables, variables declared outside + * of setup() and loop(), may be used anywhere within the program. + * If a local variable is declared with the same name as a + * global variable, the program will use the local variable to make + * its calculations within the current scope. Variables may be localized + * within classes, functions, and iterative statements. + */ + +int a = 20; // Create a global variable "a" + +void setup() +{ + size(200, 200); + background(51); + stroke(255); + noLoop(); +} + +void draw() +{ + // Draw a line using the global variable "a" + line(a, 0, a, height); + + // Create a new variable "a" local to the for() statement + for(int a=50; a<80; a += 2) { + line(a, 0, a, height); + } + + // Create a new variable "a" local to the loop() method + int a = 100; + // Draw a line using the new local variable "a" + line(a, 0, a, height); + + // Make a call to the custom function drawAnotherLine() + drawAnotherLine(); + + // Make a call to the custom function setYetAnotherLine() + drawYetAnotherLine(); +} + +void drawAnotherLine() +{ + // Create a new variable "a" local to this method + int a = 185; + // Draw a line using the local variable "a" + line(a, 0, a, height); +} + +void drawYetAnotherLine() +{ + // Because no new local variable "a" is set, + // this lines draws using the original global + // variable "a" which is set to the value 20. + line(a+2, 0, a+2, height); +} diff --git a/android/examples/Basics/Data/VariableScope/applet/VariableScope.java b/android/examples/Basics/Data/VariableScope/applet/VariableScope.java new file mode 100644 index 000000000..426ba59a1 --- /dev/null +++ b/android/examples/Basics/Data/VariableScope/applet/VariableScope.java @@ -0,0 +1,81 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class VariableScope extends PApplet { + +/** + * Variable Scope. + * + * Variables may either have a global or local "scope". + * For example, variables declared within either the + * setup() or loop() functions may be only used in these + * functions. Global variables, variables declared outside + * of setup() and loop(), may be used anywhere within the program. + * If a local variable is declared with the same name as a + * global variable, the program will use the local variable to make + * its calculations within the current scope. Variables may be localized + * within classes, functions, and iterative statements. + */ + +int a = 20; // Create a global variable "a" + +public void setup() +{ + size(200, 200); + background(51); + stroke(255); + noLoop(); +} + +public void draw() +{ + // Draw a line using the global variable "a" + line(a, 0, a, height); + + // Create a new variable "a" local to the for() statement + for(int a=50; a<80; a += 2) { + line(a, 0, a, height); + } + + // Create a new variable "a" local to the loop() method + int a = 100; + // Draw a line using the new local variable "a" + line(a, 0, a, height); + + // Make a call to the custom function drawAnotherLine() + drawAnotherLine(); + + // Make a call to the custom function setYetAnotherLine() + drawYetAnotherLine(); +} + +public void drawAnotherLine() +{ + // Create a new variable "a" local to this method + int a = 185; + // Draw a line using the local variable "a" + line(a, 0, a, height); +} + +public void drawYetAnotherLine() +{ + // Because no new local variable "a" is set, + // this lines draws using the original global + // variable "a" which is set to the value 20. + line(a+2, 0, a+2, height); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "VariableScope" }); + } +} diff --git a/android/examples/Basics/Data/VariableScope/applet/VariableScope.pde b/android/examples/Basics/Data/VariableScope/applet/VariableScope.pde new file mode 100644 index 000000000..8c2ae3559 --- /dev/null +++ b/android/examples/Basics/Data/VariableScope/applet/VariableScope.pde @@ -0,0 +1,61 @@ +/** + * Variable Scope. + * + * Variables may either have a global or local "scope". + * For example, variables declared within either the + * setup() or loop() functions may be only used in these + * functions. Global variables, variables declared outside + * of setup() and loop(), may be used anywhere within the program. + * If a local variable is declared with the same name as a + * global variable, the program will use the local variable to make + * its calculations within the current scope. Variables may be localized + * within classes, functions, and iterative statements. + */ + +int a = 20; // Create a global variable "a" + +void setup() +{ + size(200, 200); + background(51); + stroke(255); + noLoop(); +} + +void draw() +{ + // Draw a line using the global variable "a" + line(a, 0, a, height); + + // Create a new variable "a" local to the for() statement + for(int a=50; a<80; a += 2) { + line(a, 0, a, height); + } + + // Create a new variable "a" local to the loop() method + int a = 100; + // Draw a line using the new local variable "a" + line(a, 0, a, height); + + // Make a call to the custom function drawAnotherLine() + drawAnotherLine(); + + // Make a call to the custom function setYetAnotherLine() + drawYetAnotherLine(); +} + +void drawAnotherLine() +{ + // Create a new variable "a" local to this method + int a = 185; + // Draw a line using the local variable "a" + line(a, 0, a, height); +} + +void drawYetAnotherLine() +{ + // Because no new local variable "a" is set, + // this lines draws using the original global + // variable "a" which is set to the value 20. + line(a+2, 0, a+2, height); +} diff --git a/android/examples/Basics/Data/VariableScope/applet/loading.gif b/android/examples/Basics/Data/VariableScope/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Data/VariableScope/applet/loading.gif differ diff --git a/android/examples/Basics/Data/Variables/Variables.pde b/android/examples/Basics/Data/Variables/Variables.pde new file mode 100644 index 000000000..9566ae472 --- /dev/null +++ b/android/examples/Basics/Data/Variables/Variables.pde @@ -0,0 +1,23 @@ +/** + * Variables. + * + * Variables are used for storing values. In this example, changing + * the values of variables 'a' and 'b' significantly change the composition. + */ + +size(200, 200); +background(0); +stroke(153); + +int a = 20; +int b = 50; +int c = a*8; +int d = a*9; +int e = b-a; +int f = b*2; +int g = f+e; + +line(a, f, b, g); +line(b, e, b, g); +line(b, e, d, c); +line(a, e, d-e, c); diff --git a/android/examples/Basics/Data/Variables/applet/Variables.java b/android/examples/Basics/Data/Variables/applet/Variables.java new file mode 100644 index 000000000..60471a43b --- /dev/null +++ b/android/examples/Basics/Data/Variables/applet/Variables.java @@ -0,0 +1,44 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Variables extends PApplet { + public void setup() {/** + * Variables. + * + * Variables are used for storing values. In this example, changing + * the values of variables 'a' and 'b' significantly change the composition. + */ + +size(200, 200); +background(0); +stroke(153); + +int a = 20; +int b = 50; +int c = a*8; +int d = a*9; +int e = b-a; +int f = b*2; +int g = f+e; + +line(a, f, b, g); +line(b, e, b, g); +line(b, e, d, c); +line(a, e, d-e, c); + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "Variables" }); + } +} diff --git a/android/examples/Basics/Data/Variables/applet/Variables.pde b/android/examples/Basics/Data/Variables/applet/Variables.pde new file mode 100644 index 000000000..9566ae472 --- /dev/null +++ b/android/examples/Basics/Data/Variables/applet/Variables.pde @@ -0,0 +1,23 @@ +/** + * Variables. + * + * Variables are used for storing values. In this example, changing + * the values of variables 'a' and 'b' significantly change the composition. + */ + +size(200, 200); +background(0); +stroke(153); + +int a = 20; +int b = 50; +int c = a*8; +int d = a*9; +int e = b-a; +int f = b*2; +int g = f+e; + +line(a, f, b, g); +line(b, e, b, g); +line(b, e, d, c); +line(a, e, d-e, c); diff --git a/android/examples/Basics/Data/Variables/applet/loading.gif b/android/examples/Basics/Data/Variables/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Data/Variables/applet/loading.gif differ diff --git a/android/examples/Basics/Form/Bezier/Bezier.pde b/android/examples/Basics/Form/Bezier/Bezier.pde new file mode 100644 index 000000000..e0b53db21 --- /dev/null +++ b/android/examples/Basics/Form/Bezier/Bezier.pde @@ -0,0 +1,18 @@ +/** + * Bezier. + * + * The first two parameters for the bezier() function specify the + * first point in the curve and the last two parameters specify + * the last point. The middle parameters set the control points + * that define the shape of the curve. + */ + +size(200, 200); +background(0); +stroke(255); +noFill(); +smooth(); + +for(int i = 0; i < 100; i += 20) { + bezier(90-(i/2.0), 20+i, 210, 10, 220, 150, 120-(i/8.0), 150+(i/4.0)); +} diff --git a/android/examples/Basics/Form/Bezier/applet/Bezier.java b/android/examples/Basics/Form/Bezier/applet/Bezier.java new file mode 100644 index 000000000..1b0a14a3b --- /dev/null +++ b/android/examples/Basics/Form/Bezier/applet/Bezier.java @@ -0,0 +1,39 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Bezier extends PApplet { + public void setup() {/** + * Bezier. + * + * The first two parameters for the bezier() function specify the + * first point in the curve and the last two parameters specify + * the last point. The middle parameters set the control points + * that define the shape of the curve. + */ + +size(200, 200); +background(0); +stroke(255); +noFill(); +smooth(); + +for(int i = 0; i < 100; i += 20) { + bezier(90-(i/2.0f), 20+i, 210, 10, 220, 150, 120-(i/8.0f), 150+(i/4.0f)); +} + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "Bezier" }); + } +} diff --git a/android/examples/Basics/Form/Bezier/applet/Bezier.pde b/android/examples/Basics/Form/Bezier/applet/Bezier.pde new file mode 100644 index 000000000..e0b53db21 --- /dev/null +++ b/android/examples/Basics/Form/Bezier/applet/Bezier.pde @@ -0,0 +1,18 @@ +/** + * Bezier. + * + * The first two parameters for the bezier() function specify the + * first point in the curve and the last two parameters specify + * the last point. The middle parameters set the control points + * that define the shape of the curve. + */ + +size(200, 200); +background(0); +stroke(255); +noFill(); +smooth(); + +for(int i = 0; i < 100; i += 20) { + bezier(90-(i/2.0), 20+i, 210, 10, 220, 150, 120-(i/8.0), 150+(i/4.0)); +} diff --git a/android/examples/Basics/Form/Bezier/applet/loading.gif b/android/examples/Basics/Form/Bezier/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Form/Bezier/applet/loading.gif differ diff --git a/android/examples/Basics/Form/BezierEllipse/BezierEllipse.pde b/android/examples/Basics/Form/BezierEllipse/BezierEllipse.pde new file mode 100644 index 000000000..7db555f8c --- /dev/null +++ b/android/examples/Basics/Form/BezierEllipse/BezierEllipse.pde @@ -0,0 +1,103 @@ +/** + * Bezier Ellipse + * By Ira Greenberg + * + * Generates an ellipse using bezier() and + * trig functions. Approximately every 1/2 + * second a new ellipse is plotted using + * random values for control/anchor points. + */ + +// arrays to hold ellipse coordinate data +float[] px, py, cx, cy, cx2, cy2; + +// global variable-points in ellipse +int pts = 4; + +color controlPtCol = #222222; +color anchorPtCol = #BBBBBB; + +void setup(){ + size(200, 200); + smooth(); + setEllipse(pts, 65, 65); + frameRate(1); +} + +void draw(){ + background(145); + drawEllipse(); + setEllipse(int(random(3, 12)), random(-100, 150), random(-100, 150)); +} + +// draw ellipse with anchor/control points +void drawEllipse(){ + strokeWeight(1.125); + stroke(255); + noFill(); + // create ellipse + for (int i=0; i0){ + line(px[i], py[i], cx2[i-1], cy2[i-1]); + } + line(px[i], py[i], cx[i], cy[i]); + } + + for ( int i=0; i< pts; i++){ + fill(controlPtCol); + noStroke(); + //control handles + ellipse(cx[i], cy[i], 4, 4); + ellipse(cx2[i], cy2[i], 4, 4); + + fill(anchorPtCol); + stroke(0); + //anchor points + rect(px[i], py[i], 5, 5); + } +} + +// fill up arrays with ellipse coordinate data +void setEllipse(int points, float radius, float controlRadius){ + pts = points; + px = new float[points]; + py = new float[points]; + cx = new float[points]; + cy = new float[points]; + cx2 = new float[points]; + cy2 = new float[points]; + float angle = 360.0/points; + float controlAngle1 = angle/3.0; + float controlAngle2 = controlAngle1*2.0; + for ( int i=0; i0){ + line(px[i], py[i], cx2[i-1], cy2[i-1]); + } + line(px[i], py[i], cx[i], cy[i]); + } + + for ( int i=0; i< pts; i++){ + fill(controlPtCol); + noStroke(); + //control handles + ellipse(cx[i], cy[i], 4, 4); + ellipse(cx2[i], cy2[i], 4, 4); + + fill(anchorPtCol); + stroke(0); + //anchor points + rect(px[i], py[i], 5, 5); + } +} + +// fill up arrays with ellipse coordinate data +public void setEllipse(int points, float radius, float controlRadius){ + pts = points; + px = new float[points]; + py = new float[points]; + cx = new float[points]; + cy = new float[points]; + cx2 = new float[points]; + cy2 = new float[points]; + float angle = 360.0f/points; + float controlAngle1 = angle/3.0f; + float controlAngle2 = controlAngle1*2.0f; + for ( int i=0; i0){ + line(px[i], py[i], cx2[i-1], cy2[i-1]); + } + line(px[i], py[i], cx[i], cy[i]); + } + + for ( int i=0; i< pts; i++){ + fill(controlPtCol); + noStroke(); + //control handles + ellipse(cx[i], cy[i], 4, 4); + ellipse(cx2[i], cy2[i], 4, 4); + + fill(anchorPtCol); + stroke(0); + //anchor points + rect(px[i], py[i], 5, 5); + } +} + +// fill up arrays with ellipse coordinate data +void setEllipse(int points, float radius, float controlRadius){ + pts = points; + px = new float[points]; + py = new float[points]; + cx = new float[points]; + cy = new float[points]; + cx2 = new float[points]; + cy2 = new float[points]; + float angle = 360.0/points; + float controlAngle1 = angle/3.0; + float controlAngle2 = controlAngle1*2.0; + for ( int i=0; i 1) { sa = 1; } + return 1-sa; +} + +float squared(float sa) { + sa = sa*sa; + return sa; +} diff --git a/android/examples/Basics/Form/SimpleCurves/applet/SimpleCurves.java b/android/examples/Basics/Form/SimpleCurves/applet/SimpleCurves.java new file mode 100644 index 000000000..7a6f48e93 --- /dev/null +++ b/android/examples/Basics/Form/SimpleCurves/applet/SimpleCurves.java @@ -0,0 +1,101 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class SimpleCurves extends PApplet { + +/** + * Simple Curves. + * + * Simple curves are drawn with simple equations. + * By using numbers with values between 0 and 1 in + * the equations, a series of elegant curves + * are created. The numbers are then scaled to fill the screen. + */ + +public void setup() { + size(200, 200); + colorMode(RGB, 100); + background(0); + noFill(); + noLoop(); +} + +public void draw() { + stroke(40); + beginShape(); + for(int i=0; i 1) { sa = 1; } + return 1-sa; +} + +public float squared(float sa) { + sa = sa*sa; + return sa; +} + + static public void main(String args[]) { + PApplet.main(new String[] { "SimpleCurves" }); + } +} diff --git a/android/examples/Basics/Form/SimpleCurves/applet/SimpleCurves.pde b/android/examples/Basics/Form/SimpleCurves/applet/SimpleCurves.pde new file mode 100644 index 000000000..8507d6dc1 --- /dev/null +++ b/android/examples/Basics/Form/SimpleCurves/applet/SimpleCurves.pde @@ -0,0 +1,81 @@ +/** + * Simple Curves. + * + * Simple curves are drawn with simple equations. + * By using numbers with values between 0 and 1 in + * the equations, a series of elegant curves + * are created. The numbers are then scaled to fill the screen. + */ + +void setup() { + size(200, 200); + colorMode(RGB, 100); + background(0); + noFill(); + noLoop(); +} + +void draw() { + stroke(40); + beginShape(); + for(int i=0; i 1) { sa = 1; } + return 1-sa; +} + +float squared(float sa) { + sa = sa*sa; + return sa; +} diff --git a/android/examples/Basics/Form/SimpleCurves/applet/loading.gif b/android/examples/Basics/Form/SimpleCurves/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Form/SimpleCurves/applet/loading.gif differ diff --git a/android/examples/Basics/Form/TriangleStrip/TriangleStrip.pde b/android/examples/Basics/Form/TriangleStrip/TriangleStrip.pde new file mode 100644 index 000000000..8ad1dbdc0 --- /dev/null +++ b/android/examples/Basics/Form/TriangleStrip/TriangleStrip.pde @@ -0,0 +1,36 @@ +/** + * TRIANGLE_STRIP Mode + * by Ira Greenberg. + * + * Generate a closed ring using vertex() + * function and beginShape(TRIANGLE_STRIP) + * mode. outerRad and innerRad variables + * control ring's outer/inner radii respectively. + * Trig functions generate ring. + */ + +size(200, 200); +background(204); +smooth(); + +int x = width/2; +int y = height/2; +float outerRad = min(width, height) * 0.4; +float innerRad = outerRad * 0.6; +float px = 0, py = 0, angle = 0; +float pts = 36; +float rot = 360.0/pts; + +beginShape(TRIANGLE_STRIP); +for (int i = 0; i < pts; i++) { + px = x + cos(radians(angle))*outerRad; + py = y + sin(radians(angle))*outerRad; + angle += rot; + vertex(px, py); + px = x + cos(radians(angle))*innerRad; + py = y + sin(radians(angle))*innerRad; + vertex(px, py); + angle += rot; +} +endShape(); + diff --git a/android/examples/Basics/Form/TriangleStrip/applet/TriangleStrip.java b/android/examples/Basics/Form/TriangleStrip/applet/TriangleStrip.java new file mode 100644 index 000000000..ece5f8d81 --- /dev/null +++ b/android/examples/Basics/Form/TriangleStrip/applet/TriangleStrip.java @@ -0,0 +1,57 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class TriangleStrip extends PApplet { + public void setup() {/** + * TRIANGLE_STRIP Mode + * By Ira Greenberg + * + * Generate a closed ring using vertex() + * function and beginShape(TRIANGLE_STRIP) + * mode. outerRad and innerRad variables + * control ring's outer/inner radii respectively. + * Trig functions generate ring. + */ + +size(200, 200); +background(204); +smooth(); + +int x = width/2; +int y = height/2; +int outerRad = 80; +int innerRad = 50; +float px = 0, py = 0, angle = 0; +float pts = 36; +float rot = 360.0f/pts; + +beginShape(TRIANGLE_STRIP); +for (int i = 0; i < pts; i++) { + px = x + cos(radians(angle))*outerRad; + py = y + sin(radians(angle))*outerRad; + angle += rot; + vertex(px, py); + px = x + cos(radians(angle))*innerRad; + py = y + sin(radians(angle))*innerRad; + vertex(px, py); + angle += rot; +} +endShape(); + + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "TriangleStrip" }); + } +} diff --git a/android/examples/Basics/Form/TriangleStrip/applet/TriangleStrip.pde b/android/examples/Basics/Form/TriangleStrip/applet/TriangleStrip.pde new file mode 100644 index 000000000..fdb99d032 --- /dev/null +++ b/android/examples/Basics/Form/TriangleStrip/applet/TriangleStrip.pde @@ -0,0 +1,36 @@ +/** + * TRIANGLE_STRIP Mode + * By Ira Greenberg + * + * Generate a closed ring using vertex() + * function and beginShape(TRIANGLE_STRIP) + * mode. outerRad and innerRad variables + * control ring's outer/inner radii respectively. + * Trig functions generate ring. + */ + +size(200, 200); +background(204); +smooth(); + +int x = width/2; +int y = height/2; +int outerRad = 80; +int innerRad = 50; +float px = 0, py = 0, angle = 0; +float pts = 36; +float rot = 360.0/pts; + +beginShape(TRIANGLE_STRIP); +for (int i = 0; i < pts; i++) { + px = x + cos(radians(angle))*outerRad; + py = y + sin(radians(angle))*outerRad; + angle += rot; + vertex(px, py); + px = x + cos(radians(angle))*innerRad; + py = y + sin(radians(angle))*innerRad; + vertex(px, py); + angle += rot; +} +endShape(); + diff --git a/android/examples/Basics/Form/TriangleStrip/applet/loading.gif b/android/examples/Basics/Form/TriangleStrip/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Form/TriangleStrip/applet/loading.gif differ diff --git a/android/examples/Basics/Form/Vertices/Vertices.pde b/android/examples/Basics/Form/Vertices/Vertices.pde new file mode 100644 index 000000000..f8c705650 --- /dev/null +++ b/android/examples/Basics/Form/Vertices/Vertices.pde @@ -0,0 +1,47 @@ +/** + * Vertices. + * + * The beginShape() function begins recording vertices + * for a shape and endShape() stops recording. + * A vertex is a location in space specified by X, Y, + * and sometimes Z coordinates. After calling the beginShape() function, + * a series of vertex() functions must follow. + * To stop drawing the shape, call the endShape() functions. + */ + +size(200, 200); +background(0); +noFill(); + +stroke(102); +beginShape(); +curveVertex(168, 182); +curveVertex(168, 182); +curveVertex(136, 38); +curveVertex(42, 34); +curveVertex(64, 200); +curveVertex(64, 200); +endShape(); + +stroke(51); +beginShape(LINES); +vertex(60, 40); +vertex(160, 10); +vertex(170, 150); +vertex(60, 150); +endShape(); + +stroke(126); +beginShape(); +vertex(60, 40); +bezierVertex(160, 10, 170, 150, 60, 150); +endShape(); + +stroke(255); +beginShape(POINTS); +vertex(60, 40); +vertex(160, 10); +vertex(170, 150); +vertex(60, 150); +endShape(); + diff --git a/android/examples/Basics/Form/Vertices/applet/Vertices.java b/android/examples/Basics/Form/Vertices/applet/Vertices.java new file mode 100644 index 000000000..062bc838f --- /dev/null +++ b/android/examples/Basics/Form/Vertices/applet/Vertices.java @@ -0,0 +1,68 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Vertices extends PApplet { + public void setup() {/** + * Vertices. + * + * The beginShape() function begins recording vertices + * for a shape and endShape() stops recording. + * A vertex is a location in space specified by X, Y, + * and sometimes Z coordinates. After calling the beginShape() function, + * a series of vertex() functions must follow. + * To stop drawing the shape, call the endShape() functions. + */ + +size(200, 200); +background(0); +noFill(); + +stroke(102); +beginShape(); +curveVertex(168, 182); +curveVertex(168, 182); +curveVertex(136, 38); +curveVertex(42, 34); +curveVertex(64, 200); +curveVertex(64, 200); +endShape(); + +stroke(51); +beginShape(LINES); +vertex(60, 40); +vertex(160, 10); +vertex(170, 150); +vertex(60, 150); +endShape(); + +stroke(126); +beginShape(); +vertex(60, 40); +bezierVertex(160, 10, 170, 150, 60, 150); +endShape(); + +stroke(255); +beginShape(POINTS); +vertex(60, 40); +vertex(160, 10); +vertex(170, 150); +vertex(60, 150); +endShape(); + + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "Vertices" }); + } +} diff --git a/android/examples/Basics/Form/Vertices/applet/Vertices.pde b/android/examples/Basics/Form/Vertices/applet/Vertices.pde new file mode 100644 index 000000000..f8c705650 --- /dev/null +++ b/android/examples/Basics/Form/Vertices/applet/Vertices.pde @@ -0,0 +1,47 @@ +/** + * Vertices. + * + * The beginShape() function begins recording vertices + * for a shape and endShape() stops recording. + * A vertex is a location in space specified by X, Y, + * and sometimes Z coordinates. After calling the beginShape() function, + * a series of vertex() functions must follow. + * To stop drawing the shape, call the endShape() functions. + */ + +size(200, 200); +background(0); +noFill(); + +stroke(102); +beginShape(); +curveVertex(168, 182); +curveVertex(168, 182); +curveVertex(136, 38); +curveVertex(42, 34); +curveVertex(64, 200); +curveVertex(64, 200); +endShape(); + +stroke(51); +beginShape(LINES); +vertex(60, 40); +vertex(160, 10); +vertex(170, 150); +vertex(60, 150); +endShape(); + +stroke(126); +beginShape(); +vertex(60, 40); +bezierVertex(160, 10, 170, 150, 60, 150); +endShape(); + +stroke(255); +beginShape(POINTS); +vertex(60, 40); +vertex(160, 10); +vertex(170, 150); +vertex(60, 150); +endShape(); + diff --git a/android/examples/Basics/Form/Vertices/applet/loading.gif b/android/examples/Basics/Form/Vertices/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Form/Vertices/applet/loading.gif differ diff --git a/android/examples/Basics/Image/Alphamask/Alphamask.pde b/android/examples/Basics/Image/Alphamask/Alphamask.pde new file mode 100644 index 000000000..59684e6a4 --- /dev/null +++ b/android/examples/Basics/Image/Alphamask/Alphamask.pde @@ -0,0 +1,24 @@ +/** + * Alpha Mask. + * + * Loads a "mask" for an image to specify the transparency + * in different parts of the image. The two images are blended + * together using the mask() method of PImage. + */ + +PImage img; +PImage maskImg; + +void setup() { + size(200, 200); + img = loadImage("test.jpg"); + maskImg = loadImage("mask.jpg"); + img.mask(maskImg); + imageMode(CENTER); +} + +void draw() { + background(map(mouseX+mouseY, 0, width+height, 0, 255)); + image(img, width/2, height/2); + image(img, mouseX, mouseY); +} diff --git a/android/examples/Basics/Image/Alphamask/applet/Alphamask.java b/android/examples/Basics/Image/Alphamask/applet/Alphamask.java new file mode 100644 index 000000000..2d0e3317d --- /dev/null +++ b/android/examples/Basics/Image/Alphamask/applet/Alphamask.java @@ -0,0 +1,45 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Alphamask extends PApplet { + +/** + * Alpha Mask. + * + * Loads a "mask" for an image to specify the transparency + * in different parts of the image. The two images are blended + * together using the mask() method of PImage. + */ + +PImage img; +PImage maskImg; + +public void setup() +{ + size(200,200); + img = loadImage("test.jpg"); + maskImg = loadImage("mask.jpg"); + img.mask(maskImg); +} + +public void draw() +{ + background((mouseX+mouseY)/1.5f); + image(img, 50, 50); + image(img, mouseX-50, mouseY-50); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Alphamask" }); + } +} diff --git a/android/examples/Basics/Image/Alphamask/applet/Alphamask.pde b/android/examples/Basics/Image/Alphamask/applet/Alphamask.pde new file mode 100644 index 000000000..6eb55ef9f --- /dev/null +++ b/android/examples/Basics/Image/Alphamask/applet/Alphamask.pde @@ -0,0 +1,25 @@ +/** + * Alpha Mask. + * + * Loads a "mask" for an image to specify the transparency + * in different parts of the image. The two images are blended + * together using the mask() method of PImage. + */ + +PImage img; +PImage maskImg; + +void setup() +{ + size(200,200); + img = loadImage("test.jpg"); + maskImg = loadImage("mask.jpg"); + img.mask(maskImg); +} + +void draw() +{ + background((mouseX+mouseY)/1.5); + image(img, 50, 50); + image(img, mouseX-50, mouseY-50); +} diff --git a/android/examples/Basics/Image/Alphamask/applet/loading.gif b/android/examples/Basics/Image/Alphamask/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Image/Alphamask/applet/loading.gif differ diff --git a/android/examples/Basics/Image/BackgroundImage/BackgroundImage.pde b/android/examples/Basics/Image/BackgroundImage/BackgroundImage.pde new file mode 100644 index 000000000..2c5f1aac8 --- /dev/null +++ b/android/examples/Basics/Image/BackgroundImage/BackgroundImage.pde @@ -0,0 +1,30 @@ +/** + * Background Image. + * + * This example presents the fastest way to load a background image + * into Processing. To load an image as the background, it must be + * the same width and height as the program. + */ + +PImage bg; +int a; + +void setup() +{ + size(200,200); + frameRate(30); + // The background image must be the same size as the parameters + // into the size() method. In this program, the size of "milan_rubbish.jpg" + // is 200 x 200 pixels. + bg = loadImage("milan_rubbish.jpg"); +} + +void draw() +{ + background(bg); + + a = (a + 1)%(width+32); + stroke(226, 204, 0); + line(0, a, width, a-26); + line(0, a-6, width, a-32); +} diff --git a/android/examples/Basics/Image/BackgroundImage/applet/BackgroundImage.java b/android/examples/Basics/Image/BackgroundImage/applet/BackgroundImage.java new file mode 100644 index 000000000..b56dafb5b --- /dev/null +++ b/android/examples/Basics/Image/BackgroundImage/applet/BackgroundImage.java @@ -0,0 +1,50 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class BackgroundImage extends PApplet { + +/** + * Background Image. + * + * This example presents the fastest way to load a background image + * into Processing. To load an image as the background, it must be + * the same width and height as the program. + */ + +PImage bg; +int a; + +public void setup() +{ + size(200,200); + frameRate(30); + // The background image must be the same size as the parameters + // into the size() method. In this program, the size of "milan_rubbish.jpg" + // is 200 x 200 pixels. + bg = loadImage("milan_rubbish.jpg"); +} + +public void draw() +{ + background(bg); + + a = (a + 1)%(width+32); + stroke(226, 204, 0); + line(0, a, width, a-26); + line(0, a-6, width, a-32); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "BackgroundImage" }); + } +} diff --git a/android/examples/Basics/Image/BackgroundImage/applet/BackgroundImage.pde b/android/examples/Basics/Image/BackgroundImage/applet/BackgroundImage.pde new file mode 100644 index 000000000..2c5f1aac8 --- /dev/null +++ b/android/examples/Basics/Image/BackgroundImage/applet/BackgroundImage.pde @@ -0,0 +1,30 @@ +/** + * Background Image. + * + * This example presents the fastest way to load a background image + * into Processing. To load an image as the background, it must be + * the same width and height as the program. + */ + +PImage bg; +int a; + +void setup() +{ + size(200,200); + frameRate(30); + // The background image must be the same size as the parameters + // into the size() method. In this program, the size of "milan_rubbish.jpg" + // is 200 x 200 pixels. + bg = loadImage("milan_rubbish.jpg"); +} + +void draw() +{ + background(bg); + + a = (a + 1)%(width+32); + stroke(226, 204, 0); + line(0, a, width, a-26); + line(0, a-6, width, a-32); +} diff --git a/android/examples/Basics/Image/BackgroundImage/applet/loading.gif b/android/examples/Basics/Image/BackgroundImage/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Image/BackgroundImage/applet/loading.gif differ diff --git a/android/examples/Basics/Image/CreateImage/CreateImage.pde b/android/examples/Basics/Image/CreateImage/CreateImage.pde new file mode 100644 index 000000000..df095a75e --- /dev/null +++ b/android/examples/Basics/Image/CreateImage/CreateImage.pde @@ -0,0 +1,24 @@ +/** + * Create Image. + * + * The createImage() function provides a fresh buffer of pixels to play with. + * This example creates an image gradient. + */ + +PImage img; + +void setup() +{ + size(200, 200); + img = createImage(120, 120, ARGB); + for(int i=0; i < img.pixels.length; i++) { + img.pixels[i] = color(0, 90, 102, i%img.width * 2); + } +} + +void draw() +{ + background(204); + image(img, 33, 33); + image(img, mouseX-60, mouseY-60); +} diff --git a/android/examples/Basics/Image/CreateImage/applet/CreateImage.java b/android/examples/Basics/Image/CreateImage/applet/CreateImage.java new file mode 100644 index 000000000..0ae2e5bd5 --- /dev/null +++ b/android/examples/Basics/Image/CreateImage/applet/CreateImage.java @@ -0,0 +1,44 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class CreateImage extends PApplet { + +/** + * Create Image. + * + * The createImage() function provides a fresh buffer of pixels to play with. + * This example creates an image gradient. + */ + +PImage img; + +public void setup() +{ + size(200, 200); + img = createImage(120, 120, ARGB); + for(int i=0; i < img.pixels.length; i++) { + img.pixels[i] = color(0, 90, 102, i%img.width * 2); + } +} + +public void draw() +{ + background(204); + image(img, 33, 33); + image(img, mouseX-60, mouseY-60); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "CreateImage" }); + } +} diff --git a/android/examples/Basics/Image/CreateImage/applet/CreateImage.pde b/android/examples/Basics/Image/CreateImage/applet/CreateImage.pde new file mode 100644 index 000000000..df095a75e --- /dev/null +++ b/android/examples/Basics/Image/CreateImage/applet/CreateImage.pde @@ -0,0 +1,24 @@ +/** + * Create Image. + * + * The createImage() function provides a fresh buffer of pixels to play with. + * This example creates an image gradient. + */ + +PImage img; + +void setup() +{ + size(200, 200); + img = createImage(120, 120, ARGB); + for(int i=0; i < img.pixels.length; i++) { + img.pixels[i] = color(0, 90, 102, i%img.width * 2); + } +} + +void draw() +{ + background(204); + image(img, 33, 33); + image(img, mouseX-60, mouseY-60); +} diff --git a/android/examples/Basics/Image/CreateImage/applet/loading.gif b/android/examples/Basics/Image/CreateImage/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Image/CreateImage/applet/loading.gif differ diff --git a/android/examples/Basics/Image/LoadDisplayImage/LoadDisplayImage.pde b/android/examples/Basics/Image/LoadDisplayImage/LoadDisplayImage.pde new file mode 100644 index 000000000..8252c5cbc --- /dev/null +++ b/android/examples/Basics/Image/LoadDisplayImage/LoadDisplayImage.pde @@ -0,0 +1,23 @@ +/** + * Load and Display + * + * Images can be loaded and displayed to the screen at their actual size + * or any other size. + */ + +PImage a; // Declare variable "a" of type PImage + +void setup() { + size(200, 200); + // The file "jelly.jpg" must be in the data folder + // of the current sketch to load successfully + a = loadImage("jelly.jpg"); // Load the image into the program + noLoop(); // Makes draw() only run once +} + +void draw() { + // Displays the image at its actual size at point (0,0) + image(a, 0, 0); + // Displays the image at point (100, 0) at half of its size + image(a, 100, 0, a.width/2, a.height/2); +} diff --git a/android/examples/Basics/Image/LoadDisplayImage/applet/LoadDisplayImage.java b/android/examples/Basics/Image/LoadDisplayImage/applet/LoadDisplayImage.java new file mode 100644 index 000000000..8807d2d60 --- /dev/null +++ b/android/examples/Basics/Image/LoadDisplayImage/applet/LoadDisplayImage.java @@ -0,0 +1,44 @@ +import processing.core.*; +import processing.xml.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class LoadDisplayImage extends PApplet { + +/** + * Load and Display + * + * Images can be loaded and displayed to the screen at their actual size + * or any other size. + */ + +PImage a; // Declare variable "a" of type PImage + +public void setup() { + size(200, 200); + // The file "jelly.jpg" must be in the data folder + // of the current sketch to load successfully + a = loadImage("jelly.jpg"); // Load the image into the program + noLoop(); // Makes draw() only run once +} + +public void draw() { + // Displays the image at its actual size at point (0,0) + image(a, 0, 0); + // Displays the image at point (100, 0) at half of its size + image(a, 100, 0, a.width/2, a.height/2); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "LoadDisplayImage" }); + } +} diff --git a/android/examples/Basics/Image/LoadDisplayImage/applet/LoadDisplayImage.pde b/android/examples/Basics/Image/LoadDisplayImage/applet/LoadDisplayImage.pde new file mode 100644 index 000000000..8252c5cbc --- /dev/null +++ b/android/examples/Basics/Image/LoadDisplayImage/applet/LoadDisplayImage.pde @@ -0,0 +1,23 @@ +/** + * Load and Display + * + * Images can be loaded and displayed to the screen at their actual size + * or any other size. + */ + +PImage a; // Declare variable "a" of type PImage + +void setup() { + size(200, 200); + // The file "jelly.jpg" must be in the data folder + // of the current sketch to load successfully + a = loadImage("jelly.jpg"); // Load the image into the program + noLoop(); // Makes draw() only run once +} + +void draw() { + // Displays the image at its actual size at point (0,0) + image(a, 0, 0); + // Displays the image at point (100, 0) at half of its size + image(a, 100, 0, a.width/2, a.height/2); +} diff --git a/android/examples/Basics/Image/LoadDisplayImage/applet/loading.gif b/android/examples/Basics/Image/LoadDisplayImage/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Image/LoadDisplayImage/applet/loading.gif differ diff --git a/android/examples/Basics/Image/Pointillism/Pointillism.pde b/android/examples/Basics/Image/Pointillism/Pointillism.pde new file mode 100644 index 000000000..3b7c96700 --- /dev/null +++ b/android/examples/Basics/Image/Pointillism/Pointillism.pde @@ -0,0 +1,38 @@ +/** + * Pointillism + * by Daniel Shiffman. + * + * Mouse horizontal location controls size of dots. + * Creates a simple pointillist effect using ellipses colored + * according to pixels in an image. + * + * Updated 27 February 2010. + */ + +PImage img; + +int smallPoint = 2; +int largePoint; +int top, left; + +void setup() { + size(200, 200); + img = loadImage("eames.jpg"); + //img = loadImage("sunflower.jpg"); // an alternative image + noStroke(); + background(255); + smooth(); + largePoint = min(width, height) / 10; + // center the image on the screen + left = (width - img.width) / 2; + top = (height - img.height) / 2; +} + +void draw() { + float pointillize = map(mouseX, 0, width, smallPoint, largePoint); + int x = int(random(img.width)); + int y = int(random(img.height)); + color pix = img.get(x, y); + fill(pix, 128); + ellipse(left + x, top + y, pointillize, pointillize); +} diff --git a/android/examples/Basics/Image/Pointillism/applet/Pointillism.java b/android/examples/Basics/Image/Pointillism/applet/Pointillism.java new file mode 100644 index 000000000..a80eac561 --- /dev/null +++ b/android/examples/Basics/Image/Pointillism/applet/Pointillism.java @@ -0,0 +1,49 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Pointillism extends PApplet { + +/** + * Pointillism + * by Daniel Shiffman. + * + * Mouse horizontal location controls size of dots. + * Creates a simple pointillist effect using ellipses colored + * according to pixels in an image. + */ + +PImage a; + +public void setup() +{ + a = loadImage("eames.jpg"); + size(200,200); + noStroke(); + background(255); + smooth(); +} + +public void draw() +{ + float pointillize = map(mouseX, 0, width, 2, 18); + int x = PApplet.parseInt(random(a.width)); + int y = PApplet.parseInt(random(a.height)); + int pix = a.get(x, y); + fill(pix, 126); + ellipse(x, y, pointillize, pointillize); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Pointillism" }); + } +} diff --git a/android/examples/Basics/Image/Pointillism/applet/Pointillism.pde b/android/examples/Basics/Image/Pointillism/applet/Pointillism.pde new file mode 100644 index 000000000..53f5c3a48 --- /dev/null +++ b/android/examples/Basics/Image/Pointillism/applet/Pointillism.pde @@ -0,0 +1,29 @@ +/** + * Pointillism + * by Daniel Shiffman. + * + * Mouse horizontal location controls size of dots. + * Creates a simple pointillist effect using ellipses colored + * according to pixels in an image. + */ + +PImage a; + +void setup() +{ + a = loadImage("eames.jpg"); + size(200,200); + noStroke(); + background(255); + smooth(); +} + +void draw() +{ + float pointillize = map(mouseX, 0, width, 2, 18); + int x = int(random(a.width)); + int y = int(random(a.height)); + color pix = a.get(x, y); + fill(pix, 126); + ellipse(x, y, pointillize, pointillize); +} diff --git a/android/examples/Basics/Image/Pointillism/applet/loading.gif b/android/examples/Basics/Image/Pointillism/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Image/Pointillism/applet/loading.gif differ diff --git a/android/examples/Basics/Image/RequestImage/RequestImage.pde b/android/examples/Basics/Image/RequestImage/RequestImage.pde new file mode 100644 index 000000000..0e835c7ca --- /dev/null +++ b/android/examples/Basics/Image/RequestImage/RequestImage.pde @@ -0,0 +1,91 @@ +/** + * Request Image + * by Ira Greenberg. + * From Processing for Flash Developers, Friends of ED, 2009. + * + * Shows how to use the requestImage() function with preloader animation. + * The requestImage() function loads images on a separate thread so that + * the sketch does not freeze while they load. It's very useful when you are + * loading large images, as this example demonstrates. + * + * To work, this example requires 10 images named dublin0.jpg ... dublin9.jpg + * in the sketch data directory. To save space, these images are not included + * with the example. + */ + +int imgCount = 10; +PImage[] imgs = new PImage[imgCount]; +float imgW; + +// Keeps track of loaded images (true or false) +boolean[] loadStates = new boolean[imgCount]; + +// For loading animation +float loaderX, loaderY, theta; + +void setup() { + size(800, 60); + smooth(); + imgW = width/imgCount; + + // Load images asynchronously + for (int i = 0; i < imgCount; i++){ + imgs[i] = requestImage("dublin"+i+".jpg"); + } +} + +void draw(){ + background(0); + + // Start loading animation + runLoaderAni(); + + for (int i = 0; i < imgs.length; i++){ + // Check if individual images are fully loaded + if ((imgs[i].width != 0) && (imgs[i].width != -1)){ + // As images are loaded set true in boolean array + loadStates[i] = true; + } + } + // When all images are loaded draw them to the screen + if (checkLoadStates()){ + drawImages(); + } +} + +void drawImages(){ + for (int i = 0; i < imgs.length; i++){ + image(imgs[i], width/10*i, 0, imgW, height); + } +} + +// Loading animation +void runLoaderAni(){ + // Only run when images are loading + if (!checkLoadStates()){ + ellipse(loaderX, loaderY, 10, 10); + loaderX += 2; + loaderY = height/2 + sin(theta) * (height/2.5); + theta += PI/22; + // Reposition ellipse if it goes off the screen + if (loaderX > width + 5){ + loaderX = -5; + } + } +} + +// Return true when all images are loaded - no false values left in array +boolean checkLoadStates(){ + for (int i = 0; i < imgs.length; i++){ + if (loadStates[i] == false){ + return false; + } + } + return true; +} + + + + + + diff --git a/android/examples/Basics/Image/Sprite/Sprite.pde b/android/examples/Basics/Image/Sprite/Sprite.pde new file mode 100644 index 000000000..2ea0c2782 --- /dev/null +++ b/android/examples/Basics/Image/Sprite/Sprite.pde @@ -0,0 +1,38 @@ +/** + * Sprite (Teddy) + * by James Patterson. + * + * Demonstrates loading and displaying a transparent GIF image. + */ + +PImage teddy; + +float xpos; +float ypos; +float drag = 30; + +void setup() { + size(200, 200); + teddy = loadImage("teddy.gif"); + xpos = width/2; + ypos = height/2; +} + +void draw() { + background(102); + + float difx = mouseX - xpos-teddy.width/2; + if (abs(difx) > 1) { + xpos = xpos + difx/drag; + xpos = constrain(xpos, 0, width-teddy.width); + } + + float dify = mouseY - ypos-teddy.height/2; + if (abs(dify) > 1) { + ypos = ypos + dify/drag; + ypos = constrain(ypos, 0, height-teddy.height); + } + + // Display the sprite at the position xpos, ypos + image(teddy, xpos, ypos); +} diff --git a/android/examples/Basics/Image/Sprite/applet/Sprite.java b/android/examples/Basics/Image/Sprite/applet/Sprite.java new file mode 100644 index 000000000..c777d010f --- /dev/null +++ b/android/examples/Basics/Image/Sprite/applet/Sprite.java @@ -0,0 +1,61 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Sprite extends PApplet { + +/** + * Sprite (Teddy) + * by James Patterson. + * + * Demonstrates loading and displaying a transparent GIF image. + */ + +PImage teddy; + +float xpos; +float ypos; +float drag = 30.0f; + +public void setup() +{ + size(200,200); + teddy = loadImage("teddy.gif"); + xpos = width/2; + ypos = height/2; + frameRate(60); +} + +public void draw() +{ + background(102); + + float difx = mouseX - xpos-teddy.width/2; + if(abs(difx) > 1.0f) { + xpos = xpos + difx/drag; + xpos = constrain(xpos, 0, width-teddy.width); + } + + float dify = mouseY - ypos-teddy.height/2; + if(abs(dify) > 1.0f) { + ypos = ypos + dify/drag; + ypos = constrain(ypos, 0, height-teddy.height); + } + + // Display the sprite at the position xpos, ypos + image(teddy, xpos, ypos); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Sprite" }); + } +} diff --git a/android/examples/Basics/Image/Sprite/applet/Sprite.pde b/android/examples/Basics/Image/Sprite/applet/Sprite.pde new file mode 100644 index 000000000..b46edfc2f --- /dev/null +++ b/android/examples/Basics/Image/Sprite/applet/Sprite.pde @@ -0,0 +1,41 @@ +/** + * Sprite (Teddy) + * by James Patterson. + * + * Demonstrates loading and displaying a transparent GIF image. + */ + +PImage teddy; + +float xpos; +float ypos; +float drag = 30.0; + +void setup() +{ + size(200,200); + teddy = loadImage("teddy.gif"); + xpos = width/2; + ypos = height/2; + frameRate(60); +} + +void draw() +{ + background(102); + + float difx = mouseX - xpos-teddy.width/2; + if(abs(difx) > 1.0) { + xpos = xpos + difx/drag; + xpos = constrain(xpos, 0, width-teddy.width); + } + + float dify = mouseY - ypos-teddy.height/2; + if(abs(dify) > 1.0) { + ypos = ypos + dify/drag; + ypos = constrain(ypos, 0, height-teddy.height); + } + + // Display the sprite at the position xpos, ypos + image(teddy, xpos, ypos); +} diff --git a/android/examples/Basics/Image/Sprite/applet/loading.gif b/android/examples/Basics/Image/Sprite/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Image/Sprite/applet/loading.gif differ diff --git a/android/examples/Basics/Image/Sprite/data/teddy.gif b/android/examples/Basics/Image/Sprite/data/teddy.gif new file mode 100644 index 000000000..8994c1bdd Binary files /dev/null and b/android/examples/Basics/Image/Sprite/data/teddy.gif differ diff --git a/android/examples/Basics/Image/Sprite2/Sprite2.pde b/android/examples/Basics/Image/Sprite2/Sprite2.pde new file mode 100644 index 000000000..dff97453a --- /dev/null +++ b/android/examples/Basics/Image/Sprite2/Sprite2.pde @@ -0,0 +1,45 @@ +/** + * Sprite2 (Teddy) + * by James Patterson. + * + * Demonstrates loading and displaying a transparent GIF image. + * This alternate version shows a sky image in the background. + */ + +PImage teddy; +PImage sky; + +float xpos; +float ypos; +float drag = 30.0; + +void setup() { + size(200, 200); + teddy = loadImage("teddy.gif"); + sky = loadImage("sky.jpg"); + xpos = width/2; + ypos = height/2; + // resize the background image so that it fills the screen + if (sky.width != width || sky.height != height) { + sky.resize(width, height); + } +} + +void draw() { + background(sky); + + float difx = mouseX - xpos-teddy.width/2; + if (abs(difx) > 1) { + xpos = xpos + difx/drag; + xpos = constrain(xpos, 0, width-teddy.width); + } + + float dify = mouseY - ypos-teddy.height/2; + if (abs(dify) > 1 ) { + ypos = ypos + dify/drag; + ypos = constrain(ypos, 0, height-teddy.height); + } + + // Display the sprite at the position xpos, ypos + image(teddy, xpos, ypos); +} diff --git a/android/examples/Basics/Image/Sprite2/data/teddy.gif b/android/examples/Basics/Image/Sprite2/data/teddy.gif new file mode 100644 index 000000000..8994c1bdd Binary files /dev/null and b/android/examples/Basics/Image/Sprite2/data/teddy.gif differ diff --git a/android/examples/Basics/Image/Transparency/Transparency.pde b/android/examples/Basics/Image/Transparency/Transparency.pde new file mode 100644 index 000000000..a528ddb35 --- /dev/null +++ b/android/examples/Basics/Image/Transparency/Transparency.pde @@ -0,0 +1,29 @@ +/** + * Transparency. + * + * Move the pointer left and right across the image to change + * its position. This program overlays one image over another + * by modifying the alpha value of the image with the tint() function. + */ + +PImage a, b; +float offset; + +void setup() { + size(200, 200); + a = loadImage("construct.jpg"); // Load an image into the program + b = loadImage("wash.jpg"); // Load an image into the program +} + +void draw() { + image(a, 0, 0); + float offsetTarget = map(mouseX, 0, width, -b.width/2 - width/2, 0); + offset += (offsetTarget-offset)*0.05; + tint(255, 153); + image(b, offset, 20); +} + + + + + diff --git a/android/examples/Basics/Image/Transparency/applet/Transparency.java b/android/examples/Basics/Image/Transparency/applet/Transparency.java new file mode 100644 index 000000000..1aff169ee --- /dev/null +++ b/android/examples/Basics/Image/Transparency/applet/Transparency.java @@ -0,0 +1,50 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Transparency extends PApplet { + +/** + * Transparency. + * + * Move the pointer left and right across the image to change + * its position. This program overlays one image over another + * by modifying the alpha value of the image with the tint() function. + */ + +PImage a, b; +float offset; + +public void setup() { + size(200, 200); + a = loadImage("construct.jpg"); // Load an image into the program + b = loadImage("wash.jpg"); // Load an image into the program + frameRate(60); +} + +public void draw() { + image(a, 0, 0); + float offsetTarget = map(mouseX, 0, width, -b.width/2 - width/2, 0); + offset += (offsetTarget-offset)*0.05f; + tint(255, 153); + image(b, offset, 20); +} + + + + + + + static public void main(String args[]) { + PApplet.main(new String[] { "Transparency" }); + } +} diff --git a/android/examples/Basics/Image/Transparency/applet/Transparency.pde b/android/examples/Basics/Image/Transparency/applet/Transparency.pde new file mode 100644 index 000000000..ec4f66658 --- /dev/null +++ b/android/examples/Basics/Image/Transparency/applet/Transparency.pde @@ -0,0 +1,30 @@ +/** + * Transparency. + * + * Move the pointer left and right across the image to change + * its position. This program overlays one image over another + * by modifying the alpha value of the image with the tint() function. + */ + +PImage a, b; +float offset; + +void setup() { + size(200, 200); + a = loadImage("construct.jpg"); // Load an image into the program + b = loadImage("wash.jpg"); // Load an image into the program + frameRate(60); +} + +void draw() { + image(a, 0, 0); + float offsetTarget = map(mouseX, 0, width, -b.width/2 - width/2, 0); + offset += (offsetTarget-offset)*0.05; + tint(255, 153); + image(b, offset, 20); +} + + + + + diff --git a/android/examples/Basics/Image/Transparency/applet/loading.gif b/android/examples/Basics/Image/Transparency/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Image/Transparency/applet/loading.gif differ diff --git a/android/examples/Basics/Input/Clock/Clock.pde b/android/examples/Basics/Input/Clock/Clock.pde new file mode 100644 index 000000000..27ce7b334 --- /dev/null +++ b/android/examples/Basics/Input/Clock/Clock.pde @@ -0,0 +1,64 @@ +/** + * Clock. + * + * The current time can be read with the second(), minute(), + * and hour() functions. In this example, sin() and cos() values + * are used to set the position of the hands. + * + * Updated 27 February 2010 to handle size() changes. + */ + +int cx, cy; +float secondsRadius; +float minutesRadius; +float hoursRadius; +float clockDiameter; + +void setup() { + size(200, 200); + stroke(255); + smooth(); + + int radius = min(width, height) / 2; + secondsRadius = radius * 0.72; + minutesRadius = radius * 0.60; + hoursRadius = radius * 0.50; + clockDiameter = radius * 1.8; + + cx = width / 2; + cy = height / 2; +} + +void draw2() { + background(0); + + // Draw the clock background + fill(80); + noStroke(); + ellipse(cx, cy, clockDiameter, clockDiameter); + + // Angles for sin() and cos() start at 3 o'clock; + // subtract HALF_PI to make them start at the top + float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI; + float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI; + float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI; + + // Draw the hands of the clock + stroke(255); + strokeWeight(1); + line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius); + strokeWeight(2); + line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius); + strokeWeight(4); + line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius); + + // Draw the minute ticks + strokeWeight(2); + beginShape(POINTS); + for (int a = 0; a < 360; a+=6) { + float x = cx + cos(radians(a)) * secondsRadius; + float y = cy + sin(radians(a)) * secondsRadius; + vertex(x, y); + } + endShape(); +} diff --git a/android/examples/Basics/Input/Clock/applet/Clock.java b/android/examples/Basics/Input/Clock/applet/Clock.java new file mode 100644 index 000000000..7e3412158 --- /dev/null +++ b/android/examples/Basics/Input/Clock/applet/Clock.java @@ -0,0 +1,59 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Clock extends PApplet { + +/** + * Clock. + * + * The current time can be read with the second(), minute(), + * and hour() functions. In this example, sin() and cos() values + * are used to set the position of the hands. + */ + +public void setup() { + size(200, 200); + stroke(255); + smooth(); +} +public void draw() { + background(0); + fill(80); + noStroke(); + // Angles for sin() and cos() start at 3 o'clock; + // subtract HALF_PI to make them start at the top + ellipse(100, 100, 160, 160); + float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI; + float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI; + float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI; + stroke(255); + strokeWeight(1); + line(100, 100, cos(s) * 72 + 100, sin(s) * 72 + 100); + strokeWeight(2); + line(100, 100, cos(m) * 60 + 100, sin(m) * 60 + 100); + strokeWeight(4); + line(100, 100, cos(h) * 50 + 100, sin(h) * 50 + 100); + + // Draw the minute ticks + strokeWeight(2); + for (int a = 0; a < 360; a+=6) { + float x = 100 + ( cos(radians(a)) * 72 ); + float y = 100 + ( sin(radians(a)) * 72 ); + point(x, y); + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Clock" }); + } +} diff --git a/android/examples/Basics/Input/Clock/applet/Clock.pde b/android/examples/Basics/Input/Clock/applet/Clock.pde new file mode 100644 index 000000000..397af66f0 --- /dev/null +++ b/android/examples/Basics/Input/Clock/applet/Clock.pde @@ -0,0 +1,39 @@ +/** + * Clock. + * + * The current time can be read with the second(), minute(), + * and hour() functions. In this example, sin() and cos() values + * are used to set the position of the hands. + */ + +void setup() { + size(200, 200); + stroke(255); + smooth(); +} +void draw() { + background(0); + fill(80); + noStroke(); + // Angles for sin() and cos() start at 3 o'clock; + // subtract HALF_PI to make them start at the top + ellipse(100, 100, 160, 160); + float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI; + float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI; + float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI; + stroke(255); + strokeWeight(1); + line(100, 100, cos(s) * 72 + 100, sin(s) * 72 + 100); + strokeWeight(2); + line(100, 100, cos(m) * 60 + 100, sin(m) * 60 + 100); + strokeWeight(4); + line(100, 100, cos(h) * 50 + 100, sin(h) * 50 + 100); + + // Draw the minute ticks + strokeWeight(2); + for (int a = 0; a < 360; a+=6) { + float x = 100 + ( cos(radians(a)) * 72 ); + float y = 100 + ( sin(radians(a)) * 72 ); + point(x, y); + } +} diff --git a/android/examples/Basics/Input/Clock/applet/loading.gif b/android/examples/Basics/Input/Clock/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Input/Clock/applet/loading.gif differ diff --git a/android/examples/Basics/Input/Constrain/Constrain.pde b/android/examples/Basics/Input/Constrain/Constrain.pde new file mode 100644 index 000000000..84fcf06fe --- /dev/null +++ b/android/examples/Basics/Input/Constrain/Constrain.pde @@ -0,0 +1,41 @@ +/** + * Constrain. + * + * Move the mouse across the screen to move the circle. + * The program constrains the circle to its box. + * + * Updated 27 February 2010 to handle changes in size(). + */ + +float mx; +float my; +float easing = 0.05; +int radius = 24; +int edge = 56; +int inner = edge + radius; + +void setup() { + size(200, 200); + noStroke(); + smooth(); + ellipseMode(RADIUS); + rectMode(CORNERS); +} + +void draw() { + background(51); + + if (abs(mouseX - mx) > 0.1) { + mx = mx + (mouseX - mx) * easing; + } + if (abs(mouseY - my) > 0.1) { + my = my + (mouseY- my) * easing; + } + + mx = constrain(mx, inner, width - inner); + my = constrain(my, inner, height - inner); + fill(76); + rect(edge, edge, width-edge, height-edge); + fill(255); + ellipse(mx, my, radius, radius); +} diff --git a/android/examples/Basics/Input/Constrain/applet/Constrain.java b/android/examples/Basics/Input/Constrain/applet/Constrain.java new file mode 100644 index 000000000..1a11e1e02 --- /dev/null +++ b/android/examples/Basics/Input/Constrain/applet/Constrain.java @@ -0,0 +1,60 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Constrain extends PApplet { + +/** + * Constrain. + * + * Move the mouse across the screen to move the circle. + * The program constrains the circle to its box. + */ + +float mx; +float my; +float easing = 0.05f; +float esize = 25.0f; +int box = 30; + +public void setup() +{ + size(200, 200); + noStroke(); + smooth(); + ellipseMode(CENTER_RADIUS); +} + +public void draw() +{ + background(51); + + if(abs(mouseX - mx) > 0.1f) { + mx = mx + (mouseX - mx) * easing; + } + if(abs(mouseY - my) > 0.1f) { + my = my + (mouseY- my) * easing; + } + + float distance = esize * 2; + mx = constrain(mx, box+distance, width-box-distance); + my = constrain(my, box+distance, height-box-distance); + fill(76); + rect(box+esize, box+esize, box*3, box*3); + fill(255); + ellipse(mx, my, esize, esize); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Constrain" }); + } +} diff --git a/android/examples/Basics/Input/Constrain/applet/Constrain.pde b/android/examples/Basics/Input/Constrain/applet/Constrain.pde new file mode 100644 index 000000000..6d57b97d6 --- /dev/null +++ b/android/examples/Basics/Input/Constrain/applet/Constrain.pde @@ -0,0 +1,40 @@ +/** + * Constrain. + * + * Move the mouse across the screen to move the circle. + * The program constrains the circle to its box. + */ + +float mx; +float my; +float easing = 0.05; +float esize = 25.0; +int box = 30; + +void setup() +{ + size(200, 200); + noStroke(); + smooth(); + ellipseMode(CENTER_RADIUS); +} + +void draw() +{ + background(51); + + if(abs(mouseX - mx) > 0.1) { + mx = mx + (mouseX - mx) * easing; + } + if(abs(mouseY - my) > 0.1) { + my = my + (mouseY- my) * easing; + } + + float distance = esize * 2; + mx = constrain(mx, box+distance, width-box-distance); + my = constrain(my, box+distance, height-box-distance); + fill(76); + rect(box+esize, box+esize, box*3, box*3); + fill(255); + ellipse(mx, my, esize, esize); +} diff --git a/android/examples/Basics/Input/Constrain/applet/loading.gif b/android/examples/Basics/Input/Constrain/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Input/Constrain/applet/loading.gif differ diff --git a/android/examples/Basics/Input/Easing/Easing.pde b/android/examples/Basics/Input/Easing/Easing.pde new file mode 100644 index 000000000..a09011639 --- /dev/null +++ b/android/examples/Basics/Input/Easing/Easing.pde @@ -0,0 +1,41 @@ +/** + * Easing. + * + * Move the mouse across the screen and the symbol will follow. + * Between drawing each frame of the animation, the program + * calculates the difference between the position of the + * symbol and the cursor. If the distance is larger than + * 1 pixel, the symbol moves part of the distance (0.05) from its + * current position toward the cursor. + */ + +float x; +float y; +float targetX, targetY; +float easing = 0.05; + +void setup() +{ + size(200, 200); + smooth(); + noStroke(); +} + +void draw() +{ + background( 51 ); + + targetX = mouseX; + float dx = targetX - x; + if(abs(dx) > 1) { + x += dx * easing; + } + + targetY = mouseY; + float dy = targetY - y; + if(abs(dy) > 1) { + y += dy * easing; + } + + ellipse(x, y, 33, 33); +} diff --git a/android/examples/Basics/Input/Easing/applet/Easing.java b/android/examples/Basics/Input/Easing/applet/Easing.java new file mode 100644 index 000000000..7e6f2749f --- /dev/null +++ b/android/examples/Basics/Input/Easing/applet/Easing.java @@ -0,0 +1,61 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Easing extends PApplet { + +/** + * Easing. + * + * Move the mouse across the screen and the symbol will follow. + * Between drawing each frame of the animation, the program + * calculates the difference between the position of the + * symbol and the cursor. If the distance is larger than + * 1 pixel, the symbol moves part of the distance (0.05) from its + * current position toward the cursor. + */ + +float x; +float y; +float targetX, targetY; +float easing = 0.05f; + +public void setup() +{ + size(200, 200); + smooth(); + noStroke(); +} + +public void draw() +{ + background( 51 ); + + targetX = mouseX; + float dx = mouseX - x; + if(abs(dx) > 1) { + x += dx * easing; + } + + targetY = mouseY; + float dy = mouseY - y; + if(abs(dy) > 1) { + y += dy * easing; + } + + ellipse(x, y, 33, 33); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Easing" }); + } +} diff --git a/android/examples/Basics/Input/Easing/applet/Easing.pde b/android/examples/Basics/Input/Easing/applet/Easing.pde new file mode 100644 index 000000000..9ef837afc --- /dev/null +++ b/android/examples/Basics/Input/Easing/applet/Easing.pde @@ -0,0 +1,41 @@ +/** + * Easing. + * + * Move the mouse across the screen and the symbol will follow. + * Between drawing each frame of the animation, the program + * calculates the difference between the position of the + * symbol and the cursor. If the distance is larger than + * 1 pixel, the symbol moves part of the distance (0.05) from its + * current position toward the cursor. + */ + +float x; +float y; +float targetX, targetY; +float easing = 0.05; + +void setup() +{ + size(200, 200); + smooth(); + noStroke(); +} + +void draw() +{ + background( 51 ); + + targetX = mouseX; + float dx = mouseX - x; + if(abs(dx) > 1) { + x += dx * easing; + } + + targetY = mouseY; + float dy = mouseY - y; + if(abs(dy) > 1) { + y += dy * easing; + } + + ellipse(x, y, 33, 33); +} diff --git a/android/examples/Basics/Input/Easing/applet/loading.gif b/android/examples/Basics/Input/Easing/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Input/Easing/applet/loading.gif differ diff --git a/android/examples/Basics/Input/Keyboard/Keyboard.pde b/android/examples/Basics/Input/Keyboard/Keyboard.pde new file mode 100644 index 000000000..3eba1f1d2 --- /dev/null +++ b/android/examples/Basics/Input/Keyboard/Keyboard.pde @@ -0,0 +1,39 @@ +/** + * Keyboard. + * + * Click on the image to give it focus and press the letter keys + * to create forms in time and space. Each key has a unique identifying + * number called its ASCII value. These numbers can be used to position + * shapes in space. + */ + +int rectWidth; + +void setup() { + size(200, 200); + noStroke(); + background(0); + rectWidth = width/4; +} + +void draw() { + // keep draw() here to continue looping while waiting for keys +} + +void keyPressed() { + int keyIndex = -1; + if (key >= 'A' && key <= 'Z') { + keyIndex = key - 'A'; + } else if (key >= 'a' && key <= 'z') { + keyIndex = key - 'a'; + } + if (keyIndex == -1) { + // If it's not a letter key, clear the screen + background(0); + } else { + // It's a letter key, fill a rectangle + fill(millis() % 255); + float x = map(keyIndex, 0, 25, 0, width - rectWidth); + rect(x, 0, rectWidth, height); + } +} diff --git a/android/examples/Basics/Input/Keyboard/applet/Keyboard.java b/android/examples/Basics/Input/Keyboard/applet/Keyboard.java new file mode 100644 index 000000000..73d9c7202 --- /dev/null +++ b/android/examples/Basics/Input/Keyboard/applet/Keyboard.java @@ -0,0 +1,60 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Keyboard extends PApplet { + +/** + * Keyboard. + * + * Click on the image to give it focus and press the letter keys + * to create forms in time and space. Each key has a unique identifying + * number called it's ASCII value. These numbers can be used to position + * shapes in space. + */ + +int numChars = 26; +int[] colors = new int[numChars]; +int keyIndex; +float keyScale; +int rectWidth; + + +public void setup() +{ + size(200, 200); + noStroke(); + background(0); + keyScale = 200/numChars-1.0f; + rectWidth = width/4; +} + +public void draw() +{ + if(keyPressed) { + if(key >= 'A' && key <= 'z') { + if(key <= 'Z') { + keyIndex = key-'A'; + } else { + keyIndex = key-'a'; + } + fill(millis()%255); + float beginRect = rectWidth/2 + keyIndex*keyScale-rectWidth/2; + rect(beginRect, 0.0f, rectWidth, height); + } + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Keyboard" }); + } +} diff --git a/android/examples/Basics/Input/Keyboard/applet/Keyboard.pde b/android/examples/Basics/Input/Keyboard/applet/Keyboard.pde new file mode 100644 index 000000000..ee1a3c156 --- /dev/null +++ b/android/examples/Basics/Input/Keyboard/applet/Keyboard.pde @@ -0,0 +1,40 @@ +/** + * Keyboard. + * + * Click on the image to give it focus and press the letter keys + * to create forms in time and space. Each key has a unique identifying + * number called it's ASCII value. These numbers can be used to position + * shapes in space. + */ + +int numChars = 26; +color[] colors = new color[numChars]; +int keyIndex; +float keyScale; +int rectWidth; + + +void setup() +{ + size(200, 200); + noStroke(); + background(0); + keyScale = 200/numChars-1.0; + rectWidth = width/4; +} + +void draw() +{ + if(keyPressed) { + if(key >= 'A' && key <= 'z') { + if(key <= 'Z') { + keyIndex = key-'A'; + } else { + keyIndex = key-'a'; + } + fill(millis()%255); + float beginRect = rectWidth/2 + keyIndex*keyScale-rectWidth/2; + rect(beginRect, 0.0, rectWidth, height); + } + } +} diff --git a/android/examples/Basics/Input/Keyboard/applet/loading.gif b/android/examples/Basics/Input/Keyboard/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Input/Keyboard/applet/loading.gif differ diff --git a/android/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde b/android/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde new file mode 100644 index 000000000..882e92d63 --- /dev/null +++ b/android/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde @@ -0,0 +1,89 @@ +/** + * Keyboard Functions. + * Modified from code by Martin. + * Original 'Color Typewriter' concept by John Maeda. + * + * Click on the window to give it focus and press the letter keys to type colors. + * The keyboard function keyPressed() is called whenever + * a key is pressed. keyReleased() is another keyboard + * function that is called when a key is released. + */ + +int max_height = 20; +int min_height = 10; +int letter_height = max_height; // Height of the letters +int letter_width = 10; // Width of the letter + +int x = -letter_width; // X position of the letters +int y = 0; // Y position of the letters + +boolean newletter; + +int numChars = 26; // There are 26 characters in the alphabet +color[] colors = new color[numChars]; + +void setup() +{ + size(200, 200); + noStroke(); + colorMode(RGB, numChars); + background(numChars/2); + // Set a gray value for each key + for(int i=0; i= 'A' && key <= 'z') { + int keyIndex; + if(key <= 'Z') { + keyIndex = key-'A'; + letter_height = max_height; + fill(colors[key-'A']); + } else { + keyIndex = key-'a'; + letter_height = min_height; + fill(colors[key-'a']); + } + } else { + fill(0); + letter_height = 10; + } + + newletter = true; + + // Update the "letter" position + x = ( x + letter_width ); + + // Wrap horizontally + if (x > width - letter_width) { + x = 0; + y+= max_height; + } + + // Wrap vertically + if( y > height - letter_height) { + y = 0; // reset y to 0 + } +} diff --git a/android/examples/Basics/Input/KeyboardFunctions/applet/KeyboardFunctions.java b/android/examples/Basics/Input/KeyboardFunctions/applet/KeyboardFunctions.java new file mode 100644 index 000000000..7d7d4b2f4 --- /dev/null +++ b/android/examples/Basics/Input/KeyboardFunctions/applet/KeyboardFunctions.java @@ -0,0 +1,109 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class KeyboardFunctions extends PApplet { + +/** + * Keyboard Functions. + * Modified from code by Martin. + * Original 'Color Typewriter' concept by John Maeda. + * + * Click on the window to give it focus and press the letter keys to type colors. + * The keyboard function keyPressed() is called whenever + * a key is pressed. keyReleased() is another keyboard + * function that is called when a key is released. + */ + +int max_height = 20; +int min_height = 10; +int letter_height = max_height; // Height of the letters +int letter_width = 10; // Width of the letter + +int x = -letter_width; // X position of the letters +int y = 0; // Y position of the letters + +boolean newletter; + +int numChars = 26; // There are 26 characters in the alphabet +int[] colors = new int[numChars]; + +public void setup() +{ + size(200, 200); + noStroke(); + colorMode(RGB, numChars); + background(numChars/2); + // Set a gray value for each key + for(int i=0; i= 'A' && key <= 'z') { + int keyIndex; + if(key <= 'Z') { + keyIndex = key-'A'; + letter_height = max_height; + fill(colors[key-'A']); + } else { + keyIndex = key-'a'; + letter_height = min_height; + fill(colors[key-'a']); + } + } else { + fill(0); + letter_height = 10; + } + + newletter = true; + + // Update the "letter" position + x = ( x + letter_width ); + + // Wrap horizontally + if (x > width - letter_width) { + x = 0; + y+= max_height; + } + + // Wrap vertically + if( y > height - letter_height) { + y = 0; // reset y to 0 + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "KeyboardFunctions" }); + } +} diff --git a/android/examples/Basics/Input/KeyboardFunctions/applet/KeyboardFunctions.pde b/android/examples/Basics/Input/KeyboardFunctions/applet/KeyboardFunctions.pde new file mode 100644 index 000000000..882e92d63 --- /dev/null +++ b/android/examples/Basics/Input/KeyboardFunctions/applet/KeyboardFunctions.pde @@ -0,0 +1,89 @@ +/** + * Keyboard Functions. + * Modified from code by Martin. + * Original 'Color Typewriter' concept by John Maeda. + * + * Click on the window to give it focus and press the letter keys to type colors. + * The keyboard function keyPressed() is called whenever + * a key is pressed. keyReleased() is another keyboard + * function that is called when a key is released. + */ + +int max_height = 20; +int min_height = 10; +int letter_height = max_height; // Height of the letters +int letter_width = 10; // Width of the letter + +int x = -letter_width; // X position of the letters +int y = 0; // Y position of the letters + +boolean newletter; + +int numChars = 26; // There are 26 characters in the alphabet +color[] colors = new color[numChars]; + +void setup() +{ + size(200, 200); + noStroke(); + colorMode(RGB, numChars); + background(numChars/2); + // Set a gray value for each key + for(int i=0; i= 'A' && key <= 'z') { + int keyIndex; + if(key <= 'Z') { + keyIndex = key-'A'; + letter_height = max_height; + fill(colors[key-'A']); + } else { + keyIndex = key-'a'; + letter_height = min_height; + fill(colors[key-'a']); + } + } else { + fill(0); + letter_height = 10; + } + + newletter = true; + + // Update the "letter" position + x = ( x + letter_width ); + + // Wrap horizontally + if (x > width - letter_width) { + x = 0; + y+= max_height; + } + + // Wrap vertically + if( y > height - letter_height) { + y = 0; // reset y to 0 + } +} diff --git a/android/examples/Basics/Input/KeyboardFunctions/applet/loading.gif b/android/examples/Basics/Input/KeyboardFunctions/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Input/KeyboardFunctions/applet/loading.gif differ diff --git a/android/examples/Basics/Input/Milliseconds/Milliseconds.pde b/android/examples/Basics/Input/Milliseconds/Milliseconds.pde new file mode 100644 index 000000000..2439ba363 --- /dev/null +++ b/android/examples/Basics/Input/Milliseconds/Milliseconds.pde @@ -0,0 +1,26 @@ +/** + * Milliseconds. + * + * A millisecond is 1/1000 of a second. + * Processing keeps track of the number of milliseconds a program has run. + * By modifying this number with the modulo(%) operator, + * different patterns in time are created. + */ + +float scale; + +void setup() +{ + size(200, 200); + noStroke(); + scale = width/10; +} + +void draw() +{ + for(int i=0; i 90) { + gx = 90; + } + + if (gy > 90) { + gy = 90; + } else if (gy < 10) { + gy = 10; + } +} diff --git a/android/examples/Basics/Input/Mouse1D/applet/Mouse1D.java b/android/examples/Basics/Input/Mouse1D/applet/Mouse1D.java new file mode 100644 index 000000000..c08cf2368 --- /dev/null +++ b/android/examples/Basics/Input/Mouse1D/applet/Mouse1D.java @@ -0,0 +1,70 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Mouse1D extends PApplet { + +/** + * Mouse 1D. + * + * Move the mouse left and right to shift the balance. + * The "mouseX" variable is used to control both the + * size and color of the rectangles. + */ + +int gx = 15; +int gy = 35; +float leftColor = 0.0f; +float rightColor = 0.0f; + +public void setup() +{ + size(200, 200); + colorMode(RGB, 1.0f); + noStroke(); +} + +public void draw() +{ + background(0.0f); + update(mouseX); + fill(0.0f, leftColor + 0.4f, leftColor + 0.6f); + rect(width/4-gx, width/2-gx, gx*2, gx*2); + fill(0.0f, rightColor + 0.2f, rightColor + 0.4f); + rect(width/1.33f-gy, width/2-gy, gy*2, gy*2); +} + +public void update(int x) +{ + leftColor = -0.002f * x/2 + 0.06f; + rightColor = 0.002f * x/2 + 0.06f; + + gx = x/2; + gy = 100-x/2; + + if (gx < 10) { + gx = 10; + } else if (gx > 90) { + gx = 90; + } + + if (gy > 90) { + gy = 90; + } else if (gy < 10) { + gy = 10; + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Mouse1D" }); + } +} diff --git a/android/examples/Basics/Input/Mouse1D/applet/Mouse1D.pde b/android/examples/Basics/Input/Mouse1D/applet/Mouse1D.pde new file mode 100644 index 000000000..2d1da507f --- /dev/null +++ b/android/examples/Basics/Input/Mouse1D/applet/Mouse1D.pde @@ -0,0 +1,50 @@ +/** + * Mouse 1D. + * + * Move the mouse left and right to shift the balance. + * The "mouseX" variable is used to control both the + * size and color of the rectangles. + */ + +int gx = 15; +int gy = 35; +float leftColor = 0.0; +float rightColor = 0.0; + +void setup() +{ + size(200, 200); + colorMode(RGB, 1.0); + noStroke(); +} + +void draw() +{ + background(0.0); + update(mouseX); + fill(0.0, leftColor + 0.4, leftColor + 0.6); + rect(width/4-gx, width/2-gx, gx*2, gx*2); + fill(0.0, rightColor + 0.2, rightColor + 0.4); + rect(width/1.33-gy, width/2-gy, gy*2, gy*2); +} + +void update(int x) +{ + leftColor = -0.002 * x/2 + 0.06; + rightColor = 0.002 * x/2 + 0.06; + + gx = x/2; + gy = 100-x/2; + + if (gx < 10) { + gx = 10; + } else if (gx > 90) { + gx = 90; + } + + if (gy > 90) { + gy = 90; + } else if (gy < 10) { + gy = 10; + } +} diff --git a/android/examples/Basics/Input/Mouse1D/applet/loading.gif b/android/examples/Basics/Input/Mouse1D/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Input/Mouse1D/applet/loading.gif differ diff --git a/android/examples/Basics/Input/Mouse2D/Mouse2D.pde b/android/examples/Basics/Input/Mouse2D/Mouse2D.pde new file mode 100644 index 000000000..c316bc6ce --- /dev/null +++ b/android/examples/Basics/Input/Mouse2D/Mouse2D.pde @@ -0,0 +1,24 @@ +/** + * Mouse 2D. + * + * Moving the mouse changes the position and size of each box. + */ + +void setup() +{ + size(200, 200); + noStroke(); + rectMode(CENTER); +} + +void draw() +{ + background(51); + fill(255, 204); + rect(mouseX, height/2, mouseY/2+10, mouseY/2+10); + fill(255, 204); + int inverseX = width-mouseX; + int inverseY = height-mouseY; + rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10); +} + diff --git a/android/examples/Basics/Input/Mouse2D/applet/Mouse2D.java b/android/examples/Basics/Input/Mouse2D/applet/Mouse2D.java new file mode 100644 index 000000000..aee6375f4 --- /dev/null +++ b/android/examples/Basics/Input/Mouse2D/applet/Mouse2D.java @@ -0,0 +1,45 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Mouse2D extends PApplet { + +/** + * Mouse 2D. + * + * Moving the mouse changes the position and size of each box. + */ + +public void setup() +{ + size(200, 200); + noStroke(); + colorMode(RGB, 255, 255, 255, 100); + rectMode(CENTER); +} + +public void draw() +{ + background(51); + fill(255, 80); + rect(mouseX, height/2, mouseY/2+10, mouseY/2+10); + fill(255, 80); + int inverseX = width-mouseX; + int inverseY = height-mouseY; + rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10); +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "Mouse2D" }); + } +} diff --git a/android/examples/Basics/Input/Mouse2D/applet/Mouse2D.pde b/android/examples/Basics/Input/Mouse2D/applet/Mouse2D.pde new file mode 100644 index 000000000..d1c36a258 --- /dev/null +++ b/android/examples/Basics/Input/Mouse2D/applet/Mouse2D.pde @@ -0,0 +1,25 @@ +/** + * Mouse 2D. + * + * Moving the mouse changes the position and size of each box. + */ + +void setup() +{ + size(200, 200); + noStroke(); + colorMode(RGB, 255, 255, 255, 100); + rectMode(CENTER); +} + +void draw() +{ + background(51); + fill(255, 80); + rect(mouseX, height/2, mouseY/2+10, mouseY/2+10); + fill(255, 80); + int inverseX = width-mouseX; + int inverseY = height-mouseY; + rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10); +} + diff --git a/android/examples/Basics/Input/Mouse2D/applet/loading.gif b/android/examples/Basics/Input/Mouse2D/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Input/Mouse2D/applet/loading.gif differ diff --git a/android/examples/Basics/Input/MouseFunctions/MouseFunctions.pde b/android/examples/Basics/Input/MouseFunctions/MouseFunctions.pde new file mode 100644 index 000000000..8d4e0fe36 --- /dev/null +++ b/android/examples/Basics/Input/MouseFunctions/MouseFunctions.pde @@ -0,0 +1,68 @@ +/** + * Mouse Functions. + * + * Click on the box and drag it across the screen. + */ + +float bx; +float by; +int bs = 20; +boolean bover = false; +boolean locked = false; +float bdifx = 0.0; +float bdify = 0.0; + + +void setup() +{ + size(200, 200); + bx = width/2.0; + by = height/2.0; + rectMode(RADIUS); +} + +void draw() +{ + background(0); + + // Test if the cursor is over the box + if (mouseX > bx-bs && mouseX < bx+bs && + mouseY > by-bs && mouseY < by+bs) { + bover = true; + if(!locked) { + stroke(255); + fill(153); + } + } else { + stroke(153); + fill(153); + bover = false; + } + + // Draw the box + rect(bx, by, bs, bs); +} + +void mousePressed() { + if(bover) { + locked = true; + fill(255, 255, 255); + } else { + locked = false; + } + bdifx = mouseX-bx; + bdify = mouseY-by; + +} + +void mouseDragged() { + if(locked) { + bx = mouseX-bdifx; + by = mouseY-bdify; + } +} + +void mouseReleased() { + locked = false; +} + diff --git a/android/examples/Basics/Input/MouseFunctions/applet/MouseFunctions.java b/android/examples/Basics/Input/MouseFunctions/applet/MouseFunctions.java new file mode 100644 index 000000000..5b89aeff0 --- /dev/null +++ b/android/examples/Basics/Input/MouseFunctions/applet/MouseFunctions.java @@ -0,0 +1,88 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class MouseFunctions extends PApplet { + +/** + * Mouse Functions. + * + * Click on the box and drag it across the screen. + */ + +float bx; +float by; +int bs = 20; +boolean bover = false; +boolean locked = false; +float bdifx = 0.0f; +float bdify = 0.0f; + + +public void setup() +{ + size(200, 200); + bx = width/2.0f; + by = height/2.0f; + rectMode(CENTER_RADIUS); +} + +public void draw() +{ + background(0); + + // Test if the cursor is over the box + if (mouseX > bx-bs && mouseX < bx+bs && + mouseY > by-bs && mouseY < by+bs) { + bover = true; + if(!locked) { + stroke(255); + fill(153); + } + } else { + stroke(153); + fill(153); + bover = false; + } + + // Draw the box + rect(bx, by, bs, bs); +} + +public void mousePressed() { + if(bover) { + locked = true; + fill(255, 255, 255); + } else { + locked = false; + } + bdifx = mouseX-bx; + bdify = mouseY-by; + +} + +public void mouseDragged() { + if(locked) { + bx = mouseX-bdifx; + by = mouseY-bdify; + } +} + +public void mouseReleased() { + locked = false; +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "MouseFunctions" }); + } +} diff --git a/android/examples/Basics/Input/MouseFunctions/applet/MouseFunctions.pde b/android/examples/Basics/Input/MouseFunctions/applet/MouseFunctions.pde new file mode 100644 index 000000000..22717d718 --- /dev/null +++ b/android/examples/Basics/Input/MouseFunctions/applet/MouseFunctions.pde @@ -0,0 +1,68 @@ +/** + * Mouse Functions. + * + * Click on the box and drag it across the screen. + */ + +float bx; +float by; +int bs = 20; +boolean bover = false; +boolean locked = false; +float bdifx = 0.0; +float bdify = 0.0; + + +void setup() +{ + size(200, 200); + bx = width/2.0; + by = height/2.0; + rectMode(CENTER_RADIUS); +} + +void draw() +{ + background(0); + + // Test if the cursor is over the box + if (mouseX > bx-bs && mouseX < bx+bs && + mouseY > by-bs && mouseY < by+bs) { + bover = true; + if(!locked) { + stroke(255); + fill(153); + } + } else { + stroke(153); + fill(153); + bover = false; + } + + // Draw the box + rect(bx, by, bs, bs); +} + +void mousePressed() { + if(bover) { + locked = true; + fill(255, 255, 255); + } else { + locked = false; + } + bdifx = mouseX-bx; + bdify = mouseY-by; + +} + +void mouseDragged() { + if(locked) { + bx = mouseX-bdifx; + by = mouseY-bdify; + } +} + +void mouseReleased() { + locked = false; +} + diff --git a/android/examples/Basics/Input/MouseFunctions/applet/loading.gif b/android/examples/Basics/Input/MouseFunctions/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Input/MouseFunctions/applet/loading.gif differ diff --git a/android/examples/Basics/Input/MousePress/MousePress.pde b/android/examples/Basics/Input/MousePress/MousePress.pde new file mode 100644 index 000000000..526eced76 --- /dev/null +++ b/android/examples/Basics/Input/MousePress/MousePress.pde @@ -0,0 +1,23 @@ +/** + * Click. + * + * Move the mouse to position the shape. + * Press the mouse button to invert the color. + */ + + +void setup() { + size(200, 200); + fill(126); + background(102); +} + +void draw() { + if(mousePressed) { + stroke(255); + } else { + stroke(0); + } + line(mouseX-66, mouseY, mouseX+66, mouseY); + line(mouseX, mouseY-66, mouseX, mouseY+66); +} diff --git a/android/examples/Basics/Input/MousePress/applet/MousePress.java b/android/examples/Basics/Input/MousePress/applet/MousePress.java new file mode 100644 index 000000000..82bc9f6ca --- /dev/null +++ b/android/examples/Basics/Input/MousePress/applet/MousePress.java @@ -0,0 +1,43 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class MousePress extends PApplet { + +/** + * Click. + * + * Move the mouse to position the shape. + * Press the mouse button to invert the color. + */ + + +public void setup() { + size(200, 200); + fill(126); + background(102); +} + +public void draw() { + if(mousePressed) { + stroke(255); + } else { + stroke(0); + } + line(mouseX-66, mouseY, mouseX+66, mouseY); + line(mouseX, mouseY-66, mouseX, mouseY+66); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "MousePress" }); + } +} diff --git a/android/examples/Basics/Input/MousePress/applet/MousePress.pde b/android/examples/Basics/Input/MousePress/applet/MousePress.pde new file mode 100644 index 000000000..526eced76 --- /dev/null +++ b/android/examples/Basics/Input/MousePress/applet/MousePress.pde @@ -0,0 +1,23 @@ +/** + * Click. + * + * Move the mouse to position the shape. + * Press the mouse button to invert the color. + */ + + +void setup() { + size(200, 200); + fill(126); + background(102); +} + +void draw() { + if(mousePressed) { + stroke(255); + } else { + stroke(0); + } + line(mouseX-66, mouseY, mouseX+66, mouseY); + line(mouseX, mouseY-66, mouseX, mouseY+66); +} diff --git a/android/examples/Basics/Input/MousePress/applet/loading.gif b/android/examples/Basics/Input/MousePress/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Input/MousePress/applet/loading.gif differ diff --git a/android/examples/Basics/Input/MouseSignals/MouseSignals.pde b/android/examples/Basics/Input/MouseSignals/MouseSignals.pde new file mode 100644 index 000000000..6e1fd2bbc --- /dev/null +++ b/android/examples/Basics/Input/MouseSignals/MouseSignals.pde @@ -0,0 +1,54 @@ +/** + * Mouse Signals. + * + * Move and click the mouse to generate signals. + * The top row is the signal from "mouseX", + * the middle row is the signal from "mouseY", + * and the bottom row is the signal from "mousePressed". + */ + +int[] xvals; +int[] yvals; +int[] bvals; + +void setup() +{ + size(200, 200); + xvals = new int[width]; + yvals = new int[width]; + bvals = new int[width]; +} + +int arrayindex = 0; + +void draw() +{ + background(102); + + for(int i=1; i width) { xpos1 = -thin; } + if(xpos2 < -thick) { xpos2 = width; } + if(xpos2 > width) { xpos2 = -thick; } + if(xpos3 < -thin) { xpos3 = width; } + if(xpos3 > width) { xpos3 = -thin; } + if(xpos4 < -thick) { xpos4 = width; } + if(xpos4 > width) { xpos4 = -thick; } +} + diff --git a/android/examples/Basics/Math/Distance1D/applet/Distance1D.java b/android/examples/Basics/Math/Distance1D/applet/Distance1D.java new file mode 100644 index 000000000..28b2212af --- /dev/null +++ b/android/examples/Basics/Math/Distance1D/applet/Distance1D.java @@ -0,0 +1,71 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Distance1D extends PApplet { + +/** + * Distance 1D. + * + * Move the mouse left and right to control the + * speed and direction of the moving shapes. + */ + +int thin = 8; +int thick = 36; +float xpos1 = 134.0f; +float xpos2 = 44.0f; +float xpos3 = 58.0f; +float xpos4 = 120.0f; + +public void setup() +{ + size(200, 200); + noStroke(); + frameRate(60); +} + +public void draw() +{ + background(0); + + float mx = mouseX * 0.4f - width/5.0f; + + fill(102); + rect(xpos2, 0, thick, height/2); + fill(204); + rect(xpos1, 0, thin, height/2); + fill(102); + rect(xpos4, height/2, thick, height/2); + fill(204); + rect(xpos3, height/2, thin, height/2); + + xpos1 += mx/16; + xpos2 += mx/64; + xpos3 -= mx/16; + xpos4 -= mx/64; + + if(xpos1 < -thin) { xpos1 = width; } + if(xpos1 > width) { xpos1 = -thin; } + if(xpos2 < -thick) { xpos2 = width; } + if(xpos2 > width) { xpos2 = -thick; } + if(xpos3 < -thin) { xpos3 = width; } + if(xpos3 > width) { xpos3 = -thin; } + if(xpos4 < -thick) { xpos4 = width; } + if(xpos4 > width) { xpos4 = -thick; } +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "Distance1D" }); + } +} diff --git a/android/examples/Basics/Math/Distance1D/applet/Distance1D.pde b/android/examples/Basics/Math/Distance1D/applet/Distance1D.pde new file mode 100644 index 000000000..a17b3febc --- /dev/null +++ b/android/examples/Basics/Math/Distance1D/applet/Distance1D.pde @@ -0,0 +1,51 @@ +/** + * Distance 1D. + * + * Move the mouse left and right to control the + * speed and direction of the moving shapes. + */ + +int thin = 8; +int thick = 36; +float xpos1 = 134.0; +float xpos2 = 44.0; +float xpos3 = 58.0; +float xpos4 = 120.0; + +void setup() +{ + size(200, 200); + noStroke(); + frameRate(60); +} + +void draw() +{ + background(0); + + float mx = mouseX * 0.4 - width/5.0; + + fill(102); + rect(xpos2, 0, thick, height/2); + fill(204); + rect(xpos1, 0, thin, height/2); + fill(102); + rect(xpos4, height/2, thick, height/2); + fill(204); + rect(xpos3, height/2, thin, height/2); + + xpos1 += mx/16; + xpos2 += mx/64; + xpos3 -= mx/16; + xpos4 -= mx/64; + + if(xpos1 < -thin) { xpos1 = width; } + if(xpos1 > width) { xpos1 = -thin; } + if(xpos2 < -thick) { xpos2 = width; } + if(xpos2 > width) { xpos2 = -thick; } + if(xpos3 < -thin) { xpos3 = width; } + if(xpos3 > width) { xpos3 = -thin; } + if(xpos4 < -thick) { xpos4 = width; } + if(xpos4 > width) { xpos4 = -thick; } +} + diff --git a/android/examples/Basics/Math/Distance1D/applet/loading.gif b/android/examples/Basics/Math/Distance1D/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/Distance1D/applet/loading.gif differ diff --git a/android/examples/Basics/Math/Distance2D/Distance2D.pde b/android/examples/Basics/Math/Distance2D/Distance2D.pde new file mode 100644 index 000000000..e2bfe4b44 --- /dev/null +++ b/android/examples/Basics/Math/Distance2D/Distance2D.pde @@ -0,0 +1,29 @@ +/** + * Distance 2D. + * + * Move the mouse across the image to obscure and reveal the matrix. + * Measures the distance from the mouse to each square and sets the + * size proportionally. + */ + +float max_distance; + +void setup() { + size(200, 200); + smooth(); + noStroke(); + max_distance = dist(0, 0, width, height); +} + +void draw() +{ + background(51); + + for(int i = 0; i <= width; i += 20) { + for(int j = 0; j <= height; j += 20) { + float size = dist(mouseX, mouseY, i, j); + size = size/max_distance * 66; + ellipse(i, j, size, size); + } + } +} diff --git a/android/examples/Basics/Math/Distance2D/applet/Distance2D.java b/android/examples/Basics/Math/Distance2D/applet/Distance2D.java new file mode 100644 index 000000000..c4fe4f70e --- /dev/null +++ b/android/examples/Basics/Math/Distance2D/applet/Distance2D.java @@ -0,0 +1,49 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Distance2D extends PApplet { + +/** + * Distance 2D. + * + * Move the mouse across the image to obscure and reveal the matrix. + * Measures the distance from the mouse to each square and sets the + * size proportionally. + */ + +float max_distance; + +public void setup() { + size(200, 200); + smooth(); + noStroke(); + max_distance = dist(0, 0, width, height); +} + +public void draw() +{ + background(51); + + for(int i = 0; i <= width; i += 20) { + for(int j = 0; j <= height; j += 20) { + float size = dist(mouseX, mouseY, i, j); + size = size/max_distance * 66; + ellipse(i, j, size, size); + } + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Distance2D" }); + } +} diff --git a/android/examples/Basics/Math/Distance2D/applet/Distance2D.pde b/android/examples/Basics/Math/Distance2D/applet/Distance2D.pde new file mode 100644 index 000000000..e2bfe4b44 --- /dev/null +++ b/android/examples/Basics/Math/Distance2D/applet/Distance2D.pde @@ -0,0 +1,29 @@ +/** + * Distance 2D. + * + * Move the mouse across the image to obscure and reveal the matrix. + * Measures the distance from the mouse to each square and sets the + * size proportionally. + */ + +float max_distance; + +void setup() { + size(200, 200); + smooth(); + noStroke(); + max_distance = dist(0, 0, width, height); +} + +void draw() +{ + background(51); + + for(int i = 0; i <= width; i += 20) { + for(int j = 0; j <= height; j += 20) { + float size = dist(mouseX, mouseY, i, j); + size = size/max_distance * 66; + ellipse(i, j, size, size); + } + } +} diff --git a/android/examples/Basics/Math/Distance2D/applet/loading.gif b/android/examples/Basics/Math/Distance2D/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/Distance2D/applet/loading.gif differ diff --git a/android/examples/Basics/Math/DoubleRandom/DoubleRandom.pde b/android/examples/Basics/Math/DoubleRandom/DoubleRandom.pde new file mode 100644 index 000000000..a33bc7523 --- /dev/null +++ b/android/examples/Basics/Math/DoubleRandom/DoubleRandom.pde @@ -0,0 +1,20 @@ +/** + * Double Random + * by Ira Greenberg. + * + * Using two random() calls and the point() function + * to create an irregular sawtooth line. + */ + +size(200, 200); +background(0); +int totalPts = 300; +float steps = totalPts + 1; +stroke(255); +float rand = 0; + +for (int i = 1; i < steps; i++){ + point( (width/steps) * i, (height/2) + random(-rand, rand) ); + rand += random(-5, 5); +} + diff --git a/android/examples/Basics/Math/DoubleRandom/applet/DoubleRandom.java b/android/examples/Basics/Math/DoubleRandom/applet/DoubleRandom.java new file mode 100644 index 000000000..bea794379 --- /dev/null +++ b/android/examples/Basics/Math/DoubleRandom/applet/DoubleRandom.java @@ -0,0 +1,41 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class DoubleRandom extends PApplet { + public void setup() {/** + * Double Random + * by Ira Greenberg. + * + * Using 2 random() calls the and point() function + * to create an irregular sawtooth line. + */ + +size(200, 200); +background(0); +int totalPts = 300; +float steps = totalPts+1; +stroke(255); +float rand = 0; + +for (int i=1; i< steps; i++){ + point( (width/steps) * i, (height/2) + random(-rand, rand) ); + rand += random(-5, 5); +} + + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "DoubleRandom" }); + } +} diff --git a/android/examples/Basics/Math/DoubleRandom/applet/DoubleRandom.pde b/android/examples/Basics/Math/DoubleRandom/applet/DoubleRandom.pde new file mode 100644 index 000000000..10b1fe0c9 --- /dev/null +++ b/android/examples/Basics/Math/DoubleRandom/applet/DoubleRandom.pde @@ -0,0 +1,20 @@ +/** + * Double Random + * by Ira Greenberg. + * + * Using 2 random() calls the and point() function + * to create an irregular sawtooth line. + */ + +size(200, 200); +background(0); +int totalPts = 300; +float steps = totalPts+1; +stroke(255); +float rand = 0; + +for (int i=1; i< steps; i++){ + point( (width/steps) * i, (height/2) + random(-rand, rand) ); + rand += random(-5, 5); +} + diff --git a/android/examples/Basics/Math/DoubleRandom/applet/loading.gif b/android/examples/Basics/Math/DoubleRandom/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/DoubleRandom/applet/loading.gif differ diff --git a/android/examples/Basics/Math/Graphing2DEquation/Graphing2DEquation.pde b/android/examples/Basics/Math/Graphing2DEquation/Graphing2DEquation.pde new file mode 100644 index 000000000..bd20ed864 --- /dev/null +++ b/android/examples/Basics/Math/Graphing2DEquation/Graphing2DEquation.pde @@ -0,0 +1,40 @@ +/** + * Graphing 2D Equations + * by Daniel Shiffman. + * + * Graphics the following equation: + * sin(n*cos(r) + 5*theta) + * where n is a function of horizontal mouse location. + */ + +void setup() { + size(200,200); + frameRate(30); +} + +void draw() { + loadPixels(); + float n = (mouseX * 10.0) / width; + float w = 16.0; // 2D space width + float h = 16.0; // 2D space height + float dx = w / width; // Increment x this amount per pixel + float dy = h / height; // Increment y this amount per pixel + float x = -w/2; // Start x at -1 * width / 2 + for (int i = 0; i < width; i++) { + float y = -h/2; // Start y at -1 * height / 2 + for (int j = 0; j < height; j++) { + float r = sqrt((x*x) + (y*y)); // Convert cartesian to polar + float theta = atan2(y,x); // Convert cartesian to polar + // Compute 2D polar coordinate function + float val = sin(n*cos(r) + 5 * theta); // Results in a value between -1 and 1 + //float val = cos(r); // Another simple function + //float val = sin(theta); // Another simple function + // Map resulting vale to grayscale value + pixels[i+j*width] = color((val + 1.0) * 255.0/2.0); // Scale to between 0 and 255 + y += dy; // Increment y + } + x += dx; // Increment x + } + updatePixels(); +} + diff --git a/android/examples/Basics/Math/Graphing2DEquation/applet/Graphing2DEquation.java b/android/examples/Basics/Math/Graphing2DEquation/applet/Graphing2DEquation.java new file mode 100644 index 000000000..2049a3988 --- /dev/null +++ b/android/examples/Basics/Math/Graphing2DEquation/applet/Graphing2DEquation.java @@ -0,0 +1,60 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Graphing2DEquation extends PApplet { + +/** + * Graphing 2D Equations + * by Daniel Shiffman. + * + * Graphics the following equation: + * sin(n*cos(r) + 5*theta) + * where n is a function of horizontal mouse location. + */ + +public void setup() { + size(200,200); + frameRate(30); +} + +public void draw() { + loadPixels(); + float n = (mouseX * 10.0f) / width; + float w = 16.0f; // 2D space width + float h = 16.0f; // 2D space height + float dx = w / width; // Increment x this amount per pixel + float dy = h / height; // Increment y this amount per pixel + float x = -w/2; // Start x at -1 * width / 2 + for (int i = 0; i < width; i++) { + float y = -h/2; // Start y at -1 * height / 2 + for (int j = 0; j < height; j++) { + float r = sqrt((x*x) + (y*y)); // Convert cartesian to polar + float theta = atan2(y,x); // Convert cartesian to polar + // Compute 2D polar coordinate function + float val = sin(n*cos(r) + 5 * theta); // Results in a value between -1 and 1 + //float val = cos(r); // Another simple function + //float val = sin(theta); // Another simple function + // Map resulting vale to grayscale value + pixels[i+j*width] = color((val + 1.0f) * 255.0f/2.0f); // Scale to between 0 and 255 + y += dy; // Increment y + } + x += dx; // Increment x + } + updatePixels(); +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "Graphing2DEquation" }); + } +} diff --git a/android/examples/Basics/Math/Graphing2DEquation/applet/Graphing2DEquation.pde b/android/examples/Basics/Math/Graphing2DEquation/applet/Graphing2DEquation.pde new file mode 100644 index 000000000..bd20ed864 --- /dev/null +++ b/android/examples/Basics/Math/Graphing2DEquation/applet/Graphing2DEquation.pde @@ -0,0 +1,40 @@ +/** + * Graphing 2D Equations + * by Daniel Shiffman. + * + * Graphics the following equation: + * sin(n*cos(r) + 5*theta) + * where n is a function of horizontal mouse location. + */ + +void setup() { + size(200,200); + frameRate(30); +} + +void draw() { + loadPixels(); + float n = (mouseX * 10.0) / width; + float w = 16.0; // 2D space width + float h = 16.0; // 2D space height + float dx = w / width; // Increment x this amount per pixel + float dy = h / height; // Increment y this amount per pixel + float x = -w/2; // Start x at -1 * width / 2 + for (int i = 0; i < width; i++) { + float y = -h/2; // Start y at -1 * height / 2 + for (int j = 0; j < height; j++) { + float r = sqrt((x*x) + (y*y)); // Convert cartesian to polar + float theta = atan2(y,x); // Convert cartesian to polar + // Compute 2D polar coordinate function + float val = sin(n*cos(r) + 5 * theta); // Results in a value between -1 and 1 + //float val = cos(r); // Another simple function + //float val = sin(theta); // Another simple function + // Map resulting vale to grayscale value + pixels[i+j*width] = color((val + 1.0) * 255.0/2.0); // Scale to between 0 and 255 + y += dy; // Increment y + } + x += dx; // Increment x + } + updatePixels(); +} + diff --git a/android/examples/Basics/Math/Graphing2DEquation/applet/loading.gif b/android/examples/Basics/Math/Graphing2DEquation/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/Graphing2DEquation/applet/loading.gif differ diff --git a/android/examples/Basics/Math/IncrementDecrement/IncrementDecrement.pde b/android/examples/Basics/Math/IncrementDecrement/IncrementDecrement.pde new file mode 100644 index 000000000..8398c5faa --- /dev/null +++ b/android/examples/Basics/Math/IncrementDecrement/IncrementDecrement.pde @@ -0,0 +1,46 @@ +/** + * Increment Decrement. + * + * Writing "a++" is equivalent to "a = a + 1". + * Writing "a--" is equivalent to "a = a - 1". + */ + +int a; +int b; +boolean direction; + +void setup() +{ + size(200, 200); + colorMode(RGB, width); + a = 0; + b = width; + direction = true; + frameRate(30); +} + +void draw() +{ + a++; + if(a > width) { + a = 0; + direction = !direction; + } + if(direction == true){ + stroke(a); + } else { + stroke(width-a); + } + line(a, 0, a, height/2); + + b--; + if(b < 0) { + b = width; + } + if(direction == true) { + stroke(width-b); + } else { + stroke(b); + } + line(b, height/2+1, b, height); +} diff --git a/android/examples/Basics/Math/IncrementDecrement/applet/IncrementDecrement.java b/android/examples/Basics/Math/IncrementDecrement/applet/IncrementDecrement.java new file mode 100644 index 000000000..87cdd99d6 --- /dev/null +++ b/android/examples/Basics/Math/IncrementDecrement/applet/IncrementDecrement.java @@ -0,0 +1,66 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class IncrementDecrement extends PApplet { + +/** + * Increment Decrement. + * + * Writing "a++" is equivalent to "a = a + 1". + * Writing "a--" is equivalent to "a = a - 1". + */ + +int a; +int b; +boolean direction; + +public void setup() +{ + size(200, 200); + colorMode(RGB, width); + a = 0; + b = width; + direction = true; + frameRate(30); +} + +public void draw() +{ + a++; + if(a > width) { + a = 0; + direction = !direction; + } + if(direction == true){ + stroke(a); + } else { + stroke(width-a); + } + line(a, 0, a, height/2); + + b--; + if(b < 0) { + b = width; + } + if(direction == true) { + stroke(width-b); + } else { + stroke(b); + } + line(b, height/2+1, b, height); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "IncrementDecrement" }); + } +} diff --git a/android/examples/Basics/Math/IncrementDecrement/applet/IncrementDecrement.pde b/android/examples/Basics/Math/IncrementDecrement/applet/IncrementDecrement.pde new file mode 100644 index 000000000..8398c5faa --- /dev/null +++ b/android/examples/Basics/Math/IncrementDecrement/applet/IncrementDecrement.pde @@ -0,0 +1,46 @@ +/** + * Increment Decrement. + * + * Writing "a++" is equivalent to "a = a + 1". + * Writing "a--" is equivalent to "a = a - 1". + */ + +int a; +int b; +boolean direction; + +void setup() +{ + size(200, 200); + colorMode(RGB, width); + a = 0; + b = width; + direction = true; + frameRate(30); +} + +void draw() +{ + a++; + if(a > width) { + a = 0; + direction = !direction; + } + if(direction == true){ + stroke(a); + } else { + stroke(width-a); + } + line(a, 0, a, height/2); + + b--; + if(b < 0) { + b = width; + } + if(direction == true) { + stroke(width-b); + } else { + stroke(b); + } + line(b, height/2+1, b, height); +} diff --git a/android/examples/Basics/Math/IncrementDecrement/applet/loading.gif b/android/examples/Basics/Math/IncrementDecrement/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/IncrementDecrement/applet/loading.gif differ diff --git a/android/examples/Basics/Math/Modulo/Modulo.pde b/android/examples/Basics/Math/Modulo/Modulo.pde new file mode 100644 index 000000000..7ad1f5dc3 --- /dev/null +++ b/android/examples/Basics/Math/Modulo/Modulo.pde @@ -0,0 +1,31 @@ +/** + * Modulo. + * + * The modulo operator (%) returns the remainder of a number + * divided by another. As in this example, it is often used + * to keep numerical values within a set range. + */ + +int num = 20; +float c; + +void setup() +{ + size(200,200); + fill(255); + frameRate(30); +} + +void draw() +{ + background(0); + c+=0.1; + for(int i=1; i <= >= +// Equality: == != +// Logical AND: && +// Logical OR: || +// Assignment: = += -= *= /= %= + +size(200, 200); +background(51); +noFill(); +stroke(51); + +stroke(204); +for(int i=0; i< width-20; i+= 4) { + // The 30 is added to 70 and then evaluated + // if it is greater than the current value of "i" + // For clarity, write as "if(i > (30 + 70)) {" + if(i > 30 + 70) { + line(i, 0, i, 50); + } +} + +stroke(255); +// The 2 is multiplied by the 8 and the result is added to the 5 +// For clarity, write as "rect(5 + (2 * 8), 0, 90, 20);" +rect(4 + 2 * 8, 52, 90, 48); +rect((4 + 2) * 8, 100, 90, 49); + +stroke(153); +for(int i=0; i< width; i+= 2) { + // The relational statements are evaluated + // first, and then the logical AND statements and + // finally the logical OR. For clarity, write as: + // "if(((i > 10) && (i < 50)) || ((i > 80) && (i < 160))) {" + if(i > 20 && i < 50 || i > 100 && i < width-20) { + line(i, 151, i, height-1); + } +} + + diff --git a/android/examples/Basics/Math/OperatorPrecedence/applet/OperatorPrecedence.java b/android/examples/Basics/Math/OperatorPrecedence/applet/OperatorPrecedence.java new file mode 100644 index 000000000..60bb03f4e --- /dev/null +++ b/android/examples/Basics/Math/OperatorPrecedence/applet/OperatorPrecedence.java @@ -0,0 +1,79 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class OperatorPrecedence extends PApplet { + public void setup() {/** + * Operator_Precedence + * + * If you don't explicitly state the order in which + * an expression is evaluated, they are evaluated based + * on the operator precedence. For example, in the statement + * "4+2*8", the 2 will first be multiplied by 8 and then the result will + * be added to 4. This is because the "*" has a higher precedence + * than the "+". To avoid ambiguity in reading the program, + * it is recommended that is statement is written as "4+(2*8)". + * The order of evaluation can be controlled through placement of + * parenthesis in the code. A table of operator precedence follows below. + * + */ + +// The highest precedence is at the top of the list and +// the lowest is at the bottom. +// Multiplicative: * / % +// Additive: + - +// Relational: < > <= >= +// Equality: == != +// Logical AND: && +// Logical OR: || +// Assignment: = += -= *= /= %= + +size(200, 200); +background(51); +noFill(); +stroke(51); + +stroke(204); +for(int i=0; i< width-20; i+= 4) { + // The 30 is added to 70 and then evaluated + // if it is greater than the current value of "i" + // For clarity, write as "if(i > (30 + 70)) {" + if(i > 30 + 70) { + line(i, 0, i, 50); + } +} + +stroke(255); +// The 2 is multiplied by the 8 and the result is added to the 5 +// For clarity, write as "rect(5 + (2 * 8), 0, 90, 20);" +rect(4 + 2 * 8, 52, 90, 48); +rect((4 + 2) * 8, 100, 90, 49); + +stroke(153); +for(int i=0; i< width; i+= 2) { + // The relational statements are evaluated + // first, and then the logical AND statements and + // finally the logical OR. For clarity, write as: + // "if(((i > 10) && (i < 50)) || ((i > 80) && (i < 160))) {" + if(i > 20 && i < 50 || i > 100 && i < width-20) { + line(i, 151, i, height-1); + } +} + + + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "OperatorPrecedence" }); + } +} diff --git a/android/examples/Basics/Math/OperatorPrecedence/applet/OperatorPrecedence.pde b/android/examples/Basics/Math/OperatorPrecedence/applet/OperatorPrecedence.pde new file mode 100644 index 000000000..7f8cf52ca --- /dev/null +++ b/android/examples/Basics/Math/OperatorPrecedence/applet/OperatorPrecedence.pde @@ -0,0 +1,58 @@ +/** + * Operator_Precedence + * + * If you don't explicitly state the order in which + * an expression is evaluated, they are evaluated based + * on the operator precedence. For example, in the statement + * "4+2*8", the 2 will first be multiplied by 8 and then the result will + * be added to 4. This is because the "*" has a higher precedence + * than the "+". To avoid ambiguity in reading the program, + * it is recommended that is statement is written as "4+(2*8)". + * The order of evaluation can be controlled through placement of + * parenthesis in the code. A table of operator precedence follows below. + * + */ + +// The highest precedence is at the top of the list and +// the lowest is at the bottom. +// Multiplicative: * / % +// Additive: + - +// Relational: < > <= >= +// Equality: == != +// Logical AND: && +// Logical OR: || +// Assignment: = += -= *= /= %= + +size(200, 200); +background(51); +noFill(); +stroke(51); + +stroke(204); +for(int i=0; i< width-20; i+= 4) { + // The 30 is added to 70 and then evaluated + // if it is greater than the current value of "i" + // For clarity, write as "if(i > (30 + 70)) {" + if(i > 30 + 70) { + line(i, 0, i, 50); + } +} + +stroke(255); +// The 2 is multiplied by the 8 and the result is added to the 5 +// For clarity, write as "rect(5 + (2 * 8), 0, 90, 20);" +rect(4 + 2 * 8, 52, 90, 48); +rect((4 + 2) * 8, 100, 90, 49); + +stroke(153); +for(int i=0; i< width; i+= 2) { + // The relational statements are evaluated + // first, and then the logical AND statements and + // finally the logical OR. For clarity, write as: + // "if(((i > 10) && (i < 50)) || ((i > 80) && (i < 160))) {" + if(i > 20 && i < 50 || i > 100 && i < width-20) { + line(i, 151, i, height-1); + } +} + + diff --git a/android/examples/Basics/Math/OperatorPrecedence/applet/loading.gif b/android/examples/Basics/Math/OperatorPrecedence/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/OperatorPrecedence/applet/loading.gif differ diff --git a/android/examples/Basics/Math/PolarToCartesian/PolarToCartesian.pde b/android/examples/Basics/Math/PolarToCartesian/PolarToCartesian.pde new file mode 100644 index 000000000..f1f2b1e7d --- /dev/null +++ b/android/examples/Basics/Math/PolarToCartesian/PolarToCartesian.pde @@ -0,0 +1,52 @@ +/** + * PolarToCartesian + * by Daniel Shiffman. + * + * Convert a polar coordinate (r,theta) to cartesian (x,y): + * x = r * cos(theta) + * y = r * sin(theta) + */ + +float r; + +// Angle and angular velocity, accleration +float theta; +float theta_vel; +float theta_acc; + +void setup() { + size(200, 200); + frameRate(30); + smooth(); + + // Initialize all values + r = 50; + theta = 0; + theta_vel = 0; + theta_acc = 0.0001; +} + +void draw() { + background(0); + // Translate the origin point to the center of the screen + translate(width/2, height/2); + + // Convert polar to cartesian + float x = r * cos(theta); + float y = r * sin(theta); + + // Draw the ellipse at the cartesian coordinate + ellipseMode(CENTER); + noStroke(); + fill(200); + ellipse(x, y, 16, 16); + + // Apply acceleration and velocity to angle (r remains static in this example) + theta_vel += theta_acc; + theta += theta_vel; + +} + + + + diff --git a/android/examples/Basics/Math/PolarToCartesian/applet/PolarToCartesian.java b/android/examples/Basics/Math/PolarToCartesian/applet/PolarToCartesian.java new file mode 100644 index 000000000..75a8ea736 --- /dev/null +++ b/android/examples/Basics/Math/PolarToCartesian/applet/PolarToCartesian.java @@ -0,0 +1,72 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class PolarToCartesian extends PApplet { + +/** + * PolarToCartesian + * by Daniel Shiffman. + * + * Convert a polar coordinate (r,theta) to cartesian (x,y): + * x = r * cos(theta) + * y = r * sin(theta) + */ + +float r; + +// Angle and angular velocity, accleration +float theta; +float theta_vel; +float theta_acc; + +public void setup() { + size(200,200); + frameRate(30); + smooth(); + + // Initialize all values + r = 50.0f; + theta = 0.0f; + theta_vel = 0.0f; + theta_acc = 0.0001f; +} + +public void draw() { + background(0); + // Translate the origin point to the center of the screen + translate(width/2,height/2); + + // Convert polar to cartesian + float x = r * cos(theta); + float y = r * sin(theta); + + // Draw the ellipse at the cartesian coordinate + ellipseMode(CENTER); + noStroke(); + fill(200); + ellipse(x,y,16,16); + + // Apply acceleration and velocity to angle (r remains static in this example) + theta_vel += theta_acc; + theta += theta_vel; + +} + + + + + + static public void main(String args[]) { + PApplet.main(new String[] { "PolarToCartesian" }); + } +} diff --git a/android/examples/Basics/Math/PolarToCartesian/applet/PolarToCartesian.pde b/android/examples/Basics/Math/PolarToCartesian/applet/PolarToCartesian.pde new file mode 100644 index 000000000..fdcd948db --- /dev/null +++ b/android/examples/Basics/Math/PolarToCartesian/applet/PolarToCartesian.pde @@ -0,0 +1,52 @@ +/** + * PolarToCartesian + * by Daniel Shiffman. + * + * Convert a polar coordinate (r,theta) to cartesian (x,y): + * x = r * cos(theta) + * y = r * sin(theta) + */ + +float r; + +// Angle and angular velocity, accleration +float theta; +float theta_vel; +float theta_acc; + +void setup() { + size(200,200); + frameRate(30); + smooth(); + + // Initialize all values + r = 50.0f; + theta = 0.0f; + theta_vel = 0.0f; + theta_acc = 0.0001f; +} + +void draw() { + background(0); + // Translate the origin point to the center of the screen + translate(width/2,height/2); + + // Convert polar to cartesian + float x = r * cos(theta); + float y = r * sin(theta); + + // Draw the ellipse at the cartesian coordinate + ellipseMode(CENTER); + noStroke(); + fill(200); + ellipse(x,y,16,16); + + // Apply acceleration and velocity to angle (r remains static in this example) + theta_vel += theta_acc; + theta += theta_vel; + +} + + + + diff --git a/android/examples/Basics/Math/PolarToCartesian/applet/loading.gif b/android/examples/Basics/Math/PolarToCartesian/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/PolarToCartesian/applet/loading.gif differ diff --git a/android/examples/Basics/Math/Random/Random.pde b/android/examples/Basics/Math/Random/Random.pde new file mode 100644 index 000000000..5fa97b8f0 --- /dev/null +++ b/android/examples/Basics/Math/Random/Random.pde @@ -0,0 +1,19 @@ +/** + * Random. + * + * Random numbers create the basis of this image. + * Each time the program is loaded the result is different. + */ + +size(200, 200); +smooth(); +background(0); +strokeWeight(10); + +for(int i = 0; i < width; i++) { + float r = random(255); + float x = random(0, width); + stroke(r, 100); + line(i, 0, x, height); +} + diff --git a/android/examples/Basics/Math/Random/applet/Random.java b/android/examples/Basics/Math/Random/applet/Random.java new file mode 100644 index 000000000..ca26fea54 --- /dev/null +++ b/android/examples/Basics/Math/Random/applet/Random.java @@ -0,0 +1,40 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Random extends PApplet { + public void setup() {/** + * Random. + * + * Random numbers create the basis of this image. + * Each time the program is loaded the result is different. + */ + +size(200, 200); +smooth(); +background(0); +strokeWeight(10); + +for(int i = 0; i < width; i++) { + float r = random(255); + float x = random(0, width); + stroke(r, 100); + line(i, 0, x, height); +} + + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "Random" }); + } +} diff --git a/android/examples/Basics/Math/Random/applet/Random.pde b/android/examples/Basics/Math/Random/applet/Random.pde new file mode 100644 index 000000000..5fa97b8f0 --- /dev/null +++ b/android/examples/Basics/Math/Random/applet/Random.pde @@ -0,0 +1,19 @@ +/** + * Random. + * + * Random numbers create the basis of this image. + * Each time the program is loaded the result is different. + */ + +size(200, 200); +smooth(); +background(0); +strokeWeight(10); + +for(int i = 0; i < width; i++) { + float r = random(255); + float x = random(0, width); + stroke(r, 100); + line(i, 0, x, height); +} + diff --git a/android/examples/Basics/Math/Random/applet/loading.gif b/android/examples/Basics/Math/Random/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/Random/applet/loading.gif differ diff --git a/android/examples/Basics/Math/Sine/Sine.pde b/android/examples/Basics/Math/Sine/Sine.pde new file mode 100644 index 000000000..848add369 --- /dev/null +++ b/android/examples/Basics/Math/Sine/Sine.pde @@ -0,0 +1,46 @@ +/** + * Sine. + * + * Smoothly scaling size with the sin() function. + */ + +float spin = 0.0; +float diameter = 84.0; +float angle; + +float angle_rot; +int rad_points = 90; + +void setup() +{ + size(200, 200); + noStroke(); + smooth(); +} + +void draw() +{ + background(153); + + translate(130, 65); + + fill(255); + ellipse(0, 0, 16, 16); + + angle_rot = 0; + fill(51); + + for(int i=0; i<5; i++) { + pushMatrix(); + rotate(angle_rot + -45); + ellipse(-116, 0, diameter, diameter); + popMatrix(); + angle_rot += PI*2/5; + } + + diameter = 34 * sin(angle) + 168; + + angle += 0.02; + if (angle > TWO_PI) { angle = 0; } +} + diff --git a/android/examples/Basics/Math/Sine/applet/Sine.java b/android/examples/Basics/Math/Sine/applet/Sine.java new file mode 100644 index 000000000..a29502d3b --- /dev/null +++ b/android/examples/Basics/Math/Sine/applet/Sine.java @@ -0,0 +1,66 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Sine extends PApplet { + +/** + * Sine. + * + * Smoothly scaling size with the sin() function. + */ + +float spin = 0.0f; +float diameter = 84.0f; +float angle; + +float angle_rot; +int rad_points = 90; + +public void setup() +{ + size(200, 200); + noStroke(); + smooth(); +} + +public void draw() +{ + background(153); + + translate(130, 65); + + fill(255); + ellipse(0, 0, 16, 16); + + angle_rot = 0; + fill(51); + + for(int i=0; i<5; i++) { + pushMatrix(); + rotate(angle_rot + -45); + ellipse(-116, 0, diameter, diameter); + popMatrix(); + angle_rot += PI*2/5; + } + + diameter = 34 * sin(angle) + 168; + + angle += 0.02f; + if (angle > TWO_PI) { angle = 0; } +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "Sine" }); + } +} diff --git a/android/examples/Basics/Math/Sine/applet/Sine.pde b/android/examples/Basics/Math/Sine/applet/Sine.pde new file mode 100644 index 000000000..848add369 --- /dev/null +++ b/android/examples/Basics/Math/Sine/applet/Sine.pde @@ -0,0 +1,46 @@ +/** + * Sine. + * + * Smoothly scaling size with the sin() function. + */ + +float spin = 0.0; +float diameter = 84.0; +float angle; + +float angle_rot; +int rad_points = 90; + +void setup() +{ + size(200, 200); + noStroke(); + smooth(); +} + +void draw() +{ + background(153); + + translate(130, 65); + + fill(255); + ellipse(0, 0, 16, 16); + + angle_rot = 0; + fill(51); + + for(int i=0; i<5; i++) { + pushMatrix(); + rotate(angle_rot + -45); + ellipse(-116, 0, diameter, diameter); + popMatrix(); + angle_rot += PI*2/5; + } + + diameter = 34 * sin(angle) + 168; + + angle += 0.02; + if (angle > TWO_PI) { angle = 0; } +} + diff --git a/android/examples/Basics/Math/Sine/applet/loading.gif b/android/examples/Basics/Math/Sine/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/Sine/applet/loading.gif differ diff --git a/android/examples/Basics/Math/SineCosine/SineCosine.pde b/android/examples/Basics/Math/SineCosine/SineCosine.pde new file mode 100644 index 000000000..4a40ddee2 --- /dev/null +++ b/android/examples/Basics/Math/SineCosine/SineCosine.pde @@ -0,0 +1,59 @@ +/** + * Sine Cosine. + * + * Linear movement with sin() and cos(). + * Numbers between 0 and PI*2 (TWO_PI which is roughly 6.28) + * are put into these functions and numbers between -1 and 1 are + * returned. These values are then scaled to produce larger movements. + */ + +int i = 45; +int j = 225; +float pos1 = 0; +float pos2 = 0; +float pos3 = 0; +float pos4 = 0; +int sc = 40; + +void setup() +{ + size(200, 200); + noStroke(); + smooth(); +} + +void draw() +{ + background(0); + + fill(51); + rect(60, 60, 80, 80); + + fill(255); + ellipse(pos1, 36, 32, 32); + + fill(153); + ellipse(36, pos2, 32, 32); + + fill(255); + ellipse(pos3, 164, 32, 32); + + fill(153); + ellipse(164, pos4, 32, 32); + + i += 3; + j -= 3; + + if(i > 405) { + i = 45; + j = 225; + } + + float ang1 = radians(i); // convert degrees to radians + float ang2 = radians(j); // convert degrees to radians + pos1 = width/2 + (sc * cos(ang1)); + pos2 = width/2 + (sc * sin(ang1)); + pos3 = width/2 + (sc * cos(ang2)); + pos4 = width/2 + (sc * sin(ang2)); +} + diff --git a/android/examples/Basics/Math/SineCosine/applet/SineCosine.java b/android/examples/Basics/Math/SineCosine/applet/SineCosine.java new file mode 100644 index 000000000..c308f7fed --- /dev/null +++ b/android/examples/Basics/Math/SineCosine/applet/SineCosine.java @@ -0,0 +1,79 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class SineCosine extends PApplet { + +/** + * Sine Cosine. + * + * Linear movement with sin() and cos(). + * Numbers between 0 and PI*2 (TWO_PI which is roughly 6.28) + * are put into these functions and numbers between -1 and 1 are + * returned. These values are then scaled to produce larger movements. + */ + +int i = 45; +int j = 225; +float pos1 = 0; +float pos2 = 0; +float pos3 = 0; +float pos4 = 0; +int sc = 40; + +public void setup() +{ + size(200, 200); + noStroke(); + smooth(); +} + +public void draw() +{ + background(0); + + fill(51); + rect(60, 60, 80, 80); + + fill(255); + ellipse(pos1, 36, 32, 32); + + fill(153); + ellipse(36, pos2, 32, 32); + + fill(255); + ellipse(pos3, 164, 32, 32); + + fill(153); + ellipse(164, pos4, 32, 32); + + i += 3; + j -= 3; + + if(i > 405) { + i = 45; + j = 225; + } + + float ang1 = radians(i); // convert degrees to radians + float ang2 = radians(j); // convert degrees to radians + pos1 = width/2 + (sc * cos(ang1)); + pos2 = width/2 + (sc * sin(ang1)); + pos3 = width/2 + (sc * cos(ang2)); + pos4 = width/2 + (sc * sin(ang2)); +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "SineCosine" }); + } +} diff --git a/android/examples/Basics/Math/SineCosine/applet/SineCosine.pde b/android/examples/Basics/Math/SineCosine/applet/SineCosine.pde new file mode 100644 index 000000000..4a40ddee2 --- /dev/null +++ b/android/examples/Basics/Math/SineCosine/applet/SineCosine.pde @@ -0,0 +1,59 @@ +/** + * Sine Cosine. + * + * Linear movement with sin() and cos(). + * Numbers between 0 and PI*2 (TWO_PI which is roughly 6.28) + * are put into these functions and numbers between -1 and 1 are + * returned. These values are then scaled to produce larger movements. + */ + +int i = 45; +int j = 225; +float pos1 = 0; +float pos2 = 0; +float pos3 = 0; +float pos4 = 0; +int sc = 40; + +void setup() +{ + size(200, 200); + noStroke(); + smooth(); +} + +void draw() +{ + background(0); + + fill(51); + rect(60, 60, 80, 80); + + fill(255); + ellipse(pos1, 36, 32, 32); + + fill(153); + ellipse(36, pos2, 32, 32); + + fill(255); + ellipse(pos3, 164, 32, 32); + + fill(153); + ellipse(164, pos4, 32, 32); + + i += 3; + j -= 3; + + if(i > 405) { + i = 45; + j = 225; + } + + float ang1 = radians(i); // convert degrees to radians + float ang2 = radians(j); // convert degrees to radians + pos1 = width/2 + (sc * cos(ang1)); + pos2 = width/2 + (sc * sin(ang1)); + pos3 = width/2 + (sc * cos(ang2)); + pos4 = width/2 + (sc * sin(ang2)); +} + diff --git a/android/examples/Basics/Math/SineCosine/applet/loading.gif b/android/examples/Basics/Math/SineCosine/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/SineCosine/applet/loading.gif differ diff --git a/android/examples/Basics/Math/SineWave/SineWave.pde b/android/examples/Basics/Math/SineWave/SineWave.pde new file mode 100644 index 000000000..da47bed36 --- /dev/null +++ b/android/examples/Basics/Math/SineWave/SineWave.pde @@ -0,0 +1,55 @@ +/** + * Sine Wave + * by Daniel Shiffman. + * + * Render a simple sine wave. + */ + +int xspacing = 8; // How far apart should each horizontal location be spaced +int w; // Width of entire wave + +float theta = 0.0; // Start angle at 0 +float amplitude = 75.0; // Height of wave +float period = 500.0; // How many pixels before the wave repeats +float dx; // Value for incrementing X, a function of period and xspacing +float[] yvalues; // Using an array to store height values for the wave + +void setup() { + size(200,200); + frameRate(30); + colorMode(RGB,255,255,255,100); + smooth(); + w = width+16; + dx = (TWO_PI / period) * xspacing; + yvalues = new float[w/xspacing]; +} + +void draw() { + background(0); + calcWave(); + renderWave(); + +} + +void calcWave() { + // Increment theta (try different values for 'angular velocity' here + theta += 0.02; + + // For every x value, calculate a y value with sine function + float x = theta; + for (int i = 0; i < yvalues.length; i++) { + yvalues[i] = sin(x)*amplitude; + x+=dx; + } +} + +void renderWave() { + // A simple way to draw the wave with an ellipse at each location + for (int x = 0; x < yvalues.length; x++) { + noStroke(); + fill(255,50); + ellipseMode(CENTER); + ellipse(x*xspacing,width/2+yvalues[x],16,16); + } +} + diff --git a/android/examples/Basics/Math/SineWave/applet/SineWave.java b/android/examples/Basics/Math/SineWave/applet/SineWave.java new file mode 100644 index 000000000..165700473 --- /dev/null +++ b/android/examples/Basics/Math/SineWave/applet/SineWave.java @@ -0,0 +1,75 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class SineWave extends PApplet { + +/** + * Sine Wave + * by Daniel Shiffman. + * + * Render a simple sine wave. + */ + +int xspacing = 8; // How far apart should each horizontal location be spaced +int w; // Width of entire wave + +float theta = 0.0f; // Start angle at 0 +float amplitude = 75.0f; // Height of wave +float period = 500.0f; // How many pixels before the wave repeats +float dx; // Value for incrementing X, a function of period and xspacing +float[] yvalues; // Using an array to store height values for the wave + +public void setup() { + size(200,200); + frameRate(30); + colorMode(RGB,255,255,255,100); + smooth(); + w = width+16; + dx = (TWO_PI / period) * xspacing; + yvalues = new float[w/xspacing]; +} + +public void draw() { + background(0); + calcWave(); + renderWave(); + +} + +public void calcWave() { + // Increment theta (try different values for 'angular velocity' here + theta += 0.02f; + + // For every x value, calculate a y value with sine function + float x = theta; + for (int i = 0; i < yvalues.length; i++) { + yvalues[i] = sin(x)*amplitude; + x+=dx; + } +} + +public void renderWave() { + // A simple way to draw the wave with an ellipse at each location + for (int x = 0; x < yvalues.length; x++) { + noStroke(); + fill(255,50); + ellipseMode(CENTER); + ellipse(x*xspacing,width/2+yvalues[x],16,16); + } +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "SineWave" }); + } +} diff --git a/android/examples/Basics/Math/SineWave/applet/SineWave.pde b/android/examples/Basics/Math/SineWave/applet/SineWave.pde new file mode 100644 index 000000000..da47bed36 --- /dev/null +++ b/android/examples/Basics/Math/SineWave/applet/SineWave.pde @@ -0,0 +1,55 @@ +/** + * Sine Wave + * by Daniel Shiffman. + * + * Render a simple sine wave. + */ + +int xspacing = 8; // How far apart should each horizontal location be spaced +int w; // Width of entire wave + +float theta = 0.0; // Start angle at 0 +float amplitude = 75.0; // Height of wave +float period = 500.0; // How many pixels before the wave repeats +float dx; // Value for incrementing X, a function of period and xspacing +float[] yvalues; // Using an array to store height values for the wave + +void setup() { + size(200,200); + frameRate(30); + colorMode(RGB,255,255,255,100); + smooth(); + w = width+16; + dx = (TWO_PI / period) * xspacing; + yvalues = new float[w/xspacing]; +} + +void draw() { + background(0); + calcWave(); + renderWave(); + +} + +void calcWave() { + // Increment theta (try different values for 'angular velocity' here + theta += 0.02; + + // For every x value, calculate a y value with sine function + float x = theta; + for (int i = 0; i < yvalues.length; i++) { + yvalues[i] = sin(x)*amplitude; + x+=dx; + } +} + +void renderWave() { + // A simple way to draw the wave with an ellipse at each location + for (int x = 0; x < yvalues.length; x++) { + noStroke(); + fill(255,50); + ellipseMode(CENTER); + ellipse(x*xspacing,width/2+yvalues[x],16,16); + } +} + diff --git a/android/examples/Basics/Math/SineWave/applet/loading.gif b/android/examples/Basics/Math/SineWave/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Math/SineWave/applet/loading.gif differ diff --git a/android/examples/Basics/Objects/CompositeObjects/CompositeObjects.pde b/android/examples/Basics/Objects/CompositeObjects/CompositeObjects.pde new file mode 100644 index 000000000..8987bda9e --- /dev/null +++ b/android/examples/Basics/Objects/CompositeObjects/CompositeObjects.pde @@ -0,0 +1,24 @@ +/** + * Composite Objects + * + * An object can include several other objects. Creating such composite objects + * is a good way to use the principles of modularity and build higher levels of + * abstraction within a program. + */ + +EggRing er1, er2; + + +void setup() { + size(200, 200); + smooth(); + er1 = new EggRing(66, 132, 0.1, 66); + er2 = new EggRing(132, 180, 0.05, 132); +} + + +void draw() { + background(0); + er1.transmit(); + er2.transmit(); +} diff --git a/android/examples/Basics/Objects/CompositeObjects/Egg.pde b/android/examples/Basics/Objects/CompositeObjects/Egg.pde new file mode 100644 index 000000000..e6638aa79 --- /dev/null +++ b/android/examples/Basics/Objects/CompositeObjects/Egg.pde @@ -0,0 +1,36 @@ +class Egg { + float x, y; // X-coordinate, y-coordinate + float tilt; // Left and right angle offset + float angle; // Used to define the tilt + float scalar; // Height of the egg + + // Constructor + Egg(int xpos, int ypos, float t, float s) { + x = xpos; + y = ypos; + tilt = t; + scalar = s / 100.0; + } + + void wobble() { + tilt = cos(angle) / 8; + angle += 0.1; + } + + void display() { + noStroke(); + fill(255); + pushMatrix(); + translate(x, y); + rotate(tilt); + scale(scalar); + beginShape(); + vertex(0, -100); + bezierVertex(25, -100, 40, -65, 40, -40); + bezierVertex(40, -15, 25, 0, 0, 0); + bezierVertex(-25, 0, -40, -15, -40, -40); + bezierVertex(-40, -65, -25, -100, 0, -100); + endShape(); + popMatrix(); + } +} \ No newline at end of file diff --git a/android/examples/Basics/Objects/CompositeObjects/EggRing.pde b/android/examples/Basics/Objects/CompositeObjects/EggRing.pde new file mode 100644 index 000000000..2648603f9 --- /dev/null +++ b/android/examples/Basics/Objects/CompositeObjects/EggRing.pde @@ -0,0 +1,19 @@ +class EggRing { + Egg ovoid; + Ring circle = new Ring(); + + EggRing(int x, int y, float t, float sp) { + ovoid = new Egg(x, y, t, sp); + circle.start(x, y - sp/2); + } + + void transmit() { + ovoid.wobble(); + ovoid.display(); + circle.grow(); + circle.display(); + if (circle.on == false) { + circle.on = true; + } + } +} diff --git a/android/examples/Basics/Objects/CompositeObjects/Ring.pde b/android/examples/Basics/Objects/CompositeObjects/Ring.pde new file mode 100644 index 000000000..3baf5623d --- /dev/null +++ b/android/examples/Basics/Objects/CompositeObjects/Ring.pde @@ -0,0 +1,27 @@ +class Ring { + float x, y; // X-coordinate, y-coordinate + float diameter; // Diameter of the ring + boolean on = false; // Turns the display on and off + void start(float xpos, float ypos) { + x = xpos; + y = ypos; + on = true; + diameter = 1; + } + void grow() { + if (on == true) { + diameter += 0.5; + if (diameter > width*2) { + diameter = 0.0; + } + } + } + void display() { + if (on == true) { + noFill(); + strokeWeight(4); + stroke(155, 153); + ellipse(x, y, diameter, diameter); + } + } +} diff --git a/android/examples/Basics/Objects/CompositeObjects/applet/CompositeObjects.java b/android/examples/Basics/Objects/CompositeObjects/applet/CompositeObjects.java new file mode 100644 index 000000000..3da16d412 --- /dev/null +++ b/android/examples/Basics/Objects/CompositeObjects/applet/CompositeObjects.java @@ -0,0 +1,125 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class CompositeObjects extends PApplet { + +/** + * Composite Objects + * + * An object can include several other objects. Creating such composite objects + * is a good way to use the principles of modularity and build higher levels of + * abstraction within a program. + */ + +EggRing er1, er2; + +public void setup() +{ + size(200, 200); + smooth(); + er1 = new EggRing(66, 132, 0.1f, 66); + er2 = new EggRing(132, 180, 0.05f, 132); +} + +public void draw() +{ + background(0); + er1.transmit(); + er2.transmit(); +} + +class EggRing +{ + Egg ovoid; + Ring circle = new Ring(); + EggRing(int x, int y, float t, float sp) { + ovoid = new Egg(x, y, t, sp); + circle.start(x, y - sp/2); + } + public void transmit() { + ovoid.wobble(); + ovoid.display(); + circle.grow(); + circle.display(); + if (circle.on == false) { + circle.on = true; + } + } +} + +class Egg { + float x, y; // X-coordinate, y-coordinate + float tilt; // Left and right angle offset + float angle; // Used to define the tilt + float scalar; // Height of the egg + // Constructor + Egg(int xpos, int ypos, float t, float s) { + x = xpos; + y = ypos; + tilt = t; + scalar = s / 100.0f; + } + public void wobble() { + tilt = cos(angle) / 8; + angle += 0.1f; + } + public void display() { + noStroke(); + fill(255); + pushMatrix(); + translate(x, y); + rotate(tilt); + scale(scalar); + beginShape(); + vertex(0, -100); + bezierVertex(25, -100, 40, -65, 40, -40); + bezierVertex(40, -15, 25, 0, 0, 0); + bezierVertex(-25, 0, -40, -15, -40, -40); + bezierVertex(-40, -65, -25, -100, 0, -100); + endShape(); + popMatrix(); + } +} + +class Ring { + float x, y; // X-coordinate, y-coordinate + float diameter; // Diameter of the ring + boolean on = false; // Turns the display on and off + public void start(float xpos, float ypos) { + x = xpos; + y = ypos; + on = true; + diameter = 1; + } + public void grow() { + if (on == true) { + diameter += 0.5f; + if (diameter > width*2) { + diameter = 0.0f; + } + } + } + public void display() { + if (on == true) { + noFill(); + strokeWeight(4); + stroke(155, 153); + ellipse(x, y, diameter, diameter); + } + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "CompositeObjects" }); + } +} diff --git a/android/examples/Basics/Objects/CompositeObjects/applet/CompositeObjects.pde b/android/examples/Basics/Objects/CompositeObjects/applet/CompositeObjects.pde new file mode 100644 index 000000000..171c03ae9 --- /dev/null +++ b/android/examples/Basics/Objects/CompositeObjects/applet/CompositeObjects.pde @@ -0,0 +1,105 @@ +/** + * Composite Objects + * + * An object can include several other objects. Creating such composite objects + * is a good way to use the principles of modularity and build higher levels of + * abstraction within a program. + */ + +EggRing er1, er2; + +void setup() +{ + size(200, 200); + smooth(); + er1 = new EggRing(66, 132, 0.1, 66); + er2 = new EggRing(132, 180, 0.05, 132); +} + +void draw() +{ + background(0); + er1.transmit(); + er2.transmit(); +} + +class EggRing +{ + Egg ovoid; + Ring circle = new Ring(); + EggRing(int x, int y, float t, float sp) { + ovoid = new Egg(x, y, t, sp); + circle.start(x, y - sp/2); + } + void transmit() { + ovoid.wobble(); + ovoid.display(); + circle.grow(); + circle.display(); + if (circle.on == false) { + circle.on = true; + } + } +} + +class Egg { + float x, y; // X-coordinate, y-coordinate + float tilt; // Left and right angle offset + float angle; // Used to define the tilt + float scalar; // Height of the egg + // Constructor + Egg(int xpos, int ypos, float t, float s) { + x = xpos; + y = ypos; + tilt = t; + scalar = s / 100.0; + } + void wobble() { + tilt = cos(angle) / 8; + angle += 0.1; + } + void display() { + noStroke(); + fill(255); + pushMatrix(); + translate(x, y); + rotate(tilt); + scale(scalar); + beginShape(); + vertex(0, -100); + bezierVertex(25, -100, 40, -65, 40, -40); + bezierVertex(40, -15, 25, 0, 0, 0); + bezierVertex(-25, 0, -40, -15, -40, -40); + bezierVertex(-40, -65, -25, -100, 0, -100); + endShape(); + popMatrix(); + } +} + +class Ring { + float x, y; // X-coordinate, y-coordinate + float diameter; // Diameter of the ring + boolean on = false; // Turns the display on and off + void start(float xpos, float ypos) { + x = xpos; + y = ypos; + on = true; + diameter = 1; + } + void grow() { + if (on == true) { + diameter += 0.5; + if (diameter > width*2) { + diameter = 0.0; + } + } + } + void display() { + if (on == true) { + noFill(); + strokeWeight(4); + stroke(155, 153); + ellipse(x, y, diameter, diameter); + } + } +} diff --git a/android/examples/Basics/Objects/CompositeObjects/applet/loading.gif b/android/examples/Basics/Objects/CompositeObjects/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Objects/CompositeObjects/applet/loading.gif differ diff --git a/android/examples/Basics/Objects/Inheritance/Inheritance.pde b/android/examples/Basics/Objects/Inheritance/Inheritance.pde new file mode 100644 index 000000000..6c4af0bc8 --- /dev/null +++ b/android/examples/Basics/Objects/Inheritance/Inheritance.pde @@ -0,0 +1,78 @@ +/** + * Inheritance + * + * A class can be defined using another class as a foundation. In object-oriented + * programming terminology, one class can inherit fi elds and methods from another. + * An object that inherits from another is called a subclass, and the object it + * inherits from is called a superclass. A subclass extends the superclass. + */ + +SpinSpots spots; +SpinArm arm; + +void setup() +{ + size(200, 200); + smooth(); + arm = new SpinArm(width/2, height/2, 0.01); + spots = new SpinSpots(width/2, height/2, -0.02, 33.0); +} + +void draw() +{ + background(204); + arm.update(); + arm.display(); + spots.update(); + spots.display(); +} + +class Spin +{ + float x, y, speed; + float angle = 0.0; + Spin(float xpos, float ypos, float s) { + x = xpos; + y = ypos; + speed = s; + } + void update() { + angle += speed; + } +} + +class SpinArm extends Spin +{ + SpinArm(float x, float y, float s) { + super(x, y, s); + } + void display() { + strokeWeight(1); + stroke(0); + pushMatrix(); + translate(x, y); + angle += speed; + rotate(angle); + line(0, 0, 66, 0); + popMatrix(); + } +} + +class SpinSpots extends Spin +{ + float dim; + SpinSpots(float x, float y, float s, float d) { + super(x, y, s); + dim = d; + } + void display() { + noStroke(); + pushMatrix(); + translate(x, y); + angle += speed; + rotate(angle); + ellipse(-dim/2, 0, dim, dim); + ellipse(dim/2, 0, dim, dim); + popMatrix(); + } +} diff --git a/android/examples/Basics/Objects/Inheritance/applet/Inheritance.java b/android/examples/Basics/Objects/Inheritance/applet/Inheritance.java new file mode 100644 index 000000000..6b517719f --- /dev/null +++ b/android/examples/Basics/Objects/Inheritance/applet/Inheritance.java @@ -0,0 +1,98 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Inheritance extends PApplet { + +/** + * Inheritance + * + * A class can be defined using another class as a foundation. In object-oriented + * programming terminology, one class can inherit fi elds and methods from another. + * An object that inherits from another is called a subclass, and the object it + * inherits from is called a superclass. A subclass extends the superclass. + */ + +SpinSpots spots; +SpinArm arm; + +public void setup() +{ + size(200, 200); + smooth(); + arm = new SpinArm(width/2, height/2, 0.01f); + spots = new SpinSpots(width/2, height/2, -0.02f, 33.0f); +} + +public void draw() +{ + background(204); + arm.update(); + arm.display(); + spots.update(); + spots.display(); +} + +class Spin +{ + float x, y, speed; + float angle = 0.0f; + Spin(float xpos, float ypos, float s) { + x = xpos; + y = ypos; + speed = s; + } + public void update() { + angle += speed; + } +} + +class SpinArm extends Spin +{ + SpinArm(float x, float y, float s) { + super(x, y, s); + } + public void display() { + strokeWeight(1); + stroke(0); + pushMatrix(); + translate(x, y); + angle += speed; + rotate(angle); + line(0, 0, 66, 0); + popMatrix(); + } +} + +class SpinSpots extends Spin +{ + float dim; + SpinSpots(float x, float y, float s, float d) { + super(x, y, s); + dim = d; + } + public void display() { + noStroke(); + pushMatrix(); + translate(x, y); + angle += speed; + rotate(angle); + ellipse(-dim/2, 0, dim, dim); + ellipse(dim/2, 0, dim, dim); + popMatrix(); + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Inheritance" }); + } +} diff --git a/android/examples/Basics/Objects/Inheritance/applet/Inheritance.pde b/android/examples/Basics/Objects/Inheritance/applet/Inheritance.pde new file mode 100644 index 000000000..6c4af0bc8 --- /dev/null +++ b/android/examples/Basics/Objects/Inheritance/applet/Inheritance.pde @@ -0,0 +1,78 @@ +/** + * Inheritance + * + * A class can be defined using another class as a foundation. In object-oriented + * programming terminology, one class can inherit fi elds and methods from another. + * An object that inherits from another is called a subclass, and the object it + * inherits from is called a superclass. A subclass extends the superclass. + */ + +SpinSpots spots; +SpinArm arm; + +void setup() +{ + size(200, 200); + smooth(); + arm = new SpinArm(width/2, height/2, 0.01); + spots = new SpinSpots(width/2, height/2, -0.02, 33.0); +} + +void draw() +{ + background(204); + arm.update(); + arm.display(); + spots.update(); + spots.display(); +} + +class Spin +{ + float x, y, speed; + float angle = 0.0; + Spin(float xpos, float ypos, float s) { + x = xpos; + y = ypos; + speed = s; + } + void update() { + angle += speed; + } +} + +class SpinArm extends Spin +{ + SpinArm(float x, float y, float s) { + super(x, y, s); + } + void display() { + strokeWeight(1); + stroke(0); + pushMatrix(); + translate(x, y); + angle += speed; + rotate(angle); + line(0, 0, 66, 0); + popMatrix(); + } +} + +class SpinSpots extends Spin +{ + float dim; + SpinSpots(float x, float y, float s, float d) { + super(x, y, s); + dim = d; + } + void display() { + noStroke(); + pushMatrix(); + translate(x, y); + angle += speed; + rotate(angle); + ellipse(-dim/2, 0, dim, dim); + ellipse(dim/2, 0, dim, dim); + popMatrix(); + } +} diff --git a/android/examples/Basics/Objects/Inheritance/applet/loading.gif b/android/examples/Basics/Objects/Inheritance/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Objects/Inheritance/applet/loading.gif differ diff --git a/android/examples/Basics/Objects/MultipleConstructors/MultipleConstructors.pde b/android/examples/Basics/Objects/MultipleConstructors/MultipleConstructors.pde new file mode 100644 index 000000000..fd57edbfd --- /dev/null +++ b/android/examples/Basics/Objects/MultipleConstructors/MultipleConstructors.pde @@ -0,0 +1,47 @@ +/** + * Multiple constructors + * + * A class can have multiple constructors that assign the fields in different ways. + * Sometimes it's beneficial to specify every aspect of an object's data by assigning + * parameters to the fields, but other times it might be appropriate to define only + * one or a few. + */ + +Spot sp1, sp2; +void setup() +{ + size(200, 200); + background(204); + smooth(); + noLoop(); + // Run the constructor without parameters + sp1 = new Spot(); + // Run the constructor with three parameters + sp2 = new Spot(122, 100, 40); +} + +void draw() { + sp1.display(); + sp2.display(); +} + +class Spot { + float x, y, radius; + // First version of the Spot constructor; + // the fields are assigned default values + Spot() { + x = 66; + y = 100; + radius = 16; + } + // Second version of the Spot constructor; + // the fields are assigned with parameters + Spot(float xpos, float ypos, float r) { + x = xpos; + y = ypos; + radius = r; + } + void display() { + ellipse(x, y, radius*2, radius*2); + } +} diff --git a/android/examples/Basics/Objects/MultipleConstructors/applet/MultipleConstructors.java b/android/examples/Basics/Objects/MultipleConstructors/applet/MultipleConstructors.java new file mode 100644 index 000000000..db8031348 --- /dev/null +++ b/android/examples/Basics/Objects/MultipleConstructors/applet/MultipleConstructors.java @@ -0,0 +1,67 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class MultipleConstructors extends PApplet { + +/** + * Multiple constructors + * + * A class can have multiple constructors that assign the fields in different ways. + * Sometimes it's beneficial to specify every aspect of an object's data by assigning + * parameters to the fields, but other times it might be appropriate to define only + * one or a few. + */ + +Spot sp1, sp2; +public void setup() +{ + size(200, 200); + background(204); + smooth(); + noLoop(); + // Run the constructor without parameters + sp1 = new Spot(); + // Run the constructor with three parameters + sp2 = new Spot(122, 100, 40); +} + +public void draw() { + sp1.display(); + sp2.display(); +} + +class Spot { + float x, y, radius; + // First version of the Spot constructor; + // the fields are assigned default values + Spot() { + x = 66; + y = 100; + radius = 16; + } + // Second version of the Spot constructor; + // the fields are assigned with parameters + Spot(float xpos, float ypos, float r) { + x = xpos; + y = ypos; + radius = r; + } + public void display() { + ellipse(x, y, radius*2, radius*2); + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "MultipleConstructors" }); + } +} diff --git a/android/examples/Basics/Objects/MultipleConstructors/applet/MultipleConstructors.pde b/android/examples/Basics/Objects/MultipleConstructors/applet/MultipleConstructors.pde new file mode 100644 index 000000000..fd57edbfd --- /dev/null +++ b/android/examples/Basics/Objects/MultipleConstructors/applet/MultipleConstructors.pde @@ -0,0 +1,47 @@ +/** + * Multiple constructors + * + * A class can have multiple constructors that assign the fields in different ways. + * Sometimes it's beneficial to specify every aspect of an object's data by assigning + * parameters to the fields, but other times it might be appropriate to define only + * one or a few. + */ + +Spot sp1, sp2; +void setup() +{ + size(200, 200); + background(204); + smooth(); + noLoop(); + // Run the constructor without parameters + sp1 = new Spot(); + // Run the constructor with three parameters + sp2 = new Spot(122, 100, 40); +} + +void draw() { + sp1.display(); + sp2.display(); +} + +class Spot { + float x, y, radius; + // First version of the Spot constructor; + // the fields are assigned default values + Spot() { + x = 66; + y = 100; + radius = 16; + } + // Second version of the Spot constructor; + // the fields are assigned with parameters + Spot(float xpos, float ypos, float r) { + x = xpos; + y = ypos; + radius = r; + } + void display() { + ellipse(x, y, radius*2, radius*2); + } +} diff --git a/android/examples/Basics/Objects/MultipleConstructors/applet/loading.gif b/android/examples/Basics/Objects/MultipleConstructors/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Objects/MultipleConstructors/applet/loading.gif differ diff --git a/android/examples/Basics/Objects/Neighborhood/Neighborhood.pde b/android/examples/Basics/Objects/Neighborhood/Neighborhood.pde new file mode 100644 index 000000000..f70893d25 --- /dev/null +++ b/android/examples/Basics/Objects/Neighborhood/Neighborhood.pde @@ -0,0 +1,303 @@ +/** + * Neighborhood (OOP Example) + * By Ira Greenberg + * + * Draw a neighborhood of houses using + * Door, Window, Roof and House classes. + * Good example of class composition, with component + * Door, Window, Roof class references encapsulated + * within House class. This arrangement allows + * House class to handle placement and sizing of + * its components, while still allowing user + * customization of the individual components. + */ + +void setup(){ + size(200, 200); + background(190); + smooth(); + // Ground plane + int groundHeight = 10; + fill(0); + rect(0, height-groundHeight, width, groundHeight); + fill(255); + + // Center the houses + translate(12, 0); + + // Houses + Door door1 = new Door(20, 40); + Window window1 = new Window(50, 62, false, Window.DOUBLE); + Roof roof1 = new Roof(Roof.DOME); + House house1 = new House(75, 75, door1, window1, roof1, House.MIDDLE_DOOR); + house1.drawHouse(0, height-groundHeight-house1.h, true); + + Door door2 = new Door(20, 40); + Window window2 = new Window(50, 62, true, Window.QUAD); + Roof roof2 = new Roof(Roof.GAMBREL); + House house2 = new House(100, 60, door2, window2, roof2, House.LEFT_DOOR); + house2.drawHouse(house1.x + house1.w, height-groundHeight-house2.h, true); +} + +class Door{ + //door properties + int x; + int y; + int w; + int h; + + // for knob + int knobLoc = 1; + //constants + final static int RT = 0; + final static int LFT = 1; + + // constructor + Door(int w, int h){ + this.w = w; + this.h = h; + } + + // draw the door + void drawDoor(int x, int y) { + rect(x, y, w, h); + int knobsize = w/10; + if (knobLoc == 0){ + //right side + ellipse(x+w-knobsize, y+h/2, knobsize, knobsize); + } + else { + //left side + ellipse(x+knobsize, y+h/2, knobsize, knobsize); + } + } + + // set knob position + void setKnob(int knobLoc){ + this. knobLoc = knobLoc; + } +} + +class Window{ + //window properties + int x; + int y; + int w; + int h; + + // customized features + boolean hasSash = false; + + // single, double, quad pane + int style = 0; + //constants + final static int SINGLE = 0; + final static int DOUBLE = 1; + final static int QUAD = 2; + + // constructor 1 + Window(int w, int h){ + this.w = w; + this.h = h; + } + // constructor 2 + Window(int w, int h, int style){ + this.w = w; + this.h = h; + this.style = style; + } + // constructor 3 + Window(int w, int h, boolean hasSash, int style){ + this.w = w; + this.h = h; + this.hasSash = hasSash; + this.style = style; + } + + // draw the window + void drawWindow(int x, int y) { + //local variables + int margin = 0; + int winHt = 0; + int winWdth = 0; + + if (hasSash){ + margin = w/15; + } + + switch(style){ + case 0: + //outer window (sash) + rect(x, y, w, h); + //inner window + rect(x+margin, y+margin, w-margin*2, h-margin*2); + break; + case 1: + winHt = (h-margin*3)/2; + //outer window (sash) + rect(x, y, w, h); + //inner window (top) + rect(x+margin, y+margin, w-margin*2, winHt); + //inner windows (bottom) + rect(x+margin, y+winHt+margin*2, w-margin*2, winHt); + break; + case 2: + winWdth = (w-margin*3)/2; + winHt = (h-margin*3)/2; + //outer window (sash) + rect(x, y, w, h); + //inner window (top-left) + rect(x+margin, y+margin, winWdth, winHt); + //inner window (top-right) + rect(x+winWdth+margin*2, y+margin, winWdth, winHt); + //inner windows (bottom-left) + rect(x+margin, y+winHt+margin*2, winWdth, winHt); + //inner windows (bottom-right) + rect(x+winWdth+margin*2, y+winHt+margin*2, winWdth, winHt); + break; + } + } + + // set window style (number of panes) + void setStyle(int style){ + this.style = style; + } +} + +class Roof{ + //roof properties + int x; + int y; + int w; + int h; + + // roof style + int style = 0; + //constants + final static int CATHEDRAL = 0; + final static int GAMBREL = 1; + final static int DOME = 2; + + // default constructor + Roof(){ + } + + // constructor 2 + Roof(int style){ + this.style = style; + } + + // draw the roof + void drawRoof(int x, int y, int w, int h) { + switch(style){ + case 0: + beginShape(); + vertex(x, y); + vertex(x+w/2, y-h/3); + vertex(x+w, y); + endShape(CLOSE); + break; + case 1: + beginShape(); + vertex(x, y); + vertex(x+w/7, y-h/4); + vertex(x+w/2, y-h/2); + vertex(x+(w-w/7), y-h/4); + vertex(x+w, y); + endShape(CLOSE); + break; + case 2: + ellipseMode(CORNER); + arc(x, y-h/2, w, h, PI, TWO_PI); + line(x, y, x+w, y); + break; + } + + } + + // set roof style + void setStyle(int style){ + this.style = style; + } +} + +class House{ + //house properties + int x; + int y; + int w; + int h; + + //component reference variables + Door door; + Window window; + Roof roof; + + //optional autosize variable + boolean AutoSizeComponents = false; + + //door placement + int doorLoc = 0; + //constants + final static int MIDDLE_DOOR = 0; + final static int LEFT_DOOR = 1; + final static int RIGHT_DOOR = 2; + + //constructor + House(int w, int h, Door door, Window window, Roof roof, int doorLoc) { + this.w = w; + this.h = h; + this.door = door; + this.window = window; + this.roof = roof; + this.doorLoc = doorLoc; + } + + void drawHouse(int x, int y, boolean AutoSizeComponents) { + this.x = x; + this.y =y; + this.AutoSizeComponents = AutoSizeComponents; + + //automatically sizes doors and windows + if(AutoSizeComponents){ + //autosize door + door.h = h/4; + door.w = door.h/2; + + //autosize windows + window.h = h/3; + window.w = window.h/2; + + } + // draw bldg block + rect(x, y, w, h); + + // draw door + switch(doorLoc){ + case 0: + door.drawDoor(x+w/2-door.w/2, y+h-door.h); + break; + case 1: + door.drawDoor(x+w/8, y+h-door.h); + break; + case 2: + door.drawDoor(x+w-w/8-door.w, y+h-door.h); + break; + } + + // draw windows + int windowMargin = (w-window.w*2)/3; + window.drawWindow(x+windowMargin, y+h/6); + window.drawWindow(x+windowMargin*2+window.w, y+h/6); + + // draw roof + roof.drawRoof(x, y, w, h); + } + + // catch drawHouse method without boolean argument + void drawHouse(int x, int y){ + // recall with required 3rd argument + drawHouse(x, y, false); + } +} + diff --git a/android/examples/Basics/Objects/Neighborhood/applet/Neighborhood.java b/android/examples/Basics/Objects/Neighborhood/applet/Neighborhood.java new file mode 100644 index 000000000..d6646893c --- /dev/null +++ b/android/examples/Basics/Objects/Neighborhood/applet/Neighborhood.java @@ -0,0 +1,323 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Neighborhood extends PApplet { + +/** + * Neighborhood (OOP Example) + * By Ira Greenberg + * + * Draw a neighborhood of houses using + * Door, Window, Roof and House classes. + * Good example of class composition, with component + * Door, Window, Roof class references encapsulated + * within House class. This arrangement allows + * House class to handle placement and sizing of + * its components, while still allowing user + * customization of the individual components. + */ + +public void setup(){ + size(200, 200); + background(190); + smooth(); + // Ground plane + int groundHeight = 10; + fill(0); + rect(0, height-groundHeight, width, groundHeight); + fill(255); + + // Center the houses + translate(12, 0); + + // Houses + Door door1 = new Door(20, 40); + Window window1 = new Window(50, 62, false, Window.DOUBLE); + Roof roof1 = new Roof(Roof.DOME); + House house1 = new House(75, 75, door1, window1, roof1, House.MIDDLE_DOOR); + house1.drawHouse(0, height-groundHeight-house1.h, true); + + Door door2 = new Door(20, 40); + Window window2 = new Window(50, 62, true, Window.QUAD); + Roof roof2 = new Roof(Roof.GAMBREL); + House house2 = new House(100, 60, door2, window2, roof2, House.LEFT_DOOR); + house2.drawHouse(house1.x + house1.w, height-groundHeight-house2.h, true); +} + +class Door{ + //door properties + int x; + int y; + int w; + int h; + + // for knob + int knobLoc = 1; + //constants + final static int RT = 0; + final static int LFT = 1; + + // constructor + Door(int w, int h){ + this.w = w; + this.h = h; + } + + // draw the door + public void drawDoor(int x, int y) { + rect(x, y, w, h); + int knobsize = w/10; + if (knobLoc == 0){ + //right side + ellipse(x+w-knobsize, y+h/2, knobsize, knobsize); + } + else { + //left side + ellipse(x+knobsize, y+h/2, knobsize, knobsize); + } + } + + // set knob position + public void setKnob(int knobLoc){ + this. knobLoc = knobLoc; + } +} + +class Window{ + //window properties + int x; + int y; + int w; + int h; + + // customized features + boolean hasSash = false; + + // single, double, quad pane + int style = 0; + //constants + final static int SINGLE = 0; + final static int DOUBLE = 1; + final static int QUAD = 2; + + // constructor 1 + Window(int w, int h){ + this.w = w; + this.h = h; + } + // constructor 2 + Window(int w, int h, int style){ + this.w = w; + this.h = h; + this.style = style; + } + // constructor 3 + Window(int w, int h, boolean hasSash, int style){ + this.w = w; + this.h = h; + this.hasSash = hasSash; + this.style = style; + } + + // draw the window + public void drawWindow(int x, int y) { + //local variables + int margin = 0; + int winHt = 0; + int winWdth = 0; + + if (hasSash){ + margin = w/15; + } + + switch(style){ + case 0: + //outer window (sash) + rect(x, y, w, h); + //inner window + rect(x+margin, y+margin, w-margin*2, h-margin*2); + break; + case 1: + winHt = (h-margin*3)/2; + //outer window (sash) + rect(x, y, w, h); + //inner window (top) + rect(x+margin, y+margin, w-margin*2, winHt); + //inner windows (bottom) + rect(x+margin, y+winHt+margin*2, w-margin*2, winHt); + break; + case 2: + winWdth = (w-margin*3)/2; + winHt = (h-margin*3)/2; + //outer window (sash) + rect(x, y, w, h); + //inner window (top-left) + rect(x+margin, y+margin, winWdth, winHt); + //inner window (top-right) + rect(x+winWdth+margin*2, y+margin, winWdth, winHt); + //inner windows (bottom-left) + rect(x+margin, y+winHt+margin*2, winWdth, winHt); + //inner windows (bottom-right) + rect(x+winWdth+margin*2, y+winHt+margin*2, winWdth, winHt); + break; + } + } + + // set window style (number of panes) + public void setStyle(int style){ + this.style = style; + } +} + +class Roof{ + //roof properties + int x; + int y; + int w; + int h; + + // roof style + int style = 0; + //constants + final static int CATHEDRAL = 0; + final static int GAMBREL = 1; + final static int DOME = 2; + + // default constructor + Roof(){ + } + + // constructor 2 + Roof(int style){ + this.style = style; + } + + // draw the roof + public void drawRoof(int x, int y, int w, int h) { + switch(style){ + case 0: + beginShape(); + vertex(x, y); + vertex(x+w/2, y-h/3); + vertex(x+w, y); + endShape(CLOSE); + break; + case 1: + beginShape(); + vertex(x, y); + vertex(x+w/7, y-h/4); + vertex(x+w/2, y-h/2); + vertex(x+(w-w/7), y-h/4); + vertex(x+w, y); + endShape(CLOSE); + break; + case 2: + ellipseMode(CORNER); + arc(x, y-h/2, w, h, PI, TWO_PI); + line(x, y, x+w, y); + break; + } + + } + + // set roof style + public void setStyle(int style){ + this.style = style; + } +} + +class House{ + //house properties + int x; + int y; + int w; + int h; + + //component reference variables + Door door; + Window window; + Roof roof; + + //optional autosize variable + boolean AutoSizeComponents = false; + + //door placement + int doorLoc = 0; + //constants + final static int MIDDLE_DOOR = 0; + final static int LEFT_DOOR = 1; + final static int RIGHT_DOOR = 2; + + //constructor + House(int w, int h, Door door, Window window, Roof roof, int doorLoc) { + this.w = w; + this.h = h; + this.door = door; + this.window = window; + this.roof = roof; + this.doorLoc = doorLoc; + } + + public void drawHouse(int x, int y, boolean AutoSizeComponents) { + this.x = x; + this.y =y; + this.AutoSizeComponents = AutoSizeComponents; + + //automatically sizes doors and windows + if(AutoSizeComponents){ + //autosize door + door.h = h/4; + door.w = door.h/2; + + //autosize windows + window.h = h/3; + window.w = window.h/2; + + } + // draw bldg block + rect(x, y, w, h); + + // draw door + switch(doorLoc){ + case 0: + door.drawDoor(x+w/2-door.w/2, y+h-door.h); + break; + case 1: + door.drawDoor(x+w/8, y+h-door.h); + break; + case 2: + door.drawDoor(x+w-w/8-door.w, y+h-door.h); + break; + } + + // draw windows + int windowMargin = (w-window.w*2)/3; + window.drawWindow(x+windowMargin, y+h/6); + window.drawWindow(x+windowMargin*2+window.w, y+h/6); + + // draw roof + roof.drawRoof(x, y, w, h); + } + + // catch drawHouse method without boolean argument + public void drawHouse(int x, int y){ + // recall with required 3rd argument + drawHouse(x, y, false); + } +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "Neighborhood" }); + } +} diff --git a/android/examples/Basics/Objects/Neighborhood/applet/Neighborhood.pde b/android/examples/Basics/Objects/Neighborhood/applet/Neighborhood.pde new file mode 100644 index 000000000..f70893d25 --- /dev/null +++ b/android/examples/Basics/Objects/Neighborhood/applet/Neighborhood.pde @@ -0,0 +1,303 @@ +/** + * Neighborhood (OOP Example) + * By Ira Greenberg + * + * Draw a neighborhood of houses using + * Door, Window, Roof and House classes. + * Good example of class composition, with component + * Door, Window, Roof class references encapsulated + * within House class. This arrangement allows + * House class to handle placement and sizing of + * its components, while still allowing user + * customization of the individual components. + */ + +void setup(){ + size(200, 200); + background(190); + smooth(); + // Ground plane + int groundHeight = 10; + fill(0); + rect(0, height-groundHeight, width, groundHeight); + fill(255); + + // Center the houses + translate(12, 0); + + // Houses + Door door1 = new Door(20, 40); + Window window1 = new Window(50, 62, false, Window.DOUBLE); + Roof roof1 = new Roof(Roof.DOME); + House house1 = new House(75, 75, door1, window1, roof1, House.MIDDLE_DOOR); + house1.drawHouse(0, height-groundHeight-house1.h, true); + + Door door2 = new Door(20, 40); + Window window2 = new Window(50, 62, true, Window.QUAD); + Roof roof2 = new Roof(Roof.GAMBREL); + House house2 = new House(100, 60, door2, window2, roof2, House.LEFT_DOOR); + house2.drawHouse(house1.x + house1.w, height-groundHeight-house2.h, true); +} + +class Door{ + //door properties + int x; + int y; + int w; + int h; + + // for knob + int knobLoc = 1; + //constants + final static int RT = 0; + final static int LFT = 1; + + // constructor + Door(int w, int h){ + this.w = w; + this.h = h; + } + + // draw the door + void drawDoor(int x, int y) { + rect(x, y, w, h); + int knobsize = w/10; + if (knobLoc == 0){ + //right side + ellipse(x+w-knobsize, y+h/2, knobsize, knobsize); + } + else { + //left side + ellipse(x+knobsize, y+h/2, knobsize, knobsize); + } + } + + // set knob position + void setKnob(int knobLoc){ + this. knobLoc = knobLoc; + } +} + +class Window{ + //window properties + int x; + int y; + int w; + int h; + + // customized features + boolean hasSash = false; + + // single, double, quad pane + int style = 0; + //constants + final static int SINGLE = 0; + final static int DOUBLE = 1; + final static int QUAD = 2; + + // constructor 1 + Window(int w, int h){ + this.w = w; + this.h = h; + } + // constructor 2 + Window(int w, int h, int style){ + this.w = w; + this.h = h; + this.style = style; + } + // constructor 3 + Window(int w, int h, boolean hasSash, int style){ + this.w = w; + this.h = h; + this.hasSash = hasSash; + this.style = style; + } + + // draw the window + void drawWindow(int x, int y) { + //local variables + int margin = 0; + int winHt = 0; + int winWdth = 0; + + if (hasSash){ + margin = w/15; + } + + switch(style){ + case 0: + //outer window (sash) + rect(x, y, w, h); + //inner window + rect(x+margin, y+margin, w-margin*2, h-margin*2); + break; + case 1: + winHt = (h-margin*3)/2; + //outer window (sash) + rect(x, y, w, h); + //inner window (top) + rect(x+margin, y+margin, w-margin*2, winHt); + //inner windows (bottom) + rect(x+margin, y+winHt+margin*2, w-margin*2, winHt); + break; + case 2: + winWdth = (w-margin*3)/2; + winHt = (h-margin*3)/2; + //outer window (sash) + rect(x, y, w, h); + //inner window (top-left) + rect(x+margin, y+margin, winWdth, winHt); + //inner window (top-right) + rect(x+winWdth+margin*2, y+margin, winWdth, winHt); + //inner windows (bottom-left) + rect(x+margin, y+winHt+margin*2, winWdth, winHt); + //inner windows (bottom-right) + rect(x+winWdth+margin*2, y+winHt+margin*2, winWdth, winHt); + break; + } + } + + // set window style (number of panes) + void setStyle(int style){ + this.style = style; + } +} + +class Roof{ + //roof properties + int x; + int y; + int w; + int h; + + // roof style + int style = 0; + //constants + final static int CATHEDRAL = 0; + final static int GAMBREL = 1; + final static int DOME = 2; + + // default constructor + Roof(){ + } + + // constructor 2 + Roof(int style){ + this.style = style; + } + + // draw the roof + void drawRoof(int x, int y, int w, int h) { + switch(style){ + case 0: + beginShape(); + vertex(x, y); + vertex(x+w/2, y-h/3); + vertex(x+w, y); + endShape(CLOSE); + break; + case 1: + beginShape(); + vertex(x, y); + vertex(x+w/7, y-h/4); + vertex(x+w/2, y-h/2); + vertex(x+(w-w/7), y-h/4); + vertex(x+w, y); + endShape(CLOSE); + break; + case 2: + ellipseMode(CORNER); + arc(x, y-h/2, w, h, PI, TWO_PI); + line(x, y, x+w, y); + break; + } + + } + + // set roof style + void setStyle(int style){ + this.style = style; + } +} + +class House{ + //house properties + int x; + int y; + int w; + int h; + + //component reference variables + Door door; + Window window; + Roof roof; + + //optional autosize variable + boolean AutoSizeComponents = false; + + //door placement + int doorLoc = 0; + //constants + final static int MIDDLE_DOOR = 0; + final static int LEFT_DOOR = 1; + final static int RIGHT_DOOR = 2; + + //constructor + House(int w, int h, Door door, Window window, Roof roof, int doorLoc) { + this.w = w; + this.h = h; + this.door = door; + this.window = window; + this.roof = roof; + this.doorLoc = doorLoc; + } + + void drawHouse(int x, int y, boolean AutoSizeComponents) { + this.x = x; + this.y =y; + this.AutoSizeComponents = AutoSizeComponents; + + //automatically sizes doors and windows + if(AutoSizeComponents){ + //autosize door + door.h = h/4; + door.w = door.h/2; + + //autosize windows + window.h = h/3; + window.w = window.h/2; + + } + // draw bldg block + rect(x, y, w, h); + + // draw door + switch(doorLoc){ + case 0: + door.drawDoor(x+w/2-door.w/2, y+h-door.h); + break; + case 1: + door.drawDoor(x+w/8, y+h-door.h); + break; + case 2: + door.drawDoor(x+w-w/8-door.w, y+h-door.h); + break; + } + + // draw windows + int windowMargin = (w-window.w*2)/3; + window.drawWindow(x+windowMargin, y+h/6); + window.drawWindow(x+windowMargin*2+window.w, y+h/6); + + // draw roof + roof.drawRoof(x, y, w, h); + } + + // catch drawHouse method without boolean argument + void drawHouse(int x, int y){ + // recall with required 3rd argument + drawHouse(x, y, false); + } +} + diff --git a/android/examples/Basics/Objects/Neighborhood/applet/loading.gif b/android/examples/Basics/Objects/Neighborhood/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Objects/Neighborhood/applet/loading.gif differ diff --git a/android/examples/Basics/Objects/Objects/Objects.pde b/android/examples/Basics/Objects/Objects/Objects.pde new file mode 100644 index 000000000..80a09a3d6 --- /dev/null +++ b/android/examples/Basics/Objects/Objects/Objects.pde @@ -0,0 +1,71 @@ +/** + * Objects + * by hbarragan. + * + * Move the cursor across the image to change the speed and positions + * of the geometry. The class MRect defines a group of lines. + */ + +MRect r1, r2, r3, r4; + +void setup() +{ + size(200, 200); + fill(255, 204); + noStroke(); + r1 = new MRect(1, 134.0, 0.532, 0.083*height, 10.0, 60.0); + r2 = new MRect(2, 44.0, 0.166, 0.332*height, 5.0, 50.0); + r3 = new MRect(2, 58.0, 0.332, 0.4482*height, 10.0, 35.0); + r4 = new MRect(1, 120.0, 0.0498, 0.913*height, 15.0, 60.0); +} + +void draw() +{ + background(0); + + r1.display(); + r2.display(); + r3.display(); + r4.display(); + + r1.move(mouseX-(width/2), mouseY+(height*0.1), 30); + r2.move((mouseX+(width*0.05))%width, mouseY+(height*0.025), 20); + r3.move(mouseX/4, mouseY-(height*0.025), 40); + r4.move(mouseX-(width/2), (height-mouseY), 50); +} + +class MRect +{ + int w; // single bar width + float xpos; // rect xposition + float h; // rect height + float ypos ; // rect yposition + float d; // single bar distance + float t; // number of bars + + MRect(int iw, float ixp, float ih, float iyp, float id, float it) { + w = iw; + xpos = ixp; + h = ih; + ypos = iyp; + d = id; + t = it; + } + + void move (float posX, float posY, float damping) { + float dif = ypos - posY; + if (abs(dif) > 1) { + ypos -= dif/damping; + } + dif = xpos - posX; + if (abs(dif) > 1) { + xpos -= dif/damping; + } + } + + void display() { + for (int i=0; i 1) { + ypos -= dif/damping; + } + dif = xpos - posX; + if (abs(dif) > 1) { + xpos -= dif/damping; + } + } + + public void display() { + for (int i=0; i 1) { + ypos -= dif/damping; + } + dif = xpos - posX; + if (abs(dif) > 1) { + xpos -= dif/damping; + } + } + + void display() { + for (int i=0; i + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/examples/Basics/Shape/GetChild/GetChild.pde b/android/examples/Basics/Shape/GetChild/GetChild.pde new file mode 100644 index 000000000..0b9b9d393 --- /dev/null +++ b/android/examples/Basics/Shape/GetChild/GetChild.pde @@ -0,0 +1,45 @@ +/** + * Get Child. + * + * SVG files can be made of many individual shapes. + * Each of these shapes (called a "child") has its own name + * that can be used to extract it from the "parent" file. + * This example loads a map of the United States and creates + * two new PShape objects by extracting the data from two states. + */ + +PShape usa; +PShape michigan; +PShape ohio; + +void setup() { + size(640, 360); + usa = loadShape("usa-wikipedia.svg"); + michigan = usa.getChild("MI"); + ohio = usa.getChild("OH"); + smooth(); // Improves the drawing quality of the SVG + noLoop(); +} + +void draw() { + background(255); + + // Draw the full map + shape(usa, -600, -180); + + // Disable the colors found in the SVG file + michigan.disableStyle(); + // Set our own coloring + fill(0, 51, 102); + noStroke(); + // Draw a single state + shape(michigan, -600, -180); // Go Blue! + + // Disable the colors found in the SVG file + ohio.disableStyle(); + // Set our own coloring + fill(153, 0, 0); + noStroke(); + // Draw a single state + shape(ohio, -600, -180); // Boo Buckeyes! +} diff --git a/android/examples/Basics/Shape/GetChild/applet/GetChild.java b/android/examples/Basics/Shape/GetChild/applet/GetChild.java new file mode 100644 index 000000000..2854fbb45 --- /dev/null +++ b/android/examples/Basics/Shape/GetChild/applet/GetChild.java @@ -0,0 +1,66 @@ +import processing.core.*; +import processing.xml.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class GetChild extends PApplet { + +/** + * Get Child. + * + * SVG files can be made of many individual shapes. + * Each of these shapes (called a "child") has its own name + * that can be used to extract it from the "parent" file. + * This example loads a map of the United States and creates + * two new PShape objects by extracting the data from two states. + */ + +PShape usa; +PShape michigan; +PShape ohio; + +public void setup() { + size(640, 360); + usa = loadShape("usa-wikipedia.svg"); + michigan = usa.getChild("MI"); + ohio = usa.getChild("OH"); + smooth(); // Improves the drawing quality of the SVG + noLoop(); +} + +public void draw() { + background(255); + + // Draw the full map + shape(usa, -600, -180); + + // Disable the colors found in the SVG file + michigan.disableStyle(); + // Set our own coloring + fill(0, 51, 102); + noStroke(); + // Draw a single state + shape(michigan, -600, -180); // Boo Wolverines! + + // Disable the colors found in the SVG file + ohio.disableStyle(); + // Set our own coloring + fill(153, 0, 0); + noStroke(); + // Draw a single state + shape(ohio, -600, -180); // Go Buckeyes! +} + + static public void main(String args[]) { + PApplet.main(new String[] { "GetChild" }); + } +} diff --git a/android/examples/Basics/Shape/GetChild/applet/GetChild.pde b/android/examples/Basics/Shape/GetChild/applet/GetChild.pde new file mode 100644 index 000000000..0e1e69407 --- /dev/null +++ b/android/examples/Basics/Shape/GetChild/applet/GetChild.pde @@ -0,0 +1,45 @@ +/** + * Get Child. + * + * SVG files can be made of many individual shapes. + * Each of these shapes (called a "child") has its own name + * that can be used to extract it from the "parent" file. + * This example loads a map of the United States and creates + * two new PShape objects by extracting the data from two states. + */ + +PShape usa; +PShape michigan; +PShape ohio; + +void setup() { + size(640, 360); + usa = loadShape("usa-wikipedia.svg"); + michigan = usa.getChild("MI"); + ohio = usa.getChild("OH"); + smooth(); // Improves the drawing quality of the SVG + noLoop(); +} + +void draw() { + background(255); + + // Draw the full map + shape(usa, -600, -180); + + // Disable the colors found in the SVG file + michigan.disableStyle(); + // Set our own coloring + fill(0, 51, 102); + noStroke(); + // Draw a single state + shape(michigan, -600, -180); // Boo Wolverines! + + // Disable the colors found in the SVG file + ohio.disableStyle(); + // Set our own coloring + fill(153, 0, 0); + noStroke(); + // Draw a single state + shape(ohio, -600, -180); // Go Buckeyes! +} diff --git a/android/examples/Basics/Shape/GetChild/applet/loading.gif b/android/examples/Basics/Shape/GetChild/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Shape/GetChild/applet/loading.gif differ diff --git a/android/examples/Basics/Shape/GetChild/data/usa-wikipedia.svg b/android/examples/Basics/Shape/GetChild/data/usa-wikipedia.svg new file mode 100644 index 000000000..247ba7383 --- /dev/null +++ b/android/examples/Basics/Shape/GetChild/data/usa-wikipedia.svg @@ -0,0 +1,452 @@ + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/examples/Basics/Shape/LoadDisplayShape/LoadDisplayShape.pde b/android/examples/Basics/Shape/LoadDisplayShape/LoadDisplayShape.pde new file mode 100644 index 000000000..3d18b4b4a --- /dev/null +++ b/android/examples/Basics/Shape/LoadDisplayShape/LoadDisplayShape.pde @@ -0,0 +1,26 @@ +/** + * Load and Display a Shape. + * Illustration by George Brower. + * + * The loadShape() command is used to read simple SVG (Scalable Vector Graphics) + * files into a Processing sketch. This library was specifically tested under + * SVG files created from Adobe Illustrator. For now, we can't guarantee that + * it'll work for SVGs created with anything else. + */ + +PShape bot; + +void setup() { + size(640, 360); + smooth(); + // The file "bot1.svg" must be in the data folder + // of the current sketch to load successfully + bot = loadShape("bot1.svg"); + noLoop(); // Only run draw() once +} + +void draw(){ + background(102); + shape(bot, 110, 90, 100, 100); // Draw at coordinate (10, 10) at size 100 x 100 + shape(bot, 280, 40); // Draw at coordinate (70, 60) at the default size +} diff --git a/android/examples/Basics/Shape/LoadDisplayShape/applet/LoadDisplayShape.java b/android/examples/Basics/Shape/LoadDisplayShape/applet/LoadDisplayShape.java new file mode 100644 index 000000000..f7dc4e0af --- /dev/null +++ b/android/examples/Basics/Shape/LoadDisplayShape/applet/LoadDisplayShape.java @@ -0,0 +1,47 @@ +import processing.core.*; +import processing.xml.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class LoadDisplayShape extends PApplet { + +/** + * Load and Display a Shape. + * Illustration by George Brower. + * + * The loadShape() command is used to read simple SVG (Scalable Vector Graphics) + * files into a Processing sketch. This library was specifically tested under + * SVG files created from Adobe Illustrator. For now, we can't guarantee that + * it'll work for SVGs created with anything else. + */ + +PShape bot; + +public void setup() { + size(640, 360); + smooth(); + // The file "bot1.svg" must be in the data folder + // of the current sketch to load successfully + bot = loadShape("bot1.svg"); + noLoop(); // Only run draw() once +} + +public void draw(){ + background(102); + shape(bot, 110, 90, 100, 100); // Draw at coordinate (10, 10) at size 100 x 100 + shape(bot, 280, 40); // Draw at coordinate (70, 60) at the default size +} + + static public void main(String args[]) { + PApplet.main(new String[] { "LoadDisplayShape" }); + } +} diff --git a/android/examples/Basics/Shape/LoadDisplayShape/applet/LoadDisplayShape.pde b/android/examples/Basics/Shape/LoadDisplayShape/applet/LoadDisplayShape.pde new file mode 100644 index 000000000..3d18b4b4a --- /dev/null +++ b/android/examples/Basics/Shape/LoadDisplayShape/applet/LoadDisplayShape.pde @@ -0,0 +1,26 @@ +/** + * Load and Display a Shape. + * Illustration by George Brower. + * + * The loadShape() command is used to read simple SVG (Scalable Vector Graphics) + * files into a Processing sketch. This library was specifically tested under + * SVG files created from Adobe Illustrator. For now, we can't guarantee that + * it'll work for SVGs created with anything else. + */ + +PShape bot; + +void setup() { + size(640, 360); + smooth(); + // The file "bot1.svg" must be in the data folder + // of the current sketch to load successfully + bot = loadShape("bot1.svg"); + noLoop(); // Only run draw() once +} + +void draw(){ + background(102); + shape(bot, 110, 90, 100, 100); // Draw at coordinate (10, 10) at size 100 x 100 + shape(bot, 280, 40); // Draw at coordinate (70, 60) at the default size +} diff --git a/android/examples/Basics/Shape/LoadDisplayShape/applet/loading.gif b/android/examples/Basics/Shape/LoadDisplayShape/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Shape/LoadDisplayShape/applet/loading.gif differ diff --git a/android/examples/Basics/Shape/LoadDisplayShape/data/bot1.svg b/android/examples/Basics/Shape/LoadDisplayShape/data/bot1.svg new file mode 100644 index 000000000..3c56f2d60 --- /dev/null +++ b/android/examples/Basics/Shape/LoadDisplayShape/data/bot1.svg @@ -0,0 +1,160 @@ + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/examples/Basics/Shape/ScaleShape/ScaleShape.pde b/android/examples/Basics/Shape/ScaleShape/ScaleShape.pde new file mode 100644 index 000000000..879f20b68 --- /dev/null +++ b/android/examples/Basics/Shape/ScaleShape/ScaleShape.pde @@ -0,0 +1,26 @@ +/** + * Scale Shape. + * Illustration by George Brower. + * + * Move the mouse left and right to zoom the SVG file. + * This shows how, unlike an imported image, the lines + * remain smooth at any size. + */ + +PShape bot; + +void setup() { + size(640, 360); + smooth(); + // The file "bot1.svg" must be in the data folder + // of the current sketch to load successfully + bot = loadShape("bot1.svg"); +} + +void draw() { + background(102); + translate(width/2, height/2); + float zoom = map(mouseX, 0, width, 0.1, 4.5); + scale(zoom); + shape(bot, -140, -140); +} diff --git a/android/examples/Basics/Shape/ScaleShape/applet/ScaleShape.java b/android/examples/Basics/Shape/ScaleShape/applet/ScaleShape.java new file mode 100644 index 000000000..3a6aa5e19 --- /dev/null +++ b/android/examples/Basics/Shape/ScaleShape/applet/ScaleShape.java @@ -0,0 +1,47 @@ +import processing.core.*; +import processing.xml.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class ScaleShape extends PApplet { + +/** + * Scale Shape. + * Illustration by George Brower. + * + * Move the mouse left and right to zoom the SVG file. + * This shows how, unlike an imported image, the lines + * remain smooth at any size. + */ + +PShape bot; + +public void setup() { + size(640, 360); + smooth(); + // The file "bot1.svg" must be in the data folder + // of the current sketch to load successfully + bot = loadShape("bot1.svg"); +} + +public void draw() { + background(102); + translate(width/2, height/2); + float zoom = map(mouseX, 0, width, 0.1f, 4.5f); + scale(zoom); + shape(bot, -140, -140); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "ScaleShape" }); + } +} diff --git a/android/examples/Basics/Shape/ScaleShape/applet/ScaleShape.pde b/android/examples/Basics/Shape/ScaleShape/applet/ScaleShape.pde new file mode 100644 index 000000000..879f20b68 --- /dev/null +++ b/android/examples/Basics/Shape/ScaleShape/applet/ScaleShape.pde @@ -0,0 +1,26 @@ +/** + * Scale Shape. + * Illustration by George Brower. + * + * Move the mouse left and right to zoom the SVG file. + * This shows how, unlike an imported image, the lines + * remain smooth at any size. + */ + +PShape bot; + +void setup() { + size(640, 360); + smooth(); + // The file "bot1.svg" must be in the data folder + // of the current sketch to load successfully + bot = loadShape("bot1.svg"); +} + +void draw() { + background(102); + translate(width/2, height/2); + float zoom = map(mouseX, 0, width, 0.1, 4.5); + scale(zoom); + shape(bot, -140, -140); +} diff --git a/android/examples/Basics/Shape/ScaleShape/applet/loading.gif b/android/examples/Basics/Shape/ScaleShape/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Shape/ScaleShape/applet/loading.gif differ diff --git a/android/examples/Basics/Shape/ScaleShape/data/bot1.svg b/android/examples/Basics/Shape/ScaleShape/data/bot1.svg new file mode 100644 index 000000000..3c56f2d60 --- /dev/null +++ b/android/examples/Basics/Shape/ScaleShape/data/bot1.svg @@ -0,0 +1,160 @@ + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/examples/Basics/Structure/Coordinates/Coordinates.pde b/android/examples/Basics/Structure/Coordinates/Coordinates.pde new file mode 100644 index 000000000..c63c147b7 --- /dev/null +++ b/android/examples/Basics/Structure/Coordinates/Coordinates.pde @@ -0,0 +1,41 @@ +/** + * Coordinates. + * + * All shapes drawn to the screen have a position that is specified as a coordinate. + * All coordinates are measured as the distance from the origin in units of pixels. + * The origin [0, 0] is the coordinate is in the upper left of the window + * and the coordinate in the lower right is [width-1, height-1]. + */ + +// Sets the screen to be 200, 200, so the width of the window is 200 pixels +// and the height of the window is 200 pixels +size(200, 200); +background(0); +noFill(); +stroke(255); + +// The two parameters of the point() method each specify coordinates. +// This call to point() draws at the position [100, 100] +point(width/2, height/2); + +// Draws to the position [100, 50] +point(width/2, height/4); + +// It is also possible to specify a point with any parameter, +// but only coordinates on the screen are visible +point(60, 30); +point(60, 134); +point(160, 50); +point(280, -800); +point(201, 100); + +// Coordinates are used for drawing all shapes, not just points. +// Parameters for different methods are used for different purposes. +// For example, the first two parameters to line() specify the coordinates of the +// first point and the second two parameters specify the second point +stroke(204); +line(0, 73, width, 73); + +// The first two parameters to rect() are coordinates +// and the second two are the width and height +rect(110, 55, 40, 36); diff --git a/android/examples/Basics/Structure/Coordinates/applet/Coordinates.java b/android/examples/Basics/Structure/Coordinates/applet/Coordinates.java new file mode 100644 index 000000000..cc173b9aa --- /dev/null +++ b/android/examples/Basics/Structure/Coordinates/applet/Coordinates.java @@ -0,0 +1,62 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Coordinates extends PApplet { + public void setup() {/** + * Coordinates. + * + * All shapes drawn to the screen have a position that is specified as a coordinate. + * All coordinates are measured as the distance from the origin in units of pixels. + * The origin [0, 0] is the coordinate is in the upper left of the window + * and the coordinate in the lower right is [width-1, height-1]. + */ + +// Sets the screen to be 200, 200, so the width of the window is 200 pixels +// and the height of the window is 200 pixels +size(200, 200); +background(0); +noFill(); +stroke(255); + +// The two parameters of the point() method each specify coordinates. +// This call to point() draws at the position [100, 100] +point(width/2, height/2); + +// Draws to the position [100, 50] +point(width/2, height/4); + +// It is also possible to specify a point with any parameter, +// but only coordinates on the screen are visible +point(60, 30); +point(60, 134); +point(160, 50); +point(280, -800); +point(201, 100); + +// Coordinates are used for drawing all shapes, not just points. +// Parameters for different methods are used for different purposes. +// For example, the first two parameters to line() specify the coordinates of the +// first point and the second two parameters specify the second point +stroke(204); +line(0, 73, width, 73); + +// The first two parameters to rect() are coordinates +// and the second two are the width and height +rect(110, 55, 40, 36); + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "Coordinates" }); + } +} diff --git a/android/examples/Basics/Structure/Coordinates/applet/Coordinates.pde b/android/examples/Basics/Structure/Coordinates/applet/Coordinates.pde new file mode 100644 index 000000000..c63c147b7 --- /dev/null +++ b/android/examples/Basics/Structure/Coordinates/applet/Coordinates.pde @@ -0,0 +1,41 @@ +/** + * Coordinates. + * + * All shapes drawn to the screen have a position that is specified as a coordinate. + * All coordinates are measured as the distance from the origin in units of pixels. + * The origin [0, 0] is the coordinate is in the upper left of the window + * and the coordinate in the lower right is [width-1, height-1]. + */ + +// Sets the screen to be 200, 200, so the width of the window is 200 pixels +// and the height of the window is 200 pixels +size(200, 200); +background(0); +noFill(); +stroke(255); + +// The two parameters of the point() method each specify coordinates. +// This call to point() draws at the position [100, 100] +point(width/2, height/2); + +// Draws to the position [100, 50] +point(width/2, height/4); + +// It is also possible to specify a point with any parameter, +// but only coordinates on the screen are visible +point(60, 30); +point(60, 134); +point(160, 50); +point(280, -800); +point(201, 100); + +// Coordinates are used for drawing all shapes, not just points. +// Parameters for different methods are used for different purposes. +// For example, the first two parameters to line() specify the coordinates of the +// first point and the second two parameters specify the second point +stroke(204); +line(0, 73, width, 73); + +// The first two parameters to rect() are coordinates +// and the second two are the width and height +rect(110, 55, 40, 36); diff --git a/android/examples/Basics/Structure/Coordinates/applet/loading.gif b/android/examples/Basics/Structure/Coordinates/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Structure/Coordinates/applet/loading.gif differ diff --git a/android/examples/Basics/Structure/CreateGraphics/CreateGraphics.pde b/android/examples/Basics/Structure/CreateGraphics/CreateGraphics.pde new file mode 100644 index 000000000..7f1b1d0eb --- /dev/null +++ b/android/examples/Basics/Structure/CreateGraphics/CreateGraphics.pde @@ -0,0 +1,33 @@ +/** + * Create Graphics. + * + * The createGraphics() function creates an object from the PGraphics class + * (PGraphics is the main graphics and rendering context for Processing). + * The beginDraw() method is necessary to prepare for drawing and endDraw() is + * necessary to finish. Use this class if you need to draw into an off-screen + * graphics buffer or to maintain two contexts with different properties. + */ + +PGraphics pg; + +void setup() { + size(200, 200); + pg = createGraphics(80, 80, P2D); +} + +void draw() { + fill(0, 12); + rect(0, 0, width, height); + fill(255); + noStroke(); + ellipse(mouseX, mouseY, 60, 60); + + pg.beginDraw(); + pg.background(102); + pg.noFill(); + pg.stroke(255); + pg.ellipse(mouseX-60, mouseY-60, 60, 60); + pg.endDraw(); + + image(pg, 60, 60); +} diff --git a/android/examples/Basics/Structure/CreateGraphics/applet/CreateGraphics.java b/android/examples/Basics/Structure/CreateGraphics/applet/CreateGraphics.java new file mode 100644 index 000000000..8c2eaf6bb --- /dev/null +++ b/android/examples/Basics/Structure/CreateGraphics/applet/CreateGraphics.java @@ -0,0 +1,53 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class CreateGraphics extends PApplet { + +/** + * Create Graphics. + * + * The createGraphics() function creates an object from the PGraphics class + * (PGraphics is the main graphics and rendering context for Processing). + * The beginDraw() method is necessary to prepare for drawing and endDraw() is + * necessary to finish. Use this class if you need to draw into an off-screen + * graphics buffer or to maintain two contexts with different properties. + */ + +PGraphics pg; + +public void setup() { + size(200, 200); + pg = createGraphics(80, 80, P3D); +} + +public void draw() { + fill(0, 12); + rect(0, 0, width, height); + fill(255); + noStroke(); + ellipse(mouseX, mouseY, 60, 60); + + pg.beginDraw(); + pg.background(102); + pg.noFill(); + pg.stroke(255); + pg.ellipse(mouseX-60, mouseY-60, 60, 60); + pg.endDraw(); + + image(pg, 60, 60); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "CreateGraphics" }); + } +} diff --git a/android/examples/Basics/Structure/CreateGraphics/applet/CreateGraphics.pde b/android/examples/Basics/Structure/CreateGraphics/applet/CreateGraphics.pde new file mode 100644 index 000000000..5bd6710bb --- /dev/null +++ b/android/examples/Basics/Structure/CreateGraphics/applet/CreateGraphics.pde @@ -0,0 +1,33 @@ +/** + * Create Graphics. + * + * The createGraphics() function creates an object from the PGraphics class + * (PGraphics is the main graphics and rendering context for Processing). + * The beginDraw() method is necessary to prepare for drawing and endDraw() is + * necessary to finish. Use this class if you need to draw into an off-screen + * graphics buffer or to maintain two contexts with different properties. + */ + +PGraphics pg; + +void setup() { + size(200, 200); + pg = createGraphics(80, 80, P3D); +} + +void draw() { + fill(0, 12); + rect(0, 0, width, height); + fill(255); + noStroke(); + ellipse(mouseX, mouseY, 60, 60); + + pg.beginDraw(); + pg.background(102); + pg.noFill(); + pg.stroke(255); + pg.ellipse(mouseX-60, mouseY-60, 60, 60); + pg.endDraw(); + + image(pg, 60, 60); +} diff --git a/android/examples/Basics/Structure/CreateGraphics/applet/loading.gif b/android/examples/Basics/Structure/CreateGraphics/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Structure/CreateGraphics/applet/loading.gif differ diff --git a/android/examples/Basics/Structure/Functions/Functions.pde b/android/examples/Basics/Structure/Functions/Functions.pde new file mode 100644 index 000000000..b94fdb01e --- /dev/null +++ b/android/examples/Basics/Structure/Functions/Functions.pde @@ -0,0 +1,33 @@ +/** + * Functions. + * + * The drawTarget() function makes it easy to draw many distinct targets. + * Each call to drawTarget() specifies the position, size, and number of + * rings for each target. + */ + +void setup() +{ + size(200, 200); + background(51); + noStroke(); + smooth(); + noLoop(); +} + +void draw() +{ + drawTarget(68, 34, 200, 10); + drawTarget(152, 16, 100, 3); + drawTarget(100, 144, 80, 5); +} + +void drawTarget(int xloc, int yloc, int size, int num) +{ + float grayvalues = 255/num; + float steps = size/num; + for(int i=0; i 1) { + level = level - 1; + drawCircle(x - radius/2, radius/2, level); + drawCircle(x + radius/2, radius/2, level); + } +} diff --git a/android/examples/Basics/Structure/Recursion/applet/Recursion.java b/android/examples/Basics/Structure/Recursion/applet/Recursion.java new file mode 100644 index 000000000..c739d0b06 --- /dev/null +++ b/android/examples/Basics/Structure/Recursion/applet/Recursion.java @@ -0,0 +1,52 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Recursion extends PApplet { + +/** + * Recursion. + * + * A demonstration of recursion, which means functions call themselves. + * Notice how the drawCircle() function calls itself at the end of its block. + * It continues to do this until the variable "level" is equal to 1. + */ + +public void setup() +{ + size(200, 200); + noStroke(); + smooth(); + noLoop(); +} + +public void draw() +{ + drawCircle(126, 170, 6); +} + +public void drawCircle(int x, int radius, int level) +{ + float tt = 126 * level/4.0f; + fill(tt); + ellipse(x, 100, radius*2, radius*2); + if(level > 1) { + level = level - 1; + drawCircle(x - radius/2, radius/2, level); + drawCircle(x + radius/2, radius/2, level); + } +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Recursion" }); + } +} diff --git a/android/examples/Basics/Structure/Recursion/applet/Recursion.pde b/android/examples/Basics/Structure/Recursion/applet/Recursion.pde new file mode 100644 index 000000000..2e77668f4 --- /dev/null +++ b/android/examples/Basics/Structure/Recursion/applet/Recursion.pde @@ -0,0 +1,32 @@ +/** + * Recursion. + * + * A demonstration of recursion, which means functions call themselves. + * Notice how the drawCircle() function calls itself at the end of its block. + * It continues to do this until the variable "level" is equal to 1. + */ + +void setup() +{ + size(200, 200); + noStroke(); + smooth(); + noLoop(); +} + +void draw() +{ + drawCircle(126, 170, 6); +} + +void drawCircle(int x, int radius, int level) +{ + float tt = 126 * level/4.0; + fill(tt); + ellipse(x, 100, radius*2, radius*2); + if(level > 1) { + level = level - 1; + drawCircle(x - radius/2, radius/2, level); + drawCircle(x + radius/2, radius/2, level); + } +} diff --git a/android/examples/Basics/Structure/Recursion/applet/loading.gif b/android/examples/Basics/Structure/Recursion/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Structure/Recursion/applet/loading.gif differ diff --git a/android/examples/Basics/Structure/Recursion2/Recursion2.pde b/android/examples/Basics/Structure/Recursion2/Recursion2.pde new file mode 100644 index 000000000..0da7d10cc --- /dev/null +++ b/android/examples/Basics/Structure/Recursion2/Recursion2.pde @@ -0,0 +1,32 @@ +/** + * Recursion. + * + * A demonstration of recursion, which means functions call themselves. + * Notice how the drawCircle() function calls itself at the end of its block. + * It continues to do this until the variable "level" is equal to 1. + */ + +void setup() +{ + size(200, 200); + noStroke(); + smooth(); + drawCircle(100, 100, 80, 8); +} + +void drawCircle(float x, float y, int radius, int level) +{ + float tt = 126 * level/6.0; + fill(tt, 153); + ellipse(x, y, radius*2, radius*2); + if(level > 1) { + level = level - 1; + int num = int(random(2, 6)); + for(int i=0; i 1) { + level = level - 1; + int num = PApplet.parseInt(random(2, 6)); + for(int i=0; i 1) { + level = level - 1; + int num = int(random(2, 6)); + for(int i=0; i width + size) { + x = -size; + } + + translate(x, height/2-size/2); + fill(255); + rect(-size/2, -size/2, size, size); + + // Transforms accumulate. + // Notice how this rect moves twice + // as fast as the other, but it has + // the same parameter for the x-axis value + translate(x, size); + fill(0); + rect(-size/2, -size/2, size, size); +} diff --git a/android/examples/Basics/Transform/Translate/applet/Translate.java b/android/examples/Basics/Transform/Translate/applet/Translate.java new file mode 100644 index 000000000..c62a13544 --- /dev/null +++ b/android/examples/Basics/Transform/Translate/applet/Translate.java @@ -0,0 +1,61 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Translate extends PApplet { + +/** + * Translate. + * + * The translate() function allows objects to be moved + * to any location within the window. The first parameter + * sets the x-axis offset and the second parameter sets the + * y-axis offset. + */ + +float x, y; +float size = 40.0f; + +public void setup() +{ + size(200,200); + noStroke(); + frameRate(30); +} + +public void draw() +{ + background(102); + + x = x + 0.8f; + + if (x > width + size) { + x = -size; + } + + translate(x, height/2-size/2); + fill(255); + rect(-size/2, -size/2, size, size); + + // Transforms accumulate. + // Notice how this rect moves twice + // as fast as the other, but it has + // the same parameter for the x-axis value + translate(x, size); + fill(0); + rect(-size/2, -size/2, size, size); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Translate" }); + } +} diff --git a/android/examples/Basics/Transform/Translate/applet/Translate.pde b/android/examples/Basics/Transform/Translate/applet/Translate.pde new file mode 100644 index 000000000..81b39af9d --- /dev/null +++ b/android/examples/Basics/Transform/Translate/applet/Translate.pde @@ -0,0 +1,41 @@ +/** + * Translate. + * + * The translate() function allows objects to be moved + * to any location within the window. The first parameter + * sets the x-axis offset and the second parameter sets the + * y-axis offset. + */ + +float x, y; +float size = 40.0; + +void setup() +{ + size(200,200); + noStroke(); + frameRate(30); +} + +void draw() +{ + background(102); + + x = x + 0.8; + + if (x > width + size) { + x = -size; + } + + translate(x, height/2-size/2); + fill(255); + rect(-size/2, -size/2, size, size); + + // Transforms accumulate. + // Notice how this rect moves twice + // as fast as the other, but it has + // the same parameter for the x-axis value + translate(x, size); + fill(0); + rect(-size/2, -size/2, size, size); +} diff --git a/android/examples/Basics/Transform/Translate/applet/loading.gif b/android/examples/Basics/Transform/Translate/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Transform/Translate/applet/loading.gif differ diff --git a/android/examples/Basics/Transform/TriangleFlower/TriangleFlower.pde b/android/examples/Basics/Transform/TriangleFlower/TriangleFlower.pde new file mode 100644 index 000000000..e87e97c72 --- /dev/null +++ b/android/examples/Basics/Transform/TriangleFlower/TriangleFlower.pde @@ -0,0 +1,47 @@ +/** + * Triangle Flower + * by Ira Greenberg. + * + * Using rotate() and triangle() functions generate a pretty + * flower. Uncomment the line "// rotate(rot+=radians(spin));" + * in the triBlur() function for a nice variation. + * + * Updated 27 February 2010. + */ + +PVector[] p = new PVector[3]; +float shift = 1.0; +float fade = 0; +float fillCol = 0; +float rot = 0; +float spin = 0; + +void setup() { + size(200, 200); + background(0); + smooth(); + fade = 255.0 / (width/2.0/shift); + spin = 360.0 / (width/2.0/shift); + p[0] = new PVector(-width/2, height/2); + p[1] = new PVector(width/2, height/2); + p[2] = new PVector(0, -height/2); + noStroke(); + translate(width/2, height/2); + triBlur(); +} + +void triBlur() { + fill(fillCol); + fillCol += fade; + rotate(spin); + // another interesting variation: uncomment the line below + // rotate(rot+=radians(spin)); + triangle(p[0].x += shift, p[0].y -= shift/2, + p[1].x -= shift, p[1].y -= shift/2, + p[2].x, p[2].y += shift); + if (p[0].x < 0) { + // recursive call + triBlur(); + } +} + diff --git a/android/examples/Basics/Transform/TriangleFlower/applet/TriangleFlower.java b/android/examples/Basics/Transform/TriangleFlower/applet/TriangleFlower.java new file mode 100644 index 000000000..b4bf9b0ad --- /dev/null +++ b/android/examples/Basics/Transform/TriangleFlower/applet/TriangleFlower.java @@ -0,0 +1,63 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class TriangleFlower extends PApplet { + +/** + * Triangle Flower + * by Ira Greenberg. + * + * Using rotate() and triangle() functions generate a pretty + * flower. Uncomment the line "// rotate(rot+=radians(spin));" + * in the triBlur() function for a nice variation. + */ + +Point[]p = new Point[3]; +float shift = 1.0f; +float fade = 0; +float fillCol = 0; +float rot = 0; +float spin = 0; + +public void setup(){ + size(200, 200); + background(0); + smooth(); + fade = 255.0f/(width/2.0f/shift); + spin = 360.0f/(width/2.0f/shift); + p[0] = new Point(-width/2, height/2); + p[1] = new Point(width/2, height/2); + p[2] = new Point(0, -height/2); + noStroke(); + translate(width/2, height/2); + triBlur(); +} + +public void triBlur(){ + fill(fillCol); + fillCol+=fade; + rotate(spin); + // another interesting variation: uncomment the line below + // rotate(rot+=radians(spin)); + triangle(p[0].x+=shift, p[0].y-=shift/2, p[1].x-=shift, p[1].y-=shift/2, p[2].x, p[2].y+=shift); + if(p[0].x<0){ + // recursive call + triBlur(); + } +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "TriangleFlower" }); + } +} diff --git a/android/examples/Basics/Transform/TriangleFlower/applet/TriangleFlower.pde b/android/examples/Basics/Transform/TriangleFlower/applet/TriangleFlower.pde new file mode 100644 index 000000000..e46988519 --- /dev/null +++ b/android/examples/Basics/Transform/TriangleFlower/applet/TriangleFlower.pde @@ -0,0 +1,43 @@ +/** + * Triangle Flower + * by Ira Greenberg. + * + * Using rotate() and triangle() functions generate a pretty + * flower. Uncomment the line "// rotate(rot+=radians(spin));" + * in the triBlur() function for a nice variation. + */ + +Point[]p = new Point[3]; +float shift = 1.0; +float fade = 0; +float fillCol = 0; +float rot = 0; +float spin = 0; + +void setup(){ + size(200, 200); + background(0); + smooth(); + fade = 255.0/(width/2.0/shift); + spin = 360.0/(width/2.0/shift); + p[0] = new Point(-width/2, height/2); + p[1] = new Point(width/2, height/2); + p[2] = new Point(0, -height/2); + noStroke(); + translate(width/2, height/2); + triBlur(); +} + +void triBlur(){ + fill(fillCol); + fillCol+=fade; + rotate(spin); + // another interesting variation: uncomment the line below + // rotate(rot+=radians(spin)); + triangle(p[0].x+=shift, p[0].y-=shift/2, p[1].x-=shift, p[1].y-=shift/2, p[2].x, p[2].y+=shift); + if(p[0].x<0){ + // recursive call + triBlur(); + } +} + diff --git a/android/examples/Basics/Transform/TriangleFlower/applet/loading.gif b/android/examples/Basics/Transform/TriangleFlower/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Transform/TriangleFlower/applet/loading.gif differ diff --git a/android/examples/Basics/Typography/Letters/Letters.pde b/android/examples/Basics/Typography/Letters/Letters.pde new file mode 100644 index 000000000..66fd2302f --- /dev/null +++ b/android/examples/Basics/Typography/Letters/Letters.pde @@ -0,0 +1,72 @@ +/** + * Letters. + * + * Draws letters to the screen. This requires loading a font, + * setting the font, and then drawing the letters. + */ + +PFont fontA; + +void setup() +{ + size(200, 200); + background(0); + smooth(); + // Load the font. Fonts must be placed within the data + // directory of your sketch. A font must first be created + // using the 'Create Font...' option in the Tools menu. + fontA = loadFont("CourierNew36.vlw"); + textAlign(CENTER); + + // Set the font and its size (in units of pixels) + textFont(fontA, 32); + + // Only draw once + noLoop(); +} + +void draw() +{ + // Set the gray value of the letters + fill(255); + + // Set the left and top margin + int margin = 6; + int gap = 30; + translate(margin*1.5, margin*2); + + // Create a matrix of letterforms + int counter = 0; + for(int i=0; i= 26) { + counter = 0; + } + } + } +} + diff --git a/android/examples/Basics/Typography/Letters/applet/Letters.java b/android/examples/Basics/Typography/Letters/applet/Letters.java new file mode 100644 index 000000000..da77d549a --- /dev/null +++ b/android/examples/Basics/Typography/Letters/applet/Letters.java @@ -0,0 +1,86 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Letters extends PApplet { + +/** + * Letters. + * + * Draws letters to the screen. + */ + +PFont fontA; + +public void setup() +{ + size(200, 200); + background(0); + // Load the font. Fonts must be placed within the data + // directory of your sketch. A font must first be created + // using the 'Create Font...' option in the Tools menu. + fontA = loadFont("CourierNew36.vlw"); + textFont(fontA, 36); + textAlign(CENTER); + noLoop(); +} + +public void draw() +{ + // Set the gray value of the letters + fill(255); + + // Set the left and top margin + int margin = 6; + int gap = 30; + translate(margin*1.5f, margin*2); + + // Create a matrix of letterforms + int counter = 0; + for(int i=0; i= 26) { + counter = 0; + } + } + } +} + + + static public void main(String args[]) { + PApplet.main(new String[] { "Letters" }); + } +} diff --git a/android/examples/Basics/Typography/Letters/applet/Letters.pde b/android/examples/Basics/Typography/Letters/applet/Letters.pde new file mode 100644 index 000000000..82e943f2f --- /dev/null +++ b/android/examples/Basics/Typography/Letters/applet/Letters.pde @@ -0,0 +1,66 @@ +/** + * Letters. + * + * Draws letters to the screen. + */ + +PFont fontA; + +void setup() +{ + size(200, 200); + background(0); + // Load the font. Fonts must be placed within the data + // directory of your sketch. A font must first be created + // using the 'Create Font...' option in the Tools menu. + fontA = loadFont("CourierNew36.vlw"); + textFont(fontA, 36); + textAlign(CENTER); + noLoop(); +} + +void draw() +{ + // Set the gray value of the letters + fill(255); + + // Set the left and top margin + int margin = 6; + int gap = 30; + translate(margin*1.5, margin*2); + + // Create a matrix of letterforms + int counter = 0; + for(int i=0; i= 26) { + counter = 0; + } + } + } +} + diff --git a/android/examples/Basics/Typography/Letters/applet/loading.gif b/android/examples/Basics/Typography/Letters/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Typography/Letters/applet/loading.gif differ diff --git a/android/examples/Basics/Typography/Letters/data/CourierNew36.vlw b/android/examples/Basics/Typography/Letters/data/CourierNew36.vlw new file mode 100644 index 000000000..904771486 Binary files /dev/null and b/android/examples/Basics/Typography/Letters/data/CourierNew36.vlw differ diff --git a/android/examples/Basics/Typography/Words/Words.pde b/android/examples/Basics/Typography/Words/Words.pde new file mode 100644 index 000000000..d8e8a5f96 --- /dev/null +++ b/android/examples/Basics/Typography/Words/Words.pde @@ -0,0 +1,39 @@ +/** + * Words. + * + * The text() function is used for writing words to the screen. + */ + + +int x = 30; +PFont fontA; + +void setup() +{ + size(200, 200); + background(102); + + // Load the font. Fonts must be placed within the data + // directory of your sketch. Use Tools > Create Font + // to create a distributable bitmap font. + // For vector fonts, use the createFont() function. + fontA = loadFont("Ziggurat-HTF-Black-32.vlw"); + + // Set the font and its size (in units of pixels) + textFont(fontA, 32); + + // Only draw once + noLoop(); +} + +void draw() { + // Use fill() to change the value or color of the text + fill(0); + text("ichi", x, 60); + fill(51); + text("ni", x, 95); + fill(204); + text("san", x, 130); + fill(255); + text("shi", x, 165); +} diff --git a/android/examples/Basics/Typography/Words/applet/Words.java b/android/examples/Basics/Typography/Words/applet/Words.java new file mode 100644 index 000000000..192678348 --- /dev/null +++ b/android/examples/Basics/Typography/Words/applet/Words.java @@ -0,0 +1,62 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class Words extends PApplet { + +/** + * Words. + * + * The text() function is used for writing words to the screen. + * + * Created 15 January 2003 + * Updated 11 August 2008 + */ + + +int x = 30; +PFont fontA; + +public void setup() +{ + size(200, 200); + background(102); + + // Load the font. Fonts must be placed within the data + // directory of your sketch. Use Tools > Create Font + // to create a distributable bitmap font. + // For vector fonts, use the createFont() function. + fontA = loadFont("Ziggurat-HTF-Black-32.vlw"); + + // Set the font and its size (in units of pixels) + textFont(fontA, 32); + + // Only draw once + noLoop(); +} + +public void draw() { + // Use fill() to change the value or color of the text + fill(0); + text("ichi", x, 60); + fill(51); + text("ni", x, 95); + fill(204); + text("san", x, 130); + fill(255); + text("shi", x, 165); +} + + static public void main(String args[]) { + PApplet.main(new String[] { "Words" }); + } +} diff --git a/android/examples/Basics/Typography/Words/applet/Words.pde b/android/examples/Basics/Typography/Words/applet/Words.pde new file mode 100644 index 000000000..e7622a4c7 --- /dev/null +++ b/android/examples/Basics/Typography/Words/applet/Words.pde @@ -0,0 +1,42 @@ +/** + * Words. + * + * The text() function is used for writing words to the screen. + * + * Created 15 January 2003 + * Updated 11 August 2008 + */ + + +int x = 30; +PFont fontA; + +void setup() +{ + size(200, 200); + background(102); + + // Load the font. Fonts must be placed within the data + // directory of your sketch. Use Tools > Create Font + // to create a distributable bitmap font. + // For vector fonts, use the createFont() function. + fontA = loadFont("Ziggurat-HTF-Black-32.vlw"); + + // Set the font and its size (in units of pixels) + textFont(fontA, 32); + + // Only draw once + noLoop(); +} + +void draw() { + // Use fill() to change the value or color of the text + fill(0); + text("ichi", x, 60); + fill(51); + text("ni", x, 95); + fill(204); + text("san", x, 130); + fill(255); + text("shi", x, 165); +} diff --git a/android/examples/Basics/Typography/Words/applet/loading.gif b/android/examples/Basics/Typography/Words/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Typography/Words/applet/loading.gif differ diff --git a/android/examples/Basics/Typography/Words/data/Ziggurat-HTF-Black-32.vlw b/android/examples/Basics/Typography/Words/data/Ziggurat-HTF-Black-32.vlw new file mode 100644 index 000000000..84c2d4b59 Binary files /dev/null and b/android/examples/Basics/Typography/Words/data/Ziggurat-HTF-Black-32.vlw differ diff --git a/android/examples/Basics/Web/EmbeddedLinks/EmbeddedLinks.pde b/android/examples/Basics/Web/EmbeddedLinks/EmbeddedLinks.pde new file mode 100644 index 000000000..2501487e3 --- /dev/null +++ b/android/examples/Basics/Web/EmbeddedLinks/EmbeddedLinks.pde @@ -0,0 +1,67 @@ +/** + * Loading URLs. + * + * Click on the left button to open a different URL in the same window (Only + * works online). Click on the right button to open a URL in a new browser window. +*/ + +boolean overLeftButton = false; +boolean overRightButton = false; + +void setup() { + size(200, 200); +} + +void draw() { + background(204); + + // Left buttom + if (overLeftButton == true) { + fill(255); + } else { + noFill(); + } + rect(20, 60, 75, 75); + rect(50, 90, 15, 15); + + // Right button + if (overRightButton == true) { + fill(255); + } else { + noFill(); + } + rect(105, 60, 75, 75); + line(135, 105, 155, 85); + line(140, 85, 155, 85); + line(155, 85, 155, 100); +} + +void mousePressed() { + if (overLeftButton) { + link("http://www.processing.org"); + } else if (overRightButton) { + link("http://www.processing.org", "_new"); + } +} + +void mouseMoved() { + checkButtons(); +} + +void mouseDragged() { + checkButtons(); +} + +void checkButtons() { + if (mouseX > 20 && mouseX < 95 && mouseY > 60 && mouseY < 135) { + overLeftButton = true; + } else if (mouseX > 105 && mouseX < 180 && mouseY > 60 && mouseY <135) { + overRightButton = true; + } else { + overLeftButton = overRightButton = false; + } +} + + + + diff --git a/android/examples/Basics/Web/EmbeddedLinks/applet/EmbeddedLinks.java b/android/examples/Basics/Web/EmbeddedLinks/applet/EmbeddedLinks.java new file mode 100644 index 000000000..1ee4b1a64 --- /dev/null +++ b/android/examples/Basics/Web/EmbeddedLinks/applet/EmbeddedLinks.java @@ -0,0 +1,93 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class EmbeddedLinks extends PApplet { + +/** + * Loading URLs. + * + * Click on the left button to open a different URL in the same window (Only + * works online). Click on the right button to open a URL in a new browser window. +*/ + +boolean overLeftButton = false; +boolean overRightButton = false; + +public void setup() +{ + size(200, 200); +} + +public void draw() +{ + background(204); + + // Left buttom + if(overLeftButton == true) { + fill(255); + } else { + noFill(); + } + rect(20, 60, 75, 75); + rect(50, 90, 15, 15); + + // Right button + if(overRightButton == true) { + fill(255); + } else { + noFill(); + } + rect(105, 60, 75, 75); + line(135, 105, 155, 85); + line(140, 85, 155, 85); + line(155, 85, 155, 100); +} + +public void mousePressed() +{ + if(overLeftButton) { + link("http://www.processing.org"); + } else if (overRightButton) { + link("http://www.processing.org", "_new"); + } +} + +public void mouseMoved() { + checkButtons(); +} + +public void mouseDragged() { + checkButtons(); +} + +public void checkButtons() { + if(mouseX > 20 && mouseX < 95 && + mouseY > 60 && mouseY <135) { + overLeftButton = true; + } else if (mouseX > 105 && mouseX < 180 && + mouseY > 60 && mouseY <135) { + overRightButton = true; + } else { + overLeftButton = overRightButton = false; + } + +} + + + + + + static public void main(String args[]) { + PApplet.main(new String[] { "EmbeddedLinks" }); + } +} diff --git a/android/examples/Basics/Web/EmbeddedLinks/applet/EmbeddedLinks.pde b/android/examples/Basics/Web/EmbeddedLinks/applet/EmbeddedLinks.pde new file mode 100644 index 000000000..ab41385c7 --- /dev/null +++ b/android/examples/Basics/Web/EmbeddedLinks/applet/EmbeddedLinks.pde @@ -0,0 +1,73 @@ +/** + * Loading URLs. + * + * Click on the left button to open a different URL in the same window (Only + * works online). Click on the right button to open a URL in a new browser window. +*/ + +boolean overLeftButton = false; +boolean overRightButton = false; + +void setup() +{ + size(200, 200); +} + +void draw() +{ + background(204); + + // Left buttom + if(overLeftButton == true) { + fill(255); + } else { + noFill(); + } + rect(20, 60, 75, 75); + rect(50, 90, 15, 15); + + // Right button + if(overRightButton == true) { + fill(255); + } else { + noFill(); + } + rect(105, 60, 75, 75); + line(135, 105, 155, 85); + line(140, 85, 155, 85); + line(155, 85, 155, 100); +} + +void mousePressed() +{ + if(overLeftButton) { + link("http://www.processing.org"); + } else if (overRightButton) { + link("http://www.processing.org", "_new"); + } +} + +void mouseMoved() { + checkButtons(); +} + +void mouseDragged() { + checkButtons(); +} + +void checkButtons() { + if(mouseX > 20 && mouseX < 95 && + mouseY > 60 && mouseY <135) { + overLeftButton = true; + } else if (mouseX > 105 && mouseX < 180 && + mouseY > 60 && mouseY <135) { + overRightButton = true; + } else { + overLeftButton = overRightButton = false; + } + +} + + + + diff --git a/android/examples/Basics/Web/EmbeddedLinks/applet/loading.gif b/android/examples/Basics/Web/EmbeddedLinks/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Web/EmbeddedLinks/applet/loading.gif differ diff --git a/android/examples/Basics/Web/LoadingImages/LoadingImages.pde b/android/examples/Basics/Web/LoadingImages/LoadingImages.pde new file mode 100644 index 000000000..325fbba56 --- /dev/null +++ b/android/examples/Basics/Web/LoadingImages/LoadingImages.pde @@ -0,0 +1,16 @@ +/** + * Loading Images. + * + * Loading a recent image from the US National Weather Service. + * Notice the date in the upper left corner of the image. + * Processing applications can only load images from the network + * while running in the Processing environment. This example will + * not run in a web broswer and will only work when the computer + * is connected to the Internet. + */ + +size(200, 200); +PImage img1; +img1 = loadImage("http://www.processing.org/img/processing_beta_cover.gif"); +image(img1, 0, 45); + diff --git a/android/examples/Basics/Web/LoadingImages/applet/LoadingImages.java b/android/examples/Basics/Web/LoadingImages/applet/LoadingImages.java new file mode 100644 index 000000000..76bab8631 --- /dev/null +++ b/android/examples/Basics/Web/LoadingImages/applet/LoadingImages.java @@ -0,0 +1,37 @@ +import processing.core.*; + +import java.applet.*; +import java.awt.*; +import java.awt.image.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import java.util.zip.*; +import java.util.regex.*; + +public class LoadingImages extends PApplet { + public void setup() {/** + * Loading Images. + * + * Loading a recent image from the US National Weather Service. + * Notice the date in the upper left corner of the image. + * Processing applications can only load images from the network + * while running in the Processing environment. This example will + * not run in a web broswer and will only work when the computer + * is connected to the Internet. + */ + +size(200, 200); +PImage img1; +img1 = loadImage("http://www.processing.org/img/processing_beta_cover.gif"); +image(img1, 0, 45); + + + noLoop(); +} + static public void main(String args[]) { + PApplet.main(new String[] { "LoadingImages" }); + } +} diff --git a/android/examples/Basics/Web/LoadingImages/applet/LoadingImages.pde b/android/examples/Basics/Web/LoadingImages/applet/LoadingImages.pde new file mode 100644 index 000000000..325fbba56 --- /dev/null +++ b/android/examples/Basics/Web/LoadingImages/applet/LoadingImages.pde @@ -0,0 +1,16 @@ +/** + * Loading Images. + * + * Loading a recent image from the US National Weather Service. + * Notice the date in the upper left corner of the image. + * Processing applications can only load images from the network + * while running in the Processing environment. This example will + * not run in a web broswer and will only work when the computer + * is connected to the Internet. + */ + +size(200, 200); +PImage img1; +img1 = loadImage("http://www.processing.org/img/processing_beta_cover.gif"); +image(img1, 0, 45); + diff --git a/android/examples/Basics/Web/LoadingImages/applet/loading.gif b/android/examples/Basics/Web/LoadingImages/applet/loading.gif new file mode 100644 index 000000000..1ddae5089 Binary files /dev/null and b/android/examples/Basics/Web/LoadingImages/applet/loading.gif differ