├── .gitignore ├── Android-Basics ├── 3D_motion.pde ├── Robot.pde ├── animation.pde ├── arrow.pde ├── circular_ellipseanim.pde ├── cmpose3d.pde ├── color.pde ├── compose.pde ├── creature.pde ├── cursor.pde ├── cursor_position.pde ├── delya.pde ├── detect_click.pde ├── easing.pde ├── easingLines.pde ├── emoji_anim.pde ├── exit.pde ├── function_owl.pde ├── line.pde ├── lines_pde.pde ├── loading_animation.pde ├── mad_mouse.pde ├── mapclick.pde ├── motion.pde ├── owl.pde ├── pattern.pde ├── pdf_print.pde ├── randoming_drawing.pde ├── repeat.pde ├── resizable.pde ├── robotic_arm.pde ├── rotating_sq.pde ├── scale_sq.pde ├── shades.pde ├── sketch_200513a.pde ├── smooth.pde ├── spiral_animation.pde ├── test.pde ├── threeDCube.pde ├── timer_ellipse.pde ├── trac_mouse.pde ├── translate_basics.pde └── tweening.pde ├── AndroidAR ├── Basic │ └── basic.pde ├── Rotating-Cube │ └── cubes.pde └── Sphere │ └── sphere.pde ├── AndroidVR ├── Animation │ └── animation.pde ├── Box │ └── box.pde ├── Cube │ └── cube.pde ├── Intersect-Sphere │ └── intersectsphere.pde ├── Ray │ └── generatedray.pde └── mono.pde ├── ApacheaFeather ├── ApacheaFeather.pde ├── Feather1.jpg ├── Feather10.jpg ├── Feather11.jpg ├── Feather12.jpg ├── Feather2.jpg ├── Feather3.jpg ├── Feather4.jpg ├── Feather5.jpg ├── Feather6.jpg ├── Feather7.jpg ├── Feather8.jpg └── Feather9.jpg ├── CityBuilder ├── CityBuilder.pde ├── city.tif ├── city0.jpg ├── city1.jpg ├── city2.jpg ├── city3.jpg └── city4.jpg ├── DotField └── sketch.pde ├── Dreamer └── Dreamer.pde ├── FlowField └── sketch.pde ├── GraphGenerator └── generator.pde ├── LICENSE ├── Leaf └── leaf.pde ├── MountainScenery ├── MountainScenery.pde ├── landscape0.png ├── landscape1.png ├── landscape2.png ├── landscape3.png ├── landscape4.png ├── landscape5.png ├── landscape6.png ├── landscape7.png └── landscape8.png ├── ParticleSystem └── particlesystem.pde ├── README.md ├── Rings └── ringSketch.pde ├── Ripples └── ripple.pde ├── Screenshots ├── Feather1.jpg ├── Feather10.jpg ├── Feather2.jpg ├── blender.jpg ├── city1.jpg ├── city3.jpg ├── landscape1.png ├── landscape6.png ├── landscape8.png ├── leaf.jpg └── rune.pdf ├── Sensor ├── accelerometer │ ├── Accelerometer.pde │ └── AccelerometerManager.java └── compass │ ├── CompassManager.java │ └── compass.pde ├── SwirlDesing └── swirldesing.pde ├── ascii_logo └── sketch.pde ├── ketai_sketches ├── accelerometer.pde ├── audio_input.pde ├── ketai_camera.pde ├── ketai_datagraph.pde ├── ketai_geolocation.pde ├── ketai_gyroscope.pde ├── ketai_multisensor.pde ├── ketai_sqlite.pde └── ketai_ui.pde ├── logo └── Processing-Sketchbook_logo.png ├── mountain └── mountain.pde ├── oceanwaves └── oceanwave.pde ├── processing-android-api-testing ├── Camera │ ├── beginCamera.pde │ ├── camera.pde │ ├── endCamera.pde │ ├── frustum.pde │ ├── ortho.pde │ ├── perspective.pde │ ├── printCamera.pde │ └── printProjection.pde ├── Color │ ├── alpha.pde │ ├── background.pde │ ├── brightness.pde │ ├── clear.pde │ ├── color.pde │ ├── colorMode.pde │ ├── hue.pde │ ├── lerpColor.pde │ ├── red.pde │ └── saturation.pde ├── README.md ├── Random │ ├── noise.pde │ ├── noiseDetail.pde │ ├── noiseSeed.pde │ ├── random.pde │ ├── randomGaussian.pde │ └── randomSeed.pde └── light │ ├── ambientLight.pde │ ├── directionalLight.pde │ ├── lightFalloff.pde │ ├── lightSpecular.pde │ ├── lights.pde │ ├── normal.pde │ ├── pointLight.pde │ └── spotLight.pde ├── shader-codes ├── advanced │ ├── 3dlines │ │ ├── line.pde │ │ ├── linefrag.glsl │ │ └── linevert.glsl │ └── colorpoints │ │ ├── colorpoint.pde │ │ ├── pointfrag.glsl │ │ └── pointvert.glsl └── basic │ ├── points │ ├── DrawPoints.pde │ ├── pointfrag.glsl │ └── pointvert.glsl │ └── simpleTexture │ ├── lachoy.jpg │ ├── simpletexture.pde │ ├── textfrag.glsl │ └── textvert.glsl ├── voroni ├── rune.pdf └── voroniPortrait.pde └── wallclock └── wallclock.pde /.gitignore: -------------------------------------------------------------------------------- 1 | *.sh 2 | 3 | -------------------------------------------------------------------------------- /Android-Basics/3D_motion.pde: -------------------------------------------------------------------------------- 1 | import processing.opengl.*; 2 | void setup() { 3 | size(420, 220, OPENGL); 4 | noStroke(); 5 | } 6 | void draw() { 7 | lights(); 8 | background(0); 9 | float camZ = (height/2.0) / tan(PI*60.0 / 360.0); 10 | camera(mouseX, mouseY, camZ, 11 | // Camera location 12 | width/2.0, height/2.0, 0, // Camera target 13 | 0, 1, 0); // Camera orientation 14 | translate(width/2, height/2, -20); 15 | int dim = 18; 16 | for (int i = -height/2; i < height/2; i += dim*1.4) { 17 | for (int j = -height/2; j < height/2; j += dim*1.4) { 18 | pushMatrix(); 19 | translate(i, j, -j); 20 | box(dim, dim, dim); 21 | popMatrix(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Android-Basics/Robot.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(600, 600); 3 | smooth(); 4 | } 5 | void draw() { 6 | strokeWeight(2); 7 | background(204); 8 | ellipseMode(RADIUS); 9 | 10 | // Neck 11 | stroke(102); 12 | line(266, 257, 266, 162); 13 | line(276, 257, 276, 162); 14 | line(286, 257, 286, 162); 15 | 16 | // Antennae 17 | line(276, 155, 246, 112); 18 | line(276, 155, 306, 56); 19 | line(276, 155, 342, 170); 20 | 21 | // Body 22 | noStroke(); 23 | fill(102); 24 | ellipse(264, 377, 33, 33); 25 | fill(0); 26 | rect(219, 257, 90, 120); 27 | fill(102); 28 | rect(219, 274, 90, 6); 29 | 30 | // Head 31 | fill(0); 32 | ellipse(276, 155, 45, 45); 33 | fill(255); 34 | ellipse(288, 150, 14, 14); 35 | fill(0); 36 | ellipse(288, 150, 3, 3); 37 | fill(153); 38 | ellipse(263, 148, 5, 5); 39 | ellipse(296, 130, 4, 4); 40 | ellipse(305, 162, 3, 3); 41 | } 42 | -------------------------------------------------------------------------------- /Android-Basics/animation.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(800, 800); 3 | smooth(); 4 | } 5 | void draw() { 6 | fill(255); 7 | stroke(102); 8 | for (int y = 20; y <= height-20; y += 10) { 9 | for (int x = 20; x <= width-20; x += 10) { 10 | ellipse(x, y, 4, 4); 11 | // Draw a line to the center of the display 12 | line(x, y, 240, 60); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Android-Basics/arrow.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(600, 600); 3 | smooth(); 4 | } 5 | void draw() { 6 | beginShape(); 7 | vertex(180, 82); 8 | vertex(207, 36); 9 | vertex(214, 63); 10 | vertex(407, 11); 11 | vertex(412, 30); 12 | vertex(219, 82); 13 | vertex(226, 109); 14 | endShape(); 15 | } 16 | -------------------------------------------------------------------------------- /Android-Basics/circular_ellipseanim.pde: -------------------------------------------------------------------------------- 1 | float angle = 0.0; 2 | float offset = 60; 3 | float scalar = 30; 4 | float speed = 0.05; 5 | void setup() { 6 | size(120, 120); 7 | smooth(); 8 | } 9 | void draw() { 10 | float x = offset + cos(angle) * scalar; 11 | float y = offset + sin(angle) * scalar; 12 | ellipse( x, y, 40, 40); 13 | angle += speed; 14 | } 15 | -------------------------------------------------------------------------------- /Android-Basics/cmpose3d.pde: -------------------------------------------------------------------------------- 1 | float[] r1, r2; 2 | void setup() { 3 | 4 | noStroke(); 5 | r1 = new float[100]; 6 | r2 = new float[100]; 7 | for (int i = 0; i < 100; i++) { 8 | r1[i] = random(0, 1); 9 | r2[i] = random(0, 1); 10 | } 11 | } 12 | 13 | void settings() { 14 | fullScreen(P3D); 15 | } 16 | void draw() { 17 | background(157); 18 | lights(); 19 | translate(width/2, height/2); 20 | scale(4); 21 | for (int i = 0; i < 100; i++) { 22 | float tx = 0, ty = 0, tz = 0; 23 | float sx = 1, sy = 1, sz = 1; 24 | if (r1[i] < 1.0/3.0) { 25 | rotateX(millis()/1000.0); 26 | tz = sz = 10; 27 | } else if (1.0/3.0 < r1[i] && r1[i] < 2.0/3.0) { 28 | rotateY(millis()/1000.0); 29 | tz = sz = 10; 30 | } else { 31 | rotateZ(millis()/1000.0); 32 | if (r2[i] < 0.5) { 33 | tx = sx = 10; 34 | } else { 35 | ty = sy = 10; 36 | } 37 | } 38 | 39 | translate(tx/2, ty/2, tz/2); 40 | pushMatrix(); 41 | scale(sx, sy, sz); 42 | box(1); 43 | popMatrix(); 44 | translate(tx/2, ty/2, tz/2); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Android-Basics/color.pde: -------------------------------------------------------------------------------- 1 | color bg; // Yes, but ass0ign it in setup() 2 | 3 | void setup() { 4 | size(j, 100); 5 | point(i, j); 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Android-Basics/compose.pde: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Android-Basics/creature.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(600, 600); 3 | smooth(); 4 | } 5 | void draw() { 6 | // Left creature 7 | beginShape(); 8 | vertex(50, 120); 9 | vertex(100, 90); 10 | vertex(110, 60); 11 | vertex(80, 20); 12 | vertex(210, 60); 13 | vertex(160, 80); 14 | vertex(200, 90); 15 | vertex(140, 100); 16 | vertex(130, 120); 17 | endShape(); 18 | 19 | fill(0); 20 | ellipse(155, 60, 8, 8); 21 | 22 | // Right creature 23 | fill(255); 24 | beginShape(); 25 | vertex(370, 120); 26 | vertex(360, 90); 27 | vertex(290, 80); 28 | vertex(340, 70); 29 | vertex(280, 50); 30 | vertex(420, 10); 31 | vertex(390, 50); 32 | vertex(410, 90); 33 | vertex(460, 120); 34 | endShape(); 35 | 36 | //fill(0); 37 | ellipse(345, 50, 8,8); 38 | } 39 | -------------------------------------------------------------------------------- /Android-Basics/cursor.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | 3 | } 4 | void settings() { 5 | size(100, 100); 6 | } 7 | 8 | void draw() { 9 | if (mouseX < 50) { 10 | cursor(CROSS); 11 | } else { 12 | cursor(HAND); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Android-Basics/cursor_position.pde: -------------------------------------------------------------------------------- 1 | float x; 2 | int offset = 10; 3 | void setup() { 4 | size(240, 120); 5 | smooth(); 6 | x = width/2; 7 | } 8 | void draw() { 9 | background(204); 10 | if (mouseX > x) { 11 | x += 0.5; 12 | offset = -10; 13 | } 14 | if (mouseX < x) { 15 | x -= 0.5; 16 | offset = 10; 17 | } 18 | line(x, 0, x, height); 19 | line(mouseX, mouseY, mouseX + offset, mouseY - 10); 20 | line(mouseX, mouseY, mouseX + offset, mouseY + 10); 21 | line(mouseX, mouseY, mouseX + offset*3, mouseY); 22 | } 23 | -------------------------------------------------------------------------------- /Android-Basics/delya.pde: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Android-Basics/delya.pde -------------------------------------------------------------------------------- /Android-Basics/detect_click.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(120, 120); 3 | smooth(); 4 | strokeWeight(30); 5 | } 6 | void draw() { 7 | background(204); 8 | stroke(102); 9 | line(40, 0, 70, height); 10 | if (mousePressed) { 11 | if (mouseButton == LEFT) { 12 | stroke(255); 13 | } else { 14 | stroke(0); 15 | } 16 | line(0, 70, width, 50); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Android-Basics/easing.pde: -------------------------------------------------------------------------------- 1 | float x; 2 | float easing = 0.01; 3 | float diameter = 12; 4 | 5 | void setup() { 6 | size(800, 800); 7 | smooth(); 8 | } 9 | void draw() { 10 | float targetX = mouseX; 11 | x += (targetX - x) * easing; 12 | ellipse(x, 40, 12, 12); 13 | println(targetX + " : " + x); 14 | } 15 | -------------------------------------------------------------------------------- /Android-Basics/easingLines.pde: -------------------------------------------------------------------------------- 1 | 2 | float x; 3 | float y; 4 | float px; 5 | float py; 6 | float easing = 0.05; 7 | void setup() { 8 | size(800, 800); 9 | smooth(); 10 | stroke(0, 102); 11 | } 12 | void draw() { 13 | float targetX = mouseX; 14 | x += (targetX - x) * easing; 15 | float targetY = mouseY; 16 | y += (targetY - y) * easing; 17 | float weight = dist(x, y, px, py); 18 | strokeWeight(weight); 19 | line(x, y, px, py); 20 | py = y; 21 | px = x; 22 | } 23 | -------------------------------------------------------------------------------- /Android-Basics/emoji_anim.pde: -------------------------------------------------------------------------------- 1 | int radius = 40; 2 | float x = -radius; 3 | float speed = 0.5; 4 | void setup() { 5 | size(240, 120); 6 | smooth(); 7 | ellipseMode(RADIUS); 8 | } 9 | void draw() { 10 | background(0); 11 | x += speed; // Increase the value of x 12 | arc(x, 60, radius, radius, 0.52, 5.76); 13 | } 14 | -------------------------------------------------------------------------------- /Android-Basics/exit.pde: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Android-Basics/exit.pde -------------------------------------------------------------------------------- /Android-Basics/function_owl.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(480, 120); 3 | smooth(); 4 | } 5 | void draw() { 6 | background(204); 7 | owl(110, 110); 8 | owl(180, 110); 9 | } 10 | void owl(int x, int y) { 11 | pushMatrix(); 12 | translate(x, y); 13 | stroke(0); 14 | strokeWeight(70); 15 | line(0, -35, 0, -65); 16 | // Body 17 | noStroke(); 18 | fill(255); 19 | ellipse(-17.5, -65, 35, 35); // Left eye dome 20 | ellipse(17.5, -65, 35, 35); // Right eye dome 21 | arc(0, -65, 70, 70, 0, PI); // Chin 22 | fill(0); 23 | ellipse(-14, -65, 8, 8); // Left eye 24 | ellipse(14, -65, 8, 8); 25 | // Right eye 26 | quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak 27 | popMatrix(); 28 | } 29 | -------------------------------------------------------------------------------- /Android-Basics/line.pde: -------------------------------------------------------------------------------- 1 | void settings() { 2 | size(500,500); 3 | } 4 | void draw() { 5 | line(mouseX, mouseY, width, height); 6 | } 7 | 8 | void mousePressed() { 9 | exit(); 10 | } 11 | -------------------------------------------------------------------------------- /Android-Basics/lines_pde.pde: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Android-Basics/loading_animation.pde: -------------------------------------------------------------------------------- 1 | float angle = 0.0; 2 | float offset = 60; 3 | float scalar = 40; 4 | float speed = 0.05; 5 | void setup() { 6 | size(240, 120); 7 | smooth(); 8 | } 9 | void draw() { 10 | background(0); 11 | float y1 = offset + sin(angle) * scalar; 12 | float y2 = offset + sin(angle + 0.4) * scalar; 13 | float y3 = offset + sin(angle + 0.8) * scalar; 14 | ellipse( 80, y1, 40, 40); 15 | ellipse(120, y2, 40, 40); 16 | ellipse(160, y3, 40, 40); 17 | angle += speed; 18 | } 19 | -------------------------------------------------------------------------------- /Android-Basics/mad_mouse.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(600, 600); 3 | smooth(); 4 | } 5 | void draw() { 6 | if (mousePressed) { 7 | fill(0); 8 | } else { 9 | fill(255); 10 | } 11 | ellipse(mouseX, mouseY, 80, 80); 12 | } 13 | -------------------------------------------------------------------------------- /Android-Basics/mapclick.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(240, 120); 3 | smooth(); 4 | strokeWeight(30); 5 | } 6 | void draw() { 7 | background(204); 8 | stroke(102); 9 | line(40, 0, 70, height); 10 | if (mousePressed == true) { 11 | stroke(0); 12 | } 13 | line(0, 70, width, 50); 14 | } 15 | -------------------------------------------------------------------------------- /Android-Basics/motion.pde: -------------------------------------------------------------------------------- 1 | 2 | float x = 180; // X-coordinate 3 | float y = 400; // Y-coordinate 4 | float bodyHeight = 153; // Body height 5 | float neckHeight = 56; // Neck height 6 | float radius = 45; // Head radius 7 | float angle = 0.0; // Angle for motion 8 | void setup() { 9 | size(360, 480); 10 | smooth(); 11 | ellipseMode(RADIUS); 12 | background(204); 13 | } 14 | 15 | void draw() { 16 | // Change position by a small random amount 17 | x += random(-4, 4); 18 | y += random(-1, 1); 19 | // Change height of neck 20 | neckHeight = 80 + sin(angle) * 30; 21 | angle += 0.05; 22 | // Adjust the height of the head 23 | float ny = y - bodyHeight - neckHeight - radius; 24 | // Neck 25 | stroke(102); 26 | line(x+2, y-bodyHeight, x+2, ny); 27 | line(x+12, y-bodyHeight, x+12, ny); 28 | line(x+22, y-bodyHeight, x+22, ny); 29 | // Antennae 30 | line(x+12, ny, x-18, ny-43); 31 | line(x+12, ny, x+42, ny-99); 32 | line(x+12, ny, x+78, ny+15); 33 | // Body 34 | noStroke(); 35 | fill(102); 36 | ellipse(x, y-33, 33, 33); 37 | fill(0); 38 | rect(x-45, y-bodyHeight, 90, bodyHeight-33); 39 | fill(102); 40 | rect(x-45, y-bodyHeight+17, 90, 6); 41 | // Head 42 | fill(0); 43 | ellipse(x+12, ny, radius, radius); 44 | fill(255); 45 | ellipse(x+24, ny-6, 14, 14); 46 | fill(0); 47 | ellipse(x+24, ny-6, 3, 3); 48 | } 49 | -------------------------------------------------------------------------------- /Android-Basics/owl.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(240, 120); 3 | smooth(); 4 | } 5 | void draw() { 6 | background(204); 7 | translate(110, 110); 8 | stroke(0); 9 | strokeWeight(70); 10 | line(0, -35, 0, -65); 11 | // Body 12 | noStroke(); 13 | fill(255); 14 | ellipse(-17.5, -65, 35, 35); // Left eye dome 15 | ellipse(17.5, -65, 35, 35); // Right eye dome 16 | arc(0, -65, 70, 70, 0, PI); // Chin 17 | fill(0); 18 | ellipse(-14, -65, 8, 8); // Left eye 19 | ellipse(14, -65, 8, 8); 20 | // Right eye 21 | quad(0, -58, 4, -51, 0, -44, -4, -51); 22 | // Beak 23 | } 24 | -------------------------------------------------------------------------------- /Android-Basics/pattern.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(600, 600); 3 | smooth(); 4 | } 5 | void draw() { 6 | strokeWeight(2); 7 | background(0); 8 | ellipseMode(RADIUS); 9 | 10 | // Neck 11 | noStroke(); 12 | for (int y = 0; y <= height; y += 40) { 13 | for (int x = 0; x <= width; x += 40) { 14 | fill(255, 140); 15 | ellipse(x, y, 40, 40); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Android-Basics/pdf_print.pde: -------------------------------------------------------------------------------- 1 | import processing.pdf.*; 2 | void setup() { 3 | size(600, 800, PDF, "Ex-11-5.pdf"); 4 | noFill(); 5 | strokeCap(SQUARE); 6 | } 7 | void draw() { 8 | background(255); 9 | for (int y = 100; y < height - 300; y+=20) { 10 | float r = random(0, 102); 11 | strokeWeight(r / 10); 12 | beginShape(); 13 | vertex(100, y); 14 | vertex(width/2, y + 200); 15 | vertex(width-100, y); 16 | endShape(); 17 | } 18 | exit(); 19 | } 20 | -------------------------------------------------------------------------------- /Android-Basics/randoming_drawing.pde: -------------------------------------------------------------------------------- 1 | float speed = 2.5; 2 | int diameter = 20; 3 | float x; 4 | float y; 5 | void setup() { 6 | size(240, 120); 7 | smooth(); 8 | x = width/2; 9 | y = height/2; 10 | } 11 | void draw() { 12 | x += random(-speed, speed); 13 | y += random(-speed, speed); 14 | ellipse(x, y, diameter, diameter); 15 | } 16 | -------------------------------------------------------------------------------- /Android-Basics/repeat.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(600, 600); 3 | smooth(); 4 | } 5 | void draw() { 6 | strokeWeight(2); 7 | background(204); 8 | ellipseMode(RADIUS); 9 | 10 | // Neck 11 | strokeWeight(8); 12 | for (int i = 20; i < 500; i += 60) { 13 | line(i, 40, i + 60, 80); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Android-Basics/resizable.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | 3 | size(500,500); 4 | surface.setTitle("Hello World!"); 5 | surface.setResizable(true); 6 | surface.setLocation(width, width); 7 | } 8 | 9 | void draw() { 10 | background(204); 11 | line(0, 0, width, height); 12 | line(width, 0, 0, height); 13 | } 14 | -------------------------------------------------------------------------------- /Android-Basics/robotic_arm.pde: -------------------------------------------------------------------------------- 1 | float angle = 0.0; 2 | float angleDirection = 1; 3 | float speed = 0.005; 4 | void setup() { 5 | size(120, 120); 6 | smooth(); 7 | } 8 | void draw() { 9 | background(204); 10 | translate(20, 25); 11 | // Move to start position 12 | rotate(angle); 13 | strokeWeight(12); 14 | line(0, 0, 40, 0); 15 | translate(40, 0); 16 | // Move to next joint 17 | rotate(angle * 2.0); 18 | strokeWeight(6); 19 | line(0, 0, 30, 0); 20 | translate(30, 0); 21 | // Move to next joint 22 | rotate(angle * 2.5); 23 | strokeWeight(3); 24 | line(0, 0, 20, 0); 25 | angle += speed * angleDirection; 26 | if ((angle > QUARTER_PI) || (angle < 0)) { 27 | angleDirection *= -1; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Android-Basics/rotating_sq.pde: -------------------------------------------------------------------------------- 1 | float angle = 0.0; 2 | void setup() { 3 | size(120, 120); 4 | smooth(); 5 | } 6 | void draw() { 7 | translate(mouseX, mouseY); 8 | rotate(angle); 9 | rect(-15, -15, 30, 30); 10 | angle += 0.1; 11 | } 12 | -------------------------------------------------------------------------------- /Android-Basics/scale_sq.pde: -------------------------------------------------------------------------------- 1 | float angle = 0.0; 2 | void setup() { 3 | size(120, 120); 4 | smooth(); 5 | } 6 | void draw() { 7 | translate(mouseX, mouseY); 8 | scale(sin(angle) + 2); 9 | rect(-15, -15, 30, 30); 10 | angle += 0.1; 11 | } 12 | -------------------------------------------------------------------------------- /Android-Basics/shades.pde: -------------------------------------------------------------------------------- 1 | float[] gray; 2 | void setup() { 3 | size(240, 120); 4 | gray = new float[width]; 5 | for (int i = 0; i < gray.length; i++) { 6 | gray[i] = random(0, 255); 7 | } 8 | } 9 | void draw() { 10 | for (int i = 0; i < gray.length; i++) { 11 | stroke(gray[i]); 12 | line(i, 0, i, height); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Android-Basics/sketch_200513a.pde: -------------------------------------------------------------------------------- 1 | void settings() { 2 | size(500,500); 3 | } 4 | void draw() { 5 | line(mouseX, mouseY, width, height); 6 | } 7 | 8 | void mousePressed() { 9 | exit(); 10 | } 11 | -------------------------------------------------------------------------------- /Android-Basics/smooth.pde: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Android-Basics/spiral_animation.pde: -------------------------------------------------------------------------------- 1 | float angle = 0.0; 2 | float offset = 60; 3 | float scalar = 2; 4 | float speed = 0.05; 5 | void setup() { 6 | size(120, 120); 7 | fill(0); 8 | smooth(); 9 | } 10 | void draw() { 11 | float x = offset + cos(angle) * scalar; 12 | float y = offset + sin(angle) * scalar; 13 | ellipse( x, y, 10, 10); 14 | angle += speed; 15 | scalar += speed; 16 | } 17 | -------------------------------------------------------------------------------- /Android-Basics/test.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | 3 | noSmooth(); 4 | noStroke(); 5 | } 6 | void settings() { 7 | size(100, 100, P2D); 8 | } 9 | void draw() { 10 | background(0); 11 | ellipse(30, 48, 36, 36); 12 | ellipse(70, 48, 36, 36); 13 | } 14 | -------------------------------------------------------------------------------- /Android-Basics/threeDCube.pde: -------------------------------------------------------------------------------- 1 | float angle = 0; 2 | boolean rotating = true; 3 | void setup() { 4 | fill(#AD71B7); 5 | } 6 | void settings() { 7 | fullScreen(P3D); 8 | 9 | } 10 | void draw() { 11 | background(#81B771); 12 | lights(); 13 | translate(width/2, height/2); 14 | rotateY(angle); 15 | rotateX(angle*2); 16 | box(300); 17 | angle += 0.01; 18 | } 19 | 20 | void mousePressed() { 21 | if(rotating){ 22 | noLoop(); 23 | rotating = false; 24 | } 25 | else { 26 | loop(); 27 | rotating = true; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Android-Basics/timer_ellipse.pde: -------------------------------------------------------------------------------- 1 | int time1 = 2000; 2 | int time2 = 4000; 3 | float x = 0; 4 | void setup() { 5 | size(480, 120); 6 | smooth(); 7 | } 8 | void draw() { 9 | int currentTime = millis(); 10 | background(204); 11 | if (currentTime > time2) { 12 | x -= 0.5; 13 | } else if (currentTime > time1) { 14 | x += 2; 15 | } 16 | ellipse(x, 60, 90, 90); 17 | } 18 | -------------------------------------------------------------------------------- /Android-Basics/trac_mouse.pde: -------------------------------------------------------------------------------- 1 | int num = 60; 2 | int x[] = new int[num]; 3 | int y[] = new int[num]; 4 | void setup() { 5 | size(240, 120); 6 | smooth(); 7 | noStroke(); 8 | } 9 | void draw() { 10 | background(0); 11 | // Copy array values from back to front 12 | for (int i = x.length-1; i > 0; i--) { 13 | x[i] = x[i-1]; 14 | y[i] = y[i-1]; 15 | } 16 | x[0] = mouseX; // Set the first element 17 | y[0] = mouseY; // Set the first element 18 | for (int i = 0; i < x.length; i++) { 19 | fill(i * 4); 20 | ellipse(x[i], y[i], 40, 40); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Android-Basics/translate_basics.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(800, 800); 3 | } 4 | void draw() { 5 | translate(mouseX, mouseY); 6 | rect(0, 0, 50, 50); 7 | } 8 | -------------------------------------------------------------------------------- /Android-Basics/tweening.pde: -------------------------------------------------------------------------------- 1 | int startX = 20; // Initial x-coordinate 2 | int stopX = 160; // Final x-coordinate 3 | int startY = 30; // Initial y-coordinate 4 | int stopY = 80; // Final y-coordinate 5 | float x = startX; // Current x-coordinate 6 | float y = startY; // Current y-coordinate 7 | float step = 0.005; // Size of each step (0.0 to 1.0) 8 | float pct = 0.0; // Percentage traveled (0.0 to 1.0) 9 | void setup() { 10 | size(240, 120); 11 | smooth(); 12 | } 13 | void draw() { 14 | background(0); 15 | if (pct < 1.0) { 16 | x = startX + ((stopX-startX) * pct); 17 | y = startY + ((stopY-startX) * pct); 18 | pct += step; 19 | } 20 | ellipse(x, y, 20, 20); 21 | } 22 | -------------------------------------------------------------------------------- /AndroidAR/Basic/basic.pde: -------------------------------------------------------------------------------- 1 | 2 | import processing.ar.*; 3 | 4 | ARTracker tracker; 5 | ARAnchor anchor; 6 | 7 | void setup() { 8 | fullScreen(AR); 9 | tracker = new ARTracker(this); 10 | tracker.start(); 11 | } 12 | 13 | void draw() { 14 | lights(); 15 | 16 | if (mousePressed) { 17 | if (anchor != null) anchor.dispose(); 18 | ARTrackable hit = tracker.get(mouseX, mouseY); 19 | if (hit != null) anchor = new ARAnchor(hit); 20 | else anchor = null; 21 | } 22 | 23 | if (anchor != null) { 24 | anchor.attach(); 25 | box(100); 26 | anchor.detach(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AndroidAR/Rotating-Cube/cubes.pde: -------------------------------------------------------------------------------- 1 | import processing.ar.*; 2 | 3 | ARTracker tracker; 4 | ARAnchor touchAnchor; 5 | ArrayList trackAnchors; 6 | float angle; 7 | 8 | void setup() { 9 | fullScreen(AR); 10 | tracker = new ARTracker(this); 11 | tracker.start(); 12 | trackAnchors = new ArrayList(); 13 | } 14 | 15 | void draw() { 16 | // The AR Core session, frame and camera can be accessed through Processing's surface object 17 | // to obtain the full information about the AR scene: 18 | // ARSurface surface = (ARSurface) getSurface(); 19 | // surface.camera.getPose(); 20 | // surface.frame.getLightEstimate(); 21 | 22 | lights(); 23 | 24 | if (mousePressed) { 25 | // Create new anchor at the current touch point 26 | if (touchAnchor != null) touchAnchor.dispose(); 27 | ARTrackable hit = tracker.get(mouseX, mouseY); 28 | if (hit != null) touchAnchor = new ARAnchor(hit); 29 | else touchAnchor = null; 30 | } 31 | 32 | // Draw objects attached to each anchor 33 | for (ARAnchor anchor : trackAnchors) { 34 | if (anchor.isTracking()) drawBox(anchor, 255, 255, 255); 35 | 36 | // It is very important to dispose anchors once they are no longer tracked. 37 | if (anchor.isStopped()) anchor.dispose(); 38 | } 39 | if (touchAnchor != null) drawBox(touchAnchor, 255, 0, 0); 40 | 41 | // Conveniency function in the tracker object to remove disposed anchors from a list 42 | tracker.clearAnchors(trackAnchors); 43 | 44 | // Draw trackable planes 45 | for (int i = 0; i < tracker.count(); i++) { 46 | ARTrackable trackable = tracker.get(i); 47 | if (!trackable.isTracking()) continue; 48 | 49 | pushMatrix(); 50 | trackable.transform(); 51 | if (mousePressed && trackable.isSelected(mouseX, mouseY)) { 52 | fill(255, 0, 0, 100); 53 | } else { 54 | fill(255, 100); 55 | } 56 | beginShape(); 57 | float[] points = trackable.getPolygon(); 58 | for (int n = 0; n < points.length / 2; n++) { 59 | float x = points[2 * n]; 60 | float z = points[2 * n + 1]; 61 | vertex(x, 0, z); 62 | } 63 | endShape(); 64 | popMatrix(); 65 | } 66 | 67 | angle += 0.1; 68 | } 69 | 70 | void drawBox(ARAnchor anchor, int r, int g, int b) { 71 | anchor.attach(); 72 | fill(r, g, b); 73 | rotateY(angle); 74 | box(0.15f); 75 | anchor.detach(); 76 | } 77 | 78 | void trackableEvent(ARTrackable t) { 79 | if (trackAnchors.size() < 10) { 80 | float x0 = 0, y0 = 0; 81 | if (t.isWallPlane()) { 82 | // The new trackable is a wall, so adding the anchor 0.3 meters to its side 83 | x0 = 0.3; 84 | } else if (t.isFloorPlane()) { 85 | // The new trackable is a floor plane, so adding the anchor 0.3 meters above it 86 | y0 = 0.3; 87 | } else { 88 | // The new trackable is a floor plane, so adding the anchor 0.3 meters below it 89 | y0 = -0.3; 90 | } 91 | trackAnchors.add(new ARAnchor(t, x0, y0, 0.0)); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /AndroidAR/Sphere/sphere.pde: -------------------------------------------------------------------------------- 1 | import processing.ar.*; 2 | 3 | ARTracker tracker; 4 | ARAnchor anchor; 5 | PShape arObj; 6 | float angle; 7 | 8 | void setup() { 9 | fullScreen(AR); 10 | 11 | noStroke(); 12 | 13 | tracker = new ARTracker(this); 14 | tracker.start(); 15 | } 16 | 17 | void draw() { 18 | lights(); 19 | 20 | if (mousePressed) { 21 | // Create new anchor at the current touch point 22 | if (anchor != null) anchor.dispose(); 23 | ARTrackable hit = tracker.get(mouseX, mouseY); 24 | if (hit != null) anchor = new ARAnchor(hit); 25 | else anchor = null; 26 | } 27 | 28 | if (anchor != null) { 29 | anchor.attach(); 30 | fill(217, 121, 255); 31 | sphere(0.1); 32 | rotateY(angle); 33 | translate(0, 0, 0.3); 34 | sphere(0.05); 35 | angle += 0.1; 36 | anchor.detach(); 37 | } 38 | 39 | // Draw trackable planes 40 | for (int i = 0; i < tracker.count(); i++) { 41 | ARTrackable trackable = tracker.get(i); 42 | if (!trackable.isTracking()) continue; 43 | 44 | pushMatrix(); 45 | trackable.transform(); 46 | if (mousePressed && trackable.isSelected(mouseX, mouseY)) { 47 | fill(255, 0, 0, 100); 48 | } else { 49 | fill(255, 100); 50 | } 51 | 52 | beginShape(QUADS); 53 | float lx = trackable.lengthX(); 54 | float lz = trackable.lengthZ(); 55 | vertex(-lx/2, 0, -lz/2); 56 | vertex(-lx/2, 0, +lz/2); 57 | vertex(+lx/2, 0, +lz/2); 58 | vertex(+lx/2, 0, -lz/2); 59 | endShape(); 60 | popMatrix(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /AndroidVR/Animation/animation.pde: -------------------------------------------------------------------------------- 1 | import processing.vr.*; 2 | 3 | VRCamera cam; 4 | 5 | void setup() { 6 | fullScreen(VR); 7 | cam = new VRCamera(this); 8 | } 9 | 10 | void calculate() { 11 | println("in calculate function"); 12 | } 13 | 14 | void draw() { 15 | background(150); 16 | translate(width/2, height/2); 17 | noStroke(); 18 | 19 | // Some lights 20 | pointLight(255, 255, 255, 0, 0, 500); 21 | 22 | // Floor 23 | beginShape(QUADS); 24 | fill(255, 0, 0); 25 | normal(0, 0, -1); 26 | vertex(-width/2, +500, -width/2); 27 | fill(0, 0, 255); 28 | vertex(-width/2, +500, +width/2); 29 | vertex(+width/2, +500, +width/2); 30 | fill(255, 0, 0); 31 | vertex(+width/2, +500, -width/2); 32 | endShape(); 33 | 34 | // Large box at the center 35 | pushMatrix(); 36 | rotateY(millis()/1000.0); 37 | fill(220); 38 | box(200); 39 | popMatrix(); 40 | 41 | // Red box, X axis 42 | pushMatrix(); 43 | translate(200, 0, 0); 44 | fill(255, 0, 0); 45 | box(100); 46 | popMatrix(); 47 | 48 | // Green box, Y axis 49 | pushMatrix(); 50 | translate(0, 200, 0); 51 | fill(0, 255, 0); 52 | box(100); 53 | popMatrix(); 54 | 55 | // Blue box, Z axis 56 | pushMatrix(); 57 | translate(0, 0, 200); 58 | fill(0, 0, 255); 59 | box(100); 60 | popMatrix(); 61 | 62 | // Use eye coordinates at 100 units from the camera position:; 63 | cam.sticky(); 64 | stroke(255, 200); 65 | strokeWeight(50); 66 | point(0, 0, 100); 67 | cam.noSticky(); 68 | } 69 | -------------------------------------------------------------------------------- /AndroidVR/Box/box.pde: -------------------------------------------------------------------------------- 1 | import processing.vr.*; 2 | 3 | VRCamera cam; 4 | float rotSpeed = 0.3; 5 | float rotAngle = 0; 6 | 7 | void setup() { 8 | fullScreen(VR); 9 | cameraUp(); 10 | cam = new VRCamera(this); 11 | } 12 | 13 | void draw() { 14 | background(200, 0, 150); 15 | 16 | cam.setPosition(0, 0, 200); 17 | push(); 18 | rotateZ(radians(rotAngle)); 19 | translate(100, 0, 0); 20 | fill(255, 0, 0); 21 | if (intersectsBox(50, 0, 0)) { 22 | rotAngle += rotSpeed; 23 | fill(0, 0, 255); 24 | } 25 | box(50); 26 | pop(); 27 | } 28 | -------------------------------------------------------------------------------- /AndroidVR/Cube/cube.pde: -------------------------------------------------------------------------------- 1 | import processing.vr.*; 2 | 3 | void setup() { 4 | fullScreen(VR); 5 | } 6 | 7 | void draw() { 8 | background(157); 9 | lights(); 10 | translate(width/2, height/2); 11 | rotateX(frameCount * 0.01); 12 | rotateY(frameCount * 0.01); 13 | box(350); 14 | } 15 | -------------------------------------------------------------------------------- /AndroidVR/Intersect-Sphere/intersectsphere.pde: -------------------------------------------------------------------------------- 1 | import processing.vr.*; 2 | 3 | float[] randomx = new float[5]; 4 | float[] randomy = new float[5]; 5 | VRCamera cam; 6 | 7 | void setup() { 8 | fullScreen(VR); 9 | cameraUp(); 10 | cam = new VRCamera(this); 11 | 12 | for (int i = 0; i < 5; ++i) { 13 | randomx[i] = random(-500, 500); 14 | randomy[i] = random(-500, 500); 15 | } 16 | } 17 | 18 | void draw() { 19 | background(200, 0, 150); 20 | 21 | lights(); 22 | noStroke(); 23 | cam.setPosition(0, 0, 400); 24 | for (int i = 0; i < 5; ++i) { 25 | push(); 26 | translate(randomx[i], randomy[i]); 27 | fill(255, 0, 0); 28 | if (intersectsSphere(70, 0, 0)) { 29 | fill(0, 0, 255); 30 | } 31 | sphere(70); 32 | pop(); 33 | } 34 | 35 | cam.sticky(); 36 | strokeWeight(5 * displayDensity); 37 | stroke(0, 0, 255); 38 | noFill(); 39 | translate(0, 0, 200); 40 | circle(0, 0, 50); 41 | cam.noSticky(); 42 | } 43 | -------------------------------------------------------------------------------- /AndroidVR/Ray/generatedray.pde: -------------------------------------------------------------------------------- 1 | import processing.vr.*; 2 | 3 | PVector origin, direction; 4 | float[] randomx = new float[5]; 5 | float[] randomy = new float[5]; 6 | float[] randomz = new float[5]; 7 | VRCamera cam; 8 | 9 | void setup() { 10 | fullScreen(VR); 11 | cameraUp(); 12 | cam = new VRCamera(this); 13 | 14 | for (int i = 0; i < 5; ++i) { 15 | randomx[i] = random(-500, 500); 16 | randomy[i] = random(-500, 500); 17 | randomz[i] = random(-100, 100); 18 | } 19 | noStroke(); 20 | 21 | origin = new PVector(randomx[0], randomy[0], randomz[0]); 22 | direction = new PVector(); 23 | } 24 | 25 | void draw() { 26 | background(200, 0, 150); 27 | lights(); 28 | 29 | cam.setPosition(0, 0, 400); 30 | push(); 31 | translate(randomx[0], randomy[0], randomz[0]); 32 | fill(0, 255, 0); 33 | sphere(30); 34 | 35 | int r = floor(random(1, 5)); 36 | float rx = randomx[r] - randomx[0]; 37 | float ry = randomy[r] - randomy[0]; 38 | float rz = randomz[r] - randomz[0]; 39 | stroke(0); 40 | strokeWeight(1 * displayDensity); 41 | line(0, 0, 0, rx, ry, rz); 42 | noStroke(); 43 | 44 | direction.set(rx, ry, rz); 45 | direction.normalize(); 46 | 47 | pop(); 48 | 49 | for (int i = 1; i < 5; ++i) { 50 | push(); 51 | translate(randomx[i], randomy[i], randomz[i]); 52 | fill(255, 0, 0); 53 | if (intersectsSphere(70, origin, direction)) { 54 | fill(0, 0, 255); 55 | } 56 | sphere(70); 57 | pop(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /AndroidVR/mono.pde: -------------------------------------------------------------------------------- 1 | import processing.vr.*; 2 | 3 | void setup() { 4 | fullScreen(MONO); 5 | } 6 | 7 | void draw() { 8 | background(157); 9 | lights(); 10 | translate(width/2, height/2); 11 | rotateX(frameCount * 0.01f); 12 | rotateY(frameCount * 0.01f); 13 | box(500); 14 | } 15 | -------------------------------------------------------------------------------- /ApacheaFeather/ApacheaFeather.pde: -------------------------------------------------------------------------------- 1 | /** 2 | @author Barbara Almedia 3 | @edited by ranaaditya 4 | */ 5 | 6 | // counter to save the image of feather in each frame after clicks 7 | int imageCounter = 1; 8 | 9 | PGraphics bg, //background 10 | feather, //feather 11 | shadow; //shadow of the feather 12 | 13 | 14 | /*----------------------------*/ 15 | 16 | 17 | void setup() 18 | { 19 | size(800, 400); 20 | colorMode(HSB, 360, 100, 100); 21 | noLoop(); 22 | 23 | 24 | feather = createGraphics(width, height); 25 | shadow = createGraphics(width, height); 26 | bg = createGraphics(width, height); 27 | 28 | setBG(bg); 29 | } 30 | 31 | 32 | /*----------------------------*/ 33 | 34 | 35 | void draw() 36 | { 37 | createFeather(width/6, 2*height/3, PI/9, 2*width/3); 38 | 39 | image(bg, 0, 0); 40 | image(shadow, 10, 10); 41 | filter(BLUR, 2); 42 | 43 | image(feather, 0, 0); 44 | saveFrame("Feather"+imageCounter+".jpg"); 45 | } 46 | 47 | 48 | /*----------------------------*/ 49 | 50 | 51 | void mouseReleased() 52 | { 53 | redraw(); 54 | } 55 | 56 | 57 | /*----------------------------*/ 58 | 59 | 60 | void setBG(PGraphics bg) 61 | { 62 | bg.beginDraw(); 63 | bg.loadPixels(); 64 | for (int x = 0; x < width; x++) 65 | { 66 | for (int y = 0; y < height; y++) 67 | { 68 | float c = 360; 69 | if ((x + y) > width/2) { c = map(x + y, width/2, width + height, 360, 320); } 70 | bg.pixels[x + y*width] = color(c); 71 | } 72 | } 73 | bg.updatePixels(); 74 | bg.endDraw(); 75 | } 76 | 77 | 78 | /*----------------------------*/ 79 | 80 | 81 | void createFeather(float beginX, float beginY, float angle, float lFeather) 82 | { 83 | 84 | //INITIALIZE PARAMETERS// 85 | 86 | //transitions 87 | float lCalamus = 50; //length of the calamus (begin of the feather without barbs 88 | float tip = 10; //length of the tip (diference between the end of the barbs and the end of the hachis) 89 | 90 | float bAfterfeathers = 0.15; //begin of the afterfeathers (begin of the barbs) 91 | float bVane = 0.3; //begin of the vane (end fo the afterfeathers and begin of the organized barbs) 92 | 93 | //curvature of the feather 94 | float deltaCP1y = random(-50, 50); 95 | float deltaCP2y = random(-50, 50); 96 | 97 | float deltaBP1y = random(40, 80); 98 | float deltaBP2y = random(50, 90); 99 | 100 | float deltaTP1y = random(40, 80); 101 | float deltaTP2y = random(50, 90); 102 | 103 | //colors of the feather 104 | float h1= random(360); //main hue 105 | float h2 = random(360); //second hue 106 | float colorChange = random(bVane, 0.75); //point where the hue start to change 107 | 108 | 109 | 110 | //BEGIN DRAWING// 111 | 112 | feather.beginDraw(); 113 | feather.colorMode(HSB, 360, 100, 100); 114 | feather.noFill(); 115 | feather.smooth(); 116 | feather.background(0, 0); 117 | feather.translate(beginX, beginY); 118 | feather.rotate(-angle); 119 | 120 | shadow.beginDraw(); 121 | shadow.noFill(); 122 | shadow.stroke(220); 123 | shadow.background(0, 0); 124 | shadow.translate(beginX, beginY); 125 | shadow.rotate(-angle); 126 | 127 | 128 | //DEFINE THE FORM OF THE FEATHER// 129 | //center 130 | PVector cBegin = new PVector ( 0, 0 ); 131 | PVector cP1 = new PVector ( 0, deltaCP1y ); 132 | PVector cP2 = new PVector ( lFeather, deltaCP2y ); 133 | PVector cEnd = new PVector ( lFeather, 0 ); 134 | //bezier(cBegin.x, cBegin.y, cP1.x, cP1.y, cP2.x, cP2.y, cEnd.x, cEnd.y); 135 | 136 | 137 | //bottom 138 | PVector bBegin = new PVector ( cBegin.x + lCalamus, cBegin.y ); 139 | PVector bP1 = new PVector ( cP1.x + lCalamus, cP1.y + deltaBP1y ); 140 | PVector bP2 = new PVector ( cP2.x + tip, cP2.y + deltaBP2y ); 141 | PVector bEnd = new PVector ( cEnd.x + tip, cEnd.y ); 142 | //bezier(bBegin.x, bBegin.y, bP1.x, bP1.y, bP2.x, bP2.y, bEnd.x, bEnd.y); 143 | 144 | 145 | //top 146 | PVector tBegin = new PVector ( cBegin.x + lCalamus, cBegin.y ); 147 | PVector tP1 = new PVector ( cP1.x + lCalamus, cP1.y - deltaTP1y ); 148 | PVector tP2 = new PVector ( cP2.x + tip, cP2.y - deltaTP2y ); 149 | PVector tEnd = new PVector ( cEnd.x + tip, cEnd.y ); 150 | //bezier(tBegin.x, tBegin.y, tP1.x, tP1.y, tP2.x, tP2.y, tEnd.x, tEnd.y); 151 | 152 | 153 | 154 | 155 | //DRAW THE BARBS// 156 | 157 | //initialize the variables that modify the barbs 158 | float deltaBX = 0, deltaTX = 0; 159 | float deltaBY = 0, deltaTY = 0; 160 | 161 | for (float i = bAfterfeathers; i < 1; i += 0.001) 162 | { 163 | //define the points 164 | float cx = bezierPoint(cBegin.x, cP1.x, cP2.x, cEnd.x, i); 165 | float cy = bezierPoint(cBegin.y, cP1.y, cP2.y, cEnd.y, i); 166 | float bx = bezierPoint(bBegin.x, bP1.x, bP2.x, bEnd.x, i); 167 | float by = bezierPoint(bBegin.y, bP1.y, bP2.y, bEnd.y, i); 168 | float tx = bezierPoint(tBegin.x, tP1.x, tP2.x, tEnd.x, i); 169 | float ty = bezierPoint(tBegin.y, tP1.y, tP2.y, tEnd.y, i); 170 | 171 | 172 | //define the direction of the barbs 173 | float rdm = lerp(0.92, 1, i); //more probable to change the direction at the beggining 174 | float maxDeltaX = lerp(25, 0, i); //maximum change is bigger at the beggining 175 | if (random(1) > rdm) deltaBX = random(-maxDeltaX, maxDeltaX); //set the modifier for the bottom part 176 | if (random(1) > rdm) deltaTX = random(-maxDeltaX, maxDeltaX); //set the modifier for the top part 177 | 178 | 179 | //define the fuzzines at the afterfeather 180 | float fuzz = i; 181 | if (fuzz > 0.3) {fuzz = 0;} //definite barbs at the end 182 | else {fuzz = map(fuzz, 0, 0.5, 1, 0);} //fuzzy barbs at the beggining 183 | float fuzziness = random(20, 40); //set de maximum fuzziness 184 | deltaBY = fuzz*random(-fuzziness, fuzziness); //set the modifier for the bottom part 185 | deltaTY = fuzz*random(-fuzziness, fuzziness); //set the modifier for the top part 186 | 187 | 188 | //set the color 189 | if (i < bVane) //lighter colors at the beggining 190 | { 191 | float k = map(i, bAfterfeathers, bVane, 0, 1); 192 | feather.stroke(h1, lerp(1, 100, k), 95, 60); //set saturation 193 | } 194 | else if (i < colorChange) //main color 195 | { 196 | feather.stroke(h1, 100, 95, 60); 197 | } 198 | else //gradually change to the second color 199 | { 200 | color color1 = color(h1, 100, 95); 201 | color color2 = color(h2, 75, 50); 202 | float j = map(i, colorChange, 1, 0, 1); 203 | feather.stroke(lerpColor(color1,color2,j), 60); 204 | } 205 | 206 | 207 | //draw the barbs 208 | feather.strokeWeight(2); 209 | feather.bezier(cx, cy, (cx+bx)/2, cy, (cx+bx)/2, by, bx + deltaBX, by + deltaBY); 210 | feather.bezier(cx, cy, (cx+tx)/2, cy, (cx+tx)/2, ty, tx + deltaTX, ty + deltaTY); 211 | 212 | //draw the shadow of the barbs 213 | shadow.strokeWeight(2); 214 | shadow.bezier(cx, cy, (cx+bx)/2, cy, (cx+bx)/2, by, bx + deltaBX, by + deltaBY); 215 | shadow.bezier(cx, cy, (cx+tx)/2, cy, (cx+tx)/2, ty, tx + deltaTX, ty + deltaTY); 216 | 217 | 218 | } 219 | 220 | 221 | 222 | //DRAW THE HACHIS// 223 | 224 | float oldcx = bezierPoint(cBegin.x, cP1.x, cP2.x, cEnd.x, 0); 225 | float oldcy = bezierPoint(cBegin.y, cP1.y, cP2.y, cEnd.y, 0); 226 | 227 | for (float i = 0; i < 0.75; i += 0.001) 228 | { 229 | //initialize the second point 230 | float cx = bezierPoint(cBegin.x, cP1.x, cP2.x, cEnd.x, i); 231 | float cy = bezierPoint(cBegin.y, cP1.y, cP2.y, cEnd.y, i); 232 | 233 | //draw the hachis 234 | feather.stroke(h1, 10, 90, 70); //set color 235 | feather.strokeWeight(map(i, 0, 0.75, 6, 0)); //set the strokeWeight 236 | feather.line(oldcx, oldcy, cx, cy); //draw the line 237 | 238 | //draw the shadow of the hachis 239 | shadow.strokeWeight(map(i, 0, 0.75, 6, 0)); //set the strokeWeight 240 | shadow.line(oldcx, oldcy, cx, cy); //draw the line 241 | 242 | 243 | oldcx = cx; 244 | oldcy = cy; 245 | } 246 | 247 | 248 | 249 | //FINISH DRAWING// 250 | 251 | feather.resetMatrix(); 252 | feather.endDraw(); 253 | 254 | shadow.resetMatrix(); 255 | shadow.endDraw(); 256 | 257 | } 258 | -------------------------------------------------------------------------------- /ApacheaFeather/Feather1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather1.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather10.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather11.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather12.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather2.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather3.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather4.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather5.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather6.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather7.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather8.jpg -------------------------------------------------------------------------------- /ApacheaFeather/Feather9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/ApacheaFeather/Feather9.jpg -------------------------------------------------------------------------------- /CityBuilder/CityBuilder.pde: -------------------------------------------------------------------------------- 1 | /** 2 | @author David Burnett 3 | @edited by ranaaditya 4 | */ 5 | 6 | int cityNumber = 0; 7 | 8 | int penx = 0; 9 | int peny = 0; 10 | int de = 2; 11 | cLista lista = new cLista(); 12 | int el0 = 0; 13 | 14 | int by; 15 | 16 | // ------------------------------------------------------------ 17 | 18 | void setup() { 19 | size(800, 600); 20 | // size(1024, 768); 21 | // size(screen.width, screen.height); 22 | smooth(); 23 | frameRate(30); 24 | colorMode(HSB, 1); 25 | ellipseMode(CENTER); 26 | stroke(0, 0, 0, 0.7); 27 | background(0, 0, 1); 28 | // strokeWeight(0.3 * de + 1); 29 | strokeWeight(2); 30 | 31 | city(); 32 | } 33 | 34 | // ------------------------------------------------------------ 35 | 36 | void draw() { 37 | int t = 0; 38 | while((t++ < 50) && (el0 < lista.nr)) { 39 | lista._draw(el0++); 40 | } 41 | if (el0 == lista.nr) { 42 | noLoop(); 43 | } 44 | } 45 | 46 | // ------------------------------------------------------------ 47 | 48 | void mouseClicked() { 49 | lista.nr = 0; 50 | el0 = 0; 51 | city(); 52 | background(0, 0, 1); 53 | loop(); 54 | } 55 | 56 | // ------------------------------------------------------------ 57 | 58 | void keyPressed() 59 | { 60 | if( key == 's') { 61 | saveFrame("city"+cityNumber+".jpg"); 62 | cityNumber++; 63 | } 64 | } 65 | 66 | // ------------------------------------------------------------ 67 | 68 | void city() { 69 | 70 | // cielo nero 71 | // rettf(0, 0, width, int(0.95*height)); 72 | // luna 73 | int rag = height / 10; 74 | lista.agg(0, (int)random(rag, width-rag), (int)random(0.3*height, 0.5*height-rag)); 75 | lista.agg(6, rag, 0); 76 | 77 | // strade 78 | PVector p1; 79 | PVector p2; 80 | p1 = proietta(new PVector(-10, 0, 240)); 81 | p2 = proietta(new PVector(-10, 0, -60)); 82 | linea(p1, p2); 83 | p1 = proietta(new PVector(-20, 0, 240)); 84 | p2 = proietta(new PVector(-20, 0, -60)); 85 | linea(p1, p2); 86 | p1 = proietta(new PVector(-40, 0, -5)); 87 | p2 = proietta(new PVector(240, 0, -5)); 88 | linea(p1, p2); 89 | p1 = proietta(new PVector(-40, 0, -15)); 90 | p2 = proietta(new PVector(240, 0, -15)); 91 | linea(p1, p2); 92 | 93 | palazzo(new PVector(40, 0, 80)); 94 | palazzo(new PVector(40, 0, 40)); 95 | for(int z=9; z>0; z--) { 96 | palazzo(new PVector(0, 0, z*40)); 97 | } 98 | for(int x=6; x>=0; x--) { 99 | palazzo(new PVector(x*40, 0, 0)); 100 | } 101 | 102 | // alberi 103 | for(int x=220; x>=0; x-=40) { 104 | albero(new PVector(x, 0, -2)); 105 | albero(new PVector(-2, 0, x)); 106 | } 107 | 108 | // semafori 109 | semaforox(new PVector( 0, 0, 162)); 110 | semaforox(new PVector( 0, 0, 82)); 111 | semaforox(new PVector( 0, 0, 2)); 112 | semaforoz(new PVector(82, 0, 0)); 113 | semaforoz(new PVector( 2, 0, 0)); 114 | 115 | palazzo(new PVector(0, 0, -53)); 116 | } 117 | 118 | // ------------------------------------------------------------ 119 | 120 | PVector proietta(PVector pt) { 121 | float d = 60.00; 122 | float h = 1.50; 123 | float alfa = radians(30); 124 | 125 | float a = pt.x * sin(alfa) - pt.z * cos(alfa); 126 | float b = pt.x * cos(alfa) + pt.z * sin(alfa); 127 | float x = d * a / (b + d); 128 | float y = d * (pt.y - h) / (b + d); 129 | 130 | float sc = height / 90; 131 | return new PVector(0.63*width + sc*x, 0.95*height - sc*y); 132 | } 133 | 134 | // ------------------------------------------------------------ 135 | 136 | void palazzo(PVector pt) { 137 | int tipo = int(random(10)); 138 | int h = int(random(50, 100)); 139 | boolean insegne = false; 140 | switch (tipo) { 141 | case 0: 142 | box3d(new PVector(pt.x+20, h, pt.z+10), new PVector(pt.x+21, h+random(20, 40), pt.z+11)); 143 | box3d(new PVector(pt.x+10, h, pt.z+10), new PVector(pt.x+11, h+random(20, 40), pt.z+11)); 144 | rettangolo_bianco(new PVector(pt.x, h, pt.z), new PVector(pt.x+30, h, pt.z), new PVector(pt.x+30, h, pt.z+30), new PVector(pt.x, h, pt.z+30)); 145 | box3d(new PVector(pt.x, 20, pt.z), new PVector(pt.x+30, h-4, pt.z+30)); 146 | for (int fi=30-3; fi>0; fi-=3) { 147 | linea(proietta(new PVector(pt.x, 20, pt.z+fi)), proietta(new PVector(pt.x, h-4, pt.z+fi))); 148 | linea(proietta(new PVector(pt.x+fi, 20, pt.z)), proietta(new PVector(pt.x+fi, h-4, pt.z))); 149 | } 150 | box3d(pt, new PVector(pt.x+30, 19, pt.z+30)); 151 | insegne = true; 152 | break; 153 | case 1: 154 | int nr = int(random(5, 20)); 155 | for (int i=nr-1; i>=0; i--) { 156 | box3d(new PVector(pt.x, i*4+4, pt.z), new PVector(pt.x+30, i*4+6, pt.z+30)); 157 | } 158 | pilotis(pt, 30, 30, 4); 159 | insegne = true; 160 | break; 161 | case 2: 162 | box3d(new PVector(pt.x+1, h-10, pt.z+1), new PVector(pt.x+29, h, pt.z+29)); 163 | box3d(new PVector(pt.x+ 2, 10, pt.z+22), new PVector(pt.x+ 4, h-10, pt.z+28)); 164 | box3d(new PVector(pt.x+22, 10, pt.z+ 2), new PVector(pt.x+28, h-10, pt.z+ 4)); 165 | box3d(new PVector(pt.x+ 4, 10, pt.z+ 4), new PVector(pt.x+22, h-10, pt.z+22)); 166 | box3d(new PVector(pt.x+ 2, 10, pt.z+ 2), new PVector(pt.x+ 8, h-10, pt.z+ 8)); 167 | basamento(pt, 10); 168 | insegne = true; 169 | break; 170 | case 3: 171 | box3d(new PVector(pt.x+14.5, h, pt.z+14.5), new PVector(pt.x+15.5, h+40, pt.z+15.5)); 172 | if (h > 50) box3d(new PVector(pt.x+2, 50, pt.z+2), new PVector(pt.x+28, h, pt.z+28)); 173 | if (h > 50) box3d(new PVector(pt.x+4, 42, pt.z+4), new PVector(pt.x+26, 50, pt.z+26)); 174 | if (h > 42) box3d(new PVector(pt.x+2, 16, pt.z+2), new PVector(pt.x+28, 42, pt.z+28)); 175 | if (h > 16) box3d(new PVector(pt.x+4, 12, pt.z+4), new PVector(pt.x+26, 16, pt.z+26)); 176 | if (h > 12) basamento(pt, 12); 177 | insegne = true; 178 | break; 179 | case 4: 180 | cilindro3d(new PVector(pt.x, 31, pt.z), h-16, 32, 13, true); 181 | cilindro3d(new PVector(pt.x, 26, pt.z), 4, 32, 13, true); 182 | cilindro3d(new PVector(pt.x, 21, pt.z), 4, 32, 13, true); 183 | cilindro3d(new PVector(pt.x, 16, pt.z), 4, 32, 13, true); 184 | cilindro3d(new PVector(pt.x, 12, pt.z), 4, 32, 11, true); 185 | cilindro3d(new PVector(pt.x, 0, pt.z), 12, 32, 15, false); 186 | break; 187 | case 5: 188 | cilindro3d(new PVector(pt.x, h-2, pt.z), 2, 8, 13, true); 189 | cilindro3d(new PVector(pt.x, h-6, pt.z), 4, 8, 9, true); 190 | cilindro3d(new PVector(pt.x, 8, pt.z), h-14, 8, 13, true); 191 | basamento(pt, 8); 192 | insegne = true; 193 | break; 194 | case 6: // giardino 195 | box3d(pt, new PVector(pt.x+30, pt.y+1, pt.z+30)); 196 | for (int i=0; i<10; i++) { 197 | float pz = map(i, 0, 10, 0, 22); 198 | float px = random(0, pz); 199 | PVector pt0 = new PVector(pt.x+26-px, pt.y+1, pt.z+26-pz+px); 200 | albero(pt0); 201 | } 202 | break; 203 | case 7: 204 | box3d(new PVector(pt.x+5, 32, pt.z+5), new PVector(pt.x+25, h, pt.z+25)); 205 | box3d(new PVector(pt.x+10, 26, pt.z+10), new PVector(pt.x+20, 32, pt.z+20)); 206 | box3d(new PVector(pt.x+5, 26, pt.z+24), new PVector(pt.x+5, 32, pt.z+25)); 207 | box3d(new PVector(pt.x+5, 26, pt.z+18), new PVector(pt.x+5, 32, pt.z+19)); 208 | box3d(new PVector(pt.x+5, 26, pt.z+11), new PVector(pt.x+5, 32, pt.z+12)); 209 | box3d(new PVector(pt.x+24, 26, pt.z+5), new PVector(pt.x+25, 32, pt.z+6)); 210 | box3d(new PVector(pt.x+18, 26, pt.z+5), new PVector(pt.x+19, 32, pt.z+6)); 211 | box3d(new PVector(pt.x+11, 26, pt.z+5), new PVector(pt.x+12, 32, pt.z+6)); 212 | box3d(new PVector(pt.x+ 5, 26, pt.z+5), new PVector(pt.x+ 6, 32, pt.z+6)); 213 | cilindro3d(new PVector(pt.x, 6, pt.z), 20, 25, 15, false); 214 | box3d(new PVector(pt.x+10, 0, pt.z+10), new PVector(pt.x+20, 6, pt.z+20)); 215 | box3d(new PVector(pt.x+5, 0, pt.z+24), new PVector(pt.x+5, 6, pt.z+25)); 216 | box3d(new PVector(pt.x+5, 0, pt.z+18), new PVector(pt.x+5, 6, pt.z+19)); 217 | box3d(new PVector(pt.x+5, 0, pt.z+11), new PVector(pt.x+5, 6, pt.z+12)); 218 | box3d(new PVector(pt.x+24, 0, pt.z+5), new PVector(pt.x+25, 6, pt.z+6)); 219 | box3d(new PVector(pt.x+18, 0, pt.z+5), new PVector(pt.x+19, 6, pt.z+6)); 220 | box3d(new PVector(pt.x+11, 0, pt.z+5), new PVector(pt.x+12, 6, pt.z+6)); 221 | box3d(new PVector(pt.x+ 5, 0, pt.z+5), new PVector(pt.x+ 6, 6, pt.z+6)); 222 | insegne = true; 223 | break; 224 | case 8: 225 | box3d(new PVector(pt.x+2, 6, pt.z+2), new PVector(pt.x+18, h-10, pt.z+18)); 226 | box3d(new PVector(pt.x, 0, pt.z+23), new PVector(pt.x+2, h , pt.z+28)); 227 | box3d(new PVector(pt.x, 0, pt.z+18), new PVector(pt.x+2, h-5, pt.z+23)); 228 | box3d(new PVector(pt.x, 0, pt.z+ 7), new PVector(pt.x+2, h-5, pt.z+12)); 229 | box3d(new PVector(pt.x, 0, pt.z+ 2), new PVector(pt.x+2, h , pt.z+ 7)); 230 | box3d(new PVector(pt.x+23, 0, pt.z), new PVector(pt.x+28, h , pt.z+2)); 231 | box3d(new PVector(pt.x+18, 0, pt.z), new PVector(pt.x+23, h-5, pt.z+2)); 232 | box3d(new PVector(pt.x+ 7, 0, pt.z), new PVector(pt.x+12, h-5, pt.z+2)); 233 | box3d(new PVector(pt.x+ 2, 0, pt.z), new PVector(pt.x+ 7, h , pt.z+2)); 234 | insegne = true; 235 | break; 236 | case 9: 237 | cilindro3d(new PVector(pt.x, 0, pt.z), h, 32, 11, true); 238 | box3d(new PVector(pt.x, 0, pt.z+15), new PVector(pt.x+4, h, pt.z+30)); 239 | box3d(new PVector(pt.x+15, 0, pt.z), new PVector(pt.x+30, h, pt.z+4)); 240 | insegne = true; 241 | break; 242 | } 243 | 244 | if (insegne) { 245 | float iw = random(1, 1.5); 246 | float ih = random(2, 10); 247 | float ipos = random(2, 14); 248 | rettangolo_bianco(new PVector(pt.x+ipos, 4, pt.z-1), new PVector(pt.x+ipos, 4+ih, pt.z-1), new PVector(pt.x+ipos, 4+ih, pt.z-1-iw), new PVector(pt.x+ipos, 4, pt.z-1-iw)); 249 | iw = random(1, 1.5); 250 | ih = random(2, 10); 251 | ipos = random(2, 14) + 15; 252 | rettangolo_bianco(new PVector(pt.x+ipos, 4, pt.z-1), new PVector(pt.x+ipos, 4+ih, pt.z-1), new PVector(pt.x+ipos, 4+ih, pt.z-1-iw), new PVector(pt.x+ipos, 4, pt.z-1-iw)); 253 | iw = random(1, 1.5); 254 | ih = random(2, 10); 255 | ipos = random(2, 14); 256 | rettangolo_bianco(new PVector(pt.x-1, 4, pt.z+ipos), new PVector(pt.x-1, 4+ih, pt.z+ipos), new PVector(pt.x-1-iw, 4+ih, pt.z+ipos), new PVector(pt.x-1-iw, 4, pt.z+ipos)); 257 | iw = random(1, 1.5); 258 | ih = random(2, 10); 259 | ipos = random(2, 14) + 15; 260 | rettangolo_bianco(new PVector(pt.x-1, 4, pt.z+ipos), new PVector(pt.x-1, 4+ih, pt.z+ipos), new PVector(pt.x-1-iw, 4+ih, pt.z+ipos), new PVector(pt.x-1-iw, 4, pt.z+ipos)); 261 | } 262 | } 263 | 264 | // ------------------------------------------------------------ 265 | 266 | void basamento(PVector pt, float h) { 267 | int nr1 = int(random(1, 5)); 268 | int nr2 = int(random(1, 5)); 269 | float inter1 = 27.0 / nr1; 270 | float inter2 = 27.0 / nr2; 271 | box3d(pt, new PVector(pt.x+30, h, pt.z+30)); 272 | rettangolo_rigato(new PVector(pt.x, 6, pt.z+2), new PVector(pt.x, h-2, pt.z+2), new PVector(pt.x, h-2, pt.z+28), new PVector(pt.x, 6, pt.z+28)); 273 | for (int i=0; i p1.y) { 340 | lista.agg(3, (int)p1.x, (int)p1.y); 341 | lista.agg(3, (int)p3.x, (int)p3.y); 342 | lista.agg(3, (int)p5.x, (int)p5.y); 343 | lista.agg(5, (int)p7.x, (int)p7.y); 344 | } 345 | 346 | _dlinea((int)p1.x, (int)p1.y, (int)p3.x, (int)p3.y); 347 | _dlinea((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y); 348 | _dlinea((int)p2.x, (int)p2.y, (int)p4.x, (int)p4.y); 349 | _dlinea((int)p3.x, (int)p3.y, (int)p4.x, (int)p4.y); 350 | _dlinea((int)p3.x, (int)p3.y, (int)p5.x, (int)p5.y); 351 | _dlinea((int)p5.x, (int)p5.y, (int)p6.x, (int)p6.y); 352 | _dlinea((int)p4.x, (int)p4.y, (int)p6.x, (int)p6.y); 353 | if (p7.y > p1.y) { 354 | _dlinea((int)p1.x, (int)p1.y, (int)p7.x, (int)p7.y); 355 | _dlinea((int)p5.x, (int)p5.y, (int)p7.x, (int)p7.y); 356 | } 357 | 358 | striscia(pt2.y - pt1.y, p3, p4, p5, p6); 359 | } 360 | 361 | // ------------------------------------------------------------ 362 | 363 | void cilindro3d(PVector pt, float h, int nrseg, float rad, boolean contorno) { 364 | PVector [][] pv = new PVector[nrseg][2]; 365 | for (int i=0; i 0) { 374 | lista.agg(3, (int)pv[j][0].x, (int)pv[j][0].y); 375 | lista.agg(3, (int)pv[i][0].x, (int)pv[i][0].y); 376 | lista.agg(3, (int)pv[i][1].x, (int)pv[i][1].y); 377 | lista.agg(4, (int)pv[j][1].x, (int)pv[j][1].y); 378 | } 379 | } 380 | } 381 | for (int i=0; i= pv[i][0].x) { 390 | linea(pv[i][0], pv[i][1]); 391 | } 392 | if (contorno) linea(pv[i][0], pv[i][1]); 393 | if (i > 0) { 394 | dlinea(pv[j][0], pv[i][0]); 395 | dlinea(pv[j][1], pv[i][1]); 396 | if (sin(alfa) > 0) striscia(h, pv[i][0], pv[i][1], pv[j][0], pv[j][1]); 397 | } 398 | } 399 | else { 400 | if (pv[(i+1)%nrseg][0].x <= pv[i][0].x) { 401 | linea(pv[i][0], pv[i][1]); 402 | } 403 | } 404 | } 405 | } 406 | 407 | // ------------------------------------------------------------ 408 | 409 | void pilotis(PVector pt0, float dex, float dez, float h) { 410 | int nrx = int((dex - 1) / 6); 411 | int nrz = int((dez - 1) / 6); 412 | float delx = (dex-1) / nrx; 413 | float delz = (dez-1) / nrz; 414 | for (int i=nrz; i>0; i--) { 415 | box3d(new PVector(pt0.x, 0, pt0.z+i*delz), new PVector(pt0.x+1, h, pt0.z+i*delz+1)); 416 | } 417 | for (int i=nrx; i>=0; i--) { 418 | box3d(new PVector(pt0.x+i*delx, 0, pt0.z), new PVector(pt0.x+i*delx+1, h, pt0.z+1)); 419 | } 420 | } 421 | 422 | // ------------------------------------------------------------ 423 | // striscia tratteggiata in orizzontale 424 | 425 | void striscia(float del, PVector p1, PVector p2, PVector p3, PVector p4) { 426 | float r1 = (p1.y - p2.y) / del; 427 | float r2 = (p3.y - p4.y) / del; 428 | float pp = 0; 429 | while (pp < del) { 430 | _linea(int(p1.x), int(p2.y + pp * r1), int(p3.x), int(p4.y + pp * r2)); 431 | pp += 0.5; 432 | } 433 | } 434 | 435 | // ------------------------------------------------------------ 436 | 437 | void rettangolo_bianco(PVector pt1, PVector pt2, PVector pt3, PVector pt4) { 438 | PVector p1 = proietta(pt1); 439 | PVector p2 = proietta(pt2); 440 | PVector p3 = proietta(pt3); 441 | PVector p4 = proietta(pt4); 442 | lista.agg(3, (int)p1.x, (int)p1.y); 443 | lista.agg(3, (int)p2.x, (int)p2.y); 444 | lista.agg(3, (int)p3.x, (int)p3.y); 445 | lista.agg(4, (int)p4.x, (int)p4.y); 446 | linea(p1, p2); 447 | linea(p2, p3); 448 | linea(p3, p4); 449 | linea(p4, p1); 450 | } 451 | 452 | void rettangolo_rigato(PVector pt1, PVector pt2, PVector pt3, PVector pt4) { 453 | rettangolo_bianco(pt1, pt2, pt3, pt4); 454 | striscia(pt2.y - pt1.y, proietta(pt1), proietta(pt2), proietta(pt4), proietta(pt3)); 455 | } 456 | 457 | void rettangolo_nero(PVector pt1, PVector pt2, PVector pt3, PVector pt4) { 458 | PVector p1 = proietta(pt1); 459 | PVector p2 = proietta(pt2); 460 | PVector p3 = proietta(pt3); 461 | PVector p4 = proietta(pt4); 462 | lista.agg(3, (int)p1.x, (int)p1.y); 463 | lista.agg(3, (int)p2.x, (int)p2.y); 464 | lista.agg(3, (int)p3.x, (int)p3.y); 465 | lista.agg(5, (int)p4.x, (int)p4.y); 466 | } 467 | 468 | // ------------------------------------------------------------ 469 | 470 | // rettangolo pieno 471 | void rettf(int sx, int sy, int ex, int ey) { 472 | 473 | int dex = ex - sx; 474 | int dey = ey - sy; 475 | lista.agg(0, sx, sy); 476 | for (int i=0; i dey) { 481 | for (int i=0; i=0; i-=6) { 493 | lista.agg(1, ex - i, ey); 494 | lista.agg(1, ex, ey - i); 495 | } 496 | } 497 | 498 | // ------------------------------------------------------------ 499 | 500 | void _linea(int sx, int sy, int ex, int ey) { 501 | lista.agg(0, sx, sy); 502 | lista.agg(1, ex, ey); 503 | } 504 | 505 | void linea(PVector p1, PVector p2) { 506 | _linea((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y); 507 | } 508 | 509 | // ------------------------------------------------------------ 510 | 511 | void _dlinea(int sx, int sy, int ex, int ey) { 512 | _linea(sx, sy, ex, ey); 513 | _linea(sx, sy, ex, ey); 514 | } 515 | 516 | void dlinea(PVector p1, PVector p2) { 517 | _dlinea((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y); 518 | } 519 | 520 | // ------------------------------------------------------------ 521 | 522 | class cLista { 523 | int mat[][] = new int [100000][3]; 524 | int nr = 0; 525 | PVector [] pv = new PVector[100]; 526 | int nrv = 0; 527 | 528 | cLista() { 529 | for (int i=0; i 0) { 610 | line(px0, py0, px1, py1); 611 | } 612 | } 613 | break; 614 | } 615 | } 616 | } 617 | 618 | // ------------------------------------------------------------ 619 | -------------------------------------------------------------------------------- /CityBuilder/city.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/CityBuilder/city.tif -------------------------------------------------------------------------------- /CityBuilder/city0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/CityBuilder/city0.jpg -------------------------------------------------------------------------------- /CityBuilder/city1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/CityBuilder/city1.jpg -------------------------------------------------------------------------------- /CityBuilder/city2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/CityBuilder/city2.jpg -------------------------------------------------------------------------------- /CityBuilder/city3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/CityBuilder/city3.jpg -------------------------------------------------------------------------------- /CityBuilder/city4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/CityBuilder/city4.jpg -------------------------------------------------------------------------------- /DotField/sketch.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(800, 800, P3D); 3 | background(0); 4 | stroke(255); 5 | strokeWeight(5); 6 | } 7 | 8 | float changerate = 0.005; 9 | float timeslice = 0.0; 10 | float noiseScale = 0.005; 11 | void draw() { 12 | translate(width/2, height/2); 13 | background(0); 14 | rotateX((mouseY - height/2)*2*PI/width); 15 | rotateZ((mouseX - width/2)*2*PI/height); 16 | for(int i = -250; i < 250; i+=10) { 17 | for(int j = -250; j < 250; j+=10) { 18 | point(i, j, noise(i * noiseScale, j * noiseScale, timeslice) * 100 - 50); 19 | } 20 | } 21 | timeslice += changerate; 22 | } 23 | -------------------------------------------------------------------------------- /Dreamer/Dreamer.pde: -------------------------------------------------------------------------------- 1 | /** 2 | @author barbara Almedia 3 | @edited by ranaaditya 4 | */ 5 | 6 | int imageSerial = 0; 7 | 8 | final int nbWeeds = 60; 9 | SeaWeed[] weeds; 10 | PVector rootNoise = new PVector(random(123456), random(123456)); 11 | int mode = 1; 12 | float radius = 220; 13 | Boolean noiseOn = true; 14 | PVector center; 15 | 16 | void setup() 17 | { 18 | size(600, 450, P2D); 19 | center = new PVector(width/2, height/2); 20 | strokeWeight(1); 21 | weeds = new SeaWeed[nbWeeds]; 22 | for (int i = 0; i < nbWeeds; i++) 23 | { 24 | weeds[i] = new SeaWeed(i*TWO_PI/nbWeeds, 3*radius); 25 | } 26 | } 27 | 28 | void draw() 29 | { 30 | //background(50); 31 | noStroke(); 32 | fill(20, 10, 20);//, 50); 33 | rect(0, 0, width, height); 34 | rootNoise.add(new PVector(.01, .01)); 35 | strokeWeight(1); 36 | for (int i = 0; i < nbWeeds; i++) 37 | { 38 | weeds[i].update(); 39 | } 40 | stroke(120, 0, 0, 220); 41 | strokeWeight(2); 42 | noFill(); 43 | ellipse(center.x, center.y, 2*radius, 2*radius); 44 | } 45 | 46 | void keyPressed() 47 | { 48 | if(key == 'n') 49 | { 50 | noiseOn = !noiseOn; 51 | }else 52 | { 53 | mode = (mode + 1) % 2; 54 | } 55 | 56 | if(mousePressed){ 57 | saveFrame("Dream"+imageSerial+".jpg"); 58 | imageSerial++; 59 | } 60 | } 61 | 62 | 63 | class MyColor 64 | { 65 | float R, G, B, Rspeed, Gspeed, Bspeed; 66 | final static float minSpeed = .6; 67 | final static float maxSpeed = 1.8; 68 | final static float minR = 200; 69 | final static float maxR = 255; 70 | final static float minG = 20; 71 | final static float maxG = 120; 72 | final static float minB = 100; 73 | final static float maxB = 140; 74 | 75 | MyColor() 76 | { 77 | init(); 78 | } 79 | 80 | public void init() 81 | { 82 | R = random(minR, maxR); 83 | G = random(minG, maxG); 84 | B = random(minB, maxB); 85 | Rspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed); 86 | Gspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed); 87 | Bspeed = (random(1) > .5 ? 1 : -1) * random(minSpeed, maxSpeed); 88 | } 89 | 90 | public void update() 91 | { 92 | Rspeed = ((R += Rspeed) > maxR || (R < minR)) ? -Rspeed : Rspeed; 93 | Gspeed = ((G += Gspeed) > maxG || (G < minG)) ? -Gspeed : Gspeed; 94 | Bspeed = ((B += Bspeed) > maxB || (B < minB)) ? -Bspeed : Bspeed; 95 | } 96 | 97 | public color getColor() 98 | { 99 | return color(R, G, B); 100 | } 101 | } 102 | class SeaWeed 103 | { 104 | final static float DIST_MAX = 5.5;//length of each segment 105 | final static float maxWidth = 50;//max width of the base line 106 | final static float minWidth = 11;//min width of the base line 107 | final static float FLOTATION = -3.5;//flotation constant 108 | float mouseDist;//mouse interaction distance 109 | int nbSegments; 110 | PVector[] pos;//position of each segment 111 | color[] cols;//colors array, one per segment 112 | float[] rad; 113 | MyColor myCol = new MyColor(); 114 | float x, y;//origin of the weed 115 | float cosi, sinu; 116 | 117 | SeaWeed(float p_rad, float p_length) 118 | { 119 | nbSegments = (int)(p_length/DIST_MAX); 120 | pos = new PVector[nbSegments]; 121 | cols = new color[nbSegments]; 122 | rad = new float[nbSegments]; 123 | cosi = cos(p_rad); 124 | sinu = sin(p_rad); 125 | x = width/2 + radius*cosi; 126 | y = height/2 + radius*sinu; 127 | mouseDist = 40; 128 | pos[0] = new PVector(x, y); 129 | for (int i = 1; i < nbSegments; i++) 130 | { 131 | pos[i] = new PVector(pos[i-1].x - DIST_MAX*cosi, pos[i-1].y - DIST_MAX*sinu); 132 | cols[i] = myCol.getColor(); 133 | rad[i] = 3; 134 | } 135 | } 136 | 137 | void update() 138 | { 139 | PVector mouse = new PVector(mouseX, mouseY); 140 | 141 | pos[0] = new PVector(x, y); 142 | for (int i = 1; i < nbSegments; i++) 143 | { 144 | float n = noise(rootNoise.x + .002 * pos[i].x, rootNoise.y + .002 * pos[i].y); 145 | float noiseForce = (.5 - n) * 7; 146 | if(noiseOn) 147 | { 148 | pos[i].x += noiseForce; 149 | pos[i].y += noiseForce; 150 | } 151 | PVector pv = new PVector(cosi, sinu); 152 | pv.mult(map(i, 1, nbSegments, FLOTATION, .6*FLOTATION)); 153 | pos[i].add(pv); 154 | 155 | //mouse interaction 156 | //if(pmouseX != mouseX || pmouseY != mouseY) 157 | { 158 | float d = PVector.dist(mouse, pos[i]); 159 | if (d < mouseDist)// && pmouseX != mouseX && abs(pmouseX - mouseX) < 12) 160 | { 161 | PVector tmpPV = mouse.get(); 162 | tmpPV.sub(pos[i]); 163 | tmpPV.normalize(); 164 | tmpPV.mult(mouseDist); 165 | tmpPV = PVector.sub(mouse, tmpPV); 166 | pos[i] = tmpPV.get(); 167 | } 168 | } 169 | 170 | PVector tmp = PVector.sub(pos[i-1], pos[i]); 171 | tmp.normalize(); 172 | tmp.mult(DIST_MAX); 173 | pos[i] = PVector.sub(pos[i-1], tmp); 174 | 175 | //keep the points inside the circle 176 | if(PVector.dist(center, pos[i]) > radius) 177 | { 178 | PVector tmpPV = pos[i].get(); 179 | tmpPV.sub(center); 180 | tmpPV.normalize(); 181 | tmpPV.mult(radius); 182 | tmpPV.add(center); 183 | pos[i] = tmpPV.get(); 184 | } 185 | } 186 | 187 | updateColors(); 188 | 189 | if (mode == 0) 190 | { 191 | stroke(0, 100); 192 | } 193 | beginShape(); 194 | noFill(); 195 | for (int i = 0; i < nbSegments; i++) 196 | { 197 | float r = rad[i]; 198 | if (mode == 1) 199 | { 200 | stroke(cols[i]); 201 | vertex(pos[i].x, pos[i].y); 202 | //line(pos[i].x, pos[i].y, pos[i+1].x, pos[i+1].y); 203 | } else 204 | { 205 | fill(cols[i]); 206 | noStroke(); 207 | ellipse(pos[i].x, pos[i].y, 2, 2); 208 | } 209 | } 210 | endShape(); 211 | } 212 | 213 | void updateColors() 214 | { 215 | myCol.update(); 216 | cols[0] = myCol.getColor(); 217 | for (int i = nbSegments-1; i > 0; i--) 218 | { 219 | cols[i] = cols[i-1]; 220 | } 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /FlowField/sketch.pde: -------------------------------------------------------------------------------- 1 | Particle[] particles = new Particle[4000]; 2 | PGraphics bg; 3 | 4 | int bgc = color(255, 255, 255); 5 | int fgc = color(0, 0, 0); 6 | int tc = color(255, 204, 0); 7 | 8 | void setup() { 9 | background(bgc); 10 | fullScreen(); 11 | fill(255,255,255, 2); 12 | for(int i = 0; i < particles.length; i++) { 13 | particles[i] = new Particle(); 14 | } 15 | bg = createGraphics(width, height); 16 | bg.beginDraw(); 17 | bg.textFont(createFont("Playfair Display Black", 150, false)); 18 | bg.textAlign(CENTER, CENTER); 19 | bg.fill(255); 20 | bg.stroke(255); 21 | bg.text("DELTA FORCE", width/2, height/2); 22 | bg.endDraw(); 23 | println(bg.pixels.length); 24 | } 25 | 26 | float z = 0; 27 | float noiseScl = 0.003; 28 | int framecounter = 0; 29 | void draw() { 30 | stroke(bgc); 31 | rect(0, 0, width, height); 32 | stroke(fgc); 33 | z += 0.003; 34 | 35 | for(int i = 0; i < particles.length; i++) { 36 | particles[i].update(); 37 | particles[i].trace(); 38 | particles[i].wrap(); 39 | } 40 | } 41 | 42 | class Particle { 43 | 44 | PVector pos, vel, acc, prevpos; 45 | 46 | public Particle() { 47 | this.init(); 48 | } 49 | 50 | void init() { 51 | pos = new PVector(random(width), random(height)); 52 | vel = new PVector(0, 0); 53 | acc = new PVector(0, 0); 54 | prevpos = pos.copy(); 55 | } 56 | 57 | void show() { 58 | ellipse(pos.x, pos.y, 5, 5); 59 | } 60 | 61 | void trace() { 62 | line(prevpos.x, prevpos.y, pos.x, pos.y); 63 | stroke(fgc); 64 | } 65 | 66 | void update() { 67 | PVector force; 68 | 69 | if(bg.pixels[min(bg.pixels.length - 1, floor(pos.y) * width + floor(pos.x))] == color(255)) { 70 | vel.x = random(1) * TWO_PI - PI; 71 | vel.y = random(1) * TWO_PI - PI; 72 | stroke(tc); 73 | } else { 74 | force = PVector.fromAngle(noise(pos.x*noiseScl, pos.y*noiseScl, z) * TWO_PI - PI/3); 75 | force.setMag(0.1); 76 | acc.add(force); 77 | vel.add(acc); 78 | } 79 | vel.limit(1); 80 | updatePrevious(); 81 | pos.add(vel); 82 | acc.mult(0); 83 | } 84 | 85 | void wrap() { 86 | if(pos.x < 0) { 87 | pos.x = width; 88 | pos.y = random(height); 89 | updatePrevious(); 90 | } 91 | if(pos.y < 0) { 92 | pos.y = height; 93 | pos.x = random(width); 94 | updatePrevious(); 95 | } 96 | if(pos.x > width) { 97 | pos.x = 0; 98 | pos.y = random(height); 99 | updatePrevious(); 100 | } 101 | if(pos.y > height) { 102 | pos.y = 0; 103 | pos.x = random(height); 104 | updatePrevious(); 105 | } 106 | } 107 | private void updatePrevious() { 108 | prevpos.x = pos.x; 109 | prevpos.y = pos.y; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /GraphGenerator/generator.pde: -------------------------------------------------------------------------------- 1 | int MAX_RADIUS = 200; 2 | FourierSegment root; 3 | ArrayList test = new ArrayList(); 4 | 5 | void setup() { 6 | fullScreen(); 7 | frameRate(60); 8 | root = new FourierSegment(); 9 | root.radius = 200; 10 | root.offset = 0; 11 | root.frequency = 1 / TWO_PI; 12 | FourierSegment previous = root; 13 | for(int i = 1; i < 2; i++) { 14 | FourierSegment nextSegment = new FourierSegment(); 15 | nextSegment.radius = root.radius / (2 * i + 1); 16 | nextSegment.frequency = (2 * i + 1) / TWO_PI; 17 | nextSegment.offset = (2 * i + 1) / TWO_PI; 18 | previous.childSegment = nextSegment; 19 | previous = nextSegment; 20 | } 21 | smooth(); 22 | } 23 | 24 | void draw() { 25 | background(0); 26 | stroke(20); 27 | line(500, 0, 500, height); 28 | stroke(130); 29 | noFill(); 30 | pushMatrix(); 31 | translate(500, 0); 32 | strokeWeight(1); 33 | beginShape(); 34 | for(int i = 0; i < test.size(); i++) { 35 | vertex(i*2, test.get(i)); 36 | } 37 | endShape(); 38 | strokeWeight(1); 39 | popMatrix(); 40 | root.updateAndRedrawAllChildren(250, height/2, 0); 41 | if(test.size() > 600) { 42 | test.remove(test.size() - 1); 43 | } 44 | } 45 | 46 | class FourierSegment { 47 | 48 | public float frequency, radius, colour, offset; 49 | public FourierSegment childSegment; 50 | 51 | public FourierSegment() { 52 | this(random(-1, 1), 53 | random(1, MAX_RADIUS), 54 | color(random(0,255), random(0,255), random(0, 255)), 55 | random(TWO_PI) 56 | ); 57 | } 58 | public FourierSegment(float frequency, 59 | float radius, 60 | float colour, 61 | float initOffset) { 62 | this.frequency = frequency; 63 | this.radius = radius; 64 | this.colour = colour; 65 | this.offset = initOffset; 66 | } 67 | 68 | public void updateAndRedrawAllChildren(float x, float y, float parentOffset) { 69 | PVector child = PVector.fromAngle(this.offset + parentOffset); 70 | child.mult(this.radius/2); 71 | if(this.childSegment != null) { 72 | this.childSegment.updateAndRedrawAllChildren(x + child.x, y + child.y, this.offset + parentOffset); 73 | } else { 74 | stroke(130); 75 | fill(130); 76 | test.add(0,y+child.y); 77 | line(x+child.x, y+child.y, 500, y+child.y); 78 | ellipse(500, y+child.y, 5, 5); 79 | } 80 | this.offset += TWO_PI / ((1 / this.frequency) * 30); 81 | stroke(255); 82 | noFill(); 83 | ellipse(x, y, this.radius, this.radius); 84 | //child = PVector.fromAngle(this.offset + parentOffset); 85 | //child.mult(this.radius/2); 86 | line(x, y, x + child.x, y + child.y); 87 | fill(255); 88 | ellipse(x + child.x, y + child.y, 5, 5); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Aditya Rana 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Leaf/leaf.pde: -------------------------------------------------------------------------------- 1 | float x, y; 2 | void setup() { 3 | size(800, 800); 4 | background(64, 71, 87); 5 | } 6 | void drawPoint() { 7 | stroke(0, 158, 82); 8 | strokeWeight(0.5); 9 | float px = map(x, -2.1820, 2.6558, 100, width-100); 10 | float py = map(y, 0, 9.9983, height-100, 100); 11 | point(px, py); 12 | } 13 | void nextPoint() { 14 | float nextX, nextY; 15 | float r = random(1); 16 | if (r < 0.01) { 17 | nextX = 0; 18 | nextY = 0.16 * y; 19 | } else if (r < 0.86) { 20 | nextX = 0.85 * x + 0.04 * y; 21 | nextY = -0.04 * x + 0.85 * y + 1.6; 22 | } else if (r < 0.93) { 23 | nextX = 0.20 * x - 0.26 * y; 24 | nextY = 0.23 * x + 0.22 * y + 1.6; 25 | } else { 26 | nextX = -0.15 * x + 0.28 * y; 27 | nextY = 0.26 * x + 0.24 * y + 0.44; 28 | } 29 | x = nextX; 30 | y = nextY; 31 | } 32 | void draw() { 33 | for (int i = 0; i < 100; i++) { 34 | drawPoint(); 35 | nextPoint(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /MountainScenery/MountainScenery.pde: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | @author barbara Almedia 4 | @edited by ranaaditya 5 | */ 6 | 7 | // image number to save screen as frames on each click 8 | int imageSerial = 0; 9 | 10 | color cClouds, cFade, cFurther, cCloser, cMist; 11 | 12 | 13 | void setup() 14 | { 15 | size(800, 600); 16 | smooth(); 17 | 18 | //define the colors 19 | colorMode(HSB, 360, 100, 100); 20 | cClouds = color(330, 25, 100); //light rose for the clouds 21 | cFade = color(220, 50, 50); // purplish saturated medium blue for the fade of the sky 22 | cFurther = color(230, 25, 90); //purplish unsaturated light bluse for the further mountains 23 | cCloser = color(210, 70, 10); //greeny saturated dark blue for the closer mountains 24 | cMist = color(360); //white for the mist 25 | } 26 | 27 | 28 | /*------------------------------------*/ 29 | 30 | 31 | void draw() 32 | { 33 | noLoop(); 34 | background(230, 25, 90); 35 | 36 | fade(cFade); 37 | clouds(cClouds); 38 | mountains(cCloser, cFurther, cMist); 39 | } 40 | 41 | 42 | /*------------------------------------*/ 43 | 44 | 45 | void mousePressed() 46 | { 47 | loop(); 48 | } 49 | 50 | 51 | /*------------------------------------*/ 52 | 53 | 54 | void keyPressed() //save the framme when we press the letter s 55 | { 56 | if (key == 's' || key =='S') 57 | { 58 | saveFrame("landscape"+imageSerial+".png"); 59 | } 60 | } 61 | 62 | 63 | /*------------------------------------*/ 64 | 65 | 66 | void fade(color fadeColor) 67 | { 68 | for(int i = 0; i < height/3; i++) 69 | { 70 | float alfa = map(i, 0, height/3, 360, 0); 71 | 72 | strokeWeight(1); 73 | stroke(fadeColor, alfa); 74 | line(0, i, width, i); 75 | } 76 | } 77 | 78 | 79 | /*------------------------------------*/ 80 | 81 | 82 | void clouds(color cloudColor) 83 | { 84 | float begin = random(50); //changes the begin of noise each time 85 | 86 | float i = 0; 87 | 88 | for(int x = 0; x < width; x += 2) 89 | { 90 | float j = 0; 91 | 92 | for(int y = 0; y < height/3; y += 2) 93 | { 94 | float alfaMax = map(y, 0, height/4, 520, 0); //the clouds become transparent as they become near to the mountains 95 | float alfa = noise(begin + i, begin + j); 96 | alfa = map(alfa, 0.4, 1, 0, alfaMax); 97 | 98 | noStroke(); 99 | fill(cloudColor, alfa); 100 | ellipse(x, y, 2, 2); 101 | 102 | j += 0.06; //increase j faster than i so the clouds look horizontal 103 | } 104 | 105 | i += 0.01; 106 | } 107 | } 108 | 109 | 110 | /*------------------------------------*/ 111 | 112 | 113 | void mountains(color closerColor, color furtherColor, color mistColor) 114 | { 115 | //FIND THE REFERENCE Y OF EACH MOUNTAIN: 116 | float y0 = width - 500; //fist reference y 117 | int i0 = 30; //initial interval 118 | 119 | float[] cy = new float[10]; //initialize the reference y array 120 | for (int j = 0; j < 10; j++) 121 | { 122 | cy[9-j] = y0; 123 | y0 -= i0 / pow(1.2, j); 124 | } 125 | 126 | 127 | //DRAW THE MOUNTAINS/ 128 | float dx = 0; 129 | 130 | for (int j = 1; j < 10; j++) 131 | { 132 | float a = random(-width/2, width/2); //random discrepancy between the sin waves 133 | float b = random(-width/2, width/2); //random discrepancy between the sin waves 134 | float c = random(2, 4); //random amplitude for the second sin wave 135 | float d = random(40, 50); //noise function amplitude 136 | float e = random(-width/2, width/2); //adds a discrepancy between the noise of each mountain 137 | 138 | for (int x = 0; x < width; x ++) 139 | { 140 | float y = cy[j]; //y = reference y 141 | y += 10*j*sin(2*dx/j + a); //first sin wave oscillates according to j (the closer the mountain, the bigger the amplitude and smaller the frequency) 142 | y += c*j*sin(5*dx/j + b); //second sin wave has a random medium amplitude (affects more the further mountains) and bigger frequenc 143 | y += d*j*noise(1.2*dx/j +e); //first noise function adds randomness to the mountains, amplitude depends on a random number and increases with j, frequency decrases with j 144 | y += 1.7*j*noise(10*dx); //second noise function simulates the canopy, it has high frequency and small amplitude depending on j so it is smoother on the further mountains 145 | 146 | strokeWeight(2); //mountains look smoother with stroke weight of 2 147 | stroke(lerpColor(furtherColor, closerColor, j/9)); 148 | line(x, y, x, height); 149 | 150 | dx += 0.02; 151 | } 152 | 153 | 154 | //ADD MIST 155 | for (int i = height; i > cy[j]; i -= 3) 156 | { 157 | float alfa = map(i, cy[j], height, 0, 360/(j+1)); //alfa is begins bigger for the further mountains 158 | strokeWeight(3); //interval of 3 for faster rendering 159 | stroke(mistColor, alfa); 160 | line(0, i, width, i); 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /MountainScenery/landscape0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/MountainScenery/landscape0.png -------------------------------------------------------------------------------- /MountainScenery/landscape1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/MountainScenery/landscape1.png -------------------------------------------------------------------------------- /MountainScenery/landscape2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/MountainScenery/landscape2.png -------------------------------------------------------------------------------- /MountainScenery/landscape3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/MountainScenery/landscape3.png -------------------------------------------------------------------------------- /MountainScenery/landscape4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/MountainScenery/landscape4.png -------------------------------------------------------------------------------- /MountainScenery/landscape5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/MountainScenery/landscape5.png -------------------------------------------------------------------------------- /MountainScenery/landscape6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/MountainScenery/landscape6.png -------------------------------------------------------------------------------- /MountainScenery/landscape7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/MountainScenery/landscape7.png -------------------------------------------------------------------------------- /MountainScenery/landscape8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/MountainScenery/landscape8.png -------------------------------------------------------------------------------- /ParticleSystem/particlesystem.pde: -------------------------------------------------------------------------------- 1 | ArrayList particles; 2 | int NUM_PARTICLES = 400; 3 | float particleSpeed = 2; 4 | int maxdistance = 100; 5 | int bg = color(00, 00, 00); 6 | int fg = color(211, 54, 130); 7 | 8 | PGraphics textconstraint; 9 | 10 | void setup() { 11 | fullScreen(); 12 | stroke(fg); 13 | fill(fg); 14 | particles = new ArrayList(); 15 | for(int i = 0; i < NUM_PARTICLES; i++) { 16 | particles.add(new Particle()); 17 | } 18 | maxdistance *= maxdistance; 19 | } 20 | 21 | void draw() { 22 | background(bg); 23 | for(int i = 0; i < NUM_PARTICLES; i++) { 24 | particles.get(i).update(); 25 | //particles.get(i).show(); 26 | } 27 | for(int j = 0; j < NUM_PARTICLES; j++) { 28 | int connections = 0; 29 | boolean noDraw = false; 30 | for(int i = 0; i < NUM_PARTICLES; i++) { 31 | /*if(textconstraint.pixels[min(textconstraint.pixels.length - 1, floor(particles.get(j).pos.y * width + particles.get(j).pos.x))] != color(255)) { 32 | particles.get(j).reinit(); 33 | noDraw = true; 34 | } else*/ if(Math.pow(particles.get(i).pos.x - particles.get(j).pos.x, 2) 35 | + Math.pow(particles.get(i).pos.y - particles.get(j).pos.y, 2) 36 | < maxdistance) { 37 | line(particles.get(j).pos.x, particles.get(j).pos.y, particles.get(i).pos.x, particles.get(i).pos.y); 38 | connections++; 39 | } 40 | } 41 | if(!noDraw) ellipse(particles.get(j).pos.x, particles.get(j).pos.y, 5, 5); 42 | } 43 | } 44 | 45 | class Particle { 46 | public PVector pos; 47 | PVector vel; 48 | float theta; 49 | 50 | public Particle() { 51 | pos = new PVector(random(width), random(height)); 52 | vel = PVector.fromAngle(random(1) * TWO_PI); 53 | vel.setMag(particleSpeed); 54 | theta = atan2(vel.y, vel.x); 55 | } 56 | 57 | void update() { 58 | pos.add(vel); 59 | if(pos.x < 0 || pos.x > width || pos.y < 0 || pos.y > height) { 60 | reinit(); 61 | } 62 | } 63 | 64 | void reinit() { 65 | pos = new PVector(random(width), random(height)); 66 | vel = PVector.fromAngle(random(1) * TWO_PI); 67 | vel.setMag(particleSpeed); 68 | 69 | } 70 | void show() { 71 | ellipse(pos.x, pos.y, 4,4); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # processing-sketchbook 2 | 3 | 4 |

5 | Sublime's custom image 6 |

7 | 8 | ### This Sketchbook contains sketches written in [Processing](https://processing.org/) language. 9 | 10 | ```diff 11 | - Note: Sketches have been written mostly for android-mode and has some codes written for JAVA-MODE as well. 12 | ``` 13 | 14 | 21 | 22 | ### For Setting up Processing follow this [wiki](https://github.com/ranaaditya/processing-sketchbook/wiki/Setting-up-Processing) 23 | 24 | ### To use these code inside Android-studio project then include processing-android Core library in Gradle build file from [maven](https://mvnrepository.com/artifact/org.p5android/processing-core) and follow [instructions](https://android.processing.org/) how to use. 25 | 26 | # `Feather` 27 | ### Inspired from Apache logo 28 | ![Feather](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/Feather1.jpg) 29 | 30 | ![Feather](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/Feather2.jpg) 31 | 32 | ![Feather](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/Feather10.jpg) 33 | 34 | 35 | # `city` 36 | 37 | ![city](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/city1.jpg) 38 | 39 | ![city](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/city3.jpg) 40 | 41 | # `Landscape` 42 | 43 | ![landscape](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/landscape1.png) 44 | 45 | ![landscape](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/landscape6.png) 46 | 47 | ![landscape](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/landscape8.png) 48 | 49 | 50 | # `Leaf` 51 | 52 | ![Leaf](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/leaf.jpg) 53 | 54 | # `blender` 55 | 56 | ![blender](https://github.com/ranaaditya/processing-sketchbook/blob/master/Screenshots/blender.jpg) 57 | -------------------------------------------------------------------------------- /Rings/ringSketch.pde: -------------------------------------------------------------------------------- 1 | int bg = 0; 2 | int verts = 100; 3 | float xoff = 100; 4 | float yoff = -1000; 5 | float scale = 120; 6 | float e = 300; 7 | float ee = 0.4; 8 | float ringsspace = 12; 9 | float ringx = -(scale + e); 10 | float z = 111; 11 | 12 | int[][] colar = { 13 | 14 | // red-orange 15 | { color(255, 0, 0) , color(255, 160, 0) }, 16 | 17 | // blue-purple 18 | { color(0, 100, 230) , color(160, 0, 255) }, 19 | 20 | // green-aquamarine 21 | { color(55, 220, 60) , color(0, 221, 195) }, 22 | 23 | // kye meh 24 | { color(131, 96, 195) , color(46, 191, 145) }, 25 | 26 | // vanusa 27 | { color(218, 68, 83) , color(137, 33, 107) }, 28 | 29 | // shifty 30 | { color(99) , color(162, 171, 88) }, 31 | 32 | // bighead 33 | { color(201, 75, 75) , color(75, 19, 79) }, 34 | 35 | // orange coral 36 | { color(255, 153, 102), color(255, 94, 98) }, 37 | 38 | // scooter 39 | { color(54, 209, 220) , color(91, 134, 229) }, 40 | 41 | // purplepine 42 | { color(32, 0, 44) , color(203, 180, 212)}, 43 | 44 | // shades of grey 45 | { color(189, 195, 199), color(44, 62, 80) }, 46 | 47 | // dusk 48 | { color(44, 62, 80) , color(253, 116, 108)} 49 | }; 50 | 51 | int fg1, fg2; 52 | 53 | void initScheme() { 54 | int[] scheme = colar[floor(random(0, colar.length))]; 55 | if(round(random(1)) == 0) { 56 | fg1 = scheme[0]; 57 | fg2 = scheme[1]; 58 | } else { 59 | fg1 = scheme[1]; 60 | fg2 = scheme[0]; 61 | } 62 | } 63 | 64 | void setup() { 65 | fullScreen(); 66 | background(bg); 67 | stroke(255); 68 | pixelDensity(displayDensity()); 69 | noFill(); 70 | strokeWeight(2); 71 | initScheme(); 72 | smooth(); 73 | } 74 | 75 | void draw() { 76 | stroke(lerpColor(fg1, fg2, ringx / width)); 77 | beginShape(); 78 | for(int i = 0; i < verts; i++) { 79 | PVector vert = PVector.fromAngle((float) i / verts * TWO_PI); 80 | vert.mult(scale + noise((vert.x + xoff) * ee, (vert.y + yoff) * ee) * e); 81 | curveVertex(vert.x + ringx, vert.y + height * noise(z)); 82 | } 83 | endShape(CLOSE); 84 | xoff += 0.01; 85 | yoff += 0.01; 86 | ringx += ringsspace; 87 | z += 0.02; 88 | if(ringx > width + (scale + e)) { 89 | ringx = -(scale + e); 90 | delay(2000); 91 | background(bg); 92 | initScheme(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Ripples/ripple.pde: -------------------------------------------------------------------------------- 1 | int verts = 1000; 2 | float scale = 5000; 3 | float xoff = 100; 4 | float yoff = -1000; 5 | int centerx, centery; 6 | int bg = color(253, 246, 227); 7 | int fg = color(220, 50, 47); 8 | 9 | void setup() { 10 | fullScreen(); 11 | background(bg); 12 | stroke(fg); 13 | pixelDensity(displayDensity()); 14 | fill(bg); 15 | initCenter(); 16 | } 17 | 18 | void initCenter() { 19 | centerx = floor(width * random(1)); 20 | centery = floor(height * random(1)); 21 | } 22 | 23 | void draw() { 24 | translate(centerx, centery); 25 | beginShape(); 26 | for(int i = 0; i < verts; i++) { 27 | PVector vert = PVector.fromAngle((float) i / verts * TWO_PI); 28 | float n = noise(vert.x + xoff, vert.y + yoff) * scale; 29 | vert.mult(n); 30 | curveVertex(vert.x, vert.y); 31 | } 32 | endShape(CLOSE); 33 | xoff += 0.002; 34 | yoff += 0.002; 35 | scale *= 0.997; 36 | 37 | if(scale < 5) { 38 | background(bg); 39 | scale = 5000; 40 | initCenter(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Screenshots/Feather1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/Feather1.jpg -------------------------------------------------------------------------------- /Screenshots/Feather10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/Feather10.jpg -------------------------------------------------------------------------------- /Screenshots/Feather2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/Feather2.jpg -------------------------------------------------------------------------------- /Screenshots/blender.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/blender.jpg -------------------------------------------------------------------------------- /Screenshots/city1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/city1.jpg -------------------------------------------------------------------------------- /Screenshots/city3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/city3.jpg -------------------------------------------------------------------------------- /Screenshots/landscape1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/landscape1.png -------------------------------------------------------------------------------- /Screenshots/landscape6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/landscape6.png -------------------------------------------------------------------------------- /Screenshots/landscape8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/landscape8.png -------------------------------------------------------------------------------- /Screenshots/leaf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/leaf.jpg -------------------------------------------------------------------------------- /Screenshots/rune.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/Screenshots/rune.pdf -------------------------------------------------------------------------------- /Sensor/accelerometer/Accelerometer.pde: -------------------------------------------------------------------------------- 1 | AccelerometerManager accel; 2 | float ax, ay, az; 3 | 4 | 5 | void setup() { 6 | accel = new AccelerometerManager(this); 7 | orientation(PORTRAIT); 8 | noLoop(); 9 | } 10 | 11 | 12 | void draw() { 13 | background(0); 14 | fill(255); 15 | textSize(70); 16 | textAlign(CENTER, CENTER); 17 | text("x: " + nf(ax, 1, 2) + "\n" + 18 | "y: " + nf(ay, 1, 2) + "\n" + 19 | "z: " + nf(az, 1, 2), 20 | 0, 0, width, height); 21 | } 22 | 23 | 24 | public void resume() { 25 | if (accel != null) { 26 | accel.resume(); 27 | } 28 | } 29 | 30 | 31 | public void pause() { 32 | if (accel != null) { 33 | accel.pause(); 34 | } 35 | } 36 | 37 | 38 | public void shakeEvent(float force) { 39 | println("shake : " + force); 40 | } 41 | 42 | 43 | public void accelerationEvent(float x, float y, float z) { 44 | // println("acceleration: " + x + ", " + y + ", " + z); 45 | ax = x; 46 | ay = y; 47 | az = z; 48 | redraw(); 49 | } 50 | -------------------------------------------------------------------------------- /Sensor/accelerometer/AccelerometerManager.java: -------------------------------------------------------------------------------- 1 | import processing.core.PApplet; 2 | 3 | import java.lang.reflect.*; 4 | import java.util.List; 5 | 6 | import android.content.Context; 7 | import android.hardware.Sensor; 8 | import android.hardware.SensorEvent; 9 | import android.hardware.SensorEventListener; 10 | import android.hardware.SensorManager; 11 | 12 | 13 | /** 14 | * Android Accelerometer Sensor Manager Archetype 15 | * @author antoine vianey 16 | * under GPL v3 : http://www.gnu.org/licenses/gpl-3.0.html 17 | */ 18 | public class AccelerometerManager { 19 | /** Accuracy configuration */ 20 | private float threshold = 0.2f; 21 | private int interval = 1000; 22 | 23 | private Sensor sensor; 24 | private SensorManager sensorManager; 25 | // you could use an OrientationListener array instead 26 | // if you plans to use more than one listener 27 | // private AccelerometerListener listener; 28 | 29 | Method shakeEventMethod; 30 | Method accelerationEventMethod; 31 | 32 | /** indicates whether or not Accelerometer Sensor is supported */ 33 | private Boolean supported; 34 | /** indicates whether or not Accelerometer Sensor is running */ 35 | private boolean running = false; 36 | 37 | PApplet parent; 38 | Context context; 39 | 40 | public AccelerometerManager(PApplet parent) { 41 | this.parent = parent; 42 | this.context = parent.getActivity(); 43 | 44 | try { 45 | shakeEventMethod = 46 | parent.getClass().getMethod("shakeEvent", new Class[] { Float.TYPE }); 47 | } catch (Exception e) { 48 | // no such method, or an error.. which is fine, just ignore 49 | } 50 | 51 | try { 52 | accelerationEventMethod = 53 | parent.getClass().getMethod("accelerationEvent", new Class[] { Float.TYPE, Float.TYPE, Float.TYPE }); 54 | } catch (Exception e) { 55 | // no such method, or an error.. which is fine, just ignore 56 | } 57 | // System.out.println("shakeEventMethod is " + shakeEventMethod); 58 | // System.out.println("accelerationEventMethod is " + accelerationEventMethod); 59 | resume(); 60 | } 61 | 62 | 63 | public AccelerometerManager(PApplet parent, int threshold, int interval) { 64 | this(parent); 65 | this.threshold = threshold; 66 | this.interval = interval; 67 | } 68 | 69 | 70 | public void resume() { 71 | if (isSupported()) { 72 | startListening(); 73 | } 74 | } 75 | 76 | 77 | public void pause() { 78 | if (isListening()) { 79 | stopListening(); 80 | } 81 | } 82 | 83 | 84 | /** 85 | * Returns true if the manager is listening to orientation changes 86 | */ 87 | public boolean isListening() { 88 | return running; 89 | } 90 | 91 | 92 | /** 93 | * Unregisters listeners 94 | */ 95 | public void stopListening() { 96 | running = false; 97 | try { 98 | if (sensorManager != null && sensorEventListener != null) { 99 | sensorManager.unregisterListener(sensorEventListener); 100 | } 101 | } 102 | catch (Exception e) { 103 | } 104 | } 105 | 106 | 107 | /** 108 | * Returns true if at least one Accelerometer sensor is available 109 | */ 110 | public boolean isSupported() { 111 | if (supported == null) { 112 | sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); 113 | List sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); 114 | supported = new Boolean(sensors.size() > 0); 115 | } 116 | return supported; 117 | } 118 | 119 | 120 | // /** 121 | // * Configure the listener for shaking 122 | // * @param threshold 123 | // * minimum acceleration variation for considering shaking 124 | // * @param interval 125 | // * minimum interval between to shake events 126 | // */ 127 | // public static void configure(int threshold, int interval) { 128 | // AccelerometerManager.threshold = threshold; 129 | // AccelerometerManager.interval = interval; 130 | // } 131 | 132 | 133 | /** 134 | * Registers a listener and start listening 135 | * @param accelerometerListener callback for accelerometer events 136 | */ 137 | public void startListening() { 138 | // AccelerometerListener accelerometerListener = (AccelerometerListener) context; 139 | sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); 140 | List sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER); 141 | if (sensors.size() > 0) { 142 | sensor = sensors.get(0); 143 | running = sensorManager.registerListener(sensorEventListener, sensor, SensorManager.SENSOR_DELAY_GAME); 144 | // listener = accelerometerListener; 145 | } 146 | } 147 | 148 | 149 | // /** 150 | // * Configures threshold and interval 151 | // * And registers a listener and start listening 152 | // * @param accelerometerListener 153 | // * callback for accelerometer events 154 | // * @param threshold 155 | // * minimum acceleration variation for considering shaking 156 | // * @param interval 157 | // * minimum interval between to shake events 158 | // */ 159 | // public void startListening(int threshold, int interval) { 160 | // configure(threshold, interval); 161 | // startListening(); 162 | // } 163 | 164 | 165 | /** 166 | * The listener that listen to events from the accelerometer listener 167 | */ 168 | //private static SensorEventListener sensorEventListener = new SensorEventListener() { 169 | private SensorEventListener sensorEventListener = new SensorEventListener() { 170 | private long now = 0; 171 | private long timeDiff = 0; 172 | private long lastUpdate = 0; 173 | private long lastShake = 0; 174 | 175 | private float x = 0; 176 | private float y = 0; 177 | private float z = 0; 178 | private float lastX = 0; 179 | private float lastY = 0; 180 | private float lastZ = 0; 181 | private float force = 0; 182 | 183 | public void onAccuracyChanged(Sensor sensor, int accuracy) { 184 | } 185 | 186 | public void onSensorChanged(SensorEvent event) { 187 | // use the event timestamp as reference 188 | // so the manager precision won't depends 189 | // on the AccelerometerListener implementation 190 | // processing time 191 | now = event.timestamp; 192 | 193 | x = event.values[0]; 194 | y = event.values[1]; 195 | z = event.values[2]; 196 | 197 | // if not interesting in shake events 198 | // just remove the whole if then else bloc 199 | if (lastUpdate == 0) { 200 | lastUpdate = now; 201 | lastShake = now; 202 | lastX = x; 203 | lastY = y; 204 | lastZ = z; 205 | 206 | } else { 207 | timeDiff = now - lastUpdate; 208 | if (timeDiff > 0) { 209 | force = Math.abs(x + y + z - lastX - lastY - lastZ) 210 | / timeDiff; 211 | if (force > threshold) { 212 | if (now - lastShake >= interval) { 213 | // trigger shake event 214 | // listener.onShake(force); 215 | if (shakeEventMethod != null) { 216 | try { 217 | shakeEventMethod.invoke(parent, new Object[] { new Float(force) }); 218 | } catch (Exception e) { 219 | e.printStackTrace(); 220 | shakeEventMethod = null; 221 | } 222 | } 223 | } 224 | lastShake = now; 225 | } 226 | lastX = x; 227 | lastY = y; 228 | lastZ = z; 229 | lastUpdate = now; 230 | } 231 | } 232 | // trigger change event 233 | // listener.onAccelerationChanged(x, y, z); 234 | if (accelerationEventMethod != null) { 235 | try { 236 | accelerationEventMethod.invoke(parent, new Object[] { x, y, z }); 237 | } catch (Exception e) { 238 | e.printStackTrace(); 239 | accelerationEventMethod = null; 240 | } 241 | } 242 | } 243 | }; 244 | } 245 | -------------------------------------------------------------------------------- /Sensor/compass/CompassManager.java: -------------------------------------------------------------------------------- 1 | import processing.core.PApplet; 2 | 3 | import java.lang.reflect.*; 4 | import java.util.List; 5 | 6 | import android.content.Context; 7 | import android.hardware.Sensor; 8 | import android.hardware.SensorEvent; 9 | import android.hardware.SensorEventListener; 10 | import android.hardware.SensorManager; 11 | 12 | 13 | public class CompassManager { 14 | private Sensor sensor; 15 | private SensorManager sensorManager; 16 | 17 | Method compassEventMethod; 18 | Method directionEventMethod; 19 | 20 | private Boolean supported; 21 | private boolean running = false; 22 | 23 | PApplet parent; 24 | Context context; 25 | 26 | public CompassManager(PApplet parent) { 27 | this.parent = parent; 28 | this.context = parent.getActivity(); 29 | 30 | try { 31 | compassEventMethod = 32 | parent.getClass().getMethod("compassEvent", new Class[] { Float.TYPE, Float.TYPE, Float.TYPE }); 33 | } catch (Exception e) { 34 | // no such method, or an error.. which is fine, just ignore 35 | } 36 | try { 37 | directionEventMethod = 38 | parent.getClass().getMethod("directionEvent", new Class[] { Float.TYPE }); 39 | } catch (Exception e) { 40 | // no such method, or an error.. which is fine, just ignore 41 | } 42 | // System.out.println("directionEventMethod is " + directionEventMethod); 43 | 44 | resume(); 45 | } 46 | 47 | 48 | public void resume() { 49 | if (isSupported()) { 50 | startListening(); 51 | } 52 | } 53 | 54 | 55 | public void pause() { 56 | if (isListening()) { 57 | stopListening(); 58 | } 59 | } 60 | 61 | 62 | /** 63 | * Returns true if the manager is listening to orientation changes 64 | */ 65 | public boolean isListening() { 66 | return running; 67 | } 68 | 69 | 70 | /** 71 | * Unregisters listeners 72 | */ 73 | public void stopListening() { 74 | running = false; 75 | try { 76 | if (sensorManager != null && sensorEventListener != null) { 77 | sensorManager.unregisterListener(sensorEventListener); 78 | } 79 | } 80 | catch (Exception e) { 81 | } 82 | } 83 | 84 | 85 | /** 86 | * Returns true if at least one Accelerometer sensor is available 87 | */ 88 | public boolean isSupported() { 89 | if (supported == null) { 90 | sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); 91 | List sensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION); 92 | supported = new Boolean(sensors.size() > 0); 93 | } 94 | return supported; 95 | } 96 | 97 | 98 | public void startListening() { 99 | sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); 100 | List sensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION); 101 | if (sensors.size() > 0) { 102 | sensor = sensors.get(0); 103 | running = sensorManager.registerListener(sensorEventListener, sensor, SensorManager.SENSOR_DELAY_GAME); 104 | } 105 | } 106 | 107 | 108 | /** 109 | * The listener that listen to events from the accelerometer listener 110 | */ 111 | private SensorEventListener sensorEventListener = new SensorEventListener() { 112 | 113 | public void onAccuracyChanged(Sensor sensor, int accuracy) { 114 | // ignored for now 115 | } 116 | 117 | public void onSensorChanged(SensorEvent event) { 118 | float x = event.values[0]; 119 | float y = event.values[1]; 120 | float z = event.values[2]; 121 | 122 | if (compassEventMethod != null) { 123 | try { 124 | compassEventMethod.invoke(parent, new Object[] { x, y, z }); 125 | } catch (Exception e) { 126 | e.printStackTrace(); 127 | compassEventMethod = null; 128 | } 129 | } 130 | 131 | if (directionEventMethod != null) { 132 | try { 133 | directionEventMethod.invoke(parent, new Object[] { (float) (-x * Math.PI / 180) }); 134 | } catch (Exception e) { 135 | e.printStackTrace(); 136 | directionEventMethod = null; 137 | } 138 | } 139 | } 140 | }; 141 | } 142 | -------------------------------------------------------------------------------- /Sensor/compass/compass.pde: -------------------------------------------------------------------------------- 1 | CompassManager compass; 2 | float direction; 3 | 4 | 5 | void setup() { 6 | compass = new CompassManager(this); 7 | } 8 | 9 | 10 | void pause() { 11 | if (compass != null) compass.pause(); 12 | } 13 | 14 | 15 | void resume() { 16 | if (compass != null) compass.resume(); 17 | } 18 | 19 | 20 | void draw() { 21 | background(255); 22 | fill(192, 0, 0); 23 | noStroke(); 24 | 25 | translate(width/2, height/2); 26 | scale(2); 27 | rotate(direction); 28 | beginShape(); 29 | vertex(0, -50); 30 | vertex(-20, 60); 31 | vertex(0, 50); 32 | vertex(20, 60); 33 | endShape(CLOSE); 34 | } 35 | 36 | 37 | void directionEvent(float newDirection) { 38 | direction = newDirection; 39 | } 40 | -------------------------------------------------------------------------------- /SwirlDesing/swirldesing.pde: -------------------------------------------------------------------------------- 1 | // enter an image(in place of xyz.jpg) to be used by this sketch 2 | String img_name = "xyz.jpg"; 3 | 4 | PImage swirl_img; 5 | 6 | float swirlDensity = 0.03; 7 | float swirlResolution = 0.05; 8 | 9 | float swirlAngle = 0; 10 | float magnification = 0; 11 | PVector pre = new PVector(0, 0); 12 | PVector neo = new PVector(0, 0); 13 | 14 | void setup() { 15 | swirl_img = loadImage(img_name); 16 | swirl_img.resize(900, 0); 17 | swirl_img.filter(GRAY); 18 | size(800, 800); 19 | background(255); 20 | stroke(0); 21 | strokeWeight(1); 22 | } 23 | 24 | void draw() { 25 | translate(width/2, height/2); 26 | neo = PVector.fromAngle(swirlAngle); 27 | neo.mult(magnification); 28 | color swirlColor = swirl_img.get(450 + round(neo.x), 450 + round(neo.y)); 29 | strokeWeight((255-green(swirlColor)) * 6 / 255); 30 | line(pre.x, pre.y, neo.x, neo.y); 31 | magnification += swirlDensity; 32 | swirlAngle += swirlResolution; 33 | pre = neo; 34 | } 35 | -------------------------------------------------------------------------------- /ascii_logo/sketch.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | // loads the image from the sketchbook/${sketchname} folder 3 | // palce dummy.jpg image in the forementioned location 4 | PImage img = loadImage("dummy.jpg"); 5 | img.filter(GRAY); 6 | img.filter(INVERT); 7 | img.resize(75, img.height/img.width * 56); 8 | for(int i = 0; i < img.height; i++) { 9 | for(int j = 0; j < img.width; j++) { 10 | int c = round(green(img.get(j, i))); 11 | if(c < 42) { 12 | print("#"); 13 | } else if(c < 85) { 14 | print("@"); 15 | } else if(c < 128) { 16 | print("+"); 17 | } else if(c < 170) { 18 | print("-"); 19 | } else if(c < 213) { 20 | print("."); 21 | } else { 22 | print(" "); 23 | } 24 | } 25 | println(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ketai_sketches/accelerometer.pde: -------------------------------------------------------------------------------- 1 | import ketai.sensors.*; 2 | 3 | KetaiSensor sensor; 4 | float accelerometerX, accelerometerY, accelerometerZ; 5 | 6 | void setup() 7 | { 8 | fullScreen(); 9 | sensor = new KetaiSensor(this); 10 | sensor.start(); 11 | orientation(LANDSCAPE); 12 | textAlign(CENTER, CENTER); 13 | textSize(displayDensity * 36); 14 | } 15 | 16 | void draw() 17 | { 18 | background(78, 93, 75); 19 | text("Accelerometer: \n" + 20 | "x: " + nfp(accelerometerX, 1, 3) + "\n" + 21 | "y: " + nfp(accelerometerY, 1, 3) + "\n" + 22 | "z: " + nfp(accelerometerZ, 1, 3), 0, 0, width, height); 23 | } 24 | 25 | void onAccelerometerEvent(float x, float y, float z) 26 | { 27 | accelerometerX = x; 28 | accelerometerY = y; 29 | accelerometerZ = z; 30 | } 31 | -------------------------------------------------------------------------------- /ketai_sketches/audio_input.pde: -------------------------------------------------------------------------------- 1 | // give necessary permissions for runtime in android 2 | // choose necessary permissions from sketch -> permissions 3 | 4 | import ketai.sensors.*; 5 | 6 | 7 | KetaiAudioInput mic; 8 | short[] data; 9 | 10 | void setup() 11 | { 12 | fullScreen(); 13 | orientation(LANDSCAPE); 14 | mic = new KetaiAudioInput(this); 15 | fill(255,0,0); 16 | textSize(displayDensity * 24); 17 | fill(255, 0, 0); 18 | textSize(48); 19 | requestPermission("android.permission.RECORD_AUDIO", "initAudio"); 20 | } 21 | 22 | void initAudio(boolean granted) 23 | { 24 | if (granted) 25 | { 26 | mic = new KetaiAudioInput(this); 27 | println("Audio recording permission granted"); 28 | } else { 29 | println("Audio recording permission denied"); 30 | } 31 | } 32 | 33 | 34 | void draw() 35 | { 36 | background(128); 37 | if (data != null) 38 | { 39 | for (int i = 0; i < data.length; i++) 40 | { 41 | if (i != data.length-1) 42 | line(i, map(data[i], -32768, 32767, height, 0), i+1, map(data[i+1], -32768, 32767, height, 0)); 43 | } 44 | } 45 | 46 | if (mic != null && mic.isActive()) 47 | text("READING MIC", width/2, height/2); 48 | else 49 | text("NOT READING MIC", width/2, height/2); 50 | } 51 | 52 | 53 | void onAudioEvent(short[] _data) 54 | { 55 | data= _data; 56 | } 57 | 58 | void mousePressed() 59 | { 60 | if (mic != null && mic.isActive()) 61 | mic.stop(); 62 | else 63 | mic.start(); 64 | } 65 | -------------------------------------------------------------------------------- /ketai_sketches/ketai_camera.pde: -------------------------------------------------------------------------------- 1 | // add CAMERA permission in the pde for running this sketch 2 | 3 | import ketai.camera.*; 4 | 5 | KetaiCamera cam; 6 | 7 | void setup() { 8 | fullScreen(); 9 | orientation(LANDSCAPE); 10 | 11 | imageMode(CENTER); 12 | textAlign(CENTER, CENTER); 13 | textSize(displayDensity * 25); 14 | cam = new KetaiCamera(this, 640, 480, 24); 15 | } 16 | 17 | void draw() { 18 | 19 | if (cam != null && cam.isStarted()) 20 | image(cam, width/2, height/2, width, height); 21 | else 22 | { 23 | background(128); 24 | text("Camera is currently off.", width/2, height/2); 25 | } 26 | drawUI(); 27 | } 28 | 29 | void onCameraPreviewEvent() 30 | { 31 | cam.read(); 32 | } 33 | 34 | void mousePressed() 35 | { 36 | //Toggle Camera on/off 37 | if (mouseX < width/3 && mouseY < 100) 38 | { 39 | if (cam.isStarted()) 40 | { 41 | cam.stop(); 42 | } else 43 | cam.start(); 44 | } 45 | 46 | if (mouseX < 2*width/3 && mouseX > width/3 && mouseY < 100) 47 | { 48 | if (cam.getNumberOfCameras() > 1) 49 | { 50 | cam.setCameraID((cam.getCameraID() + 1 ) % cam.getNumberOfCameras()); 51 | } 52 | } 53 | 54 | //Toggle Camera Flash 55 | if (mouseX > 2*width/3 && mouseY < 100) 56 | { 57 | if (cam.isFlashEnabled()) 58 | cam.disableFlash(); 59 | else 60 | cam.enableFlash(); 61 | } 62 | } 63 | 64 | void drawUI() 65 | { 66 | pushStyle(); 67 | textAlign(LEFT); 68 | fill(0); 69 | stroke(255); 70 | rect(0, 0, width/3, 100); 71 | rect(width/3, 0, width/3, 100); 72 | 73 | rect((width/3)*2, 0, width/3, 100); 74 | 75 | fill(255); 76 | if (cam.isStarted()) 77 | text("Camera Off", 5, 80); 78 | else 79 | text("Camera On", 5, 80); 80 | 81 | if (cam.getNumberOfCameras() > 0) 82 | { 83 | text("Switch Camera", width/3 + 5, 80); 84 | } 85 | 86 | if (cam.isFlashEnabled()) 87 | text("Flash Off", width/3*2 + 5, 80); 88 | else 89 | text("Flash On", width/3*2 + 5, 80); 90 | 91 | popStyle(); 92 | } 93 | -------------------------------------------------------------------------------- /ketai_sketches/ketai_datagraph.pde: -------------------------------------------------------------------------------- 1 | // add WRITE_EXTERNAL_STORAGE permission in pde for android sketch 2 | 3 | import ketai.data.*; 4 | import ketai.sensors.*; 5 | 6 | KetaiSensor sensor; 7 | KetaiSQLite db; 8 | Boolean isCapturing = false; 9 | 10 | String CREATE_DB_SQL = "CREATE TABLE data ( time INTEGER PRIMARY KEY, x FLOAT NOT NULL, y FLOAT NOT NULL, z FLOAT NOT NULL);"; 11 | 12 | void setup() 13 | { 14 | 15 | fullScreen(); 16 | orientation(LANDSCAPE); 17 | requestPermission("android.permission.WRITE_EXTERNAL_STORAGE", "handleRequest"); 18 | 19 | frameRate(5); 20 | textAlign(CENTER, CENTER); 21 | textSize(displayDensity * 25); 22 | 23 | sensor = new KetaiSensor(this); 24 | sensor.start(); 25 | } 26 | 27 | void draw() { 28 | background(78, 93, 75); 29 | 30 | // Status and data count 31 | if (isCapturing) 32 | text("Recording Accellerometer Data...\n(touch screen to stop)", width/2, height/4); 33 | else 34 | { 35 | plotData(); 36 | text("Visualizing last " + width + " point(s) of data.", width/2, height/4); 37 | } 38 | if (db != null) { 39 | text("Current Data count: " + db.getDataCount(), width/2, height-height/4); 40 | } else { 41 | text("Cannot save data", width/2, height-height/4); 42 | } 43 | } 44 | 45 | void mousePressed() 46 | { 47 | if (isCapturing) 48 | isCapturing = false; 49 | else 50 | isCapturing = true; 51 | } 52 | 53 | // collect accelerometer data and save it to the database 54 | void onAccelerometerEvent(float x, float y, float z, long time, int accuracy) 55 | { 56 | if (db != null && db.connect() && isCapturing) 57 | { 58 | if (!db.execute("INSERT into data (`time`,`x`,`y`,`z`) VALUES ('"+System.currentTimeMillis()+"', '"+x+"', '"+y+"', '"+z+"')")) 59 | println("Failed to record data!" ); 60 | } 61 | } 62 | 63 | void plotData() 64 | { 65 | if (db != null && db.connect()) 66 | { 67 | pushStyle(); 68 | noStroke(); 69 | db.query( "SELECT * FROM data ORDER BY time DESC LIMIT " + width ); 70 | int i = 0; 71 | long mymin = Long.parseLong(db.getFieldMin("data", "time")); 72 | long mymax = Long.parseLong(db.getFieldMax("data", "time")); 73 | while (db.next ()) 74 | { 75 | 76 | float x = db.getFloat("x"); 77 | float y = db.getFloat("y"); 78 | float z = db.getFloat("z"); 79 | long t = db.getLong("time"); 80 | int plotx = (int)maplong(t, mymin, mymax, 0, width); 81 | 82 | fill(255, 0, 0); 83 | ellipse(plotx, map(x, -30, 30, 0, height), 5, 5); 84 | fill(0, 255, 0); 85 | ellipse(i, map(y, -30, 30, 0, height), 5, 5); 86 | fill(0, 0, 255); 87 | ellipse(i, map(z, -30, 30, 0, height), 5, 5); 88 | 89 | i++; 90 | } 91 | popStyle(); 92 | } 93 | } 94 | 95 | 96 | long maplong(long value, long istart, long istop, long ostart, long ostop) { 97 | long divisor = istop - istart; 98 | return (ostart + (ostop - ostart) * (value - istart) / divisor); 99 | 100 | } 101 | 102 | void handleRequest(boolean granted) { 103 | if (granted) { 104 | db = new KetaiSQLite(this); 105 | //lets make our table if it is the first time we're running 106 | if ( db.connect() ) 107 | { 108 | // for initial app launch there are no tables so we make one 109 | if (!db.tableExists("data")) 110 | db.execute(CREATE_DB_SQL); 111 | } 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /ketai_sketches/ketai_geolocation.pde: -------------------------------------------------------------------------------- 1 | // provide ACCESS_COARSE_LOCATION 2 | // provide ACCESS_FINE_LOCATION 3 | // provide ACCESS_LOCATION_EXTRA_COMMANDS 4 | // permissions for running sketch in android 5 | 6 | import ketai.sensors.*; 7 | 8 | double longitude, latitude, altitude; 9 | KetaiLocation location; 10 | 11 | void setup() { 12 | fullScreen(); 13 | orientation(LANDSCAPE); 14 | location = new KetaiLocation(this); 15 | 16 | textAlign(CENTER, CENTER); 17 | textSize(displayDensity * 36); 18 | } 19 | 20 | void draw() { 21 | background(78, 93, 75); 22 | if (location == null || location.getProvider() == "none") 23 | text("Location data is unavailable. \n" + 24 | "Please check your location settings.", 0, 0, width, height); 25 | else 26 | text("Latitude: " + latitude + "\n" + 27 | "Longitude: " + longitude + "\n" + 28 | "Altitude: " + altitude + "\n" + 29 | "Provider: " + location.getProvider(), 0, 0, width, height); 30 | // getProvider() returns "gps" if GPS is available 31 | // otherwise "network" (cell network) or "passive" (WiFi MACID) 32 | } 33 | 34 | void onLocationEvent(double _latitude, double _longitude, double _altitude) 35 | { 36 | longitude = _longitude; 37 | latitude = _latitude; 38 | altitude = _altitude; 39 | println("lat/lon/alt: " + latitude + "/" + longitude + "/" + altitude); 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /ketai_sketches/ketai_gyroscope.pde: -------------------------------------------------------------------------------- 1 | import ketai.sensors.*; 2 | 3 | KetaiSensor sensor; 4 | float rotationX, rotationY, rotationZ; 5 | 6 | void setup() 7 | { 8 | fullScreen(); 9 | sensor = new KetaiSensor(this); 10 | sensor.start(); 11 | fullScreen(); 12 | orientation(PORTRAIT); 13 | 14 | textAlign(CENTER, CENTER); 15 | textSize(displayDensity * 24); 16 | } 17 | 18 | void draw() 19 | { 20 | background(78, 93, 75); 21 | text("Gyroscope: \n" + 22 | "x: " + nfp(rotationX, 1, 3) + "\n" + 23 | "y: " + nfp(rotationY, 1, 3) + "\n" + 24 | "z: " + nfp(rotationZ, 1, 3), 0, 0, width, height); 25 | } 26 | 27 | void onGyroscopeEvent(float x, float y, float z) 28 | { 29 | rotationX = x; 30 | rotationY = y; 31 | rotationZ = z; 32 | } 33 | -------------------------------------------------------------------------------- /ketai_sketches/ketai_multisensor.pde: -------------------------------------------------------------------------------- 1 | import ketai.sensors.*; 2 | 3 | KetaiSensor sensor; 4 | PVector magneticField, accelerometer; 5 | float light, proximity; 6 | 7 | void setup() 8 | { 9 | fullScreen(); 10 | sensor = new KetaiSensor(this); 11 | sensor.start(); 12 | sensor.list(); 13 | accelerometer = new PVector(); 14 | magneticField = new PVector(); 15 | orientation(LANDSCAPE); 16 | 17 | textAlign(CENTER, CENTER); 18 | textSize(displayDensity * 28); 19 | } 20 | 21 | void draw() 22 | { 23 | background(78, 93, 75); 24 | text("Accelerometer :" + "\n" 25 | + "x: " + nfp(accelerometer.x, 1, 2) + "\n" 26 | + "y: " + nfp(accelerometer.y, 1, 2) + "\n" 27 | + "z: " + nfp(accelerometer.z, 1, 2) + "\n" 28 | + "MagneticField :" + "\n" 29 | + "x: " + nfp(magneticField.x, 1, 2) + "\n" 30 | + "y: " + nfp(magneticField.y, 1, 2) + "\n" 31 | + "z: " + nfp(magneticField.z, 1, 2) + "\n" 32 | + "Light Sensor : " + light + "\n" 33 | + "Proximity Sensor : " + proximity + "\n" 34 | , 20, 0, width, height); 35 | } 36 | 37 | void onAccelerometerEvent(float x, float y, float z, long time, int accuracy) 38 | { 39 | accelerometer.set(x, y, z); 40 | } 41 | 42 | void onMagneticFieldEvent(float x, float y, float z, long time, int accuracy) 43 | { 44 | magneticField.set(x, y, z); 45 | } 46 | 47 | void onLightEvent(float v) 48 | { 49 | light = v; 50 | } 51 | 52 | void onProximityEvent(float v) 53 | { 54 | proximity = v; 55 | } 56 | 57 | public void mousePressed() { 58 | if (sensor.isStarted()) 59 | sensor.stop(); 60 | else 61 | sensor.start(); 62 | println("KetaiSensor isStarted: " + sensor.isStarted()); 63 | } 64 | -------------------------------------------------------------------------------- /ketai_sketches/ketai_sqlite.pde: -------------------------------------------------------------------------------- 1 | import ketai.data.*; 2 | 3 | KetaiSQLite db; 4 | String CREATE_DB_SQL = "CREATE TABLE data ( _id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, age INTEGER NOT NULL DEFAULT '0');"; 5 | 6 | void setup() 7 | { 8 | fullScreen(); 9 | db = new KetaiSQLite( this); // open database file 10 | 11 | if ( db.connect() ) 12 | { 13 | // for initial app launch there are no tables so we make one 14 | if (!db.tableExists("data")) 15 | db.execute(CREATE_DB_SQL); 16 | 17 | println("data count for data table: "+db.getRecordCount("data")); 18 | 19 | //lets insert a random number or records 20 | int count = (int)random(1, 5); 21 | 22 | for (int i=0; i < count; i++) 23 | if (!db.execute("INSERT into data (`name`,`age`) VALUES ('person"+(int)random(0, 100)+"', '"+(int)random(1, 100)+"' )")) 24 | println("error w/sql insert"); 25 | 26 | println("data count for data table after insert: "+db.getRecordCount("data")); 27 | 28 | // read all in table "table_one" 29 | db.query( "SELECT * FROM data" ); 30 | 31 | while (db.next ()) 32 | { 33 | println("----------------"); 34 | print( db.getString("name") ); 35 | print( "\t"+db.getInt("age") ); 36 | println("\t"+db.getInt("foobar")); //doesn't exist we get '0' returned 37 | println("----------------"); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ketai_sketches/ketai_ui.pde: -------------------------------------------------------------------------------- 1 | // add VIBRATE permission before running sketch in android 2 | 3 | import ketai.ui.*; 4 | 5 | KetaiList selectionlist; 6 | KetaiVibrate vibe; 7 | ArrayList colorlist = new ArrayList(); 8 | color backgroundcolor = color(0, 0, 0); 9 | 10 | void setup() 11 | { 12 | fullScreen(); 13 | orientation(LANDSCAPE); 14 | textSize(24*displayDensity); 15 | textAlign(CENTER); 16 | vibe = new KetaiVibrate(this); 17 | colorlist.add("Black"); 18 | colorlist.add("Red"); 19 | colorlist.add("Green"); 20 | colorlist.add("Blue"); 21 | colorlist.add("Gray"); 22 | for (int i = 0; i < 20; i++) 23 | colorlist.add("Stub Entry " + i); 24 | colorlist.add("Cancel"); 25 | //register for key events(keyPressed currently Broken) 26 | //registerMethod("keyEvent", this); 27 | } 28 | 29 | void draw() 30 | { 31 | background(backgroundcolor); 32 | 33 | drawUI(); 34 | text("click screen to change background color", width/2, height/2); 35 | } 36 | 37 | 38 | void mousePressed() 39 | { 40 | if (mouseY < 100) 41 | { 42 | if (mouseX < width/3) 43 | KetaiKeyboard.toggle(this); 44 | else if (mouseX > width/3 && mouseX < width-(width/3)) 45 | KetaiAlertDialog.popup(this, "Pop Up!", "this is a popup message box"); 46 | else 47 | vibe.vibrate(1000); 48 | } else 49 | selectionlist = new KetaiList(this, colorlist); 50 | } 51 | 52 | void onKetaiListSelection(KetaiList klist) 53 | { 54 | String selection = klist.getSelection(); 55 | if (selection == "Black") 56 | backgroundcolor = color(0, 0, 0); 57 | else if (selection == "Red") 58 | backgroundcolor = color(255, 0, 0); 59 | else if (selection == "Green") 60 | backgroundcolor = color(0, 255, 0); 61 | else if (selection == "Blue") 62 | backgroundcolor = color(0, 0, 255); 63 | else if (selection == "Gray") 64 | backgroundcolor = color(128, 128, 128); 65 | else 66 | println("invalid color selection or non-color selected"); 67 | } 68 | 69 | 70 | void drawUI() 71 | { 72 | pushStyle(); 73 | textAlign(LEFT); 74 | fill(0); 75 | stroke(255); 76 | rect(0, 0, width/3, 100); 77 | rect(width/3, 0, width/3, 100); 78 | 79 | rect((width/3)*2, 0, width/3, 100); 80 | 81 | fill(255); 82 | text("Keyboard", 5, 60); 83 | text("PopUp", width/3 + 5, 60); 84 | text("Vibrate", width/3*2 + 5, 60); 85 | popStyle(); 86 | } 87 | 88 | //use event framework temporarily 89 | public void keyPressed() { 90 | 91 | if (key == ' ') 92 | KetaiAlertDialog.popup(this, "SPACE pressed", "You pressed the key!"); 93 | else 94 | println(key); 95 | } 96 | -------------------------------------------------------------------------------- /logo/Processing-Sketchbook_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/logo/Processing-Sketchbook_logo.png -------------------------------------------------------------------------------- /mountain/mountain.pde: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Arrays; 3 | 4 | 5 | ArrayList cells = new ArrayList(); 6 | int scale = 3; 7 | int rule = 18; 8 | boolean[] startingcondition = {true}; 9 | boolean[] rules; 10 | 11 | void setup() { 12 | fullScreen(); 13 | stroke(0); 14 | strokeWeight(scale); 15 | // precompute rule array 16 | rules = new boolean[8]; 17 | regenerateRules(); 18 | //noSmooth(); 19 | smooth(); 20 | } 21 | 22 | int cheapocounter = 0; 23 | void draw() { 24 | background(255); 25 | genRows(); 26 | drawRows(); 27 | cheapocounter++; 28 | } 29 | 30 | void genRows() { 31 | if (cells.size() == 0) { 32 | cells.add(startingcondition); 33 | } else { 34 | if (cells.size() >= height / scale) cells.remove(0); 35 | cells.add(next(cells.get(cells.size() - 1))); 36 | } 37 | } 38 | 39 | boolean[] next(boolean[] previous) { 40 | // pad previous with two whites on both sides 41 | boolean[] x = new boolean[previous.length + 4]; 42 | x[0] = false; 43 | x[1] = false; 44 | x[x.length - 2] = false; 45 | x[x.length - 1] = false; 46 | for(int i = 0; i < previous.length; i++) { 47 | x[i + 2] = previous[i]; 48 | } 49 | 50 | // compute next row 51 | boolean[] result = new boolean[previous.length + 2]; 52 | 53 | for(int i = 0; i < x.length - 2; i++) { 54 | int ruleindex = 0; 55 | if(x[i]) ruleindex += 4; 56 | if(x[i+1]) ruleindex +=2; 57 | if(x[i+2]) ruleindex += 1; 58 | 59 | result[i] = rules[ruleindex]; 60 | } 61 | 62 | return result; 63 | } 64 | 65 | void drawRows() { 66 | int start = (width + startingcondition.length) / 2; 67 | for(int i = 0; i < cells.size(); i++) { 68 | for(int j = 0; j < cells.get(i).length; j++) { 69 | if(cells.get(i)[j]) stroke(255); 70 | else stroke(0); 71 | rect(j*scale + start, i*scale, scale, scale); 72 | } 73 | start-=scale; 74 | } 75 | } 76 | 77 | void regenerateRules() { 78 | for(int i = 0; i < rules.length; i++) { 79 | rules[i] = ((rule >> i) & 0x01) != 0; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /oceanwaves/oceanwave.pde: -------------------------------------------------------------------------------- 1 | float time = 0; 2 | float speed = 0.05; 3 | 4 | void setup() { 5 | size(400, 400); 6 | } 7 | 8 | void draw() { 9 | background(255); 10 | 11 | float x = 0; 12 | 13 | while (x < width) { 14 | line(x, 200 + 50 * noise(x / 100, time), x, height); 15 | x = x + 1; 16 | } 17 | 18 | time = time + speed ; 19 | } 20 | -------------------------------------------------------------------------------- /processing-android-api-testing/Camera/beginCamera.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | noFill(); 3 | 4 | beginCamera(); 5 | camera(); 6 | rotateX(-PI/6); 7 | endCamera(); 8 | 9 | translate(50, 50, 0); 10 | rotateY(PI/3); 11 | box(45); 12 | -------------------------------------------------------------------------------- /processing-android-api-testing/Camera/camera.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | noFill(); 3 | background(204); 4 | camera(70.0, 35.0, 120.0, 50.0, 50.0, 0.0, 5 | 0.0, 1.0, 0.0); 6 | translate(50, 50, 0); 7 | rotateX(-PI/6); 8 | rotateY(PI/3); 9 | box(45); 10 | 11 | -------------------------------------------------------------------------------- /processing-android-api-testing/Camera/endCamera.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | noFill(); 3 | 4 | beginCamera(); 5 | camera(); 6 | rotateX(-PI/6); 7 | endCamera(); 8 | 9 | translate(50, 50, 0); 10 | rotateY(PI/3); 11 | box(45); 12 | -------------------------------------------------------------------------------- /processing-android-api-testing/Camera/frustum.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | noFill(); 3 | background(204); 4 | frustum(-10, 0, 0, 10, 10, 200); 5 | rotateY(PI/6); 6 | box(45); 7 | 8 | -------------------------------------------------------------------------------- /processing-android-api-testing/Camera/ortho.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | noFill(); 3 | ortho(-width/2, width/2, -height/2, height/2); // Same as ortho() 4 | translate(width/2, height/2, 0); 5 | rotateX(-PI/6); 6 | rotateY(PI/3); 7 | box(45); 8 | -------------------------------------------------------------------------------- /processing-android-api-testing/Camera/perspective.pde: -------------------------------------------------------------------------------- 1 | // Re-creates the default perspective 2 | size(100, 100, P3D); 3 | noFill(); 4 | float fov = PI/3.0; 5 | float cameraZ = (height/2.0) / tan(fov/2.0); 6 | perspective(fov, float(width)/float(height), 7 | cameraZ/10.0, cameraZ*10.0); 8 | translate(50, 50, 0); 9 | rotateX(-PI/6); 10 | rotateY(PI/3); 11 | box(45); 12 | 13 | -------------------------------------------------------------------------------- /processing-android-api-testing/Camera/printCamera.pde: -------------------------------------------------------------------------------- 1 | 2 | 3 | size(100, 100, P3D); 4 | printCamera(); 5 | 6 | // The program above prints this data: 7 | // 01.0000 00.0000 00.0000 -50.0000 8 | // 00.0000 01.0000 00.0000 -50.0000 9 | // 00.0000 00.0000 01.0000 -86.6025 10 | // 00.0000 00.0000 00.0000 01.0000 11 | 12 | -------------------------------------------------------------------------------- /processing-android-api-testing/Camera/printProjection.pde: -------------------------------------------------------------------------------- 1 | 2 | 3 | size(100, 100, P3D); 4 | printProjection(); 5 | 6 | // The program above prints this data: 7 | // 01.7321 00.0000 00.0000 00.0000 8 | // 00.0000 -01.7321 00.0000 00.0000 9 | // 00.0000 00.0000 -01.0202 -17.4955 10 | // 00.0000 00.0000 -01.0000 00.0000 11 | 12 | 13 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/alpha.pde: -------------------------------------------------------------------------------- 1 | noStroke(); 2 | color c = color(0, 126, 255, 102); 3 | fill(c); 4 | rect(15, 15, 35, 70); 5 | float value = alpha(c); // Sets 'value' to 102 6 | fill(value); 7 | rect(50, 15, 35, 70); 8 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/background.pde: -------------------------------------------------------------------------------- 1 | background(255, 204, 0); 2 | 3 | // add sample.jpg inside data folder of the sketch or by using Addfile.. from PDE 4 | /* 5 | PImage img; 6 | img = loadImage("sample.jpg"); 7 | background(img); 8 | */ 9 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/brightness.pde: -------------------------------------------------------------------------------- 1 | noStroke(); 2 | colorMode(HSB, 255); 3 | color c = color(0, 126, 255); 4 | fill(c); 5 | rect(15, 20, 35, 60); 6 | float value = brightness(c); // Sets 'value' to 255 7 | fill(value); 8 | rect(50, 20, 35, 60); 9 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/clear.pde: -------------------------------------------------------------------------------- 1 | 2 | 3 | PGraphics pg; 4 | 5 | void setup() { 6 | size(200, 200); 7 | pg = createGraphics(width, height); 8 | } 9 | 10 | void draw() { 11 | background(204); 12 | 13 | // Clear the PGraphics when the mouse is pressed 14 | if (mousePressed == true) { 15 | pg.beginDraw(); 16 | pg.clear(); 17 | pg.endDraw(); 18 | } else { 19 | pg.beginDraw(); 20 | pg.stroke(0, 102, 153); 21 | pg.line(width/2, height/2, mouseX, mouseY); 22 | pg.endDraw(); 23 | } 24 | 25 | image(pg, 0, 0); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/color.pde: -------------------------------------------------------------------------------- 1 | color c = color(255, 204, 0); // Define color 'c' 2 | fill(c); // Use color variable 'c' as fill color 3 | noStroke(); // Don't draw a stroke around shapes 4 | ellipse(25, 25, 80, 80); // Draw left circle 5 | 6 | // Using only one value with color() 7 | // generates a grayscale value. 8 | c = color(65); // Update 'c' with grayscale value 9 | fill(c); // Use updated 'c' as fill color 10 | ellipse(75, 75, 80, 80); // Draw right circle 11 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/colorMode.pde: -------------------------------------------------------------------------------- 1 | noStroke(); 2 | colorMode(HSB, 100); 3 | for (int i = 0; i < 100; i++) { 4 | for (int j = 0; j < 100; j++) { 5 | stroke(i, j, 100); 6 | point(i, j); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/hue.pde: -------------------------------------------------------------------------------- 1 | noStroke(); 2 | colorMode(HSB, 255); 3 | color c = color(0, 126, 255); 4 | fill(c); 5 | rect(15, 20, 35, 60); 6 | float value = hue(c); // Sets 'value' to "0" 7 | fill(value); 8 | rect(50, 20, 35, 60); 9 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/lerpColor.pde: -------------------------------------------------------------------------------- 1 | // not an official api now for processing-android mode, but can be used with JAVA-MODE of processing. 2 | 3 | stroke(255); 4 | background(51); 5 | color from = color(204, 102, 0); 6 | color to = color(0, 102, 153); 7 | color interA = lerpColor(from, to, .33); 8 | color interB = lerpColor(from, to, .66); 9 | fill(from); 10 | rect(10, 20, 20, 60); 11 | fill(interA); 12 | rect(30, 20, 20, 60); 13 | fill(interB); 14 | rect(50, 20, 20, 60); 15 | fill(to); 16 | rect(70, 20, 20, 60); 17 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/red.pde: -------------------------------------------------------------------------------- 1 | color c = color(255, 204, 0); // Define color 'c' 2 | fill(c); // Use color variable 'c' as fill color 3 | rect(15, 20, 35, 60); // Draw left rectangle 4 | 5 | float redValue = red(c); // Get red in 'c' 6 | println(redValue); // Print "255.0" 7 | fill(redValue, 0, 0); // Use 'redValue' in new fill 8 | rect(50, 20, 35, 60); // Draw right rectangle 9 | -------------------------------------------------------------------------------- /processing-android-api-testing/Color/saturation.pde: -------------------------------------------------------------------------------- 1 | noStroke(); 2 | colorMode(HSB, 255); 3 | color c = color(0, 126, 255); 4 | fill(c); 5 | rect(15, 20, 35, 60); 6 | float value = saturation(c); // Sets 'value' to 126 7 | fill(value); 8 | rect(50, 20, 35, 60) 9 | -------------------------------------------------------------------------------- /processing-android-api-testing/README.md: -------------------------------------------------------------------------------- 1 | # processing-api-testing 2 | 3 | ### All these codes can be found on this [official-docs](https://processing.org/reference/) page 4 | 5 | ### To test and run these code clone and build PDE from [here](https://github.com/processing/processing) and android-mode from [here](https://github.com/processing/processing-android) 6 | 7 | ### Or simply download latest porcessing distribution from [here](https://processing.org/download/) and run android-mode. 8 | 9 | ### To use these code inside Android-studio project then download processing-android Core library from [maven](https://mvnrepository.com/artifact/org.p5android/processing-core) and follow [instructions](https://android.processing.org/) how to use. 10 | -------------------------------------------------------------------------------- /processing-android-api-testing/Random/noise.pde: -------------------------------------------------------------------------------- 1 | float noiseScale = 0.02; 2 | 3 | void draw() { 4 | background(0); 5 | for (int x=0; x < width; x++) { 6 | float noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale); 7 | stroke(noiseVal*255); 8 | line(x, mouseY+noiseVal*80, x, height); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /processing-android-api-testing/Random/noiseDetail.pde: -------------------------------------------------------------------------------- 1 | 2 | 3 | float noiseVal; 4 | float noiseScale=0.02; 5 | 6 | void draw() { 7 | for (int y = 0; y < height; y++) { 8 | for (int x = 0; x < width/2; x++) { 9 | noiseDetail(3,0.5); 10 | noiseVal = noise((mouseX+x) * noiseScale, (mouseY+y) * noiseScale); 11 | stroke(noiseVal*255); 12 | point(x,y); 13 | noiseDetail(8,0.65); 14 | noiseVal = noise((mouseX + x + width/2) * noiseScale, 15 | (mouseY + y) * noiseScale); 16 | stroke(noiseVal * 255); 17 | point(x + width/2, y); 18 | } 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /processing-android-api-testing/Random/noiseSeed.pde: -------------------------------------------------------------------------------- 1 | 2 | 3 | float xoff = 0.0; 4 | 5 | void setup() { 6 | noiseSeed(0); 7 | stroke(0, 10); 8 | } 9 | 10 | void draw() { 11 | xoff = xoff + .01; 12 | float n = noise(xoff) * width; 13 | line(n, 0, n, height); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /processing-android-api-testing/Random/random.pde: -------------------------------------------------------------------------------- 1 | 2 | 3 | for (int i = 0; i < 100; i++) { 4 | float r = random(50); 5 | stroke(r*5); 6 | line(50, i, 50+r, i); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /processing-android-api-testing/Random/randomGaussian.pde: -------------------------------------------------------------------------------- 1 | float[] distribution = new float[360]; 2 | 3 | void setup() { 4 | size(100, 100); 5 | for (int i = 0; i < distribution.length; i++) { 6 | distribution[i] = int(randomGaussian() * 15); 7 | } 8 | } 9 | 10 | void draw() { 11 | background(204); 12 | 13 | translate(width/2, width/2); 14 | 15 | for (int i = 0; i < distribution.length; i++) { 16 | rotate(TWO_PI/distribution.length); 17 | stroke(0); 18 | float dist = abs(distribution[i]); 19 | line(0, 0, dist, 0); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /processing-android-api-testing/Random/randomSeed.pde: -------------------------------------------------------------------------------- 1 | 2 | 3 | randomSeed(0); 4 | for (int i=0; i < 100; i++) { 5 | float r = random(0, 255); 6 | stroke(r); 7 | line(i, 0, i, 100); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /processing-android-api-testing/light/ambientLight.pde: -------------------------------------------------------------------------------- 1 | 2 | 3 | size(100, 100, P3D); 4 | printProjection(); 5 | 6 | // The program above prints this data: 7 | // 01.7321 00.0000 00.0000 00.0000 8 | // 00.0000 -01.7321 00.0000 00.0000 9 | // 00.0000 00.0000 -01.0202 -17.4955 10 | // 00.0000 00.0000 -01.0000 00.0000 11 | 12 | -------------------------------------------------------------------------------- /processing-android-api-testing/light/directionalLight.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | background(0); 3 | noStroke(); 4 | directionalLight(51, 102, 126, -1, 0, 0); 5 | translate(20, 50, 0); 6 | sphere(30); 7 | -------------------------------------------------------------------------------- /processing-android-api-testing/light/lightFalloff.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | noStroke(); 3 | background(0); 4 | lightFalloff(1.0, 0.001, 0.0); 5 | pointLight(150, 250, 150, 50, 50, 50); 6 | beginShape(); 7 | vertex(0, 0, 0); 8 | vertex(100, 0, -100); 9 | vertex(100, 100, -100); 10 | vertex(0, 100, 0); 11 | endShape(CLOSE); 12 | -------------------------------------------------------------------------------- /processing-android-api-testing/light/lightSpecular.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | background(0); 3 | noStroke(); 4 | directionalLight(102, 102, 102, 0, 0, -1); 5 | lightSpecular(204, 204, 204); 6 | directionalLight(102, 102, 102, 0, 1, -1); 7 | lightSpecular(102, 102, 102); 8 | translate(20, 50, 0); 9 | specular(51, 51, 51); 10 | sphere(30); 11 | translate(60, 0, 0); 12 | specular(102, 102, 102); 13 | sphere(30); 14 | 15 | -------------------------------------------------------------------------------- /processing-android-api-testing/light/lights.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | background(0); 3 | noStroke(); 4 | // Sets the default ambient 5 | // and directional light 6 | lights(); 7 | translate(20, 50, 0); 8 | sphere(30); 9 | translate(60, 0, 0); 10 | sphere(30); 11 | 12 | -------------------------------------------------------------------------------- /processing-android-api-testing/light/normal.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | noStroke(); 3 | background(0); 4 | pointLight(150, 250, 150, 10, 30, 50); 5 | beginShape(); 6 | normal(0, 0, 1); 7 | vertex(20, 20, -10); 8 | vertex(80, 20, 10); 9 | vertex(80, 80, -10); 10 | vertex(20, 80, 10); 11 | endShape(CLOSE); 12 | -------------------------------------------------------------------------------- /processing-android-api-testing/light/pointLight.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | background(0); 3 | noStroke(); 4 | pointLight(51, 102, 126, 35, 40, 36); 5 | translate(80, 50, 0); 6 | sphere(30); 7 | 8 | -------------------------------------------------------------------------------- /processing-android-api-testing/light/spotLight.pde: -------------------------------------------------------------------------------- 1 | size(100, 100, P3D); 2 | int concentration = 600; // Try 1 -> 10000 3 | background(0); 4 | noStroke(); 5 | spotLight(51, 102, 126, 50, 50, 400, 6 | 0, 0, -1, PI/16, concentration); 7 | translate(80, 50, 0); 8 | sphere(30); 9 | -------------------------------------------------------------------------------- /shader-codes/advanced/3dlines/line.pde: -------------------------------------------------------------------------------- 1 | /* Lines by Andres Colubri 2 | Description: Draws and rotates a wireframe 3D cube 3 | Note: Please note that examples are read-only, therefore if you modify an example you must save it as a new project for the changes to apply). 4 | */ 5 | 6 | PShape cube; 7 | PShader lineShader; 8 | float angle; 9 | 10 | float weight = 10; 11 | 12 | void setup() { 13 | size(640, 360, P3D); 14 | 15 | lineShader = loadShader("linefrag.glsl", "linevert.glsl"); 16 | 17 | cube = createShape(BOX, 150); 18 | cube.setFill(false); 19 | cube.setStroke(color(255)); 20 | cube.setStrokeWeight(weight); 21 | } 22 | 23 | void draw() { 24 | background(0); 25 | 26 | translate(width/2, height/2); 27 | rotateX(angle); 28 | rotateY(angle); 29 | 30 | shader(lineShader, LINES); 31 | shape(cube); 32 | 33 | angle += 0.01; 34 | } 35 | -------------------------------------------------------------------------------- /shader-codes/advanced/3dlines/linefrag.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | precision mediump int; 4 | #endif 5 | 6 | varying vec4 vertColor; 7 | 8 | void main() { 9 | gl_FragColor = vertColor; 10 | } 11 | -------------------------------------------------------------------------------- /shader-codes/advanced/3dlines/linevert.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 transform; 2 | uniform vec4 viewport; 3 | 4 | attribute vec4 position; 5 | attribute vec4 color; 6 | attribute vec4 direction; 7 | 8 | varying vec4 vertColor; 9 | 10 | vec3 clipToWindow(vec4 clip, vec4 viewport) { 11 | vec3 dclip = clip.xyz / clip.w; 12 | vec2 xypos = (dclip.xy + vec2(1.0, 1.0)) * 0.5 * viewport.zw; 13 | return vec3(xypos, dclip.z * 0.5 + 0.5); 14 | } 15 | 16 | void main() { 17 | vec4 clip0 = transform * position; 18 | vec4 clip1 = clip0 + transform * vec4(direction.xyz, 0); 19 | float thickness = direction.w; 20 | 21 | vec3 win0 = clipToWindow(clip0, viewport); 22 | vec3 win1 = clipToWindow(clip1, viewport); 23 | vec2 tangent = win1.xy - win0.xy; 24 | 25 | vec2 normal = normalize(vec2(-tangent.y, tangent.x)); 26 | vec2 offset = normal * thickness; 27 | gl_Position.xy = clip0.xy + offset.xy; 28 | gl_Position.zw = clip0.zw; 29 | vertColor = color; 30 | } 31 | -------------------------------------------------------------------------------- /shader-codes/advanced/colorpoints/colorpoint.pde: -------------------------------------------------------------------------------- 1 | /* Taken from http://glsl.heroku.com/e#4633.5 2 | Description: Draws filled circles with random sizes and colors. Click and drag your mouse on the screen to generate them. 3 | Note: Please note that examples are read-only, therefore if you modify an example you must save it as a new project for the changes to apply). 4 | */ 5 | 6 | PShader pointShader; 7 | 8 | void setup() { 9 | size(640, 360, P3D); 10 | 11 | pointShader = loadShader("pointfrag.glsl", "pointvert.glsl"); 12 | pointShader.set("sharpness", 0.9); 13 | 14 | strokeCap(SQUARE); 15 | background(0); 16 | } 17 | 18 | void draw() { 19 | if (mousePressed) { 20 | shader(pointShader); 21 | 22 | float w = random(5, 50); 23 | pointShader.set("weight", w); 24 | strokeWeight(w); 25 | 26 | stroke(random(255), random(255), random(255)); 27 | point(mouseX, mouseY); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /shader-codes/advanced/colorpoints/pointfrag.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | precision mediump int; 4 | #endif 5 | 6 | uniform float weight; 7 | uniform float sharpness; 8 | 9 | varying vec4 vertColor; 10 | varying vec2 center; 11 | varying vec2 pos; 12 | 13 | void main() { 14 | float len = weight/2.0 - length(pos); 15 | vec4 color = vec4(1.0, 1.0, 1.0, len); 16 | color = mix(vec4(0.0), color, sharpness); 17 | color = clamp(color, 0.0, 1.0); 18 | gl_FragColor = color * vertColor; 19 | } 20 | -------------------------------------------------------------------------------- /shader-codes/advanced/colorpoints/pointvert.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 projection; 2 | uniform mat4 transform; 3 | 4 | attribute vec4 position; 5 | attribute vec4 color; 6 | attribute vec2 offset; 7 | 8 | varying vec4 vertColor; 9 | varying vec2 center; 10 | varying vec2 pos; 11 | 12 | void main() { 13 | vec4 clip = transform * position; 14 | gl_Position = clip + projection * vec4(offset, 0, 0); 15 | 16 | vertColor = color; 17 | center = clip.xy; 18 | pos = offset; 19 | } 20 | -------------------------------------------------------------------------------- /shader-codes/basic/points/DrawPoints.pde: -------------------------------------------------------------------------------- 1 | /* Draw Points by Andres Colubri 2 | Description: Draws points as you move your mouse. Point sizes are random 3 | Note: Please note that examples are read-only, therefore if you modify an example you must save it as a new project for the changes to apply). 4 | 5 | */ 6 | 7 | PShader pointShader; 8 | 9 | void setup() { 10 | size(640, 360, P3D); 11 | 12 | pointShader = loadShader("pointfrag.glsl", "pointvert.glsl"); 13 | 14 | stroke(255); 15 | strokeWeight(50); 16 | 17 | background(0); 18 | } 19 | 20 | void draw() { 21 | shader(pointShader); 22 | // It is possible to set the shader type, but not needed, Processing will try to 23 | // autodetect the type 24 | //shader(pointShader, POINTS); 25 | if (mousePressed) { 26 | point(mouseX, mouseY); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /shader-codes/basic/points/pointfrag.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | precision mediump int; 4 | #endif 5 | 6 | varying vec4 vertColor; 7 | 8 | void main() { 9 | gl_FragColor = vertColor; // assigns the final pixel color 10 | } 11 | -------------------------------------------------------------------------------- /shader-codes/basic/points/pointvert.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 projection; 2 | uniform mat4 modelview; 3 | 4 | attribute vec4 position; 5 | attribute vec4 color; 6 | attribute vec2 offset; 7 | 8 | varying vec4 vertColor; 9 | 10 | void main() { 11 | vec4 pos = modelview * position; 12 | vec4 clip = projection * pos; 13 | 14 | gl_Position = clip + projection * vec4(offset, 0, 0); 15 | 16 | vertColor = color; 17 | } 18 | -------------------------------------------------------------------------------- /shader-codes/basic/simpleTexture/lachoy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/shader-codes/basic/simpleTexture/lachoy.jpg -------------------------------------------------------------------------------- /shader-codes/basic/simpleTexture/simpletexture.pde: -------------------------------------------------------------------------------- 1 | /* Simple Texture by Andres Colubri 2 | Description: Applies a texture on a rotating 3D cylinder 3 | Texture from Jason Liebig's FLICKR collection of vintage labels and wrappers: 4 | http://www.flickr.com/photos/jasonliebigstuff/3739263136/in/photostream/ 5 | Note: Please note that examples are read-only, therefore if you modify an example you must save it as a new project for the changes to apply). 6 | */ 7 | 8 | PImage label; 9 | PShape can; 10 | float angle; 11 | 12 | PShader texShader; 13 | 14 | void setup() { 15 | size(640, 360, P3D); 16 | label = loadImage("lachoy.jpg"); 17 | can = createCan(100, 200, 32, label); 18 | texShader = loadShader("texfrag.glsl", "texvert.glsl"); 19 | } 20 | 21 | void draw() { 22 | background(0); 23 | 24 | shader(texShader); 25 | 26 | translate(width/2, height/2); 27 | rotateY(angle); 28 | shape(can); 29 | angle += 0.01; 30 | } 31 | 32 | PShape createCan(float r, float h, int detail, PImage tex) { 33 | textureMode(NORMAL); 34 | PShape sh = createShape(); 35 | sh.beginShape(QUAD_STRIP); 36 | sh.noStroke(); 37 | sh.texture(tex); 38 | for (int i = 0; i <= detail; i++) { 39 | float angle = TWO_PI / detail; 40 | float x = sin(i * angle); 41 | float z = cos(i * angle); 42 | float u = float(i) / detail; 43 | sh.normal(x, 0, z); 44 | sh.vertex(x * r, -h/2, z * r, u, 0); 45 | sh.vertex(x * r, +h/2, z * r, u, 1); 46 | } 47 | sh.endShape(); 48 | return sh; 49 | } 50 | -------------------------------------------------------------------------------- /shader-codes/basic/simpleTexture/textfrag.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | precision mediump int; 4 | #endif 5 | 6 | uniform sampler2D texture; 7 | 8 | varying vec4 vertColor; 9 | varying vec4 vertTexCoord; 10 | 11 | void main() { 12 | gl_FragColor = texture2D(texture, vertTexCoord.st) * vertColor; // assigns the final pixel color 13 | 14 | // Try changing the value of vertColor in the fragment shader to see what effect it has 15 | // on the final pixel color. e.g you could do vertColor = vec4(0,1,0,1); 16 | } 17 | -------------------------------------------------------------------------------- /shader-codes/basic/simpleTexture/textvert.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 transform; 2 | uniform mat4 texMatrix; 3 | 4 | attribute vec4 position; 5 | attribute vec4 color; 6 | attribute vec2 texCoord; 7 | 8 | varying vec4 vertColor; 9 | varying vec4 vertTexCoord; 10 | 11 | void main() { 12 | gl_Position = transform * position; 13 | 14 | vertColor = color; 15 | vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0); 16 | } 17 | -------------------------------------------------------------------------------- /voroni/rune.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ranaaditya/processing-sketchbook/8f1e3727cdef3736a654ce7d3cc0bea038893f70/voroni/rune.pdf -------------------------------------------------------------------------------- /voroni/voroniPortrait.pde: -------------------------------------------------------------------------------- 1 | import processing.pdf.*; 2 | import toxi.math.conversion.*; 3 | import toxi.geom.*; 4 | import toxi.math.*; 5 | import toxi.geom.mesh2d.*; 6 | //import toxi.geom.nurbs.*; 7 | import toxi.util.datatypes.*; 8 | import toxi.util.events.*; 9 | import toxi.geom.mesh.subdiv.*; 10 | import toxi.math.waves.*; 11 | import toxi.geom.mesh.*; 12 | import toxi.util.*; 13 | import toxi.math.noise.*; 14 | import toxi.processing.*; 15 | 16 | //Image for portrait 17 | PImage img; 18 | 19 | // ranges for x/y positions of points 20 | FloatRange xpos, ypos; 21 | 22 | // helper class for rendering 23 | ToxiclibsSupport gfx; 24 | 25 | // empty voronoi mesh container 26 | Voronoi voronoi = new Voronoi(); 27 | 28 | // optional polygon clipper 29 | PolygonClipper2D clip; 30 | 31 | // switches 32 | boolean doShowPoints = false; 33 | boolean doShowDelaunay; 34 | boolean doShowHelp=false; 35 | boolean doClip; 36 | boolean doSave; 37 | 38 | void setup() { 39 | //image must be same size as sketch 40 | size(400, 300); 41 | noLoop(); 42 | smooth(); 43 | PGraphics pdf=beginRecord(PDF, "rune.pdf"); 44 | //make 400x300, grayscale before loading 45 | img = loadImage("rune.jpg"); 46 | // focus x positions around horizontal center (w/ 33% standard deviation) 47 | xpos=new BiasedFloatRange(0, width, width/2, 0.333f); 48 | // focus y positions around bottom (w/ 50% standard deviation) 49 | ypos=new BiasedFloatRange(0, height, height, 0.5f); 50 | // setup clipper with centered rectangle 51 | clip=new SutherlandHodgemanClipper(new Rect(width*0.125, height*0.125, width*0.75, height*0.75)); 52 | gfx = new ToxiclibsSupport(this); 53 | textFont(createFont("SansSerif", 10)); 54 | 55 | 56 | // saveFrame("voronoi-" + DateUtils.timeStamp() + ".dxm"); 57 | 58 | 59 | pixelArray(); 60 | //comment out the following line to see the sketch 61 | gfx.setGraphics(pdf); 62 | veronoiFunctions(); 63 | endRecord(); 64 | exit(); 65 | } 66 | 67 | 68 | 69 | void keyPressed() { 70 | switch(key) { 71 | case ' ': 72 | doSave = true; 73 | break; 74 | case 't': 75 | doShowDelaunay = !doShowDelaunay; 76 | break; 77 | case 'x': 78 | voronoi = new Voronoi(); 79 | break; 80 | case 'p': 81 | doShowPoints = !doShowPoints; 82 | break; 83 | case 'c': 84 | doClip=!doClip; 85 | break; 86 | case 'h': 87 | doShowHelp=!doShowHelp; 88 | break; 89 | case 'r': 90 | for (int i = 0; i < 10; i++) { 91 | voronoi.addPoint(new Vec2D(xpos.pickRandom(), ypos.pickRandom())); 92 | } 93 | break; 94 | } 95 | } 96 | 97 | 98 | 99 | void addPoint(int x, int y){ 100 | 101 | voronoi.addPoint(new Vec2D(x,y)); 102 | 103 | } 104 | 105 | 106 | 107 | 108 | 109 | 110 | void veronoiFunctions(){ 111 | // draw all voronoi polygons, clip them if needed... 112 | for (Polygon2D poly : voronoi.getRegions()) { 113 | if (doClip) { 114 | gfx.polygon2D(clip.clipPolygon(poly)); 115 | } 116 | else { 117 | gfx.polygon2D(poly); 118 | } 119 | } 120 | // draw delaunay triangulation 121 | if (doShowDelaunay) { 122 | stroke(0, 0, 255, 50); 123 | beginShape(TRIANGLES); 124 | for (Triangle2D t : voronoi.getTriangles()) { 125 | gfx.triangle(t, false); 126 | } 127 | endShape(); 128 | } 129 | // draw original points added to voronoi 130 | if (doShowPoints) { 131 | fill(255, 0, 255); 132 | noStroke(); 133 | for (Vec2D c : voronoi.getSites()) { 134 | ellipse(c.x, c.y, 5, 5); 135 | } 136 | } 137 | 138 | if (doShowHelp) { 139 | fill(255, 0, 0); 140 | text("p: toggle points", 20, 20); 141 | text("t: toggle triangles", 20, 40); 142 | text("x: clear all", 20, 60); 143 | text("r: add random", 20, 80); 144 | text("c: toggle clipping", 20, 100); 145 | text("h: toggle help display", 20, 120); 146 | text("space: save frame", 20, 140); 147 | } 148 | 149 | } 150 | 151 | void pixelArray(){ 152 | loadPixels(); 153 | 154 | // We must also call loadPixels() on the PImage since we are going to read its pixels. 155 | img.loadPixels(); 156 | for (int y = 0; y < height; y++ ) { 157 | for (int x = 0; x < width; x++ ) { 158 | int loc = x + y*width; 159 | // The functions red(), green(), and blue() pull out the three color components from a pixel. 160 | float r = red(img.pixels [loc]); 161 | float g = green(img.pixels[loc]); 162 | float b = blue(img.pixels[loc]); 163 | 164 | float h = hue(img.pixels [loc]); 165 | float s = saturation(img.pixels [loc]); 166 | float br = brightness(img.pixels [loc]); 167 | 168 | 169 | colorMode(HSB); 170 | 171 | 172 | //This number controls the brightness threshold (0-255) 173 | if (br < 250) { 174 | //This is the percentage of points that are drawn at above threshold (5-10% is best) 175 | if(random(1) < 0.07){ 176 | 177 | addPoint(x,y); 178 | println("x: " + x + ", y: " + y); 179 | } 180 | } 181 | 182 | pixels[loc] = color(h, s, br); 183 | } 184 | } 185 | 186 | } 187 | -------------------------------------------------------------------------------- /wallclock/wallclock.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | size(450, 450); 3 | background(49, 128, 147); 4 | } 5 | void draw () { 6 | 7 | //Clock center, radius and diameter 8 | int xcenter = width / 2; 9 | int ycenter = width / 2; 10 | int rclock = min(width,height) / 4; 11 | float dclock = rclock * 2; 12 | float rseconds = rclock * 0.8; 13 | float rminutes = rclock * 0.7; 14 | float rhours = rclock * 0.4; 15 | 16 | //Clock edge and background 17 | stroke(50, 58, 59); 18 | strokeWeight(4); 19 | ellipse(xcenter, ycenter, dclock, dclock); 20 | fill(215, 227, 226); 21 | 22 | //Mapping 23 | float s = map(second(),0,60,0,TWO_PI) - HALF_PI; 24 | float m = map(minute()+norm(second(),0,60),0,60,0,TWO_PI) - HALF_PI; 25 | float h = map(hour()+norm(minute(),0,60),0,24,0,TWO_PI) - HALF_PI; 26 | 27 | //Clock arms 28 | stroke(50, 58, 59); 29 | strokeWeight(2); 30 | line(xcenter, ycenter, xcenter + cos(s) * rseconds, ycenter + sin(s) * rseconds); 31 | line(xcenter, ycenter, xcenter + cos(m) * rminutes, ycenter + sin(m) * rminutes); 32 | line(xcenter, ycenter, xcenter + cos(h) * rhours, ycenter + sin(h) * rhours); 33 | 34 | //minute indicators 35 | stroke(50, 58, 59); 36 | beginShape(POINTS); 37 | for (int a = 0; a < 360; a += 360/60 ) { 38 | float xpoint = xcenter + cos(radians(a)) * rclock * 0.9; 39 | float ypoint = ycenter + sin(radians(a)) * rclock * 0.9; 40 | vertex(xpoint, ypoint); 41 | } 42 | endShape(); 43 | 44 | } 45 | --------------------------------------------------------------------------------