diff --git a/android/examples/OpenGL/Camera/MoveEye/MoveEye.pde b/android/examples/Basics/Camera/MoveEye/MoveEye.pde similarity index 99% rename from android/examples/OpenGL/Camera/MoveEye/MoveEye.pde rename to android/examples/Basics/Camera/MoveEye/MoveEye.pde index 6e1fc472c..0e305f592 100644 --- a/android/examples/OpenGL/Camera/MoveEye/MoveEye.pde +++ b/android/examples/Basics/Camera/MoveEye/MoveEye.pde @@ -26,4 +26,4 @@ void draw() { line(-100, 0, 0, 100, 0, 0); line(0, -100, 0, 0, 100, 0); line(0, 0, -100, 0, 0, 100); -} +} diff --git a/android/examples/OpenGL/Camera/Perspective/Perspective.pde b/android/examples/Basics/Camera/Perspective/Perspective.pde similarity index 96% rename from android/examples/OpenGL/Camera/Perspective/Perspective.pde rename to android/examples/Basics/Camera/Perspective/Perspective.pde index c2d53e42d..819248d05 100644 --- a/android/examples/OpenGL/Camera/Perspective/Perspective.pde +++ b/android/examples/Basics/Camera/Perspective/Perspective.pde @@ -15,7 +15,7 @@ */ void setup() { - size(640, 360, P3D); + size(displayWidth, displayHeight, P3D); orientation(LANDSCAPE); noStroke(); } @@ -39,4 +39,4 @@ void draw() { translate(0, 0, -50); box(30); } - + diff --git a/android/examples/OpenGL/Form/Primitives3D/Primitives3D.pde b/android/examples/Basics/Form/Primitives3D/Primitives3D.pde similarity index 99% rename from android/examples/OpenGL/Form/Primitives3D/Primitives3D.pde rename to android/examples/Basics/Form/Primitives3D/Primitives3D.pde index ff18fc85b..2db5ec81d 100644 --- a/android/examples/OpenGL/Form/Primitives3D/Primitives3D.pde +++ b/android/examples/Basics/Form/Primitives3D/Primitives3D.pde @@ -28,4 +28,4 @@ translate(500, height*0.35, -200); sphere(280); popMatrix(); - + diff --git a/android/examples/OpenGL/Lights/Directional/Directional.pde b/android/examples/Basics/Lights/Directional/Directional.pde similarity index 92% rename from android/examples/OpenGL/Lights/Directional/Directional.pde rename to android/examples/Basics/Lights/Directional/Directional.pde index 8613d8ac8..690a1bf97 100644 --- a/android/examples/OpenGL/Lights/Directional/Directional.pde +++ b/android/examples/Basics/Lights/Directional/Directional.pde @@ -20,10 +20,10 @@ void draw() { background(0); float dirY = (mouseY / float(height) - 0.5) * 2; float dirX = (mouseX / float(width) - 0.5) * 2; - directionalLight(204, 204, 204, -dirX, -dirY, -1); + directionalLight(204, 204, 204, -dirX, -dirY, -1); translate(width/2 - 100, height/2, 0); sphere(80); translate(200, 0, 0); sphere(80); } - + diff --git a/android/examples/OpenGL/Lights/Lights2/Lights2.pde b/android/examples/Basics/Lights/Mixture/Mixture.pde similarity index 94% rename from android/examples/OpenGL/Lights/Lights2/Lights2.pde rename to android/examples/Basics/Lights/Mixture/Mixture.pde index 8567b0564..c00a44a23 100644 --- a/android/examples/OpenGL/Lights/Lights2/Lights2.pde +++ b/android/examples/Basics/Lights/Mixture/Mixture.pde @@ -1,19 +1,17 @@ /** - * Lights 2 + * Mixture * by Simon Greenwold. * * Display a box with three different kinds of lights. */ -void setup() -{ +void setup() { size(640, 360, P3D); orientation(LANDSCAPE); noStroke(); } -void draw() -{ +void draw() { background(0); translate(width / 2, height / 2); @@ -34,4 +32,4 @@ void draw() rotateY(map(mouseX, 0, width, 0, PI)); rotateX(map(mouseY, 0, height, 0, PI)); box(150); -} +} diff --git a/android/examples/OpenGL/Lights/LightsGL/LightsGL.pde b/android/examples/Basics/Lights/MixtureGrid/MixtureGrid.pde similarity index 75% rename from android/examples/OpenGL/Lights/LightsGL/LightsGL.pde rename to android/examples/Basics/Lights/MixtureGrid/MixtureGrid.pde index f1f879342..3a6467ca5 100644 --- a/android/examples/OpenGL/Lights/LightsGL/LightsGL.pde +++ b/android/examples/Basics/Lights/MixtureGrid/MixtureGrid.pde @@ -1,23 +1,21 @@ /** - * LightsGL. - * Modified from an example by Simon Greenwold. + * Mixture Grid + * modified from an example by Simon Greenwold. * - * Display a box with three different kinds of lights. + * Display a 2D grid of boxes with three different kinds of lights. */ -void setup() -{ +void setup() { size(displayWidth, displayHeight, P3D); noStroke(); } -void draw() -{ +void draw() { defineLights(); background(0); - for (int x = 0; x <= width; x += 100) { - for (int y = 0; y <= height; y += 100) { + for (int x = 0; x <= width; x += 60) { + for (int y = 0; y <= height; y += 60) { pushMatrix(); translate(x, y); rotateY(map(mouseX, 0, width, 0, PI)); @@ -42,4 +40,4 @@ void defineLights() { 0, 40, 200, // Position 0, -0.5, -0.5, // Direction PI / 2, 2); // Angle, concentration -} +} diff --git a/android/examples/OpenGL/Lights/Lights1/Lights1.pde b/android/examples/Basics/Lights/OnOff/OnOff.pde similarity index 60% rename from android/examples/OpenGL/Lights/Lights1/Lights1.pde rename to android/examples/Basics/Lights/OnOff/OnOff.pde index 3a92fa736..0ec4f27e5 100644 --- a/android/examples/OpenGL/Lights/Lights1/Lights1.pde +++ b/android/examples/Basics/Lights/OnOff/OnOff.pde @@ -1,23 +1,26 @@ /** - * Lights 1. + * On/Off. * * Uses the default lights to show a simple box. The lights() function - * is used to turn on the default lighting. + * is used to turn on the default lighting. Click the mouse to turn the + * lights off. */ float spin = 0.0; +boolean on = true; -void setup() -{ +void setup() { size(640, 360, P3D); orientation(LANDSCAPE); noStroke(); } -void draw() -{ +void draw() { background(51); - lights(); + + if (on) { + lights(); + } spin += 0.01; @@ -28,3 +31,7 @@ void draw() box(150); popMatrix(); } + +void mousePressed() { + on = !on; +} diff --git a/android/examples/OpenGL/Lights/Reflection/Reflection.pde b/android/examples/Basics/Lights/Reflection/Reflection.pde similarity index 99% rename from android/examples/OpenGL/Lights/Reflection/Reflection.pde rename to android/examples/Basics/Lights/Reflection/Reflection.pde index efcf4639e..2349b4b83 100644 --- a/android/examples/OpenGL/Lights/Reflection/Reflection.pde +++ b/android/examples/Basics/Lights/Reflection/Reflection.pde @@ -23,4 +23,4 @@ void draw() { float s = mouseX / float(width); specular(s, s, s); sphere(120); -} +} diff --git a/android/examples/OpenGL/Lights/Spot/Spot.pde b/android/examples/Basics/Lights/Spot/Spot.pde similarity index 88% rename from android/examples/OpenGL/Lights/Spot/Spot.pde rename to android/examples/Basics/Lights/Spot/Spot.pde index 6f4a860ed..a03ad8aaa 100644 --- a/android/examples/OpenGL/Lights/Spot/Spot.pde +++ b/android/examples/Basics/Lights/Spot/Spot.pde @@ -6,7 +6,6 @@ */ int concentration = 600; // Try values 1 -> 10000 -PShape ball; void setup() { @@ -14,8 +13,7 @@ void setup() orientation(LANDSCAPE); noStroke(); fill(204); - sphereDetail(60); - ball = createShape(SPHERE, 120); + sphereDetail(30); } void draw() @@ -32,6 +30,6 @@ void draw() spotLight(102, 153, 204, 360, mouseY, 600, 0, 0, -1, PI/2, 600); translate(width/2, height/2, 0); - shape(ball); + sphere(120); } - + diff --git a/android/examples/Basics/Shape/LoadDisplayOBJ/LoadDisplayOBJ.pde b/android/examples/Basics/Shape/LoadDisplayOBJ/LoadDisplayOBJ.pde new file mode 100644 index 000000000..154eeb4f0 --- /dev/null +++ b/android/examples/Basics/Shape/LoadDisplayOBJ/LoadDisplayOBJ.pde @@ -0,0 +1,31 @@ +/** + * Load and Display an OBJ Shape. + * + * The loadShape() command is used to read simple SVG (Scalable Vector Graphics) + * files and OBJ (Object) files into a Processing sketch. This example loads an + * OBJ file of a rocket and displays it to the screen. + */ + + +PShape rocket; + +float ry; + +public void setup() { + size(640, 360, P3D); + orientation(LANDSCAPE); + + rocket = loadShape("rocket.obj"); +} + +public void draw() { + background(0); + lights(); + + translate(width/2, height/2 + 100, -200); + rotateZ(PI); + rotateY(ry); + shape(rocket); + + ry += 0.02; +} diff --git a/android/examples/OpenGL/IO/LoadOBJ/data/rocket.mtl b/android/examples/Basics/Shape/LoadDisplayOBJ/data/rocket.mtl similarity index 100% rename from android/examples/OpenGL/IO/LoadOBJ/data/rocket.mtl rename to android/examples/Basics/Shape/LoadDisplayOBJ/data/rocket.mtl diff --git a/android/examples/OpenGL/IO/LoadOBJ/data/rocket.obj b/android/examples/Basics/Shape/LoadDisplayOBJ/data/rocket.obj similarity index 100% rename from android/examples/OpenGL/IO/LoadOBJ/data/rocket.obj rename to android/examples/Basics/Shape/LoadDisplayOBJ/data/rocket.obj diff --git a/android/examples/Basics/Shape/LoadDisplaySVG/LoadDisplaySVG.pde b/android/examples/Basics/Shape/LoadDisplaySVG/LoadDisplaySVG.pde new file mode 100644 index 000000000..5cb9c91d4 --- /dev/null +++ b/android/examples/Basics/Shape/LoadDisplaySVG/LoadDisplaySVG.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 and OBJ (Object) files into a Processing sketch. This example loads an + * SVG file of a monster robot face and displays it to the screen. + */ + +// The next line is needed if running in JavaScript Mode with Processing.js +/* @pjs preload="bot1.svg"; */ + +PShape bot; + +void setup() { + size(640, 360); + // 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); + shape(bot, 110, 90, 100, 100); // Draw at coordinate (110, 90) at size 100 x 100 + shape(bot, 280, 40); // Draw at coordinate (280, 40) at the default size +} diff --git a/android/examples/Basics/Shape/LoadDisplayShape/data/bot1.svg b/android/examples/Basics/Shape/LoadDisplaySVG/data/bot1.svg similarity index 100% rename from android/examples/Basics/Shape/LoadDisplayShape/data/bot1.svg rename to android/examples/Basics/Shape/LoadDisplaySVG/data/bot1.svg diff --git a/android/examples/Basics/Shape/LoadDisplayShape/LoadDisplayShape.pde b/android/examples/Basics/Shape/LoadDisplayShape/LoadDisplayShape.pde deleted file mode 100644 index 3d18b4b4a..000000000 --- a/android/examples/Basics/Shape/LoadDisplayShape/LoadDisplayShape.pde +++ /dev/null @@ -1,26 +0,0 @@ -/** - * 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/Structure/CreateGraphics/CreateGraphics.pde b/android/examples/Basics/Structure/CreateGraphics/CreateGraphics.pde index 7f1b1d0eb..af137112e 100644 --- a/android/examples/Basics/Structure/CreateGraphics/CreateGraphics.pde +++ b/android/examples/Basics/Structure/CreateGraphics/CreateGraphics.pde @@ -12,7 +12,7 @@ PGraphics pg; void setup() { size(200, 200); - pg = createGraphics(80, 80, P2D); + pg = createGraphics(80, 80); } void draw() { diff --git a/android/examples/OpenGL/Transform/Rotate2/Rotate2.pde b/android/examples/Basics/Transform/RotatePushPop/RotatePushPop.pde similarity index 97% rename from android/examples/OpenGL/Transform/Rotate2/Rotate2.pde rename to android/examples/Basics/Transform/RotatePushPop/RotatePushPop.pde index a055564fa..0a948ff25 100644 --- a/android/examples/OpenGL/Transform/Rotate2/Rotate2.pde +++ b/android/examples/Basics/Transform/RotatePushPop/RotatePushPop.pde @@ -1,5 +1,5 @@ /** - * Rotate 2. + * Rotate Push Pop. * * The push() and pop() functions allow for more control over transformations. * The push function saves the current coordinate system to the stack @@ -40,4 +40,4 @@ void draw() box(200); popMatrix(); } -} +} diff --git a/android/examples/OpenGL/Transform/Rotate1/Rotate1.pde b/android/examples/Basics/Transform/RotateXY/RotateXY.pde similarity index 91% rename from android/examples/OpenGL/Transform/Rotate1/Rotate1.pde rename to android/examples/Basics/Transform/RotateXY/RotateXY.pde index a497aa394..800d736a7 100644 --- a/android/examples/OpenGL/Transform/Rotate1/Rotate1.pde +++ b/android/examples/Basics/Transform/RotateXY/RotateXY.pde @@ -18,8 +18,8 @@ void setup() { fill(204, 204); } -void draw() { - background(0); +void draw() { + background(126); a += 0.005; if(a > TWO_PI) { @@ -30,10 +30,12 @@ void draw() { rotateX(a); rotateY(a * 2.0); + fill(255); rect(-rSize, -rSize, rSize*2, rSize*2); rotateX(a * 1.001); rotateY(a * 2.002); + fill(0); rect(-rSize, -rSize, rSize*2, rSize*2); -} +} diff --git a/android/examples/OpenGL/Advanced/Particles/Particle.pde b/android/examples/Demos/Graphics/Particles/Particle.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Particles/Particle.pde rename to android/examples/Demos/Graphics/Particles/Particle.pde diff --git a/android/examples/OpenGL/Advanced/Particles/ParticleSystem.pde b/android/examples/Demos/Graphics/Particles/ParticleSystem.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Particles/ParticleSystem.pde rename to android/examples/Demos/Graphics/Particles/ParticleSystem.pde diff --git a/android/examples/OpenGL/Advanced/Particles/Particles.pde b/android/examples/Demos/Graphics/Particles/Particles.pde similarity index 87% rename from android/examples/OpenGL/Advanced/Particles/Particles.pde rename to android/examples/Demos/Graphics/Particles/Particles.pde index aad1a1bfb..4d9cd03e6 100644 --- a/android/examples/OpenGL/Advanced/Particles/Particles.pde +++ b/android/examples/Demos/Graphics/Particles/Particles.pde @@ -4,10 +4,10 @@ ParticleSystem ps; PImage sprite; void setup() { - size(640, 400, P3D); + size(displayWidth, displayHeight, P2D); orientation(LANDSCAPE); sprite = loadImage("sprite.png"); - ps = new ParticleSystem(1000); + ps = new ParticleSystem(2000); // Writing to the depth buffer is disabled to avoid rendering // artifacts due to the fact that the particles are semi-transparent @@ -25,7 +25,6 @@ void draw () { fill(255); textSize(16); text("Frame rate: " + int(frameRate),10,20); - } - + diff --git a/android/examples/OpenGL/Advanced/Patch/Patch.pde b/android/examples/Demos/Graphics/Patch/Patch.pde similarity index 98% rename from android/examples/OpenGL/Advanced/Patch/Patch.pde rename to android/examples/Demos/Graphics/Patch/Patch.pde index 5ac82ff4f..2b11d6f3a 100644 --- a/android/examples/OpenGL/Advanced/Patch/Patch.pde +++ b/android/examples/Demos/Graphics/Patch/Patch.pde @@ -10,7 +10,7 @@ PVector normp[][]; boolean autoNormals = false; void setup() { - size(600, 600, P3D); + size(displayWidth, displayHeight, P3D); orientation(LANDSCAPE); build(); } @@ -159,4 +159,4 @@ double DBezierBlend(int k, double mu, int n) { dblendf *= (dk * fnk + fk * dnk); return(dblendf); -} +} diff --git a/android/examples/OpenGL/Advanced/Planets/Perlin.pde b/android/examples/Demos/Graphics/Planets/Perlin.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Planets/Perlin.pde rename to android/examples/Demos/Graphics/Planets/Perlin.pde diff --git a/android/examples/OpenGL/Advanced/Planets/Planets.pde b/android/examples/Demos/Graphics/Planets/Planets.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Planets/Planets.pde rename to android/examples/Demos/Graphics/Planets/Planets.pde diff --git a/android/examples/OpenGL/Advanced/Ribbons/ArcBall.pde b/android/examples/Demos/Graphics/Ribbons/ArcBall.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Ribbons/ArcBall.pde rename to android/examples/Demos/Graphics/Ribbons/ArcBall.pde diff --git a/android/examples/OpenGL/Advanced/Ribbons/BSpline.pde b/android/examples/Demos/Graphics/Ribbons/BSpline.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Ribbons/BSpline.pde rename to android/examples/Demos/Graphics/Ribbons/BSpline.pde diff --git a/android/examples/OpenGL/Advanced/Ribbons/Geometry.pde b/android/examples/Demos/Graphics/Ribbons/Geometry.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Ribbons/Geometry.pde rename to android/examples/Demos/Graphics/Ribbons/Geometry.pde diff --git a/android/examples/OpenGL/Advanced/Ribbons/PDB.pde b/android/examples/Demos/Graphics/Ribbons/PDB.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Ribbons/PDB.pde rename to android/examples/Demos/Graphics/Ribbons/PDB.pde diff --git a/android/examples/OpenGL/Advanced/Ribbons/Ribbons.pde b/android/examples/Demos/Graphics/Ribbons/Ribbons.pde similarity index 94% rename from android/examples/OpenGL/Advanced/Ribbons/Ribbons.pde rename to android/examples/Demos/Graphics/Ribbons/Ribbons.pde index 84f1e513c..0a0f7cc23 100644 --- a/android/examples/OpenGL/Advanced/Ribbons/Ribbons.pde +++ b/android/examples/Demos/Graphics/Ribbons/Ribbons.pde @@ -22,7 +22,7 @@ ArrayList models; Arcball arcball; void setup() { - size(800, 600, P3D); + size(displayWidth, displayHeight, P3D); orientation(LANDSCAPE); arcball = new Arcball(width/2, height/2, 600); @@ -31,9 +31,10 @@ void setup() { void draw() { background(0); - - lights(); - + + ambient(80); + lights(); + translate(width/2, height/2, 200); arcball.run(); @@ -48,4 +49,4 @@ void mousePressed(){ void mouseDragged(){ arcball.mouseDragged(); -} +} diff --git a/android/examples/OpenGL/Advanced/Ribbons/data/1CBS.pdb b/android/examples/Demos/Graphics/Ribbons/data/1CBS.pdb similarity index 100% rename from android/examples/OpenGL/Advanced/Ribbons/data/1CBS.pdb rename to android/examples/Demos/Graphics/Ribbons/data/1CBS.pdb diff --git a/android/examples/OpenGL/Advanced/Ribbons/data/2POR.pdb b/android/examples/Demos/Graphics/Ribbons/data/2POR.pdb similarity index 100% rename from android/examples/OpenGL/Advanced/Ribbons/data/2POR.pdb rename to android/examples/Demos/Graphics/Ribbons/data/2POR.pdb diff --git a/android/examples/OpenGL/Advanced/Ribbons/data/4HHB.pdb b/android/examples/Demos/Graphics/Ribbons/data/4HHB.pdb similarity index 100% rename from android/examples/OpenGL/Advanced/Ribbons/data/4HHB.pdb rename to android/examples/Demos/Graphics/Ribbons/data/4HHB.pdb diff --git a/android/examples/OpenGL/Form/Geometry/Geometry.pde b/android/examples/Demos/Graphics/RotatingArcs/RotatingArcs.pde similarity index 100% rename from android/examples/OpenGL/Form/Geometry/Geometry.pde rename to android/examples/Demos/Graphics/RotatingArcs/RotatingArcs.pde diff --git a/android/examples/OpenGL/Advanced/Trefoil/Surface.pde b/android/examples/Demos/Graphics/Trefoil/Surface.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Trefoil/Surface.pde rename to android/examples/Demos/Graphics/Trefoil/Surface.pde diff --git a/android/examples/OpenGL/Advanced/Trefoil/Trefoil.pde b/android/examples/Demos/Graphics/Trefoil/Trefoil.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Trefoil/Trefoil.pde rename to android/examples/Demos/Graphics/Trefoil/Trefoil.pde diff --git a/android/examples/OpenGL/Advanced/Wiggling/Wiggling.pde b/android/examples/Demos/Graphics/Wiggling/Wiggling.pde similarity index 100% rename from android/examples/OpenGL/Advanced/Wiggling/Wiggling.pde rename to android/examples/Demos/Graphics/Wiggling/Wiggling.pde diff --git a/android/examples/OpenGL/Animation/Yellowtail/Gesture.pde b/android/examples/Demos/Graphics/Yellowtail/Gesture.pde similarity index 100% rename from android/examples/OpenGL/Animation/Yellowtail/Gesture.pde rename to android/examples/Demos/Graphics/Yellowtail/Gesture.pde diff --git a/android/examples/OpenGL/Animation/Yellowtail/Polygon.pde b/android/examples/Demos/Graphics/Yellowtail/Polygon.pde similarity index 100% rename from android/examples/OpenGL/Animation/Yellowtail/Polygon.pde rename to android/examples/Demos/Graphics/Yellowtail/Polygon.pde diff --git a/android/examples/OpenGL/Animation/Yellowtail/Vec3f.pde b/android/examples/Demos/Graphics/Yellowtail/Vec3f.pde similarity index 100% rename from android/examples/OpenGL/Animation/Yellowtail/Vec3f.pde rename to android/examples/Demos/Graphics/Yellowtail/Vec3f.pde diff --git a/android/examples/OpenGL/Animation/Yellowtail/Yellowtail.pde b/android/examples/Demos/Graphics/Yellowtail/Yellowtail.pde similarity index 100% rename from android/examples/OpenGL/Animation/Yellowtail/Yellowtail.pde rename to android/examples/Demos/Graphics/Yellowtail/Yellowtail.pde diff --git a/android/examples/OpenGL/Performance/CubicGridImmediate/CubicGridImmediate.pde b/android/examples/Demos/Performance/CubicGridImmediate/CubicGridImmediate.pde similarity index 100% rename from android/examples/OpenGL/Performance/CubicGridImmediate/CubicGridImmediate.pde rename to android/examples/Demos/Performance/CubicGridImmediate/CubicGridImmediate.pde diff --git a/android/examples/OpenGL/Performance/CubicGridRetained/CubicGridRetained.pde b/android/examples/Demos/Performance/CubicGridRetained/CubicGridRetained.pde similarity index 100% rename from android/examples/OpenGL/Performance/CubicGridRetained/CubicGridRetained.pde rename to android/examples/Demos/Performance/CubicGridRetained/CubicGridRetained.pde diff --git a/android/examples/OpenGL/Performance/DynamicParticlesImmediate/DynamicParticlesImmediate.pde b/android/examples/Demos/Performance/DynamicParticlesImmediate/DynamicParticlesImmediate.pde similarity index 100% rename from android/examples/OpenGL/Performance/DynamicParticlesImmediate/DynamicParticlesImmediate.pde rename to android/examples/Demos/Performance/DynamicParticlesImmediate/DynamicParticlesImmediate.pde diff --git a/android/examples/OpenGL/Performance/DynamicParticlesRetained/DynamicParticlesRetained.pde b/android/examples/Demos/Performance/DynamicParticlesRetained/DynamicParticlesRetained.pde similarity index 100% rename from android/examples/OpenGL/Performance/DynamicParticlesRetained/DynamicParticlesRetained.pde rename to android/examples/Demos/Performance/DynamicParticlesRetained/DynamicParticlesRetained.pde diff --git a/android/examples/OpenGL/Performance/Esfera/Esfera.pde b/android/examples/Demos/Performance/Esfera/Esfera.pde similarity index 100% rename from android/examples/OpenGL/Performance/Esfera/Esfera.pde rename to android/examples/Demos/Performance/Esfera/Esfera.pde diff --git a/android/examples/OpenGL/Performance/LineRendering/LineRendering.pde b/android/examples/Demos/Performance/LineRendering/LineRendering.pde similarity index 100% rename from android/examples/OpenGL/Performance/LineRendering/LineRendering.pde rename to android/examples/Demos/Performance/LineRendering/LineRendering.pde diff --git a/android/examples/OpenGL/Performance/QuadRendering/QuadRendering.pde b/android/examples/Demos/Performance/QuadRendering/QuadRendering.pde similarity index 100% rename from android/examples/OpenGL/Performance/QuadRendering/QuadRendering.pde rename to android/examples/Demos/Performance/QuadRendering/QuadRendering.pde diff --git a/android/examples/OpenGL/Performance/StaticParticlesImmediate/StaticParticlesImmediate.pde b/android/examples/Demos/Performance/StaticParticlesImmediate/StaticParticlesImmediate.pde similarity index 100% rename from android/examples/OpenGL/Performance/StaticParticlesImmediate/StaticParticlesImmediate.pde rename to android/examples/Demos/Performance/StaticParticlesImmediate/StaticParticlesImmediate.pde diff --git a/android/examples/OpenGL/Performance/StaticParticlesRetained/StaticParticlesRetained.pde b/android/examples/Demos/Performance/StaticParticlesRetained/StaticParticlesRetained.pde similarity index 100% rename from android/examples/OpenGL/Performance/StaticParticlesRetained/StaticParticlesRetained.pde rename to android/examples/Demos/Performance/StaticParticlesRetained/StaticParticlesRetained.pde diff --git a/android/examples/OpenGL/Performance/TextRendering/TextRendering.pde b/android/examples/Demos/Performance/TextRendering/TextRendering.pde similarity index 100% rename from android/examples/OpenGL/Performance/TextRendering/TextRendering.pde rename to android/examples/Demos/Performance/TextRendering/TextRendering.pde diff --git a/android/examples/OpenGL/Tests/OffscreenTest/OffscreenTest.pde b/android/examples/Demos/Tests/OffscreenTest/OffscreenTest.pde similarity index 100% rename from android/examples/OpenGL/Tests/OffscreenTest/OffscreenTest.pde rename to android/examples/Demos/Tests/OffscreenTest/OffscreenTest.pde diff --git a/android/examples/OpenGL/Tests/RedrawTest/RedrawTest.pde b/android/examples/Demos/Tests/RedrawTest/RedrawTest.pde similarity index 100% rename from android/examples/OpenGL/Tests/RedrawTest/RedrawTest.pde rename to android/examples/Demos/Tests/RedrawTest/RedrawTest.pde diff --git a/android/examples/OpenGL/Camera/NearFar/NearFar.pde b/android/examples/OpenGL/Camera/NearFar/NearFar.pde deleted file mode 100644 index eb17f146a..000000000 --- a/android/examples/OpenGL/Camera/NearFar/NearFar.pde +++ /dev/null @@ -1,119 +0,0 @@ -// Issues: The interaction is terrible on Android, and the visual cues are not -// visible. - -/** - * Near and Far example - * - * This example shows the effect of setting the near and far values - * in the ortho() and perspective() functions. Both values are always - * measured from the camera eye position and along the eye-center - * vector. - * - * The spacebar switches between perspective and orthographic - * projections, to set the near value press 'n' and 'f' for far. - * A mouse click switches the near/far setting on and off. - * 'r' enables/disables rotating the object with the mouse. - */ - -boolean usingPerspective = true; -boolean settingFar = true; -boolean settingEnabled = true; -boolean rotating = false; - -float cameraFOV; -float cameraZ; -float cameraMaxFar; -float cameraNear; -float cameraFar; - -float angleX = -PI/6; -float angleY = PI/3; - -void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - - cameraFOV = PI/3.0; - cameraZ = (height/2.0) / tan(cameraFOV/2.0); - cameraMaxFar = cameraZ * 2.0; - - cameraNear = cameraZ / 2.0; - cameraFar = cameraZ * 2.0; -} - -void draw() { - background(0); - lights(); - - if (settingEnabled) { - if (settingFar) { - float minx = map(cameraNear, 0, cameraMaxFar, 0, width); - cameraFar = map(mouseX, minx, width, cameraNear, cameraMaxFar); - } else { - float maxx = map(cameraFar, 0, cameraMaxFar, 0, width); - cameraNear = map(mouseX, 0, maxx, 0, cameraFar); - } - } - - if (usingPerspective) { - perspective(cameraFOV, float(width)/float(height), cameraNear, cameraFar); - } else { - ortho(-width/2, width/2, -height/2, height/2, cameraNear, cameraFar); - } - - pushMatrix(); - - translate(width/2, height/2, 0); - - if (rotating) { - angleX = map(mouseX, 0, width, -PI, PI); - angleY = map(mouseY, 0, width, -PI, PI); - } - rotateX(angleX); - rotateY(angleY); - - stroke(50); - fill(204); - box(160); - - popMatrix(); - - // Drawing visual clues for the near and far values. - perspective(); // Restoring to the default perspective matrix. - noStroke(); - float near = map(cameraNear, 0, cameraMaxFar, 0, width); - float far = map(cameraFar, 0, cameraMaxFar, 0, width); - fill(204); - rect(0, 0, near, 20); - rect(far, 0, width - far, 20); - if (near <= far) { - fill(160); - } else { - fill(200, 50, 50); - } - rect(near, 0, far - near, 20); -} - -void keyPressed() { - if (key == ' ') { - usingPerspective = !usingPerspective; - } else if (key == 'f' || key == 'F') { - settingFar = true; - } else if (key == 'n' || key == 'N') { - settingFar = false; - } else if (key == 'r' || key == 'R') { - if (rotating) { - rotating = false; - } else { - rotating = true; - settingEnabled = false; - } - } -} - -void mousePressed() { - if (!rotating) { - settingEnabled = !settingEnabled; - } -} - diff --git a/android/examples/OpenGL/Camera/OrthoVSPerspective/OrthoVSPerspective.pde b/android/examples/OpenGL/Camera/OrthoVSPerspective/OrthoVSPerspective.pde deleted file mode 100644 index 01e67a06b..000000000 --- a/android/examples/OpenGL/Camera/OrthoVSPerspective/OrthoVSPerspective.pde +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Ortho vs Perspective. - * - * Click to see the difference between orthographic projection - * and perspective projection as applied to a simple box. - * The ortho() function sets an orthographic projection and - * defines a parallel clipping volume. All objects with the - * same dimension appear the same size, regardless of whether - * they are near or far from the camera. The parameters to this - * function specify the clipping volume where left and right - * are the minimum and maximum x values, top and bottom are the - * minimum and maximum y values, and near and far are the minimum - * and maximum z values. - */ - -void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - noStroke(); - fill(204); -} - -void draw() { - background(0); - lights(); - - if(mousePressed) { - float fov = PI/3.0; - float cameraZ = (height/2.0) / tan(fov/2.0); - perspective(fov, float(width)/float(height), - cameraZ/2.0, cameraZ*2.0); - } else { - ortho(-width/2, width/2, -height/2, height/2, 0, 400); - } - - translate(width/2, height/2, 0); - rotateX(-PI/6); - rotateY(PI/3); - box(160); -} diff --git a/android/examples/OpenGL/Form/BrickTower/BrickTower.pde b/android/examples/OpenGL/Form/BrickTower/BrickTower.pde deleted file mode 100644 index 88f25d63e..000000000 --- a/android/examples/OpenGL/Form/BrickTower/BrickTower.pde +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Brick Tower - * by Ira Greenberg. - * - * 3D castle tower constructed out of individual bricks. - * Uses the PVector and Cube classes. - */ - -float bricksPerLayer = 16.0; -float brickLayers = 18.0; -Cube brick; -float brickWidth = 60, brickHeight = 25, brickDepth = 25; -float radius = 175.0; -float angle = 0; - -void setup(){ - size(640, 360, P3D); - orientation(LANDSCAPE); - brick = new Cube(brickWidth, brickHeight, brickDepth); -} - -void draw(){ - background(0); - float tempX = 0, tempY = 0, tempZ = 0; - fill(182, 62, 29); - noStroke(); - // Add basic light setup - lights(); - translate(width/2, height*1.2, -380); - // Tip tower to see inside - rotateX(radians(-45)); - // Slowly rotate tower - rotateY(frameCount * PI/600); - for (int i = 0; i < brickLayers; i++){ - // Increment rows - tempY-=brickHeight; - // Alternate brick seams - angle = 360.0 / bricksPerLayer * i/2; - for (int j = 0; j < bricksPerLayer; j++){ - tempZ = cos(radians(angle))*radius; - tempX = sin(radians(angle))*radius; - pushMatrix(); - translate(tempX, tempY, tempZ); - rotateY(radians(angle)); - // Add crenelation - if (i==brickLayers-1){ - if (j%2 == 0){ - brick.create(); - } - } - // Create main tower - else { - brick.create(); - } - popMatrix(); - angle += 360.0/bricksPerLayer; - } - } -} diff --git a/android/examples/OpenGL/Form/BrickTower/Cube.pde b/android/examples/OpenGL/Form/BrickTower/Cube.pde deleted file mode 100644 index df772c0cf..000000000 --- a/android/examples/OpenGL/Form/BrickTower/Cube.pde +++ /dev/null @@ -1,68 +0,0 @@ -class Cube { - - PVector[] vertices = new PVector[24]; - PVector[] normals = new PVector[6]; - float w, h, d; - - Cube(){ } - - Cube(float w, float h, float d){ - this.w = w; - this.h = h; - this.d = d; - - // Cube composed of 6 quads - // Front - normals[0] = new PVector(0, 0, 1); - vertices[0] = new PVector(-w/2, -h/2, d/2); - vertices[1] = new PVector(w/2, -h/2, d/2); - vertices[2] = new PVector(w/2, h/2, d/2); - vertices[3] = new PVector(-w/2, h/2, d/2); - - // Left - normals[1] = new PVector(-1, 0, 0); - vertices[4] = new PVector(-w/2, -h/2, d/2); - vertices[5] = new PVector(-w/2, -h/2, -d/2); - vertices[6] = new PVector(-w/2, h/2, -d/2); - vertices[7] = new PVector(-w/2, h/2, d/2); - - // Right - normals[2] = new PVector(1, 0, 0); - vertices[8] = new PVector(w/2, -h/2, d/2); - vertices[9] = new PVector(w/2, -h/2, -d/2); - vertices[10] = new PVector(w/2, h/2, -d/2); - vertices[11] = new PVector(w/2, h/2, d/2); - - // Back - normals[3] = new PVector(0, 0, -1); - vertices[12] = new PVector(-w/2, -h/2, -d/2); - vertices[13] = new PVector(w/2, -h/2, -d/2); - vertices[14] = new PVector(w/2, h/2, -d/2); - vertices[15] = new PVector(-w/2, h/2, -d/2); - - // Top - normals[4] = new PVector(0, 1, 0); - vertices[16] = new PVector(-w/2, -h/2, d/2); - vertices[17] = new PVector(-w/2, -h/2, -d/2); - vertices[18] = new PVector(w/2, -h/2, -d/2); - vertices[19] = new PVector(w/2, -h/2, d/2); - - // Bottom - normals[5] = new PVector(0, 1, 0); - vertices[20] = new PVector(-w/2, h/2, d/2); - vertices[21] = new PVector(-w/2, h/2, -d/2); - vertices[22] = new PVector(w/2, h/2, -d/2); - vertices[23] = new PVector(w/2, h/2, d/2); - } - - void create(){ - for (int i=0; i<6; i++){ - beginShape(QUADS); - normal(normals[i].x, normals[i].y, normals[i].z); - for (int j = 0; j < 4; j++){ - vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z); - } - endShape(); - } - } -} \ No newline at end of file diff --git a/android/examples/OpenGL/Form/CubicGrid/CubicGrid.pde b/android/examples/OpenGL/Form/CubicGrid/CubicGrid.pde deleted file mode 100644 index 069550266..000000000 --- a/android/examples/OpenGL/Form/CubicGrid/CubicGrid.pde +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Cubic Grid - * by Ira Greenberg. - * - * 3D translucent colored grid uses nested pushMatrix() - * and popMatrix() functions. - */ - -float boxSize = 80; -float margin = boxSize*2; -float depth = 400; -color boxFill; - -void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - noStroke(); - hint(DISABLE_DEPTH_TEST); -} - -void draw() { - background(255); - - // Center and spin grid - translate(width/2, height/2, -depth); - rotateY(frameCount * 0.01); - rotateX(frameCount * 0.01); - - // Build grid using multiple translations - for (float i =- depth/2+margin; i <= depth/2-margin; i += boxSize){ - pushMatrix(); - for (float j =- height+margin; j <= height-margin; j += boxSize){ - pushMatrix(); - for (float k =- width+margin; k <= width-margin; k += boxSize){ - // Base fill color on counter values, abs function - // ensures values stay within legal range - boxFill = color(abs(i), abs(j), abs(k), 50); - pushMatrix(); - translate(k, j, i); - fill(boxFill); - box(boxSize, boxSize, boxSize); - popMatrix(); - } - popMatrix(); - } - popMatrix(); - } -} - diff --git a/android/examples/OpenGL/Form/RunAmuck/Legs.pde b/android/examples/OpenGL/Form/RunAmuck/Legs.pde deleted file mode 100644 index eb74d7859..000000000 --- a/android/examples/OpenGL/Form/RunAmuck/Legs.pde +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Legs class - * By Ira Greenberg
- * Processing for Flash Developers, - * Friends of ED, 2009 - */ - -class Legs { - // Instance properties with default values - float x = 0, y = 0, z = 0, w = 150, ht = 125; - color col = #77AA22; - // Advanced properties - float detailW = w/6.0; - float detailHt = ht/8.0; - float shoeBulge = detailHt*2.0; - float legGap = w/7.0; - - // Dynamics properties - float velocity = .02, stepL, stepR, stepRate = random(10, 50); - float speedX = 1.0, speedZ, spring, damping = .5, theta; - - // Default constructor - Legs() { - } - - // Standard constructor - Legs(float x, float z, float w, float ht, color col) { - this.x = x; - this.z = z; - this.w = w; - this.ht = ht; - this.col = col; - fill(col); - detailW = w/6.0; - detailHt = ht/8.0; - shoeBulge = detailHt*2.0; - legGap = w/7.0; - speedX = random(-speedX, speedX); - } - - // Advanced constructor - Legs(float x, float z, float w, float ht, color col, float detailW, - float detailHt, float shoeBulge, float legGap) { - this.x = x; - this.z = z; - this.w = w; - this.ht = ht; - this.col = col; - this.detailW = detailW; - this.detailHt = detailHt; - this.shoeBulge = shoeBulge; - this.legGap = legGap; - speedX = random(-speedX, speedX); - } - - // Draw legs - void create() { - fill(col); - float footWidth = (w - legGap)/2; - beginShape(); - vertex(x - w/2, y - ht, z); - vertex(x - w/2, y - ht + detailHt, z); - vertex(x - w/2 + detailW, y - ht + detailHt, z); - // left foot - vertex(x - w/2 + detailW, y + stepL, z); - curveVertex(x - w/2 + detailW, y + stepL, z); - curveVertex(x - w/2 + detailW, y + stepL, z); - curveVertex(x - w/2 + detailW - shoeBulge, y + detailHt/2 + stepL, z); - curveVertex(x - w/2, y + detailHt + stepL, z); - curveVertex(x - w/2, y + detailHt + stepL, z); - vertex(x - w/2 + footWidth, y + detailHt + stepL*.9, z); - // end left foot - vertex(x - w/2 + footWidth + legGap/2, y - ht + detailHt, z); - vertex(x - w/2 + footWidth + legGap/2, y - ht + detailHt, z); - // right foot - vertex(x - w/2 + footWidth + legGap, y + detailHt + stepR*.9, z); - vertex(x + w/2, y + detailHt + stepR, z); - curveVertex(x + w/2, y + detailHt + stepR, z); - curveVertex(x + w/2, y + detailHt + stepR, z); - curveVertex(x + w/2 - detailW + shoeBulge, y + detailHt/2 + stepR, z); - curveVertex(x + w/2 - detailW, y + stepR, z); - vertex(x + w/2 - detailW, y + stepR, z); - // end right foot - vertex(x + w/2 - detailW, y - ht + detailHt, z); - vertex(x + w/2, y - ht + detailHt, z); - vertex(x + w/2, y - ht, z); - endShape(CLOSE); - } - - // Set advanced property values - void setDetails(float detailW, float detailHt, float shoeBulge, float legGap) { - this.detailW = detailW; - this.detailHt = detailHt; - this.shoeBulge = shoeBulge; - this.legGap = legGap; - } - - // Make the legs step - void step(float stepRate) { - this.stepRate = stepRate; - spring = ht/2.0; - stepL = sin(theta)*spring; - stepR = cos(theta)*spring; - theta += radians(stepRate); - } - - // Alternative overloaded step method - void step() { - spring = ht/2.0; - stepL = sin(theta)*spring; - stepR = cos(theta)*spring; - theta += radians(stepRate); - } - - - // Moves legs along x, y, z axes - void move() { - // Move legs along y-axis - y = stepR*damping; - - // Move legs along x-axis and - // check for collision against frame edge - x += speedX; - if (screenX(x, y, z) > width) { - speedX *= -1; - } - if (screenX(x, y, z) < 0) { - speedX *= -1; - } - - // Move legs along z-axis based on speed of stepping - // and check for collision against extremes - speedZ = (stepRate*velocity); - z += speedZ; - if (z > 400) { - z = 400; - velocity *= -1; - } - if (z < -100) { - z = -100; - velocity *= -1; - } - } - - void setDynamics(float speedX, float spring, float damping) { - this.speedX = speedX; - this.spring = spring; - this.damping = damping; - } -} - - - - - - - - - - - - diff --git a/android/examples/OpenGL/Form/RunAmuck/RunAmuck.pde b/android/examples/OpenGL/Form/RunAmuck/RunAmuck.pde deleted file mode 100644 index 555301537..000000000 --- a/android/examples/OpenGL/Form/RunAmuck/RunAmuck.pde +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Run-Amuck - * By Ira Greenberg
- * Processing for Flash Developers, - * Friends of ED, 2009 - */ - -int count = 10; -Legs[] legs = new Legs[count]; - -void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - noStroke(); - for (int i = 0; i < legs.length; i++) { - legs[i] = new Legs(random(-10, 10), random(-50, 150), random(.5, 5), - random(.5, 5), color(random(255), random(255), random(255))); - } -} - -void draw() { - background(0); - translate(width/2, height/2); - noStroke(); - fill(35); - - // Draw ground plane - beginShape(); - vertex(-width*2, 0, -1000); - vertex(width*2, 0, -1000); - vertex(width/2, height/2, 400); - vertex(-width/2, height/2, 400); - endShape(CLOSE); - - // Update and draw the legs - for (int i = 0; i < legs.length; i++) { - legs[i].create(); - // Set foot step rate - legs[i].step(random(10, 50)); - // Move legs along x, y, z axes - // z-movement dependent upon step rate - legs[i].move(); - } -} - - diff --git a/android/examples/OpenGL/Form/TexturedSphere/TexturedSphere.pde b/android/examples/OpenGL/Form/TexturedSphere/TexturedSphere.pde deleted file mode 100644 index 917eee34b..000000000 --- a/android/examples/OpenGL/Form/TexturedSphere/TexturedSphere.pde +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Textured Sphere - * by Mike 'Flux' Chang (cleaned up by Aaron Koblin). - * Based on code by Toxi. - * - * A 3D textured sphere with simple rotation control. - * Note: Controls will be inverted when sphere is upside down. - * Use an "arc ball" to deal with this appropriately. - */ - -PShape globe; -PImage texmap; - -int sDetail = 30; // Sphere detail setting -float rotationX = 0; -float rotationY = 0; -float velocityX = 0; -float velocityY = 0; -float globeRadius = 350; -float pushBack = -300; - -float[] cx, cz, sphereX, sphereY, sphereZ; -float sinLUT[]; -float cosLUT[]; -float SINCOS_PRECISION = 0.5; -int SINCOS_LENGTH = int(360.0 / SINCOS_PRECISION); - - -void setup() { - size(displayWidth, displayHeight, P3D); - - sphereDetail(sDetail); - texmap = loadImage("world32k.jpg"); - globe = createShape(SPHERE, globeRadius); - globe.noStroke(); - globe.texture(texmap); -} - -void draw() { - background(0); - renderGlobe(); -} - -void renderGlobe() { - translate(width/2.0, height/2.0, pushBack); - lights(); - rotateX(radians(-rotationX)); - rotateY(radians(-rotationY)); - shape(globe); - - rotationX += velocityX; - rotationY += velocityY; - velocityX *= 0.95; - velocityY *= 0.95; - - // Implements mouse control (interaction will be inverse when sphere is upside down) - if(mousePressed){ - velocityX += (mouseY-pmouseY) * 0.01; - velocityY -= (mouseX-pmouseX) * 0.01; - } -} diff --git a/android/examples/OpenGL/IO/LoadOBJ/LoadOBJ.pde b/android/examples/OpenGL/IO/LoadOBJ/LoadOBJ.pde deleted file mode 100644 index 637ddd273..000000000 --- a/android/examples/OpenGL/IO/LoadOBJ/LoadOBJ.pde +++ /dev/null @@ -1,19 +0,0 @@ -PShape rocket; - -public void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - - rocket = loadShape("rocket.obj"); -} - -public void draw() { - background(0); - - lights(); - - translate(width/2, height/2 + 100, -200); - rotateX(PI); - rotateY(frameCount * 0.01f); - shape(rocket); -} diff --git a/android/examples/OpenGL/IO/LoadSVG/LoadSVG.pde b/android/examples/OpenGL/IO/LoadSVG/LoadSVG.pde deleted file mode 100644 index 3dcaf6c63..000000000 --- a/android/examples/OpenGL/IO/LoadSVG/LoadSVG.pde +++ /dev/null @@ -1,35 +0,0 @@ -PShape world; -float resizeFactor; -float offsetX, offsetY; - -void setup() { - size(displayWidth, displayWidth, P2D); - orientation(LANDSCAPE); - - world = loadShape("World_map-lowres.svg"); - - PVector top = world.getTop(); - world.translate(-top.x, -top.y); - - - float r = world.getWidth() / world.getHeight(); - float w = width; - float h = width / r; - if (height < h) { - h = height; - w = r * h; - offsetX = (width - w) / 2; - offsetY = 0; - } else { - offsetX = 0; - offsetY = (height - h) / 2; - } - resizeFactor = w / world.getWidth(); - - world.scale(resizeFactor); -} - -public void draw() { - shape(world); -} - diff --git a/android/examples/OpenGL/IO/LoadSVG/data/World_map-lowres.svg b/android/examples/OpenGL/IO/LoadSVG/data/World_map-lowres.svg deleted file mode 100644 index b587dd669..000000000 --- a/android/examples/OpenGL/IO/LoadSVG/data/World_map-lowres.svg +++ /dev/null @@ -1,345 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/android/examples/OpenGL/Image/Blending/Blending.pde b/android/examples/OpenGL/Image/Blending/Blending.pde deleted file mode 100644 index 87e88b83e..000000000 --- a/android/examples/OpenGL/Image/Blending/Blending.pde +++ /dev/null @@ -1,81 +0,0 @@ -// Blending, by Andres Colubri -// Images can be blended using one of the 10 blending modes -// available in P3D. -// Images by Kevin Bjorke. - -PImage pic1, pic2; -int selMode = REPLACE; -String name = "replace"; -int picAlpha = 255; - -void setup() { - size(800, 480, P3D); - orientation(LANDSCAPE); - - PFont font = createFont(PFont.list()[0], 20); - textFont(font, 20); - - pic1 = loadImage("bjorke1.jpg"); - pic2 = loadImage("bjorke2.jpg"); -} - -void draw() { - background(0); - - tint(255, 255); - image(pic1, 0, 0, pic1.width, pic1.height); - - blendMode(selMode); - tint(255, picAlpha); - image(pic2, 0, 0, pic2.width, pic2.height); - - blendMode(REPLACE); - fill(200, 50, 50); - rect(0, height - 50, map(picAlpha, 0, 255, 0, width), 50); - fill(255); - - text("Selected blend mode: " + name + ". Click to move to next", 10, pic1.height + 30); - text("Drag this bar to change alpha of image", 10, height - 18); -} - -void mousePressed() { - if (height - 50 < mouseY) return; - - if (selMode == REPLACE) { - selMode = BLEND; - name = "blend"; - } else if (selMode == BLEND) { - selMode = ADD; - name = "add"; - } else if (selMode == ADD) { - selMode = SUBTRACT; - name = "subtract"; - } else if (selMode == SUBTRACT) { - selMode = LIGHTEST; - name = "lightest"; - } else if (selMode == LIGHTEST) { - selMode = DARKEST; - name = "darkest"; - } else if (selMode == DARKEST) { - selMode = DIFFERENCE; - name = "difference"; - } else if (selMode == DIFFERENCE) { - selMode = EXCLUSION; - name = "exclusion"; - } else if (selMode == EXCLUSION) { - selMode = MULTIPLY; - name = "multiply"; - } else if (selMode == MULTIPLY) { - selMode = SCREEN; - name = "screen"; - } else if (selMode == SCREEN) { - selMode = REPLACE; - name = "replace"; - } -} - -void mouseDragged() { - if (height - 50 < mouseY) { - picAlpha = int(map(mouseX, 0, width, 0, 255)); - } -} diff --git a/android/examples/OpenGL/Image/Explode/Explode.pde b/android/examples/OpenGL/Image/Explode/Explode.pde deleted file mode 100644 index 259f5f368..000000000 --- a/android/examples/OpenGL/Image/Explode/Explode.pde +++ /dev/null @@ -1,47 +0,0 @@ -// Issues: the image appears corrupted... - -/** - * Explode - * by Daniel Shiffman. - * - * Mouse horizontal location controls breaking apart of image and - * Maps pixels from a 2D image into 3D space. Pixel brightness controls - * translation along z axis. - */ - -PImage img; // The source image -int cellsize = 2; // Dimensions of each cell in the grid -int columns, rows; // Number of columns and rows in our system - -void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - img = loadImage("eames.jpg"); // Load the image - columns = img.width / cellsize; // Calculate # of columns - rows = img.height / cellsize; // Calculate # of rows - img.loadPixels(); -} - -void draw() { - background(0); - // Begin loop for columns - for ( int i = 0; i < columns; i++) { - // Begin loop for rows - for ( int j = 0; j < rows; j++) { - int x = i*cellsize + cellsize/2; // x position - int y = j*cellsize + cellsize/2; // y position - int loc = x + y*img.width; // Pixel array location - color c = img.pixels[loc]; // Grab the color - // Calculate a z position as a function of mouseX and pixel brightness - float z = (mouseX / float(width)) * brightness(img.pixels[loc]) - 20.0; - // Translate to the location, set fill and stroke, and draw the rect - pushMatrix(); - translate(x + 200, y + 100, z); - fill(c, 204); - noStroke(); - rectMode(CENTER); - rect(0, 0, cellsize, cellsize); - popMatrix(); - } - } -} diff --git a/android/examples/OpenGL/Image/Extrusion/Extrusion.pde b/android/examples/OpenGL/Image/Extrusion/Extrusion.pde deleted file mode 100644 index 2c5eacaa0..000000000 --- a/android/examples/OpenGL/Image/Extrusion/Extrusion.pde +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Extrusion. - * - * Converts a flat image into spatial data points and rotates the points - * around the center. - */ - -PImage extrude; -int[][] values; -float angle = 0; - -void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - - // Load the image into a new array - extrude = loadImage("ystone08.jpg"); - extrude.loadPixels(); - values = new int[extrude.width][extrude.height]; - for (int y = 0; y < extrude.height; y++) { - for (int x = 0; x < extrude.width; x++) { - color pixel = extrude.get(x, y); - values[x][y] = int(brightness(pixel)); - } - } -} - -void draw() { - background(0); - - // Update the angle - angle += 0.005; - - // Rotate around the center axis - translate(width/2, 0, +128); - rotateY(angle); - translate(-extrude.width/2, 100, +128); - - // Display the image mass - for (int y = 0; y < extrude.height; y++) { - for (int x = 0; x < extrude.width; x++) { - stroke(values[x][y]); - point(x, y, -values[x][y]); - } - } - -} diff --git a/android/examples/OpenGL/Image/ExtrusionGL/ExtrusionGL.pde b/android/examples/OpenGL/Image/ExtrusionGL/ExtrusionGL.pde deleted file mode 100644 index 850d88891..000000000 --- a/android/examples/OpenGL/Image/ExtrusionGL/ExtrusionGL.pde +++ /dev/null @@ -1,51 +0,0 @@ -// Lines appear repeated along horizontal strips (similar to Explode) - -/** - * Extrusion. - * - * Converts a flat image into spatial data points and rotates the points - * around the center. - */ - -PImage a; -boolean onetime = true; -int[][] aPixels; -int[][] values; -float angle; - -void setup() { - size(displayWidth, displayHeight, P3D); - - aPixels = new int[width][height]; - values = new int[width][height]; - noFill(); - - // Load the image into a new array - // Extract the values and store in an array - a = loadImage("ystone08.jpg"); - a.loadPixels(); - for (int i = 0; i < a.height; i++) { - for (int j = 0; j < a.width; j++) { - aPixels[j][i] = a.pixels[i*a.width + j]; - values[j][i] = int(blue(aPixels[j][i])); - } - } -} - -void draw() { - background(255); - translate(width/2, height/2, 0); - scale(2.0); - - // Update and constrain the angle - angle += 0.005; - rotateY(angle); - - // Display the image mass - for (int i = 0; i < a.height; i += 2) { - for (int j = 0; j < a.width; j += 2) { - stroke(values[j][i], 153); - line(j-a.width/2, i-a.height/2, -values[j][i], j-a.width/2, i-a.height/2, -values[j][i]-10); - } - } -} diff --git a/android/examples/OpenGL/Image/Zoom/Zoom.pde b/android/examples/OpenGL/Image/Zoom/Zoom.pde deleted file mode 100644 index 8c5c058b7..000000000 --- a/android/examples/OpenGL/Image/Zoom/Zoom.pde +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Zoom. - * - * Move the cursor over the image to alter its position. Click and press - * the mouse to zoom and set the density of the matrix by typing numbers 1-5. - * This program displays a series of lines with their heights corresponding to - * a color value read from an image. - */ - -PImage img; -//boolean onetime = true; -int[][] imgPixels; -float sval = 1.0; -float nmx, nmy; -int res = 5; - -void setup() -{ - size(640, 360, P3D); - orientation(LANDSCAPE); - noFill(); - stroke(255); - img = loadImage("ystone08.jpg"); - imgPixels = new int[img.width][img.height]; - for (int i = 0; i < img.height; i++) { - for (int j = 0; j < img.width; j++) { - imgPixels[j][i] = img.get(j, i); - } - } -} - -void draw() -{ - background(0); - - nmx = nmx + (mouseX-nmx)/20; - nmy += (mouseY-nmy)/20; - - if(mousePressed) { - sval += 0.005; - } - else { - sval -= 0.01; - } - - sval = constrain(sval, 1.0, 2.5); - - translate(width/2 + nmx * sval-100, height/2 + nmy*sval - 200, -50); - scale(sval); - rotateZ(PI/9 - sval + 1.0); - rotateX(PI/sval/8 - 0.125); - rotateY(sval/8 - 0.125); - - translate(-width/2, -height/2, 0); - - for (int i = 0; i < img.height; i += res) { - for (int j = 0; j < img.width; j += res) { - float rr = red(imgPixels[j][i]); - float gg = green(imgPixels[j][i]); - float bb = blue(imgPixels[j][i]); - float tt = rr+gg+bb; - stroke(rr, gg, gg); - line(i, j, tt/10-20, i, j, tt/10 ); - } - } -} - -void keyPressed() { - if(key == '1') { - res = 1; - } - else if (key == '2') { - res = 2; - } - else if (key == '3') { - res = 3; - } - else if (key == '4') { - res = 4; - } - else if (key == '5') { - res = 5; - } -} - - - - - - diff --git a/android/examples/OpenGL/Immediate/Bezier/Bezier.pde b/android/examples/OpenGL/Immediate/Bezier/Bezier.pde deleted file mode 100644 index 3e81819cf..000000000 --- a/android/examples/OpenGL/Immediate/Bezier/Bezier.pde +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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. - */ - -void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - stroke(255); - noFill(); -} - -void draw() { - background(0); - for (int i = 0; i < 200; i += 20) { - bezier(mouseX-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0)); - } -} - diff --git a/android/examples/OpenGL/Immediate/Robot1_Draw/Robot1_Draw.pde b/android/examples/OpenGL/Immediate/Robot1_Draw/Robot1_Draw.pde deleted file mode 100644 index 2238778c6..000000000 --- a/android/examples/OpenGL/Immediate/Robot1_Draw/Robot1_Draw.pde +++ /dev/null @@ -1,41 +0,0 @@ -// Robot 1: Draw from "Getting Started with Processing" -// by Reas & Fry. O'Reilly / Make 2010 - -size(720, 480, P2D); -orientation(LANDSCAPE); -strokeWeight(2); -background(204); -ellipseMode(RADIUS); - -// Neck -stroke(102); // Set stroke to gray -line(266, 257, 266, 162); // Left -line(276, 257, 276, 162); // Middle -line(286, 257, 286, 162); // Right - -// Antennae -line(276, 155, 246, 112); // Small -line(276, 155, 306, 56); // Tall -line(276, 155, 342, 170); // Medium - -// Body -noStroke(); // Disable stroke -fill(102); // Set fill to gray -ellipse(264, 377, 33, 33); // Antigravity orb -fill(0); // Set fill to black -rect(219, 257, 90, 120); // Main body -fill(102); // Set fill to gray -rect(219, 274, 90, 6); // Gray stripe - -// Head -fill(0); // Set fill to black -ellipse(276, 155, 45, 45); // Head -fill(255); // Set fill to white -ellipse(288, 150, 14, 14); // Large eye -fill(0); // Set fill to black -ellipse(288, 150, 3, 3); // Pupil -fill(153); // Set fill to light gray -ellipse(263, 148, 5, 5); // Small eye 1 -ellipse(296, 130, 4, 4); // Small eye 2 -ellipse(305, 162, 3, 3); // Small eye 3 - diff --git a/android/examples/OpenGL/Immediate/ShapePrimitives/ShapePrimitives.pde b/android/examples/OpenGL/Immediate/ShapePrimitives/ShapePrimitives.pde deleted file mode 100644 index 20e0d5f74..000000000 --- a/android/examples/OpenGL/Immediate/ShapePrimitives/ShapePrimitives.pde +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Shape Primitives. - * - * The basic shape primitive functions are triangle(), - * rect(), quad(), ellipse(), and arc(). Squares are made - * with rect() and circles are made with ellipse(). Each - * of these functions requires a number of parameters to - * determine the shape's position and size. - */ - -size(640, 360, P3D); -orientation(LANDSCAPE); -background(0); -noStroke(); - -fill(204); -triangle(18, 18, 18, 360, 81, 360); - -fill(102); -rect(81, 81, 63, 63); - -fill(204); -quad(189, 18, 216, 18, 216, 360, 144, 360); - -fill(255); -ellipse(252, 144, 72, 72); - -fill(204); -triangle(288, 18, 351, 360, 288, 360); - -fill(255); -arc(479, 300, 280, 280, PI, TWO_PI); - diff --git a/android/examples/OpenGL/Immediate/TriangleStrip/TriangleStrip.pde b/android/examples/OpenGL/Immediate/TriangleStrip/TriangleStrip.pde deleted file mode 100644 index 7c183c937..000000000 --- a/android/examples/OpenGL/Immediate/TriangleStrip/TriangleStrip.pde +++ /dev/null @@ -1,45 +0,0 @@ -/** - * TRIANGLE_STRIP Mode - * by Ira Greenberg. - * - * Generate a closed ring using the vertex() function and - * beginShape(TRIANGLE_STRIP) mode. The outerRad and innerRad - * variables control ring's radii respectively. - */ - -int x; -int y; -float outerRad; -float innerRad; - -void setup() { - size(640, 360, P2D); - orientation(LANDSCAPE); - background(204); - x = width/2; - y = height/2; - outerRad = min(width, height) * 0.4; - innerRad = outerRad * 0.6; -} - -void draw() { - background(204); - - int pts = int(map(mouseX, 0, width, 6, 60)); - float rot = 180.0/pts; - float angle = 0; - - beginShape(TRIANGLE_STRIP); - for (int i = 0; i <= pts; i++) { - float px = x + cos(radians(angle)) * outerRad; - float 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/OpenGL/Lights/CameraLight/CameraLight.pde b/android/examples/OpenGL/Lights/CameraLight/CameraLight.pde deleted file mode 100644 index 4d99aa00e..000000000 --- a/android/examples/OpenGL/Lights/CameraLight/CameraLight.pde +++ /dev/null @@ -1,39 +0,0 @@ -// CameraLight, by Andres Colubri -// Simple example showing a lit rotating cube. The projection -// is set to orthographic if the mouse is pressed. - -float spin = 0.0; - -void setup() { - size(400, 400, P3D); - - noStroke(); -} - -void draw() { - background(51); - - lights(); - - if (mousePressed) { - ortho(-width/2, width/2, -height/2, height/2); - } else { - float fov = PI/3.0; - float cameraZ = (height/2.0) / tan(fov/2.0); - perspective(fov, float(width)/float(height), - cameraZ/2.0, cameraZ*2.0); - } - - spin += 0.01; - - pushMatrix(); - translate(width/2, height/2, 0); - rotateX(PI/9); - rotateY(PI/5 + spin); - box(100); - popMatrix(); -} - - - - diff --git a/android/examples/OpenGL/Lights/Spot/AndroidManifest.xml b/android/examples/OpenGL/Lights/Spot/AndroidManifest.xml deleted file mode 100644 index 95459da70..000000000 --- a/android/examples/OpenGL/Lights/Spot/AndroidManifest.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - diff --git a/android/examples/OpenGL/Pixels/GetPixels/GetPixels.pde b/android/examples/OpenGL/Pixels/GetPixels/GetPixels.pde deleted file mode 100644 index a40c2a08f..000000000 --- a/android/examples/OpenGL/Pixels/GetPixels/GetPixels.pde +++ /dev/null @@ -1,30 +0,0 @@ -void setup() { - size(255, 255, P3D); - -// for (int x = 0; x < width; x++) { -// for (int y = 0; y < height; y++) { -// int c = color(x, y, 0); -// set(x, y, c); -// } -// } - - loadPixels(); - for (int i = 0; i < pixels.length; i++) { - int x = i % width; - int y = i / height; - int c = color(x, y, 0); - set(x, y, c); - } - updatePixels(); -} - -void draw() { - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - int c = get(x, y); - set(x, y, c); - } - } - - println(frameRate); -} diff --git a/android/examples/OpenGL/Pixels/SetPixels/SetPixels.pde b/android/examples/OpenGL/Pixels/SetPixels/SetPixels.pde deleted file mode 100644 index e7be75708..000000000 --- a/android/examples/OpenGL/Pixels/SetPixels/SetPixels.pde +++ /dev/null @@ -1,16 +0,0 @@ -void setup() { - size(400, 400, P3D); - - background(0); -} - -void draw() { - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - int c = color(random(255), random(255), random(255)); - set(x, y, c); - } - } - - println(frameRate); -} diff --git a/android/examples/OpenGL/Pixels/UpdatePixels/UpdatePixels.pde b/android/examples/OpenGL/Pixels/UpdatePixels/UpdatePixels.pde deleted file mode 100644 index 211bc320e..000000000 --- a/android/examples/OpenGL/Pixels/UpdatePixels/UpdatePixels.pde +++ /dev/null @@ -1,15 +0,0 @@ -void setup() { - size(400, 400, P3D); - - background(0); - loadPixels(); -} - -void draw() { - for (int i = 0; i < pixels.length; i++) { - pixels[i] = color(random(255), random(255), random(255)); - } - updatePixels(); - - println(frameRate); -} diff --git a/android/examples/OpenGL/Retained/PolyImmediate/PolyImmediate.pde b/android/examples/OpenGL/Retained/PolyImmediate/PolyImmediate.pde deleted file mode 100644 index d7ecc3e59..000000000 --- a/android/examples/OpenGL/Retained/PolyImmediate/PolyImmediate.pde +++ /dev/null @@ -1,21 +0,0 @@ -size(100, 100, P2D); - -beginShape(POLYGON); -fill(0, 255, 0, 255); -stroke(0, 0, 255, 255); -strokeWeight(5); -strokeJoin(ROUND); -beginContour(); -vertex(10, 10); -vertex(10, 90); -vertex(90, 90); -vertex(90, 10); -endContour(); -beginContour(); -vertex(40, 40); -vertex(70, 40); -vertex(70, 70); -vertex(40, 70); -endContour(); -endShape(CLOSE); - diff --git a/android/examples/OpenGL/Retained/PolyRetain/PolyRetain.pde b/android/examples/OpenGL/Retained/PolyRetain/PolyRetain.pde deleted file mode 100644 index 97e0a6311..000000000 --- a/android/examples/OpenGL/Retained/PolyRetain/PolyRetain.pde +++ /dev/null @@ -1,22 +0,0 @@ -size(100, 100, P2D); - -PShape obj = createShape(POLYGON); -obj.fill(0, 255, 0, 255); -obj.stroke(0, 0, 255, 255); -obj.strokeWeight(5); -obj.strokeJoin(ROUND); -obj.beginContour(); -obj.vertex(10, 10); -obj.vertex(10, 90); -obj.vertex(90, 90); -obj.vertex(90, 10); -obj.endContour(); -obj.beginContour(); -obj.vertex(40, 40); -obj.vertex(70, 40); -obj.vertex(70, 70); -obj.vertex(40, 70); -obj.endContour(); -obj.end(CLOSE); - -shape(obj); diff --git a/android/examples/OpenGL/Retained/Primitive/Primitive.pde b/android/examples/OpenGL/Retained/Primitive/Primitive.pde deleted file mode 100644 index 47854d798..000000000 --- a/android/examples/OpenGL/Retained/Primitive/Primitive.pde +++ /dev/null @@ -1,43 +0,0 @@ -PShape circle; -boolean filled = true; -boolean stroked = true; - -public void setup() { - size(400, 400, P2D); - frameRate(60); - - fill(255, 0, 0); - stroke(0, 0, 255); - strokeWeight(3); - circle = createShape(ELLIPSE, 0, 0, 100, 100); -} - -public void draw () { - background(0); - - if (5000 < millis()) { - if (filled) circle.fill(map(mouseX, 0, width, 255, 0), 0, 0); - if (stroked) circle.stroke(0, 0, map(mouseY, 0, height, 255, 0)); - } - - translate(mouseX, mouseY); - shape(circle); -} - -void keyPressed() { - if (key == 's') { - if (stroked) { - circle.noStroke(); - stroked = false; - } else { - stroked = true; - } - } else if (key == 'f') { - if (filled) { - circle.noFill(); - filled = false; - } else { - filled = true; - } - } -} diff --git a/android/examples/OpenGL/Retained/Shape2_18/Shape2_18.pde b/android/examples/OpenGL/Retained/Shape2_18/Shape2_18.pde deleted file mode 100644 index 854aa8060..000000000 --- a/android/examples/OpenGL/Retained/Shape2_18/Shape2_18.pde +++ /dev/null @@ -1,16 +0,0 @@ -size(100, 100, P2D); -smooth(); - -PShape obj = createShape(); -obj.noFill(); -obj.stroke(0); -obj.strokeWeight(1); -obj.vertex(15, 40); // V1 (see p.76) -obj.bezierVertex(5, 0, 80, 0, 50, 55); // C1, C2, V2 -obj.vertex(30, 45); // V3 -obj.vertex(25, 75); // V4 -obj.bezierVertex(50, 70, 75, 90, 80, 70); // C3, C4, V5 -obj.end(); - -background(150); -shape(obj); diff --git a/android/examples/OpenGL/Shaders/BlurFilter/BlurFilter.pde b/android/examples/OpenGL/Shaders/BlurFilter/BlurFilter.pde deleted file mode 100644 index 9914df206..000000000 --- a/android/examples/OpenGL/Shaders/BlurFilter/BlurFilter.pde +++ /dev/null @@ -1,14 +0,0 @@ -PShader blur; - -void setup() { - size(400, 400, P2D); - blur = loadShader("blur.glsl"); -} - -void draw() { - rect(mouseX, mouseY, 50, 50); - filter(blur); -} - - - diff --git a/android/examples/OpenGL/Shaders/EdgeDetect/EdgeDetect.pde b/android/examples/OpenGL/Shaders/EdgeDetect/EdgeDetect.pde deleted file mode 100644 index 6840399ea..000000000 --- a/android/examples/OpenGL/Shaders/EdgeDetect/EdgeDetect.pde +++ /dev/null @@ -1,32 +0,0 @@ -// This example shows how to change the default fragment shader used -// in P2D to render textures, by a custom one that applies a simple -// edge detection filter. -// -// Press any key to switch between the custom and the default shader. - -PImage img; -PShader edges; -boolean customShader; - -void setup() { - size(400, 400, P2D); - img = loadImage("berlin-1.jpg"); - - edges = loadShader(PShader.TEXTURED, "edges.glsl"); - shader(edges); - customShader = true; -} - -public void draw() { - image(img, 0, 0, width, height); -} - -public void mousePressed() { - if (customShader) { - resetShader(PShader.TEXTURED); - customShader = false; - } else { - shader(edges); - customShader = true; - } -} diff --git a/android/examples/OpenGL/Shaders/EdgeDetect/data/edges.glsl b/android/examples/OpenGL/Shaders/EdgeDetect/data/edges.glsl deleted file mode 100644 index 56e0a8b3f..000000000 --- a/android/examples/OpenGL/Shaders/EdgeDetect/data/edges.glsl +++ /dev/null @@ -1,43 +0,0 @@ -// Edge detection shader - -#ifdef GL_ES -precision mediump float; -precision mediump int; -#endif - -uniform sampler2D textureSampler; - -// The inverse of the texture dimensions along X and Y -uniform vec2 texcoordOffset; - -varying vec4 vertColor; -varying vec4 vertTexcoord; - -void main() { - vec4 sum = vec4(0); - - float kernel[9]; - kernel[0] = -1.0; kernel[1] = -1.0; kernel[2] = -1.0; - kernel[3] = -1.0; kernel[4] = +8.0; kernel[5] = -1.0; - kernel[6] = -1.0; kernel[7] = -1.0; kernel[8] = -1.0; - - vec2 offset[9]; - offset[0] = vec2(-texcoordOffset.s, -texcoordOffset.t); - offset[1] = vec2( 0.0, -texcoordOffset.t); - offset[2] = vec2(+texcoordOffset.s, -texcoordOffset.t); - - offset[3] = vec2(-texcoordOffset.s, 0.0); - offset[4] = vec2( 0.0, 0.0); - offset[5] = vec2(+texcoordOffset.s, 0.0); - - offset[6] = vec2(-texcoordOffset.s, +texcoordOffset.t); - offset[7] = vec2( 0.0, +texcoordOffset.t); - offset[8] = vec2(+texcoordOffset.s, +texcoordOffset.t); - - for (int i = 0; i < 9; i++) { - vec4 tmp = texture2D(textureSampler, vertTexcoord.st + offset[i]); - sum += tmp * kernel[i]; - } - - gl_FragColor = vec4(sum.rgb, 1.0); -} \ No newline at end of file diff --git a/android/examples/OpenGL/Shaders/FXAA/FXAA.pde b/android/examples/OpenGL/Shaders/FXAA/FXAA.pde deleted file mode 100644 index 92c10cd0a..000000000 --- a/android/examples/OpenGL/Shaders/FXAA/FXAA.pde +++ /dev/null @@ -1,93 +0,0 @@ -// This example uses a FxAA post-processing filter for fast -// fullscreen antialiasing: -// http://www.kotaku.com.au/2011/12/what-is-fxaa/ -// -// Press any key to enable/disable the shader. - -PGraphics canvas; -boolean drawing = false; -PShader fxaa; -boolean usingShader; -String message; -float msgLen; - -void setup() { - size(displayWidth, displayHeight, P2D); - orientation(LANDSCAPE); - noSmooth(); // doesn't realy matter, as mobile devices don't have anti-aliasing anyways - - canvas = createGraphics(width, height, P2D); - canvas.noSmooth(); - - fxaa = loadShader(PShader.TEXTURED, "fxaa.glsl"); - shader(fxaa); - usingShader = true; - - canvas.beginDraw(); - canvas.background(255); - canvas.stroke(0); - canvas.strokeWeight(15); - canvas.strokeCap(ROUND); - canvas.endDraw(); - - PFont font = createFont("Arial", 18); - textFont(font); - updateMessage(); - - drawing = false; -} - -public void draw() { - if (drawing) { - canvas.beginDraw(); - if (1 < dist(mouseX, mouseY, pmouseX, pmouseY)) { - canvas.line(pmouseX, pmouseY, mouseX, mouseY); - } - canvas.endDraw(); - } - - image(canvas, 0, 0); - - drawMessage(); -} - -public void mousePressed() { - if (!drawing && width - msgLen < mouseX && height - 23 < mouseY) { - if (usingShader) { - resetShader(PShader.TEXTURED); - usingShader = false; - } else { - shader(fxaa); - usingShader = true; - } - updateMessage(); - } else { - drawing = true; - } -} - -void mouseReleased() { - drawing = false; -} - -void updateMessage() { - if (usingShader) { - message = "Anti-aliasing enabled"; - } else { - message = "Anti-aliasing disabled"; - } - msgLen = textWidth(message); -} - -void drawMessage() { - if (usingShader) { - // We need the default texture shader to - // render text. - resetShader(PShader.TEXTURED); - } - fill(0); - text(message, width - msgLen, height - 5); - if (usingShader) { - shader(fxaa); - } -} diff --git a/android/examples/OpenGL/Shaders/FXAA/data/fxaa.glsl b/android/examples/OpenGL/Shaders/FXAA/data/fxaa.glsl deleted file mode 100644 index 693db482b..000000000 --- a/android/examples/OpenGL/Shaders/FXAA/data/fxaa.glsl +++ /dev/null @@ -1,69 +0,0 @@ -// FXAA shader, GLSL code adapted from: -// http://horde3d.org/wiki/index.php5?title=Shading_Technique_-_FXAA -// Whitepaper describing the technique: -// http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf - -#ifdef GL_ES -precision mediump float; -precision mediump int; -#endif - -uniform sampler2D textureSampler; - -// The inverse of the texture dimensions along X and Y -uniform vec2 texcoordOffset; - -varying vec4 vertColor; -varying vec4 vertTexcoord; - -void main() { - // The parameters are hardcoded for now, but could be - // made into uniforms to control fromt he program. - float FXAA_SPAN_MAX = 8.0; - float FXAA_REDUCE_MUL = 1.0/8.0; - float FXAA_REDUCE_MIN = (1.0/128.0); - - vec3 rgbNW = texture2D(textureSampler, vertTexcoord.xy + (vec2(-1.0, -1.0) * texcoordOffset)).xyz; - vec3 rgbNE = texture2D(textureSampler, vertTexcoord.xy + (vec2(+1.0, -1.0) * texcoordOffset)).xyz; - vec3 rgbSW = texture2D(textureSampler, vertTexcoord.xy + (vec2(-1.0, +1.0) * texcoordOffset)).xyz; - vec3 rgbSE = texture2D(textureSampler, vertTexcoord.xy + (vec2(+1.0, +1.0) * texcoordOffset)).xyz; - vec3 rgbM = texture2D(textureSampler, vertTexcoord.xy).xyz; - - vec3 luma = vec3(0.299, 0.587, 0.114); - float lumaNW = dot(rgbNW, luma); - float lumaNE = dot(rgbNE, luma); - float lumaSW = dot(rgbSW, luma); - float lumaSE = dot(rgbSE, luma); - float lumaM = dot( rgbM, luma); - - float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); - float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); - - vec2 dir; - dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); - dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); - - float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN); - - float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce); - - dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), - max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * texcoordOffset; - - vec3 rgbA = (1.0/2.0) * ( - texture2D(textureSampler, vertTexcoord.xy + dir * (1.0/3.0 - 0.5)).xyz + - texture2D(textureSampler, vertTexcoord.xy + dir * (2.0/3.0 - 0.5)).xyz); - vec3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * ( - texture2D(textureSampler, vertTexcoord.xy + dir * (0.0/3.0 - 0.5)).xyz + - texture2D(textureSampler, vertTexcoord.xy + dir * (3.0/3.0 - 0.5)).xyz); - float lumaB = dot(rgbB, luma); - - if((lumaB < lumaMin) || (lumaB > lumaMax)){ - gl_FragColor.xyz=rgbA; - } else { - gl_FragColor.xyz=rgbB; - } - gl_FragColor.a = 1.0; - - gl_FragColor *= vertColor; -} diff --git a/android/examples/OpenGL/Shaders/FishEye/FishEye.pde b/android/examples/OpenGL/Shaders/FishEye/FishEye.pde deleted file mode 100644 index cc536f128..000000000 --- a/android/examples/OpenGL/Shaders/FishEye/FishEye.pde +++ /dev/null @@ -1,37 +0,0 @@ -// Fish-eye shader, useful for dome projection - -PGraphics canvas; -PShader fisheye; -PImage img; - -void setup() { - size(400, 400, P3D); - canvas = createGraphics(400, 400, P3D); - - fisheye = loadShader(PShader.TEXTURED, "FishEye.glsl"); - fisheye.set("aperture", 180.0); - shader(fisheye); -} - -void draw() { - canvas.beginDraw(); - canvas.background(0); - canvas.stroke(255, 0, 0); - for (int i = 0; i < width; i += 10) { - canvas.line(i, 0, i, height); - } - for (int i = 0; i < height; i += 10) { - canvas.line(0, i, width, i); - } - canvas.lights(); - canvas.noStroke(); - canvas.translate(mouseX, mouseY, 100); - canvas.rotateX(frameCount * 0.01f); - canvas.rotateY(frameCount * 0.01f); - canvas.box(50); - canvas.endDraw(); - - // The rendering of this image will be done through the fisheye shader, since - // it was set as the PShader.TEXTURED shader of the main surface. - image(canvas, 0, 0, width, height); -} diff --git a/android/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl b/android/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl deleted file mode 100644 index 65d005e0a..000000000 --- a/android/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl +++ /dev/null @@ -1,57 +0,0 @@ -// Inspired by the "Angular Fisheye à la Bourke" sketch from -// Jonathan Cremieux, as shown in the OpenProcessing website: -// http://openprocessing.org/visuals/?visualID=12140 -// Using the inverse transform of the angular fisheye as -// explained in Paul Bourke's website: -// http://paulbourke.net/miscellaneous/domefisheye/fisheye/ - -#ifdef GL_ES -precision mediump float; -precision mediump int; -#endif - -uniform sampler2D textureSampler; -uniform mat4 texcoordMatrix; - -varying vec4 vertColor; -varying vec4 vertTexcoord; - -uniform float aperture; - -const float PI = 3.1415926535; - -void main(void) { - float apertureHalf = 0.5 * aperture * (PI / 180.0); - - // This factor ajusts the coordinates in the case that - // the aperture angle is less than 180 degrees, in which - // case the area displayed is not the entire half-sphere. - float maxFactor = sin(apertureHalf); - - // The st factor takes into account the situation when non-pot - // textures are not supported, so that the maximum texture - // coordinate to cover the entire image might not be 1. - vec2 stFactor = vec2(1.0 / abs(texcoordMatrix[0][0]), 1.0 / abs(texcoordMatrix[1][1])); - vec2 pos = (2.0 * vertTexcoord.st * stFactor - 1.0); - - float l = length(pos); - if (l > 1.0) { - gl_FragColor = vec4(0, 0, 0, 1); - } else { - float x = maxFactor * pos.x; - float y = maxFactor * pos.y; - - float n = length(vec2(x, y)); - - float z = sqrt(1.0 - n * n); - - float r = atan(n, z) / PI; - - float phi = atan(y, x); - - float u = r * cos(phi) + 0.5; - float v = r * sin(phi) + 0.5; - - gl_FragColor = texture2D(textureSampler, vec2(u, v) / stFactor) * vertColor; - } -} \ No newline at end of file diff --git a/android/examples/OpenGL/Shaders/GlossyFishEye/GlossyFishEye.pde b/android/examples/OpenGL/Shaders/GlossyFishEye/GlossyFishEye.pde deleted file mode 100644 index e2a060541..000000000 --- a/android/examples/OpenGL/Shaders/GlossyFishEye/GlossyFishEye.pde +++ /dev/null @@ -1,70 +0,0 @@ -// Fish-eye shader on the main surface, glossy specular reflection shader -// on the offscreen canvas. - -PGraphics canvas; -PShader fisheye; -PShader glossy; -PImage img; -PShape ball; - -boolean usingFishEye; - -void setup() { - size(400, 400, P3D); - canvas = createGraphics(400, 400, P3D); - - fisheye = loadShader(PShader.TEXTURED, "FishEye.glsl"); - fisheye.set("aperture", 180.0); - shader(fisheye); - usingFishEye = true; - - glossy = loadShader(PShader.LIT, "GlossyFrag.glsl", "GlossyVert.glsl"); - glossy.set("AmbientColour", 0, 0, 0); - glossy.set("DiffuseColour", 0.9, 0.2, 0.2); - glossy.set("SpecularColour", 1.0, 1.0, 1.0); - glossy.set("AmbientIntensity", 1.0); - glossy.set("DiffuseIntensity", 1.0); - glossy.set("SpecularIntensity", 0.7); - glossy.set("Roughness", 0.7); - glossy.set("Sharpness", 0.0); - canvas.shader(glossy); - - ball = createShape(SPHERE, 50); - //ball.fill(200, 50, 50); - ball.noStroke(); -} - -void draw() { - canvas.beginDraw(); - canvas.noStroke(); - canvas.background(0); - canvas.pushMatrix(); - canvas.rotateY(frameCount * 0.01); - canvas.pointLight(204, 204, 204, 1000, 1000, 1000); - canvas.popMatrix(); - for (float x = 0; x < canvas.width + 100; x += 100) { - for (float y = 0; y < canvas.height + 100; y += 100) { - for (float z = 0; z < 200; z += 100) { - canvas.pushMatrix(); - canvas.translate(x, y, -z); - canvas.shape(ball); - canvas.popMatrix(); - } - } - } - canvas.endDraw(); - - image(canvas, 0, 0, width, height); - - println(frameRate); -} - -public void mousePressed() { - if (usingFishEye) { - resetShader(PShader.TEXTURED); - usingFishEye = false; - } else { - shader(fisheye); - usingFishEye = true; - } -} diff --git a/android/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl b/android/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl deleted file mode 100644 index 65d005e0a..000000000 --- a/android/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl +++ /dev/null @@ -1,57 +0,0 @@ -// Inspired by the "Angular Fisheye à la Bourke" sketch from -// Jonathan Cremieux, as shown in the OpenProcessing website: -// http://openprocessing.org/visuals/?visualID=12140 -// Using the inverse transform of the angular fisheye as -// explained in Paul Bourke's website: -// http://paulbourke.net/miscellaneous/domefisheye/fisheye/ - -#ifdef GL_ES -precision mediump float; -precision mediump int; -#endif - -uniform sampler2D textureSampler; -uniform mat4 texcoordMatrix; - -varying vec4 vertColor; -varying vec4 vertTexcoord; - -uniform float aperture; - -const float PI = 3.1415926535; - -void main(void) { - float apertureHalf = 0.5 * aperture * (PI / 180.0); - - // This factor ajusts the coordinates in the case that - // the aperture angle is less than 180 degrees, in which - // case the area displayed is not the entire half-sphere. - float maxFactor = sin(apertureHalf); - - // The st factor takes into account the situation when non-pot - // textures are not supported, so that the maximum texture - // coordinate to cover the entire image might not be 1. - vec2 stFactor = vec2(1.0 / abs(texcoordMatrix[0][0]), 1.0 / abs(texcoordMatrix[1][1])); - vec2 pos = (2.0 * vertTexcoord.st * stFactor - 1.0); - - float l = length(pos); - if (l > 1.0) { - gl_FragColor = vec4(0, 0, 0, 1); - } else { - float x = maxFactor * pos.x; - float y = maxFactor * pos.y; - - float n = length(vec2(x, y)); - - float z = sqrt(1.0 - n * n); - - float r = atan(n, z) / PI; - - float phi = atan(y, x); - - float u = r * cos(phi) + 0.5; - float v = r * sin(phi) + 0.5; - - gl_FragColor = texture2D(textureSampler, vec2(u, v) / stFactor) * vertColor; - } -} \ No newline at end of file diff --git a/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyFrag.glsl b/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyFrag.glsl deleted file mode 100644 index 4f96b6f6d..000000000 --- a/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyFrag.glsl +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2007 Dave Griffiths -// Copyright (C) 2007 Dave Griffiths -// Licence: GPLv2 (see COPYING) -// Fluxus Shader Library -// --------------------- -// Glossy Specular Reflection Shader -// A more controllable version of blinn shading, -// Useful for ceramic or fluids - from Advanced -// Renderman, thanks to Larry Gritz - -#ifdef GL_ES -precision mediump float; -precision mediump int; -#endif - -uniform vec3 AmbientColour; -uniform vec3 DiffuseColour; -uniform vec3 SpecularColour; -uniform float AmbientIntensity; -uniform float DiffuseIntensity; -uniform float SpecularIntensity; -uniform float Roughness; -uniform float Sharpness; - -varying vec3 N; -varying vec3 P; -varying vec3 V; -varying vec3 L; - -void main() -{ - float w = 0.18*(1.0-Sharpness); - - vec3 l = normalize(L); - vec3 n = normalize(N); - vec3 v = normalize(V); - vec3 h = normalize(l+v); - - float diffuse = dot(l,n); - float specular = smoothstep(0.72-w,0.72+w,pow(max(0.0,dot(n,h)),1.0/Roughness)); - - gl_FragColor = vec4(AmbientColour*AmbientIntensity + - DiffuseColour*diffuse*DiffuseIntensity + - SpecularColour*specular*SpecularIntensity,1); -} diff --git a/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyVert.glsl b/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyVert.glsl deleted file mode 100644 index fa0c29590..000000000 --- a/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyVert.glsl +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2007 Dave Griffiths -// Licence: GPLv2 (see COPYING) -// Fluxus Shader Library -// --------------------- -// Glossy Specular Reflection Shader -// A more controllable version of blinn shading, -// Useful for ceramic or fluids - from Advanced -// Renderman, thanks to Larry Gritz - -uniform mat4 modelviewMatrix; -uniform mat4 projmodelviewMatrix; -uniform mat3 normalMatrix; - -uniform vec4 lightPosition[8]; - -attribute vec4 inVertex; -attribute vec3 inNormal; - -varying vec3 N; -varying vec3 P; -varying vec3 V; -varying vec3 L; - -void main() { - N = normalize(normalMatrix * inNormal); - P = inVertex.xyz; - V = -vec3(modelviewMatrix * inVertex); - L = vec3(modelviewMatrix * (lightPosition[0] - inVertex)); - gl_Position = projmodelviewMatrix * inVertex; -} - diff --git a/android/examples/OpenGL/Shaders/ToonShading/ToonShading.pde b/android/examples/OpenGL/Shaders/ToonShading/ToonShading.pde deleted file mode 100644 index c5cb11350..000000000 --- a/android/examples/OpenGL/Shaders/ToonShading/ToonShading.pde +++ /dev/null @@ -1,41 +0,0 @@ -// Example showing the use of a custom lighting shader in order -// to apply a toon effect on the scene. -// Based on the glsl tutorial from lighthouse 3D: -// http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shader-version-ii/ - -PShader toon; -boolean customShader; - -public void setup() { - size(400, 400, P3D); - noStroke(); - fill(204); - - toon = loadShader(PShader.LIT, "ToonFrag.glsl", "ToonVert.glsl"); - shader(toon); - customShader = true; -} - -public void draw() { - noStroke(); - background(0); - float dirY = (mouseY / float(height) - 0.5) * 2; - float dirX = (mouseX / float(width) - 0.5) * 2; - directionalLight(204, 204, 204, -dirX, -dirY, -1); - translate(width/2, height/2); - sphere(80); -} - -public void mousePressed() { - if (dist(mouseX, mouseY, width/2, height/2) < 80) { - if (customShader) { - resetShader(PShader.LIT); - customShader = false; - } - else { - shader(toon); - customShader = true; - } - } -} - diff --git a/android/examples/OpenGL/Transform/Bird/Bird.pde b/android/examples/OpenGL/Transform/Bird/Bird.pde deleted file mode 100644 index 686c08c63..000000000 --- a/android/examples/OpenGL/Transform/Bird/Bird.pde +++ /dev/null @@ -1,66 +0,0 @@ -// Issues: the entire screen is white for a second at the beginning, then -// the wings of the bird are black - -/** - * Simple 3D Bird - * by Ira Greenberg. - * - * Using a box and 2 rects to simulate a flying bird. - * Trig functions handle the flapping and sinuous movement. - */ - -float ang = 0, ang2 = 0, ang3 = 0, ang4 = 0; -float px = 0, py = 0, pz = 0; -float flapSpeed = 0.2; - -void setup(){ - size(displayWidth, displayHeight, P3D); - noStroke(); -} - -void draw(){ - background(0); - lights(); - - // Flight - px = sin(radians(ang3)) * 170; - py = cos(radians(ang3)) * 300; - pz = sin(radians(ang4)) * 500; - translate(width/2 + px, height/2 + py, -700+pz); - rotateX(sin(radians(ang2)) * 120); - rotateY(sin(radians(ang2)) * 50); - rotateZ(sin(radians(ang2)) * 65); - - // Body - fill(153); - box(20, 100, 20); - - - // Left wing - fill(204); - pushMatrix(); - rotateY(sin(radians(ang)) * -20); - rect(-75, -50, 75, 100); - popMatrix(); - - // Right wing - pushMatrix(); - rotateY(sin(radians(ang)) * 20); - rect(0, -50, 75, 100); - popMatrix(); - - // Wing flap - ang += flapSpeed; - if (ang > 3) { - flapSpeed *= -1; - } - if (ang < -3) { - flapSpeed *= -1; - } - - // Increment angles - ang2 += 0.01; - ang3 += 2.0; - ang4 += 0.75; -} - diff --git a/android/examples/OpenGL/Transform/Birds/Bird.pde b/android/examples/OpenGL/Transform/Birds/Bird.pde deleted file mode 100644 index 84ada2603..000000000 --- a/android/examples/OpenGL/Transform/Birds/Bird.pde +++ /dev/null @@ -1,99 +0,0 @@ -class Bird { - - // Properties - float offsetX, offsetY, offsetZ; - float w, h; - int bodyFill; - int wingFill; - float ang = 0, ang2 = 0, ang3 = 0, ang4 = 0; - float radiusX = 120, radiusY = 200, radiusZ = 700; - float rotX = 15, rotY = 10, rotZ = 5; - float flapSpeed = 0.4; - float rotSpeed = 0.1; - - // Constructors - Bird(){ - this(0, 0, 0, 60, 80); - } - - Bird(float offsetX, float offsetY, float offsetZ, - float w, float h){ - this.offsetX = offsetX; - this.offsetY = offsetY; - this.offsetZ = offsetZ; - this.h = h; - this.w = w; - bodyFill = color(153); - wingFill = color(204); - } - - void setFlight(float radiusX, float radiusY, float radiusZ, - float rotX, float rotY, float rotZ){ - this.radiusX = radiusX; - this.radiusY = radiusY; - this.radiusZ = radiusZ; - - this.rotX = rotX; - this.rotY = rotY; - this.rotZ = rotZ; - } - - void setWingSpeed(float flapSpeed){ - this.flapSpeed = flapSpeed; - } - - void setRotSpeed(float rotSpeed){ - this.rotSpeed = rotSpeed; - } - - void fly() { - pushMatrix(); - float px, py, pz; - - // Flight - px = sin(radians(ang3)) * radiusX; - py = cos(radians(ang3)) * radiusY; - pz = sin(radians(ang4)) * radiusZ; - - translate(width/2 + offsetX + px, height/2 + offsetY+py, -700 + offsetZ+pz); - - rotateX(sin(radians(ang2)) * rotX); - rotateY(sin(radians(ang2)) * rotY); - rotateZ(sin(radians(ang2)) * rotZ); - - // Body - fill(bodyFill); - box(w/5, h, w/5); - - // Left wing - fill(wingFill); - pushMatrix(); - rotateY(sin(radians(ang)) * 20); - rect(0, -h/2, w, h); - popMatrix(); - - // Right wing - pushMatrix(); - rotateY(sin(radians(ang)) * -20); - rect(-w, -h/2, w, h); - popMatrix(); - - // Wing flap - ang += flapSpeed; - if (ang > 3) { - flapSpeed*=-1; - } - if (ang < -3) { - flapSpeed*=-1; - } - - // Ang's run trig functions - ang2 += rotSpeed; - ang3 += 1.25; - ang4 += 0.55; - popMatrix(); - } -} - - - diff --git a/android/examples/OpenGL/Transform/Birds/Birds.pde b/android/examples/OpenGL/Transform/Birds/Birds.pde deleted file mode 100644 index f4088489c..000000000 --- a/android/examples/OpenGL/Transform/Birds/Birds.pde +++ /dev/null @@ -1,56 +0,0 @@ -// Issues: the entire screen is white for a second at the beginning, then -// the wings of the birds are black - -/** - * Crazy Flocking 3D Birds - * by Ira Greenberg. - * - * Simulates a flock of birds using a Bird class and nested - * pushMatrix() / popMatrix() functions. - * Trigonometry functions handle the flapping and sinuous movement. - */ - -// Flock array -int birdCount = 200; -Bird[]birds = new Bird[birdCount]; -float[]x = new float[birdCount]; -float[]y = new float[birdCount]; -float[]z = new float[birdCount]; -float[]rx = new float[birdCount]; -float[]ry = new float[birdCount]; -float[]rz = new float[birdCount]; -float[]spd = new float[birdCount]; -float[]rot = new float[birdCount]; - -void setup() { - size(displayWidth, displayHeight, P3D); - noStroke(); - - // Initialize arrays with random values - for (int i = 0; i < birdCount; i++){ - birds[i] = new Bird(random(-300, 300), random(-300, 300), - random(-500, -2500), random(5, 30), random(5, 30)); - - x[i] = random(20, 340); - y[i] = random(30, 350); - z[i] = random(1000, 4800); - rx[i] = random(-160, 160); - ry[i] = random(-55, 55); - rz[i] = random(-20, 20); - spd[i] = random(.1, 3.75); - rot[i] = random(.025, .15); - } -} - -void draw() { - background(0); - lights(); - for (int i = 0; i < birdCount; i++){ - birds[i].setFlight(x[i], y[i], z[i], rx[i], ry[i], rz[i]); - birds[i].setWingSpeed(spd[i]); - birds[i].setRotSpeed(rot[i]); - birds[i].fly(); - } -} - - diff --git a/android/examples/OpenGL/Transform/CubesWithinCube/Cube.pde b/android/examples/OpenGL/Transform/CubesWithinCube/Cube.pde deleted file mode 100644 index 271792623..000000000 --- a/android/examples/OpenGL/Transform/CubesWithinCube/Cube.pde +++ /dev/null @@ -1,72 +0,0 @@ - -// Custom Cube Class - -class Cube{ - PVector[] vertices = new PVector[24]; - float w, h, d; - - // Default constructor - Cube(){ } - - // Constructor 2 - Cube(float w, float h, float d) { - this.w = w; - this.h = h; - this.d = d; - - // cube composed of 6 quads - //front - vertices[0] = new PVector(-w/2,-h/2,d/2); - vertices[1] = new PVector(w/2,-h/2,d/2); - vertices[2] = new PVector(w/2,h/2,d/2); - vertices[3] = new PVector(-w/2,h/2,d/2); - //left - vertices[4] = new PVector(-w/2,-h/2,d/2); - vertices[5] = new PVector(-w/2,-h/2,-d/2); - vertices[6] = new PVector(-w/2,h/2,-d/2); - vertices[7] = new PVector(-w/2,h/2,d/2); - //right - vertices[8] = new PVector(w/2,-h/2,d/2); - vertices[9] = new PVector(w/2,-h/2,-d/2); - vertices[10] = new PVector(w/2,h/2,-d/2); - vertices[11] = new PVector(w/2,h/2,d/2); - //back - vertices[12] = new PVector(-w/2,-h/2,-d/2); - vertices[13] = new PVector(w/2,-h/2,-d/2); - vertices[14] = new PVector(w/2,h/2,-d/2); - vertices[15] = new PVector(-w/2,h/2,-d/2); - //top - vertices[16] = new PVector(-w/2,-h/2,d/2); - vertices[17] = new PVector(-w/2,-h/2,-d/2); - vertices[18] = new PVector(w/2,-h/2,-d/2); - vertices[19] = new PVector(w/2,-h/2,d/2); - //bottom - vertices[20] = new PVector(-w/2,h/2,d/2); - vertices[21] = new PVector(-w/2,h/2,-d/2); - vertices[22] = new PVector(w/2,h/2,-d/2); - vertices[23] = new PVector(w/2,h/2,d/2); - } - void create(){ - // Draw cube - for (int i=0; i<6; i++){ - beginShape(QUADS); - for (int j=0; j<4; j++){ - vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z); - } - endShape(); - } - } - void create(color[]quadBG){ - // Draw cube - for (int i=0; i<6; i++){ - fill(quadBG[i]); - beginShape(QUADS); - for (int j=0; j<4; j++){ - vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z); - } - endShape(); - } - } -} - - diff --git a/android/examples/OpenGL/Transform/CubesWithinCube/CubesWithinCube.pde b/android/examples/OpenGL/Transform/CubesWithinCube/CubesWithinCube.pde deleted file mode 100644 index 9a07dbc12..000000000 --- a/android/examples/OpenGL/Transform/CubesWithinCube/CubesWithinCube.pde +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Cubes Contained Within a Cube - * by Ira Greenberg. - * - * Collision detection against all - * outer cube's surfaces. - * Uses the Point3D and Cube classes. - */ - -Cube stage; // external large cube -int cubies = 20; -Cube[]c = new Cube[cubies]; // internal little cubes -color[][]quadBG = new color[cubies][6]; - -// Controls cubie's movement -float[]x = new float[cubies]; -float[]y = new float[cubies]; -float[]z = new float[cubies]; -float[]xSpeed = new float[cubies]; -float[]ySpeed = new float[cubies]; -float[]zSpeed = new float[cubies]; - -// Controls cubie's rotation -float[]xRot = new float[cubies]; -float[]yRot = new float[cubies]; -float[]zRot = new float[cubies]; - -// Size of external cube -float bounds = 300; - -void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - - for (int i = 0; i < cubies; i++){ - // Each cube face has a random color component - float colorShift = random(-75, 75); - quadBG[i][0] = color(0); - quadBG[i][1] = color(51); - quadBG[i][2] = color(102); - quadBG[i][3] = color(153); - quadBG[i][4] = color(204); - quadBG[i][5] = color(255); - - // Cubies are randomly sized - float cubieSize = random(5, 15); - c[i] = new Cube(cubieSize, cubieSize, cubieSize); - - // Initialize cubie's position, speed and rotation - x[i] = 0; - y[i] = 0; - z[i] = 0; - - xSpeed[i] = random(-1, 1); - ySpeed[i] = random(-1, 1); - zSpeed[i] = random(-1, 1); - - xRot[i] = random(40, 100); - yRot[i] = random(40, 100); - zRot[i] = random(40, 100); - } - - // Instantiate external large cube - stage = new Cube(bounds, bounds, bounds); -} - -void draw(){ - background(50); - lights(); - - // Center in display window - translate(width/2, height/2, -130); - - // Outer transparent cube - noFill(); - - // Rotate everything, including external large cube - rotateX(frameCount * 0.001); - rotateY(frameCount * 0.002); - rotateZ(frameCount * 0.001); - stroke(255); - - // Draw external large cube - stage.create(); - - // Move and rotate cubies - for (int i = 0; i < cubies; i++){ - pushMatrix(); - translate(x[i], y[i], z[i]); - rotateX(frameCount*PI/xRot[i]); - rotateY(frameCount*PI/yRot[i]); - rotateX(frameCount*PI/zRot[i]); - noStroke(); - c[i].create(quadBG[i]); - x[i] += xSpeed[i]; - y[i] += ySpeed[i]; - z[i] += zSpeed[i]; - popMatrix(); - - // Draw lines connecting cubbies - stroke(0); - if (i < cubies-1){ - line(x[i], y[i], z[i], x[i+1], y[i+1], z[i+1]); - } - - // Check wall collisions - if (x[i] > bounds/2 || x[i] < -bounds/2){ - xSpeed[i]*=-1; - } - if (y[i] > bounds/2 || y[i] < -bounds/2){ - ySpeed[i]*=-1; - } - if (z[i] > bounds/2 || z[i] < -bounds/2){ - zSpeed[i]*=-1; - } - } -} - diff --git a/android/examples/OpenGL/Transform/PushPopCubes/PushPopCubes.pde b/android/examples/OpenGL/Transform/PushPopCubes/PushPopCubes.pde deleted file mode 100644 index 21b252b74..000000000 --- a/android/examples/OpenGL/Transform/PushPopCubes/PushPopCubes.pde +++ /dev/null @@ -1,149 +0,0 @@ -/** - * PushPop Cubes - * by Ira Greenberg. - * - * Array of rotating cubes creates - * dynamic field patterns. Color - * controlled by light sources. Example - * of pushMatrix() and popMatrix(). - */ - -// Cube class required -float ang; -int rows = 21; -int cols = 21; -int cubeCount = rows*cols; -int colSpan, rowSpan; -float rotspd = 2.0; -Cube[] cubes = new Cube[cubeCount]; -float[] angs = new float[cubeCount]; -float[] rotvals = new float[cubeCount]; - -void setup(){ - size(displayWidth, displayHeight, P3D); - - colSpan = width/(cols-1); - rowSpan = height/(rows-1); - noStroke(); - - // instantiate cubes - for (int i = 0; i < cubeCount; i++){ - cubes[i] = new Cube(24, 20, 10, 0, 0, 0); - /* 3 different rotation options - - 1st option: cubes each rotate uniformly - - 2nd option: cubes each rotate randomly - - 3rd option: cube columns rotate as waves - To try the different rotations, leave one - of the rotVals[i] lines uncommented below - and the other 2 commented out. */ - - //rotvals[i] = rotspd; - //rotvals[i] = random(-rotspd * 2, rotspd * 2); - rotvals[i] = rotspd += .01; - } -} - -void draw(){ - int cubeCounter = 0; - background(0); - fill(200); - - // Set up some different colored lights - pointLight(51, 102, 255, width/3, height/2, 100); - pointLight(200, 40, 60, width/1.5, height/2, -150); - - // Raise overall light in scene - ambientLight(170, 170, 100); - - // Translate, rotate and draw cubes - for (int i = 0; i < cols; i++){ - for (int j = 0; j < rows; j++){ - pushMatrix(); - /* Translate each block. - pushmatix and popmatrix add each cube - translation to matrix, but restore - original, so each cube rotates around its - owns center */ - translate(i * colSpan, j * rowSpan, -20); - //rotate each cube around y and x axes - rotateY(radians(angs[cubeCounter])); - rotateX(radians(angs[cubeCounter])); - cubes[cubeCounter].drawCube(); - popMatrix(); - cubeCounter++; - } - } - // Angs used in rotate function calls above - for (int i = 0; i < cubeCount; i++){ - angs[i] += rotvals[i]; - } -} - -// Simple Cube class, based on Quads -class Cube { - - // Properties - int w, h, d; - int shiftX, shiftY, shiftZ; - - // Constructor - Cube(int w, int h, int d, int shiftX, int shiftY, int shiftZ){ - this.w = w; - this.h = h; - this.d = d; - this.shiftX = shiftX; - this.shiftY = shiftY; - this.shiftZ = shiftZ; - } - - /* Main cube drawing method, which looks - more confusing than it really is. It's - just a bunch of rectangles drawn for - each cube face */ - void drawCube(){ - - // Front face - beginShape(QUADS); - normal(1, 0, 0); - vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); - vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); - vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); - vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ); - - // Back face - normal(-1, 0, 0); - vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ); - vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); - vertex(w + shiftX, h + shiftY, d + shiftZ); - vertex(-w/2 + shiftX, h + shiftY, d + shiftZ); - - // Left face - normal(0, -1, 0); - vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); - vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ); - vertex(-w/2 + shiftX, h + shiftY, d + shiftZ); - vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ); - - // Right face - normal(0, 1, 0); - vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); - vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); - vertex(w + shiftX, h + shiftY, d + shiftZ); - vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); - - // Top face - normal(0, 0, 1); - vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); - vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); - vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); - vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ); - - // Bottom face - normal(0, 0, -1); - vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ); - vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); - vertex(w + shiftX, h + shiftY, d + shiftZ); - vertex(-w/2 + shiftX, h + shiftY, d + shiftZ); - endShape(); - } -} diff --git a/android/examples/OpenGL/Typography/KineticType/KineticType.pde b/android/examples/OpenGL/Typography/KineticType/KineticType.pde deleted file mode 100644 index e2f694dcd..000000000 --- a/android/examples/OpenGL/Typography/KineticType/KineticType.pde +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Kinetic Type - * by Zach Lieberman. - * - * Using push() and pop() to define the curves of the lines of type. - */ - -Line ln; -Line lns[]; - -String words[] = { - "sometimes it's like", "the lines of text", "are so happy", "that they want to dance", - "or leave the page or jump", "can you blame them?", "living on the page like that", - "waiting to be read..." -}; - -void setup() { - size(displayWidth, displayHeight, P3D); - orientation(LANDSCAPE); - - // Array of line objects - lns = new Line[8]; - - // Load the font from the sketch's data directory - textFont(loadFont("Univers-66.vlw"), 1.0); - - // White type - fill(255); - - // Creating the line objects - for(int i = 0; i < 8; i++) { - // For every line in the array, create a Line object to animate - // i * 70 is the spacing - ln = new Line(words[i], 0, i * 70); - lns[i] = ln; - } - - // To avoid letter occluding each other on the edges - hint(DISABLE_DEPTH_TEST); -} - -void draw() { - background(0); - - translate(-200, -50, -450); - rotateY(0.3); - - // Now animate every line object & draw it... - for(int i = 0; i < 8; i++) { - float f1 = sin((i + 1.0) * (millis() / 10000.0) * TWO_PI); - float f2 = sin((8.0 - i) * (millis() / 10000.0) * TWO_PI); - Line line = lns[i]; - pushMatrix(); - translate(0.0, line.yPosition, 0.0); - for(int j = 0; j < line.myLetters.length; j++) { - if(j != 0) { - translate(textWidth(line.myLetters[j - 1].myChar) * 75, 0.0, 0.0); - } - rotateY(f1 * 0.005 * f2); - pushMatrix(); - scale(75.0); - text(line.myLetters[j].myChar, 0.0, 0.0); - popMatrix(); - } - popMatrix(); - } -} - diff --git a/android/examples/OpenGL/Typography/KineticType/Letter.pde b/android/examples/OpenGL/Typography/KineticType/Letter.pde deleted file mode 100644 index d12a9a78d..000000000 --- a/android/examples/OpenGL/Typography/KineticType/Letter.pde +++ /dev/null @@ -1,13 +0,0 @@ -class Letter -{ - char myChar; - float x; - float y; - - Letter(char c, float f, float f1) - { - myChar = c; - x = f; - y = f1; - } -} diff --git a/android/examples/OpenGL/Typography/KineticType/Line.pde b/android/examples/OpenGL/Typography/KineticType/Line.pde deleted file mode 100644 index f01b9cdc8..000000000 --- a/android/examples/OpenGL/Typography/KineticType/Line.pde +++ /dev/null @@ -1,28 +0,0 @@ -class Line -{ - String myString; - int xPosition; - int yPosition; - int highlightNum; - float speed; - float curlInX; - Letter myLetters[]; - - Line(String s, int i, int j) - { - myString = s; - xPosition = i; - yPosition = j; - myLetters = new Letter[s.length()]; - float f1 = 0.0; - for(int k = 0; k < s.length(); k++) - { - char c = s.charAt(k); - f1 += textWidth(c); - Letter letter = new Letter(c, f1, 0.0); - myLetters[k] = letter; - } - - curlInX = 0.1; - } -} diff --git a/android/examples/OpenGL/Typography/KineticType/Word.pde b/android/examples/OpenGL/Typography/KineticType/Word.pde deleted file mode 100644 index 6bc2f2deb..000000000 --- a/android/examples/OpenGL/Typography/KineticType/Word.pde +++ /dev/null @@ -1,10 +0,0 @@ -class Word -{ - String myName; - int x; - - Word(String s) - { - myName = s; - } -} diff --git a/android/examples/OpenGL/Typography/KineticType/data/Univers-66.vlw b/android/examples/OpenGL/Typography/KineticType/data/Univers-66.vlw deleted file mode 100644 index d2d08c247..000000000 Binary files a/android/examples/OpenGL/Typography/KineticType/data/Univers-66.vlw and /dev/null differ diff --git a/android/examples/OpenGL/Typography/LetterK/LetterK.pde b/android/examples/OpenGL/Typography/LetterK/LetterK.pde deleted file mode 100644 index 4bed80077..000000000 --- a/android/examples/OpenGL/Typography/LetterK/LetterK.pde +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Letter K - * by Peter Cho. - * - * Move the mouse across the screen to fold the "K". - */ - -color backgroundColor; -color foregroundColor; -color foregroundColor2; - -float px, py; -float pfx, pfy; -float pv2, pvx, pvy; -float pa2, pax, pay; -float pMass, pDrag; - -void setup() { - size(640, 360, P3D); - orientation(LANDSCAPE); - noStroke(); - backgroundColor = color(134, 144, 154); - foregroundColor = color(235, 235, 30); - foregroundColor2 = color(240, 130, 20); - initParticle(0.6, 0.9, width/2, height/2); -} - -void draw() { - background(backgroundColor); - pushMatrix(); - - iterateParticle(0.15*(-px+mouseX), 0.15*(-py+(height-mouseY))); - - translate(width/2, height/2, 0); - fill(foregroundColor); - drawK(); - - pushMatrix(); - translate(0, 0, 1); - translate(0.75 * (px-width/2), -0.75 * (py-height/2), 0); - translate(0.75 * (px-width/2), -0.75 * (py-height/2), 0); - rotateZ(atan2(-(py-height/2), (px-width/2)) + PI/2); - rotateX(PI); - rotateZ(-(atan2(-(py-height/2), (px-width/2)) + PI/2)); - - fill(foregroundColor2); - drawK(); - popMatrix(); - - translate(0.75 * (px-width/2), -0.75 * (py-height/2), 2); - rotateZ(atan2(-(py-height/2), (px-width/2)) + PI/2); - - fill(backgroundColor); - beginShape(QUADS); - vertex(-640, 0); - vertex( 640, 0); - vertex( 640, -360); - vertex(-640, -360); - endShape(); - - popMatrix(); - -} - -void initParticle(float _mass, float _drag, float ox, float oy) { - px = ox; - py = oy; - pv2 = 0.0; - pvx = 0.0; - pvy = 0.0; - pa2 = 0.0; - pax = 0.0; - pay = 0.0; - pMass = _mass; - pDrag = _drag; -} - -void iterateParticle(float fkx, float fky) { - // iterate for a single force acting on the particle - pfx = fkx; - pfy = fky; - pa2 = pfx*pfx + pfy*pfy; - if (pa2 < 0.0000001) { - return; - } - pax = pfx/pMass; - pay = pfy/pMass; - pvx += pax; - pvy += pay; - pv2 = pvx*pvx + pvy*pvy; - if (pv2 < 0.0000001) { - return; - } - pvx *= (1.0 - pDrag); - pvy *= (1.0 - pDrag); - px += pvx; - py += pvy; -} - -void drawK() { - pushMatrix(); - - scale(1.5); - translate(-63, 71); - beginShape(QUADS); - vertex(0, 0, 0); - vertex(0, -142.7979, 0); - vertex(37.1992, -142.7979, 0); - vertex(37.1992, 0, 0); - - vertex(37.1992, -87.9990, 0); - vertex(84.1987, -142.7979, 0); - vertex(130.3979, -142.7979, 0); - vertex(37.1992, -43.999, 0); - - vertex(77.5986-.2, -86.5986-.3, 0); - vertex(136.998, 0, 0); - vertex(90.7988, 0, 0); - vertex(52.3994-.2, -59.999-.3, 0); - endShape(); - //translate(63, -71); - popMatrix(); -} - - - diff --git a/android/examples/OpenGL/Typography/Typing/Typing.pde b/android/examples/OpenGL/Typography/Typing/Typing.pde deleted file mode 100644 index 6204faac2..000000000 --- a/android/examples/OpenGL/Typography/Typing/Typing.pde +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Typing (Excerpt from the piece Textension) - * by Josh Nimoy. - * - * Click in the window to give it focus. - * Type to add letters and press backspace or delete to remove them. - */ - - -int leftmargin = 10; -int rightmargin = 20; -String buff = ""; -boolean didntTypeYet = true; - -void setup() -{ - size(displayWidth, displayHeight, P3D); - orientation(LANDSCAPE); - textFont(loadFont("Univers45.vlw"), 25); -} - -void draw() -{ - background(176); - - if((millis() % 500) < 250){ // Only fill cursor half the time - noFill(); - } - else { - fill(255); - stroke(0); - } - float rPos; - // Store the cursor rectangle's position - rPos = textWidth(buff) + leftmargin; - rect(rPos+1, 19, 10, 21); - - // Some instructions at first - if(didntTypeYet) { - fill(0); - //text("Use the keyboard.", 22, 40); - } - - fill(0); - pushMatrix(); - translate(rPos,10+25); - char k; - for(int i = 0;i < buff.length(); i++) { - k = buff.charAt(i); - translate(-textWidth(k),0); - rotateY(-textWidth(k)/70.0); - rotateX(textWidth(k)/70.0); - scale(1.1); - text(k,0,0); - } - popMatrix(); -} - -void keyPressed() -{ - char k; - k = (char)key; - switch(k){ - case 8: - if(buff.length()>0){ - buff = buff.substring(1); - } - break; - case 13: // Avoid special keys - case 10: - case 65535: - case 127: - case 27: - break; - default: - if(textWidth(buff+k)+leftmargin < width-rightmargin){ - didntTypeYet = false; - buff=k+buff; - } - break; - } -} - diff --git a/android/examples/OpenGL/Typography/Typing/data/Univers45.vlw b/android/examples/OpenGL/Typography/Typing/data/Univers45.vlw deleted file mode 100644 index 040e02170..000000000 Binary files a/android/examples/OpenGL/Typography/Typing/data/Univers45.vlw and /dev/null differ diff --git a/android/examples/Topics/Create Shapes/BeginEndContour/BeginEndContour.pde b/android/examples/Topics/Create Shapes/BeginEndContour/BeginEndContour.pde new file mode 100644 index 000000000..71a2b5801 --- /dev/null +++ b/android/examples/Topics/Create Shapes/BeginEndContour/BeginEndContour.pde @@ -0,0 +1,48 @@ +/** + * BeginEndContour + * + * How to cut a shape out of another using beginContour() and endContour() + */ + +PShape s; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + smooth(); + // Make a shape + s = createShape(); + s.fill(0); + s.stroke(255); + s.strokeWeight(2); + // Exterior part of shape + s.beginContour(); + s.vertex(-100,-100); + s.vertex(100,-100); + s.vertex(100,100); + s.vertex(-100,100); + s.vertex(-100,-100); + s.endContour(); + + // Interior part of shape + s.beginContour(); + s.vertex(-10,-10); + s.vertex(10,-10); + s.vertex(10,10); + s.vertex(-10,10); + s.vertex(-10,-10); + s.endContour(); + + // Finishing off shape + s.end(); +} + +void draw() { + background(52); + // Display shape + translate(width/2, height/2); + // Shapes can be rotated + s.rotate(0.01); + shape(s); +} + diff --git a/android/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde b/android/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde new file mode 100644 index 000000000..aa9133564 --- /dev/null +++ b/android/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde @@ -0,0 +1,69 @@ +/** + * GroupPShape + * + * How to group multiple PShapes into one PShape + */ + + +// A PShape that will group PShapes +PShape group; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + smooth(); + // Create the shape as a group + group = createShape(GROUP); + + // Make a polygon PShape + PShape star = createShape(); + star.noFill(); + star.stroke(255); + star.vertex(0, -50); + star.vertex(14, -20); + star.vertex(47, -15); + star.vertex(23, 7); + star.vertex(29, 40); + star.vertex(0, 25); + star.vertex(-29, 40); + star.vertex(-23, 7); + star.vertex(-47, -15); + star.vertex(-14, -20); + star.end(CLOSE); + + // Make a path PShape + PShape path = createShape(); + path = createShape(); + path.noFill(); + path.stroke(255); + for (float a = -PI; a < 0; a += 0.1) { + float r = random(60, 70); + path.vertex(r*cos(a), r*sin(a)); + } + path.end(); + + // Make a primitive (Rectangle) PShape + PShape rectangle = createShape(RECT,-10,-10,20,20); + rectangle.noFill(); + rectangle.stroke(255); + + // Add them all to the group + group.addChild(star); + group.addChild(path); + group.addChild(rectangle); // Rectangle is missing??? + +} + +void draw() { + + // We can access them individually via the group PShape + PShape rectangle = group.getChild(2); + // Shapes can be rotated + rectangle.rotate(0.1); + + background(52); + // Display the group PShape + translate(mouseX, mouseY); + shape(group); +} + diff --git a/android/examples/Topics/Create Shapes/ParticleSystemPShape/Particle.pde b/android/examples/Topics/Create Shapes/ParticleSystemPShape/Particle.pde new file mode 100644 index 000000000..6034e52bb --- /dev/null +++ b/android/examples/Topics/Create Shapes/ParticleSystemPShape/Particle.pde @@ -0,0 +1,81 @@ +// An individual Particle + +class Particle { + + // Velocity + PVector center; + PVector velocity; + // Lifespane is tied to alpha + float lifespan; + + // The particle PShape + PShape part; + // The particle size + float partSize; + + // A single force + PVector gravity = new PVector(0, 0.1); + + Particle() { + partSize = random(10, 60); + // The particle is a textured quad + part = createShape(QUAD); + part.noStroke(); + part.texture(sprite); + part.normal(0, 0, 1); + part.vertex(-partSize/2, -partSize/2, 0, 0); + part.vertex(+partSize/2, -partSize/2, sprite.width, 0); + part.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height); + part.vertex(-partSize/2, +partSize/2, 0, sprite.height); + part.end(); + + // Initialize center vector + center = new PVector(); + + // Set the particle starting location + rebirth(width/2, height/2); + } + + PShape getShape() { + return part; + } + + void rebirth(float x, float y) { + float a = random(TWO_PI); + float speed = random(0.5, 4); + // A velocity with random angle and magnitude + velocity = PVector.fromAngle(a); + velocity.mult(speed); + // Set lifespan + lifespan = 255; + // Set location using translate + part.resetMatrix(); + part.translate(x, y); + + // Update center vector + center.set(x, y, 0); + } + + // Is it off the screen, or its lifespan is over? + boolean isDead() { + if (center.x > width || center.x < 0 || + center.y > height || center.y < 0 || lifespan < 0) { + return true; + } + else { + return false; + } + } + + void update() { + // Decrease life + lifespan = lifespan - 1; + // Apply gravity + velocity.add(gravity); + part.tint(255, lifespan); + // Move the particle according to its velocity + part.translate(velocity.x, velocity.y); + // and also update the center + center.add(velocity); + } +} diff --git a/android/examples/Topics/Create Shapes/ParticleSystemPShape/ParticleSystem.pde b/android/examples/Topics/Create Shapes/ParticleSystemPShape/ParticleSystem.pde new file mode 100644 index 000000000..e2215046e --- /dev/null +++ b/android/examples/Topics/Create Shapes/ParticleSystemPShape/ParticleSystem.pde @@ -0,0 +1,43 @@ +// The Particle System + +class ParticleSystem { + // It's just an ArrayList of particle objects + ArrayList particles; + + // The PShape to group all the particle PShapes + PShape particleShape; + + ParticleSystem(int n) { + particles = new ArrayList(); + // The PShape is a group + particleShape = createShape(GROUP); + + // Make all the Particles + for (int i = 0; i < n; i++) { + Particle p = new Particle(); + particles.add(p); + // Each particle's PShape gets added to the System PShape + particleShape.addChild(p.getShape()); + } + } + + void update() { + for (Particle p : particles) { + p.update(); + } + } + + void setEmitter(float x, float y) { + for (Particle p : particles) { + // Each particle gets reborn at the emitter location + if (p.isDead()) { + p.rebirth(x, y); + } + } + } + + void display() { + shape(particleShape); + } +} + diff --git a/android/examples/Topics/Create Shapes/ParticleSystemPShape/ParticleSystemPShape.pde b/android/examples/Topics/Create Shapes/ParticleSystemPShape/ParticleSystemPShape.pde new file mode 100644 index 000000000..a9a30d0f5 --- /dev/null +++ b/android/examples/Topics/Create Shapes/ParticleSystemPShape/ParticleSystemPShape.pde @@ -0,0 +1,42 @@ +/** + * ParticleSystemPShape + * + * A particle system optimized for drawing using PShape + */ + +// Particle System object +ParticleSystem ps; +// A PImage for particle's texture +PImage sprite; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + // Load the image + sprite = loadImage("sprite.png"); + // A new particle system with 1,000 particles + ps = new ParticleSystem(1000); + + // Writing to the depth buffer is disabled to avoid rendering + // artifacts due to the fact that the particles are semi-transparent + // but not z-sorted. + hint(DISABLE_DEPTH_MASK); + +} + +void draw () { + background(0); + // Update and display system + ps.update(); + ps.display(); + + // Set the particle system's emitter location to the mouse + ps.setEmitter(mouseX,mouseY); + + // Display frame rate + fill(255); + textSize(16); + text("Frame rate: " + int(frameRate),10,20); + +} + diff --git a/android/examples/Topics/Create Shapes/PathPShape/PathPShape.pde b/android/examples/Topics/Create Shapes/PathPShape/PathPShape.pde new file mode 100644 index 000000000..becab8e4c --- /dev/null +++ b/android/examples/Topics/Create Shapes/PathPShape/PathPShape.pde @@ -0,0 +1,37 @@ +/** + * PathPShape + * + * A simple path using PShape + */ + +// A PShape object +PShape path; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + // Create the shape + path = createShape(); + // Set fill and stroke + path.noFill(); + path.stroke(255); + path.strokeWeight(2); + + float x = 0; + // Calculate the path as a sine wave + for (float a = 0; a < TWO_PI; a+=0.1) { + path.vertex(x,sin(a)*100); + x+= 5; + } + // The path is complete + path.end(); + +} + +void draw() { + background(51); + // Draw the path at the mouse location + translate(mouseX, mouseY); + shape(path); +} + diff --git a/android/examples/Topics/Create Shapes/PolygonPShape/PolygonPShape.pde b/android/examples/Topics/Create Shapes/PolygonPShape/PolygonPShape.pde new file mode 100644 index 000000000..c4c67340f --- /dev/null +++ b/android/examples/Topics/Create Shapes/PolygonPShape/PolygonPShape.pde @@ -0,0 +1,41 @@ + +/** + * PrimitivePShape. + * + * Using a PShape to display a custom polygon. + */ + +// The PShape object +PShape star; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + // First create the shape + star = createShape(); + // You can set fill and stroke + star.fill(102); + star.stroke(255); + star.strokeWeight(2); + // Here, we are hardcoding a series of vertices + star.vertex(0, -50); + star.vertex(14, -20); + star.vertex(47, -15); + star.vertex(23, 7); + star.vertex(29, 40); + star.vertex(0, 25); + star.vertex(-29, 40); + star.vertex(-23, 7); + star.vertex(-47, -15); + star.vertex(-14, -20); + star.end(CLOSE); +} + +void draw() { + background(51); + // We can use translate to move the PShape + translate(mouseX, mouseY); + // Display the shape + shape(star); +} + diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP/PolygonPShapeOOP.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP/PolygonPShapeOOP.pde new file mode 100644 index 000000000..e20dd90fd --- /dev/null +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP/PolygonPShapeOOP.pde @@ -0,0 +1,26 @@ +/** + * PolygonPShapeOOP. + * + * Wrapping a PShape inside a custom class + */ + + +// A Star object +Star s; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + // Make a new Star + s = new Star(); + +} + +void draw() { + background(51); + // Display the star + s.display(); + // Move the star + s.move(); +} + diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP/Star.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP/Star.pde new file mode 100644 index 000000000..9899910d1 --- /dev/null +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP/Star.pde @@ -0,0 +1,50 @@ +// A class to describe a Star shape + +class Star { + + // The PShape object + PShape s; + // The location where we will draw the shape + float x, y; + + Star() { + x = 0; + y = height/2; + // First create the shape + s = createShape(); + // You can set fill and stroke + s.fill(102); + s.stroke(255); + s.strokeWeight(2); + // Here, we are hardcoding a series of vertices + s.vertex(0, -50); + s.vertex(14, -20); + s.vertex(47, -15); + s.vertex(23, 7); + s.vertex(29, 40); + s.vertex(0, 25); + s.vertex(-29, 40); + s.vertex(-23, 7); + s.vertex(-47, -15); + s.vertex(-14, -20); + // The shape is complete + s.end(CLOSE); + } + + void move() { + // Demonstrating some simple motion + x++; + if (x > width+100) { + x = -100; + } + } + + void display() { + // Locating and drawing the shape + pushMatrix(); + translate(x, y); + shape(s); + popMatrix(); + } +} + diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/Polygon.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/Polygon.pde new file mode 100644 index 000000000..e775fb436 --- /dev/null +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/Polygon.pde @@ -0,0 +1,34 @@ +// A class to describe a Polygon (with a PShape) + +class Polygon { + // The PShape object + PShape s; + // The location where we will draw the shape + float x, y; + // Variable for simple motion + float speed; + + Polygon(PShape s_) { + x = random(width); + y = random(-500, -100); + s = s_; + speed = random(2, 6); + } + + // Simple motion + void move() { + y+=speed; + if (y > height+100) { + y = -100; + } + } + + // Draw the object + void display() { + pushMatrix(); + translate(x, y); + shape(s); + popMatrix(); + } +} + diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/PolygonPShapeOOP2.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/PolygonPShapeOOP2.pde new file mode 100644 index 000000000..6d8cb7ed5 --- /dev/null +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/PolygonPShapeOOP2.pde @@ -0,0 +1,52 @@ +/** + * PolygonPShapeOOP. + * + * Wrapping a PShape inside a custom class + * and demonstrating how we can have a multiple objects each + * using the same PShape. + */ + + +// A list of objects +ArrayList polygons; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + // Make a PShape + PShape star = createShape(); + star.fill(0,127); + star.stroke(0); + star.vertex(0, -50); + star.vertex(14, -20); + star.vertex(47, -15); + star.vertex(23, 7); + star.vertex(29, 40); + star.vertex(0, 25); + star.vertex(-29, 40); + star.vertex(-23, 7); + star.vertex(-47, -15); + star.vertex(-14, -20); + star.end(CLOSE); + + // Make an ArrayList + polygons = new ArrayList(); + + // Add a bunch of objects to the ArrayList + // Pass in reference to the PShape + // We coud make polygons with different PShapes + for (int i = 0; i < 25; i++) { + polygons.add(new Polygon(star)); + } +} + +void draw() { + background(255); + + // Display and move them all + for (Polygon poly : polygons) { + poly.display(); + poly.move(); + } +} + diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/Polygon.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/Polygon.pde new file mode 100644 index 000000000..e775fb436 --- /dev/null +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/Polygon.pde @@ -0,0 +1,34 @@ +// A class to describe a Polygon (with a PShape) + +class Polygon { + // The PShape object + PShape s; + // The location where we will draw the shape + float x, y; + // Variable for simple motion + float speed; + + Polygon(PShape s_) { + x = random(width); + y = random(-500, -100); + s = s_; + speed = random(2, 6); + } + + // Simple motion + void move() { + y+=speed; + if (y > height+100) { + y = -100; + } + } + + // Draw the object + void display() { + pushMatrix(); + translate(x, y); + shape(s); + popMatrix(); + } +} + diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/PolygonPShapeOOP3.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/PolygonPShapeOOP3.pde new file mode 100644 index 000000000..7a5c87bb3 --- /dev/null +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/PolygonPShapeOOP3.pde @@ -0,0 +1,63 @@ +/** + * PolygonPShapeOOP. + * + * Wrapping a PShape inside a custom class + * and demonstrating how we can have a multiple objects each + * using the same PShape. + */ + + +// A list of objects +ArrayList polygons; + +// Three possible shapes +PShape[] shapes = new PShape[3]; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + + shapes[0] = createShape(ELLIPSE,0,0,100,100); + shapes[0].fill(255,127); + shapes[0].stroke(0); + shapes[1] = createShape(RECT,0,0,100,100); + shapes[1].fill(255,127); + shapes[1].stroke(0); + shapes[2] = createShape(); + shapes[2].fill(0,127); + shapes[2].stroke(0); + shapes[2].vertex(0, -50); + shapes[2].vertex(14, -20); + shapes[2].vertex(47, -15); + shapes[2].vertex(23, 7); + shapes[2].vertex(29, 40); + shapes[2].vertex(0, 25); + shapes[2].vertex(-29, 40); + shapes[2].vertex(-23, 7); + shapes[2].vertex(-47, -15); + shapes[2].vertex(-14, -20); + shapes[2].end(CLOSE); + + + // Make an ArrayList + polygons = new ArrayList(); + + polygons = new ArrayList(); + + for (int i = 0; i < 25; i++) { + int selection = int(random(shapes.length)); // Pick a random index + Polygon p = new Polygon(shapes[selection]); // Use corresponding PShape to create Polygon + polygons.add(p); + } +} + +void draw() { + background(51); + + // Display and move them all + for (Polygon poly : polygons) { + poly.display(); + poly.move(); + } +} + diff --git a/android/examples/Topics/Create Shapes/PrimitivePShape/PrimitivePShape.pde b/android/examples/Topics/Create Shapes/PrimitivePShape/PrimitivePShape.pde new file mode 100644 index 000000000..c0b3f6091 --- /dev/null +++ b/android/examples/Topics/Create Shapes/PrimitivePShape/PrimitivePShape.pde @@ -0,0 +1,30 @@ +/** + * PrimitivePShape. + * + * Using a PShape to display a primitive shape (in this case, ellipse). + */ + + +// The PShape object +PShape circle; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + // Creating the PShape as an ellipse + // The corner is -50,-50 so that the center is at 0,0 + circle = createShape(RECT, -50, -25, 100, 50); +} + +void draw() { + background(51); + // We can dynamically set the stroke and fill of the shape + circle.stroke(255); + circle.strokeWeight(4); + circle.fill(map(mouseX, 0, width, 0, 255)); + // We can use translate to move the PShape + translate(mouseX, mouseY); + // Drawing the PShape + shape(circle); +} + diff --git a/android/examples/Topics/Create Shapes/WigglePShape/WigglePShape.pde b/android/examples/Topics/Create Shapes/WigglePShape/WigglePShape.pde new file mode 100644 index 000000000..7a2cc9f47 --- /dev/null +++ b/android/examples/Topics/Create Shapes/WigglePShape/WigglePShape.pde @@ -0,0 +1,23 @@ +/** + * WigglePShape. + * + * How to move the individual vertices of a PShape + */ + + +// A "Wiggler" object +Wiggler w; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + w = new Wiggler(); +} + +void draw() { + background(255); + w.display(); + w.wiggle(); +} + + diff --git a/android/examples/Topics/Create Shapes/WigglePShape/Wiggler.pde b/android/examples/Topics/Create Shapes/WigglePShape/Wiggler.pde new file mode 100644 index 000000000..bb601dccd --- /dev/null +++ b/android/examples/Topics/Create Shapes/WigglePShape/Wiggler.pde @@ -0,0 +1,66 @@ +// An object that wraps the PShape + +class Wiggler { + + // The PShape to be "wiggled" + PShape s; + // Its location + float x, y; + + // For 2D Perlin noise + float yoff = 0; + + // We are using an ArrayList to keep a duplicate copy + // of vertices original locations. + ArrayList original; + + Wiggler() { + x = width/2; + y = height/2; + + // The "original" locations of the vertices make up a circle + original = new ArrayList(); + for (float a = 0; a < TWO_PI; a+=0.2) { + PVector v = PVector.fromAngle(a); + v.mult(100); + original.add(v); + } + + // Now make the PShape with those vertices + s = createShape(); + s.fill(127); + s.stroke(0); + s.strokeWeight(2); + for (PVector v : original) { + s.vertex(v.x, v.y); + } + s.end(CLOSE); + } + + void wiggle() { + float xoff = 0; + // Apply an offset to each vertex + for (int i = 0; i < s.getVertexCount(); i++) { + // Calculate a new vertex location based on noise around "original" location + PVector pos = original.get(i); + float a = TWO_PI*noise(xoff,yoff); + PVector r = PVector.fromAngle(a); + r.mult(4); + r.add(pos); + // Set the location of each vertex to the new one + s.setVertex(i, r.x, r.y); + // increment perlin noise x value + xoff+= 0.5; + } + // Increment perlin noise y value + yoff += 0.02; + } + + void display() { + pushMatrix(); + translate(x, y); + shape(s); + popMatrix(); + } +} + diff --git a/android/examples/OpenGL/Form/Icosahedra/Dimension3D.pde b/android/examples/Topics/Geometry/Icosahedra/Dimension3D.pde similarity index 100% rename from android/examples/OpenGL/Form/Icosahedra/Dimension3D.pde rename to android/examples/Topics/Geometry/Icosahedra/Dimension3D.pde diff --git a/android/examples/OpenGL/Form/Icosahedra/Icosahedra.pde b/android/examples/Topics/Geometry/Icosahedra/Icosahedra.pde similarity index 99% rename from android/examples/OpenGL/Form/Icosahedra/Icosahedra.pde rename to android/examples/Topics/Geometry/Icosahedra/Icosahedra.pde index 94df9e73b..8d318c7ce 100644 --- a/android/examples/OpenGL/Form/Icosahedra/Icosahedra.pde +++ b/android/examples/Topics/Geometry/Icosahedra/Icosahedra.pde @@ -50,4 +50,4 @@ void draw(){ popMatrix(); } - + diff --git a/android/examples/OpenGL/Form/Icosahedra/Icosahedron.pde b/android/examples/Topics/Geometry/Icosahedra/Icosahedron.pde similarity index 100% rename from android/examples/OpenGL/Form/Icosahedra/Icosahedron.pde rename to android/examples/Topics/Geometry/Icosahedra/Icosahedron.pde diff --git a/android/examples/OpenGL/Form/Icosahedra/Shape3D.pde b/android/examples/Topics/Geometry/Icosahedra/Shape3D.pde similarity index 100% rename from android/examples/OpenGL/Form/Icosahedra/Shape3D.pde rename to android/examples/Topics/Geometry/Icosahedra/Shape3D.pde diff --git a/android/examples/Topics/Geometry/NoiseSphere/NoiseSphere.pde b/android/examples/Topics/Geometry/NoiseSphere/NoiseSphere.pde new file mode 100644 index 000000000..9c4e138f3 --- /dev/null +++ b/android/examples/Topics/Geometry/NoiseSphere/NoiseSphere.pde @@ -0,0 +1,83 @@ +/** + * Noise Sphere + * by David Pena. + * + * Uniform random distribution on the surface of a sphere. + */ + +int cuantos = 1000; +Pelo[] lista ; +float[] z = new float[cuantos]; +float[] phi = new float[cuantos]; +float[] largos = new float[cuantos]; +float radio; +float rx = 0; +float ry =0; + +void setup() { + size(displayWidth, displayHeight, P3D); + orientation(LANDSCAPE); + radio = height/3; + lista = new Pelo[cuantos]; + for (int i=0; i - * Up Arrow - increases points
- * Down Arrow - decreases points
- * 'p' key toggles between cube/pyramid
+ * tap rigth side of screen - increases points
+ * tap left side of screen - decreases points
+ * tap screen center toggles between cube/pyramid
*/ int pts = 4; @@ -24,7 +24,7 @@ boolean isPyramid = false; float angleInc; void setup(){ - size(640, 360, P3D); + size(displayWidth, displayHeight, P3D); orientation(LANDSCAPE); noStroke(); angleInc = PI/300.0; @@ -88,30 +88,25 @@ void draw(){ /* - up/down arrow keys control - polygon detail. + tapping controls polygon detail. */ -void keyPressed(){ - if(key == CODED) { - // pts - if (keyCode == UP) { - if (pts < 90){ - pts++; - } - } - else if (keyCode == DOWN) { - if (pts > 4){ - pts--; - } - } - } - if (key =='p'){ +void mousePressed(){ + if (abs(mouseX - width/2) < 50 && + abs(mouseY - height/2) < 50) { if (isPyramid){ isPyramid = false; } else { isPyramid = true; - } + } + } else if (mouseX < width/2) { + if (pts > 4){ + pts--; + } + } else if (mouseX > width/2) { + if (pts < 90){ + pts++; + } } } - + diff --git a/android/examples/OpenGL/Form/SpaceJunk/Cube.pde b/android/examples/Topics/Geometry/SpaceJunk/Cube.pde similarity index 91% rename from android/examples/OpenGL/Form/SpaceJunk/Cube.pde rename to android/examples/Topics/Geometry/SpaceJunk/Cube.pde index 168ceb5ca..121b33f9b 100644 --- a/android/examples/OpenGL/Form/SpaceJunk/Cube.pde +++ b/android/examples/Topics/Geometry/SpaceJunk/Cube.pde @@ -22,46 +22,40 @@ class Cube { void drawCube(){ beginShape(QUADS); // Front face - normal(0, 0, 1); vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ); // Back face - normal(0, 0, -1); vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ); vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); vertex(w + shiftX, h + shiftY, d + shiftZ); vertex(-w/2 + shiftX, h + shiftY, d + shiftZ); // Left face - normal(1, 0, 0); vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ); vertex(-w/2 + shiftX, h + shiftY, d + shiftZ); vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ); // Right face - normal(-1, 0, 0); vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); vertex(w + shiftX, h + shiftY, d + shiftZ); vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); // Top face - normal(0, 1, 0); vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ); // Bottom face - normal(0, -1, 0); vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ); vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); vertex(w + shiftX, h + shiftY, d + shiftZ); - vertex(-w/2 + shiftX, h + shiftY, d + shiftZ); + vertex(-w/2 + shiftX, h + shiftY, d + shiftZ); endShape(); diff --git a/android/examples/OpenGL/Form/SpaceJunk/SpaceJunk.pde b/android/examples/Topics/Geometry/SpaceJunk/SpaceJunk.pde similarity index 81% rename from android/examples/OpenGL/Form/SpaceJunk/SpaceJunk.pde rename to android/examples/Topics/Geometry/SpaceJunk/SpaceJunk.pde index af59af02a..6d8bd944d 100644 --- a/android/examples/OpenGL/Form/SpaceJunk/SpaceJunk.pde +++ b/android/examples/Topics/Geometry/SpaceJunk/SpaceJunk.pde @@ -1,8 +1,6 @@ /** * Space Junk - * by Ira Greenberg. - * Zoom suggestion - * by Danny Greenberg. + * by Ira Greenberg (zoom suggestion by Danny Greenberg). * * Rotating cubes in space using a custom Cube class. * Color controlled by light sources. Move the mouse left @@ -12,7 +10,7 @@ // Used for oveall rotation float ang; -// Cube count-lower/raise to test P3D/OPENGL performance +// Cube count-lower/raise to test performance int limit = 100; // Array for all cubes @@ -26,8 +24,8 @@ void setup() { // Instantiate cubes, passing in random vals for size and postion for (int i = 0; i< cubes.length; i++){ cubes[i] = new Cube(int(random(-10, 10)), int(random(-10, 10)), - int(random(-10, 10)), int(random(-140, 140)), int(random(-140, 140)), - int(random(-140, 140))); + int(random(-10, 10)), int(random(-140, 140)), + int(random(-140, 140)), int(random(-140, 140))); } } @@ -57,7 +55,7 @@ void draw(){ } // Used in rotate function calls above - ang++; + ang += 0.2; } - + diff --git a/android/examples/OpenGL/Form/Toroid/Toroid.pde b/android/examples/Topics/Geometry/Toroid/Toroid.pde similarity index 95% rename from android/examples/OpenGL/Form/Toroid/Toroid.pde rename to android/examples/Topics/Geometry/Toroid/Toroid.pde index 776a9cf05..a085e8159 100644 --- a/android/examples/OpenGL/Form/Toroid/Toroid.pde +++ b/android/examples/Topics/Geometry/Toroid/Toroid.pde @@ -1,6 +1,3 @@ -// Strange "lights flashing" effect, particularly noticeable at low res (pts=10, segments=20) -// ...some problem with the automatic normal calculation maybe? - /** * Interactive Toroid * by Ira Greenberg. @@ -183,4 +180,4 @@ void keyPressed(){ } } } - + diff --git a/android/examples/OpenGL/Form/Vertices/Vertices.pde b/android/examples/Topics/Geometry/Vertices/Vertices.pde similarity index 99% rename from android/examples/OpenGL/Form/Vertices/Vertices.pde rename to android/examples/Topics/Geometry/Vertices/Vertices.pde index 3d1fa1860..4aae8eb51 100644 --- a/android/examples/OpenGL/Form/Vertices/Vertices.pde +++ b/android/examples/Topics/Geometry/Vertices/Vertices.pde @@ -65,4 +65,4 @@ void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) { } endShape(); } -} +} diff --git a/android/examples/Topics/Shaders/BlurFilter/BlurFilter.pde b/android/examples/Topics/Shaders/BlurFilter/BlurFilter.pde new file mode 100644 index 000000000..67b2e6ca0 --- /dev/null +++ b/android/examples/Topics/Shaders/BlurFilter/BlurFilter.pde @@ -0,0 +1,26 @@ +/** + * Blur Filter + * + * Change the default shader to apply a simple, custom blur filter. + * + * Press the mouse to switch between the custom and default shader. + */ + +PShader blur; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + blur = loadShader("blur.glsl"); + stroke(255, 0, 0); + rectMode(CENTER); +} + +void draw() { + filter(blur); + rect(mouseX, mouseY, 150, 150); + ellipse(mouseX, mouseY, 100, 100); +} + + + diff --git a/android/examples/OpenGL/Shaders/BlurFilter/data/blur.glsl b/android/examples/Topics/Shaders/BlurFilter/data/blur.glsl similarity index 100% rename from android/examples/OpenGL/Shaders/BlurFilter/data/blur.glsl rename to android/examples/Topics/Shaders/BlurFilter/data/blur.glsl diff --git a/android/examples/Topics/Shaders/EdgeDetect/EdgeDetect.pde b/android/examples/Topics/Shaders/EdgeDetect/EdgeDetect.pde new file mode 100644 index 000000000..aa3bd2695 --- /dev/null +++ b/android/examples/Topics/Shaders/EdgeDetect/EdgeDetect.pde @@ -0,0 +1,32 @@ +/** + * Edge Detection + * + * Change the default shader to apply a simple, custom edge detection filter. + * + * Press the mouse to switch between the custom and default shader. + */ + +PShader edges; +PImage img; +boolean enabled = true; + +void setup() { + size(640, 360, P2D); + orientation(LANDSCAPE); + img = loadImage("leaves.jpg"); + edges = loadShader("edges.glsl"); +} + +void draw() { + if (enabled == true) { + shader(edges); + } + image(img, 0, 0); +} + +void mousePressed() { + enabled = !enabled; + if (!enabled == true) { + resetShader(); + } +} diff --git a/android/examples/OpenGL/Shaders/EdgeFilter/data/edges.glsl b/android/examples/Topics/Shaders/EdgeDetect/data/edges.glsl similarity index 100% rename from android/examples/OpenGL/Shaders/EdgeFilter/data/edges.glsl rename to android/examples/Topics/Shaders/EdgeDetect/data/edges.glsl diff --git a/android/examples/OpenGL/Shaders/EdgeFilter/EdgeFilter.pde b/android/examples/Topics/Shaders/EdgeFilter/EdgeFilter.pde similarity index 64% rename from android/examples/OpenGL/Shaders/EdgeFilter/EdgeFilter.pde rename to android/examples/Topics/Shaders/EdgeFilter/EdgeFilter.pde index 8556b9bd2..c740f003d 100644 --- a/android/examples/OpenGL/Shaders/EdgeFilter/EdgeFilter.pde +++ b/android/examples/Topics/Shaders/EdgeFilter/EdgeFilter.pde @@ -1,8 +1,17 @@ +/** + * Edge Filter + * + * Apply a custom shader to the filter() function to affect the geometry drawn to the screen. + * + * Press the mouse to turn the filter on and off. + */ + PShader edges; boolean applyFilter = true; void setup() { - size(400, 400, P3D); + size(640, 360, P3D); + orientation(LANDSCAPE); edges = loadShader("edges.glsl"); noStroke(); } @@ -15,11 +24,13 @@ void draw() { pushMatrix(); rotateX(frameCount * 0.01); rotateY(frameCount * 0.01); - box(100); + box(120); popMatrix(); - if (applyFilter) filter(edges); - + if (applyFilter == true) { + filter(edges); + } + // The sphere doesn't have the edge detection applied // on it because it is drawn after filter() is called. rotateY(frameCount * 0.02); @@ -29,4 +40,4 @@ void draw() { void mousePressed() { applyFilter = !applyFilter; -} +} diff --git a/android/examples/Topics/Shaders/EdgeFilter/data/edges.glsl b/android/examples/Topics/Shaders/EdgeFilter/data/edges.glsl new file mode 100644 index 000000000..b032743d0 --- /dev/null +++ b/android/examples/Topics/Shaders/EdgeFilter/data/edges.glsl @@ -0,0 +1,48 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif + +uniform sampler2D textureSampler; +uniform vec2 texcoordOffset; + +varying vec4 vertColor; +varying vec4 vertTexcoord; + +#define KERNEL_SIZE 9 + +// Edge detection kernel +// -1 -1 -1 +// -1 +8 -1 +// -1 -1 -1 +float kernel[KERNEL_SIZE]; + +vec2 offset[KERNEL_SIZE]; + +void main(void) { + int i = 0; + vec4 sum = vec4(0.0); + + offset[0] = vec2(-texcoordOffset.s, -texcoordOffset.t); + offset[1] = vec2(0.0, -texcoordOffset.t); + offset[2] = vec2(texcoordOffset.s, -texcoordOffset.t); + + offset[3] = vec2(-texcoordOffset.s, 0.0); + offset[4] = vec2(0.0, 0.0); + offset[5] = vec2(texcoordOffset.s, 0.0); + + offset[6] = vec2(-texcoordOffset.s, texcoordOffset.t); + offset[7] = vec2(0.0, texcoordOffset.t); + offset[8] = vec2(texcoordOffset.s, texcoordOffset.t); + + kernel[0] = -1.0; kernel[1] = -1.0; kernel[2] = -1.0; + kernel[3] = -1.0; kernel[4] = 8.0; kernel[5] = -1.0; + kernel[6] = -1.0; kernel[7] = -1.0; kernel[8] = -1.0; + + for(i = 0; i < KERNEL_SIZE; i++) { + vec4 tmp = texture2D(textureSampler, vertTexcoord.st + offset[i]); + sum += tmp * kernel[i]; + } + + gl_FragColor = vec4(sum.rgb, 1.0) * vertColor; +} diff --git a/android/examples/OpenGL/Shaders/LowLevelGL/LowLevelGL.pde b/android/examples/Topics/Shaders/LowLevelGL/LowLevelGL.pde similarity index 62% rename from android/examples/OpenGL/Shaders/LowLevelGL/LowLevelGL.pde rename to android/examples/Topics/Shaders/LowLevelGL/LowLevelGL.pde index d046d6690..7731fe161 100644 --- a/android/examples/OpenGL/Shaders/LowLevelGL/LowLevelGL.pde +++ b/android/examples/Topics/Shaders/LowLevelGL/LowLevelGL.pde @@ -1,9 +1,7 @@ // Draws a triangle using low-level OpenGL calls. -import java.nio.FloatBuffer; +import java.nio.*; -PGraphicsOpenGL pg; PGL pgl; - PShader flatShader; int vertLoc; @@ -16,13 +14,12 @@ FloatBuffer vertData; FloatBuffer colorData; void setup() { - size(400, 400, P3D); + size(640, 360, P3D); + orientation(LANDSCAPE); - pg = (PGraphicsOpenGL)g; - - // Get the default shader that Processing uses to - // render flat geometry (w/out textures and lights). - flatShader = getShader(PShader.FLAT); + // Loads a shader to render geometry w/out + // textures and lights. + flatShader = loadShader("frag.glsl", "vert.glsl"); vertices = new float[12]; vertData = allocateDirectFloatBuffer(12); @@ -36,29 +33,30 @@ void draw() { // The geometric transformations will be automatically passed // to the shader. - rotate(frameCount * 0.01f, width, height, 0); + rotate(frameCount * 0.01, width, height, 0); updateGeometry(); - pgl = pg.beginGL(); + pgl = beginPGL(); flatShader.bind(); - vertLoc = pgl.glGetAttribLocation(flatShader.glProgram, "inVertex"); - colorLoc = pgl.glGetAttribLocation(flatShader.glProgram, "inColor"); + vertLoc = pgl.getAttribLocation(flatShader.glProgram, "inVertex"); + colorLoc = pgl.getAttribLocation(flatShader.glProgram, "inColor"); - pgl.glEnableVertexAttribArray(vertLoc); - pgl.glEnableVertexAttribArray(colorLoc); + pgl.enableVertexAttribArray(vertLoc); + pgl.enableVertexAttribArray(colorLoc); - pgl.glVertexAttribPointer(vertLoc, 4, PGL.GL_FLOAT, false, 0, vertData); - pgl.glVertexAttribPointer(colorLoc, 4, PGL.GL_FLOAT, false, 0, colorData); + pgl.vertexAttribPointer(vertLoc, 4, PGL.FLOAT, false, 0, vertData); + pgl.vertexAttribPointer(colorLoc, 4, PGL.FLOAT, false, 0, colorData); - pgl.glDrawArrays(PGL.GL_TRIANGLES, 0, 3); + pgl.drawArrays(PGL.TRIANGLES, 0, 3); - pgl.glDisableVertexAttribArray(vertLoc); - pgl.glDisableVertexAttribArray(colorLoc); + pgl.disableVertexAttribArray(vertLoc); + pgl.disableVertexAttribArray(colorLoc); flatShader.unbind(); - pg.endGL(); + + endPGL(); } void updateGeometry() { @@ -103,4 +101,4 @@ void updateGeometry() { FloatBuffer allocateDirectFloatBuffer(int n) { return ByteBuffer.allocateDirect(n * Float.SIZE/8).order(ByteOrder.nativeOrder()).asFloatBuffer(); -} +} diff --git a/android/examples/Topics/Shaders/LowLevelGL/data/frag.glsl b/android/examples/Topics/Shaders/LowLevelGL/data/frag.glsl new file mode 100644 index 000000000..16742d2bd --- /dev/null +++ b/android/examples/Topics/Shaders/LowLevelGL/data/frag.glsl @@ -0,0 +1,30 @@ +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2011-12 Ben Fry and Casey Reas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + */ + +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif + +varying vec4 vertColor; + +void main() { + gl_FragColor = vertColor; +} \ No newline at end of file diff --git a/android/examples/Topics/Shaders/LowLevelGL/data/vert.glsl b/android/examples/Topics/Shaders/LowLevelGL/data/vert.glsl new file mode 100644 index 000000000..95c266a76 --- /dev/null +++ b/android/examples/Topics/Shaders/LowLevelGL/data/vert.glsl @@ -0,0 +1,32 @@ +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2011-12 Ben Fry and Casey Reas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + */ + +uniform mat4 projmodelviewMatrix; + +attribute vec4 inVertex; +attribute vec4 inColor; + +varying vec4 vertColor; + +void main() { + gl_Position = projmodelviewMatrix * inVertex; + + vertColor = inColor; +} \ No newline at end of file diff --git a/android/examples/OpenGL/Shaders/SepBlur/SepBlur.pde b/android/examples/Topics/Shaders/SepBlur/SepBlur.pde similarity index 81% rename from android/examples/OpenGL/Shaders/SepBlur/SepBlur.pde rename to android/examples/Topics/Shaders/SepBlur/SepBlur.pde index 35add4abe..c08bc40ee 100644 --- a/android/examples/OpenGL/Shaders/SepBlur/SepBlur.pde +++ b/android/examples/Topics/Shaders/SepBlur/SepBlur.pde @@ -7,19 +7,18 @@ PGraphics pass1, pass2; void setup() { size(200, 200, P2D); + orientation(LANDSCAPE); - blur = loadShader(PShader.TEXTURED, "blur.glsl"); + blur = loadShader("blur.glsl"); blur.set("sigma", 5.0f); src = createGraphics(width, height, P2D); pass1 = createGraphics(width, height, P2D); - pass1.noSmooth(); - pass1.shader(blur); + pass1.noSmooth(); pass2 = createGraphics(width, height, P2D); pass2.noSmooth(); - pass2.shader(blur); } void draw() { @@ -31,16 +30,18 @@ void draw() { // Applying the blur shader along the vertical direction blur.set("horizontalPass", 0); - pass1.beginDraw(); + pass1.beginDraw(); + pass1.shader(blur); pass1.image(src, 0, 0); pass1.endDraw(); // Applying the blur shader along the horizontal direction blur.set("horizontalPass", 1); - pass2.beginDraw(); + pass2.beginDraw(); + pass2.shader(blur); pass2.image(pass1, 0, 0); pass2.endDraw(); image(pass2, 0, 0); } - + diff --git a/android/examples/OpenGL/Shaders/SepBlur/data/blur.glsl b/android/examples/Topics/Shaders/SepBlur/data/blur.glsl similarity index 100% rename from android/examples/OpenGL/Shaders/SepBlur/data/blur.glsl rename to android/examples/Topics/Shaders/SepBlur/data/blur.glsl diff --git a/android/examples/Topics/Shaders/ToonShading/ToonShading.pde b/android/examples/Topics/Shaders/ToonShading/ToonShading.pde new file mode 100644 index 000000000..fd18d24b8 --- /dev/null +++ b/android/examples/Topics/Shaders/ToonShading/ToonShading.pde @@ -0,0 +1,44 @@ +/** + * Toon Shading. + * + * Example showing the use of a custom lighting shader in order + * to apply a "toon" effect on the scene. Based on the glsl tutorial + * from lighthouse 3D: + * http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shader-version-ii/ + */ + +PShader toon; +boolean shaderEnabled = true; + +void setup() { + size(640, 360, P3D); + orientation(LANDSCAPE); + noStroke(); + fill(204); + toon = loadShader("ToonFrag.glsl", "ToonVert.glsl"); +} + +void draw() { + if (shaderEnabled == true) { + shader(toon); + } + + noStroke(); + background(0); + float dirY = (mouseY / float(height) - 0.5) * 2; + float dirX = (mouseX / float(width) - 0.5) * 2; + directionalLight(204, 204, 204, -dirX, -dirY, -1); + translate(width/2, height/2); + sphere(120); +} + +void mousePressed() { + if (shaderEnabled) { + shaderEnabled = false; + resetShader(); + } + else { + shaderEnabled = true; + } +} + diff --git a/android/examples/OpenGL/Shaders/ToonShading/data/ToonFrag.glsl b/android/examples/Topics/Shaders/ToonShading/data/ToonFrag.glsl similarity index 100% rename from android/examples/OpenGL/Shaders/ToonShading/data/ToonFrag.glsl rename to android/examples/Topics/Shaders/ToonShading/data/ToonFrag.glsl diff --git a/android/examples/OpenGL/Shaders/ToonShading/data/ToonVert.glsl b/android/examples/Topics/Shaders/ToonShading/data/ToonVert.glsl similarity index 100% rename from android/examples/OpenGL/Shaders/ToonShading/data/ToonVert.glsl rename to android/examples/Topics/Shaders/ToonShading/data/ToonVert.glsl diff --git a/android/examples/Topics/Simulate/Fluid/Fluid.pde b/android/examples/Topics/Simulate/Fluid/Fluid.pde deleted file mode 100644 index fd5f36bf6..000000000 --- a/android/examples/Topics/Simulate/Fluid/Fluid.pde +++ /dev/null @@ -1,208 +0,0 @@ -/** - * Fluid - * by Glen Murphy. - * - * Click and drag the mouse to move the simulated fluid. - * Adjust the "res" variable below to change resolution. - * Code has not been optimised, and will run fairly slowly. - */ - -int res = 2; -int penSize = 30; -int lwidth; -int lheight; -int pnum = 30000; -vsquare[][] v; -vbuffer[][] vbuf; -particle[] p = new particle[pnum]; -int pcount = 0; -int mouseXvel = 0; -int mouseYvel = 0; - -void setup() -{ - size(200, 200); - noStroke(); - frameRate(30); - lwidth = width/res; - lheight = height/res; - v = new vsquare[lwidth+1][lheight+1]; - vbuf = new vbuffer[lwidth+1][lheight+1]; - for (int i = 0; i < pnum; i++) { - p[i] = new particle(random(res,width-res),random(res,height-res)); - } - for (int i = 0; i <= lwidth; i++) { - for (int u = 0; u <= lheight; u++) { - v[i][u] = new vsquare(i*res,u*res); - vbuf[i][u] = new vbuffer(i*res,u*res); - } - } -} - -void draw() -{ - background(#666666); - - int axvel = mouseX-pmouseX; - int ayvel = mouseY-pmouseY; - - mouseXvel = (axvel != mouseXvel) ? axvel : 0; - mouseYvel = (ayvel != mouseYvel) ? ayvel : 0; - - for (int i = 0; i < lwidth; i++) { - for (int u = 0; u < lheight; u++) { - vbuf[i][u].updatebuf(i,u); - v[i][u].col = 32; - } - } - for (int i = 0; i < pnum-1; i++) { - p[i].updatepos(); - } - for (int i = 0; i < lwidth; i++) { - for (int u = 0; u < lheight; u++) { - v[i][u].addbuffer(i, u); - v[i][u].updatevels(mouseXvel, mouseYvel); - v[i][u].display(i, u); - } - } -} - -class particle { - float x; - float y; - float xvel; - float yvel; - int pos; - particle(float xIn, float yIn) { - x = xIn; - y = yIn; - } - - void updatepos() { - float col1; - if (x > 0 && x < width && y > 0 && y < height) { - int vi = (int)(x/res); - int vu = (int)(y/res); - vsquare o = v[vi][vu]; - - float ax = (x%res)/res; - float ay = (y%res)/res; - - xvel += (1-ax)*v[vi][vu].xvel*0.05; - yvel += (1-ay)*v[vi][vu].yvel*0.05; - - xvel += ax*v[vi+1][vu].xvel*0.05; - yvel += ax*v[vi+1][vu].yvel*0.05; - - xvel += ay*v[vi][vu+1].xvel*0.05; - yvel += ay*v[vi][vu+1].yvel*0.05; - - o.col += 4; - - x += xvel; - y += yvel; - } - else { - x = random(0,width); - y = random(0,height); - xvel = 0; - yvel = 0; - } - - xvel *= 0.5; - yvel *= 0.5; - } -} - -class vbuffer { - int x; - int y; - float xvel; - float yvel; - float pressurex = 0; - float pressurey = 0; - float pressure = 0; - - vbuffer(int xIn,int yIn) { - x = xIn; - y = yIn; - pressurex = 0; - pressurey = 0; - } - - void updatebuf(int i, int u) { - if (i>0 && i0 && u0 && i0 && u 255) col = 255; - if (i>0 && i0 && u x && l.x < x + w && l.y > y && l.y < y + h) { + return true; + } + else { + return false; + } + } + + // Calculate drag force + PVector drag(Mover m) { + // Magnitude is coefficient * speed squared + float speed = m.velocity.mag(); + float dragMagnitude = c * speed * speed; + + // Direction is inverse of velocity + PVector drag = m.velocity.get(); + drag.mult(-1); + + // Scale according to magnitude + drag.setMag(dragMagnitude); + return drag; + } + + void display() { + noStroke(); + fill(127); + rect(x,y,w,h); + } + +} + diff --git a/android/examples/Topics/Simulate/ForcesWithVectors/Mover.pde b/android/examples/Topics/Simulate/ForcesWithVectors/Mover.pde new file mode 100644 index 000000000..b14754b71 --- /dev/null +++ b/android/examples/Topics/Simulate/ForcesWithVectors/Mover.pde @@ -0,0 +1,64 @@ +/** + * Forces (Gravity and Fluid Resistence) with Vectors + * by Daniel Shiffman. + * + * Demonstration of multiple force acting on bodies (Mover class) + * Bodies experience gravity continuously + * Bodies experience fluid resistance when in "water" + */ + + +class Mover { + + // location, velocity, and acceleration + PVector location; + PVector velocity; + PVector acceleration; + + // Mass is tied to size + float mass; + + Mover(float m, float x, float y) { + mass = m; + location = new PVector(x, y); + velocity = new PVector(0, 0); + acceleration = new PVector(0, 0); + } + + // Newton's 2nd law: F = M * A + // or A = F / M + void applyForce(PVector force) { + // Divide by mass + PVector f = PVector.div(force, mass); + // Accumulate all forces in acceleration + acceleration.add(f); + } + + void update() { + + // Velocity changes according to acceleration + velocity.add(acceleration); + // Location changes by velocity + location.add(velocity); + // We must clear acceleration each frame + acceleration.mult(0); + } + + // Draw Mover + void display() { + stroke(255); + strokeWeight(2); + fill(255, 200); + ellipse(location.x, location.y, mass*16, mass*16); + } + + // Bounce off bottom of window + void checkEdges() { + if (location.y > height) { + velocity.y *= -0.9; // A little dampening when hitting the bottom + location.y = height; + } + } +} + + diff --git a/android/examples/Topics/Simulate/GravitationalAttraction3D/GravitationalAttraction3D.pde b/android/examples/Topics/Simulate/GravitationalAttraction3D/GravitationalAttraction3D.pde new file mode 100644 index 000000000..87a7ed9ef --- /dev/null +++ b/android/examples/Topics/Simulate/GravitationalAttraction3D/GravitationalAttraction3D.pde @@ -0,0 +1,71 @@ +/** + * Gravitational Attraction (3D) + * by Daniel Shiffman. + * + * Simulating gravitational attraction + * G ---> universal gravitational constant + * m1 --> mass of object #1 + * m2 --> mass of object #2 + * d ---> distance between objects + * F = (G*m1*m2)/(d*d) + * + * For the basics of working with PVector, see + * http://processing.org/learning/pvector/ + * as well as examples in Topics/Vectors/ + * + */ + +// A bunch of planets +Planet[] planets = new Planet[10]; +// One sun (note sun is not attracted to planets (violation of Newton's 3rd Law) +Sun s; + +// An angle to rotate around the scene +float angle = 0; + +void setup() { + size(displayWidth, displayHeight, P3D); + orientation(LANDSCAPE); + // Some random planets + for (int i = 0; i < planets.length; i++) { + planets[i] = new Planet(random(0.1, 2), random(-width/2, width/2), random(-height/2, height/2), random(-100, 100)); + } + // A single sun + s = new Sun(); +} + +void draw() { + background(0); + // Setup the scene + sphereDetail(8); + lights(); + translate(width/2, height/2); + rotateY(angle); + + + // Display the Sun + s.display(); + + // All the Planets + for (int i = 0; i < planets.length; i++) { + // Sun attracts Planets + PVector force = s.attract(planets[i]); + planets[i].applyForce(force); + // Update and draw Planets + planets[i].update(); + planets[i].display(); + } + + // Rotate around the scene + angle += 0.003; +} + + + + + + + + + + diff --git a/android/examples/Topics/Simulate/GravitationalAttraction3D/Planet.pde b/android/examples/Topics/Simulate/GravitationalAttraction3D/Planet.pde new file mode 100644 index 000000000..ae8be2537 --- /dev/null +++ b/android/examples/Topics/Simulate/GravitationalAttraction3D/Planet.pde @@ -0,0 +1,45 @@ +// Gravitational Attraction (3D) +// Daniel Shiffman + +// A class for an orbiting Planet + +class Planet { + + // Basic physics model (location, velocity, acceleration, mass) + PVector location; + PVector velocity; + PVector acceleration; + float mass; + + Planet(float m, float x, float y, float z) { + mass = m; + location = new PVector(x,y,z); + velocity = new PVector(1,0); // Arbitrary starting velocity + acceleration = new PVector(0,0); + } + + // Newton's 2nd Law (F = M*A) applied + void applyForce(PVector force) { + PVector f = PVector.div(force,mass); + acceleration.add(f); + } + + // Our motion algorithm (aka Euler Integration) + void update() { + velocity.add(acceleration); // Velocity changes according to acceleration + location.add(velocity); // Location changes according to velocity + acceleration.mult(0); + } + + // Draw the Planet + void display() { + noStroke(); + fill(255); + pushMatrix(); + translate(location.x,location.y,location.z); + sphere(mass*8); + popMatrix(); + } +} + + diff --git a/android/examples/Topics/Simulate/GravitationalAttraction3D/Sun.pde b/android/examples/Topics/Simulate/GravitationalAttraction3D/Sun.pde new file mode 100644 index 000000000..3253bc02f --- /dev/null +++ b/android/examples/Topics/Simulate/GravitationalAttraction3D/Sun.pde @@ -0,0 +1,39 @@ +// Gravitational Attraction (3D) +// Daniel Shiffman + +// A class for an attractive body in our world + +class Sun { + float mass; // Mass, tied to size + PVector location; // Location + float G; // Universal gravitational constant (arbitrary value) + + Sun() { + location = new PVector(0,0); + mass = 20; + G = 0.4; + } + + + PVector attract(Planet m) { + PVector force = PVector.sub(location,m.location); // Calculate direction of force + float d = force.mag(); // Distance between objects + d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects + force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) + float strength = (G * mass * m.mass) / (d * d); // Calculate gravitional force magnitude + force.mult(strength); // Get force vector --> magnitude * direction + return force; + } + + // Draw Sun + void display() { + stroke(255); + noFill(); + pushMatrix(); + translate(location.x,location.y,location.z); + sphere(mass*2); + popMatrix(); + } +} + + diff --git a/android/examples/Topics/Simulate/Smoke/Smoke.pde b/android/examples/Topics/Simulate/Smoke/Smoke.pde deleted file mode 100644 index 2716209ac..000000000 --- a/android/examples/Topics/Simulate/Smoke/Smoke.pde +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Smoke - * by Glen Murphy. - * - * Drag the mouse across the image to move the particles. - * Code has not been optimised and will run fairly slowly. - */ - -int res = 2; -int penSize = 30; -int lwidth; -int lheight; -int pnum = 30000; -vsquare[][] v; -vbuffer[][] vbuf; -particle[] p; -int pcount = 0; -int mouseXvel = 0; -int mouseYvel = 0; - -int randomGust = 0; -int randomGustMax; -float randomGustX; -float randomGustY; -float randomGustSize; -float randomGustXvel; -float randomGustYvel; - -void setup() -{ - size(200, 200); - lwidth = width/res; - lheight = height/res; - v = new vsquare[lwidth+1][lheight+1]; - vbuf = new vbuffer[lwidth+1][lheight+1]; - p = new particle[pnum]; - noStroke(); - for(int i = 0; i < pnum; i++) { - p[i] = new particle(random(width/2-20,width/2+20),random(height-20,height)); - } - for(int i = 0; i <= lwidth; i++) { - for(int u = 0; u <= lheight; u++) { - v[i][u] = new vsquare(i*res,u*res); - vbuf[i][u] = new vbuffer(i*res,u*res); - } - } -} - -void draw() -{ - background(#cccccc); - - int axvel = mouseX-pmouseX; - int ayvel = mouseY-pmouseY; - - mouseXvel = (axvel != mouseXvel) ? axvel : 0; - mouseYvel = (ayvel != mouseYvel) ? ayvel : 0; - - if(randomGust <= 0) { - if(random(0,10)<1) { - randomGustMax = (int)random(5,12); - randomGust = randomGustMax; - randomGustX = random(0,width); - randomGustY = random(0,height-10); - randomGustSize = random(0,50); - if(randomGustX > width/2) { - randomGustXvel = random(-8,0); - } else { - randomGustXvel = random(0,8); - } - randomGustYvel = random(-2,1); - } - randomGust--; - } - - for(int i = 0; i < lwidth; i++) { - for(int u = 0; u < lheight; u++) { - vbuf[i][u].updatebuf(i,u); - v[i][u].col = 0; - } - } - for(int i = 0; i < pnum-1; i++) { - p[i].updatepos(); - } - for(int i = 0; i < lwidth; i++) { - for(int u = 0; u < lheight; u++) { - v[i][u].addbuffer(i, u); - v[i][u].updatevels(mouseXvel, mouseYvel); - v[i][u].display(i, u); - } - } - randomGust = 0; -} - -class particle -{ - float x; - float y; - float xvel; - float yvel; - float temp; - int pos; - - particle(float xIn, float yIn) { - x = xIn; - y = yIn; - } - - void reposition() { - x = width/2+random(-20,20); - y = random(height-10,height); - - xvel = random(-1,1); - yvel = random(-1,1); - } - - void updatepos() { - int vi = (int)(x/res); - int vu = (int)(y/res); - - if(vi > 0 && vi < lwidth && vu > 0 && vu < lheight) { - v[vi][vu].addcolour(2); - - float ax = (x%res)/res; - float ay = (y%res)/res; - - xvel += (1-ax)*v[vi][vu].xvel*0.05; - yvel += (1-ay)*v[vi][vu].yvel*0.05; - - xvel += ax*v[vi+1][vu].xvel*0.05; - yvel += ax*v[vi+1][vu].yvel*0.05; - - xvel += ay*v[vi][vu+1].xvel*0.05; - yvel += ay*v[vi][vu+1].yvel*0.05; - - v[vi][vu].yvel -= (1-ay)*0.003; - v[vi+1][vu].yvel -= ax*0.003; - - if(v[vi][vu].yvel < 0) v[vi][vu].yvel *= 1.00025; - - x += xvel; - y += yvel; - } - else { - reposition(); - } - if(random(0,400) < 1) { - reposition(); - } - xvel *= 0.6; - yvel *= 0.6; - } -} - -class vbuffer -{ - int x; - int y; - float xvel; - float yvel; - float pressurex = 0; - float pressurey = 0; - float pressure = 0; - - vbuffer(int xIn,int yIn) { - x = xIn; - y = yIn; - pressurex = 0; - pressurey = 0; - } - - void updatebuf(int i, int u) { - if(i>0 && i0 && u0 && i0 && u 0) { - adj = x - randomGustX; - opp = y - randomGustY; - dist = sqrt(opp*opp + adj*adj); - if(dist < randomGustSize) { - if(dist < res*2) dist = randomGustSize; - mod = randomGustSize/dist; - xvel += (randomGustMax-randomGust)*randomGustXvel*mod; - yvel += (randomGustMax-randomGust)*randomGustYvel*mod; - } - } - xvel *= 0.99; - yvel *= 0.98; - } - - void addcolour(int amt) { - col += amt; - if(col > 196) col = 196; - } - - void display(int i, int u) { - float tcol = 0; - if(i>0 && i0 && u width) || (location.x < 0)) { + velocity.x = velocity.x * -1; + } + if (location.y > height) { + // We're reducing velocity ever so slightly + // when it hits the bottom of the window + velocity.y = velocity.y * -0.95; + location.y = height; + } + + // Display circle at location vector + stroke(255); + strokeWeight(2); + fill(127); + ellipse(location.x,location.y,48,48); +} + + diff --git a/android/examples/Topics/Vectors/Normalize/Normalize.pde b/android/examples/Topics/Vectors/Normalize/Normalize.pde new file mode 100644 index 000000000..95bd8525a --- /dev/null +++ b/android/examples/Topics/Vectors/Normalize/Normalize.pde @@ -0,0 +1,37 @@ +/** + * Normalize + * by Daniel Shiffman. + * + * Demonstration of normalizing a vector. + * Normalizing a vector sets its length to 1. + */ + +void setup() { + size(640,360); + smooth(); +} + +void draw() { + background(0); + + // A vector that points to the mouse location + PVector mouse = new PVector(mouseX,mouseY); + // A vector that points to the center of the window + PVector center = new PVector(width/2,height/2); + // Subtract center from mouse which results in a vector that points from center to mouse + mouse.sub(center); + + // Normalize the vector + mouse.normalize(); + + // Multiply its length by 50 + mouse.mult(150); + + translate(width/2,height/2); + // Draw the resulting vector + stroke(255); + line(0,0,mouse.x,mouse.y); + +} + + diff --git a/android/examples/Topics/Vectors/VectorMath/VectorMath.pde b/android/examples/Topics/Vectors/VectorMath/VectorMath.pde new file mode 100644 index 000000000..fcc609234 --- /dev/null +++ b/android/examples/Topics/Vectors/VectorMath/VectorMath.pde @@ -0,0 +1,37 @@ +/** + * Vector + * by Daniel Shiffman. + * + * Demonstration some basic vector math: subtraction, normalization, scaling + * Normalizing a vector sets its length to 1. + */ + +void setup() { + size(640,360); + smooth(); +} + +void draw() { + background(0); + + // A vector that points to the mouse location + PVector mouse = new PVector(mouseX,mouseY); + // A vector that points to the center of the window + PVector center = new PVector(width/2,height/2); + // Subtract center from mouse which results in a vector that points from center to mouse + mouse.sub(center); + + // Normalize the vector + mouse.normalize(); + + // Multiply its length by 150 (Scaling its length) + mouse.mult(150); + + translate(width/2,height/2); + // Draw the resulting vector + stroke(255); + line(0,0,mouse.x,mouse.y); + +} + +