From 68c460be7d404b6514dbce7cd5f48453f8c02345 Mon Sep 17 00:00:00 2001 From: Casey Reas Date: Tue, 6 Sep 2011 03:51:23 +0000 Subject: [PATCH] Removing some examples --- .../Basics/Math/Arctangent/Arctangent.pde | 13 +- java/examples/Basics/Math/Modulo/Modulo.pde | 31 -- java/examples/Basics/Math/Random/Random.pde | 5 +- .../Objects/Neighborhood/Neighborhood.pde | 303 ------------------ .../Animation/Sequential/Sequential.pde | 14 +- .../Topics/Drawing/Animator/Animator.pde | 2 +- .../ContinuousLines/ContinuousLines.pde | 8 +- .../examples/Topics/Drawing/Pulses/Pulses.pde | 4 +- java/examples/Topics/GUI/Button/Button.pde | 6 +- java/examples/Topics/GUI/Buttons/Buttons.pde | 2 +- java/examples/Topics/GUI/Handles/Handles.pde | 39 +-- .../Topics/GUI/ImageButton/ImageButton.pde | 108 ------- .../Topics/GUI/ImageButton/data/base.gif | Bin 774 -> 0 bytes .../Topics/GUI/ImageButton/data/down.gif | Bin 656 -> 0 bytes .../Topics/GUI/ImageButton/data/roll.gif | Bin 774 -> 0 bytes .../examples/Topics/GUI/Rollover/Rollover.pde | 21 +- .../Topics/GUI/Scrollbar/Scrollbar.pde | 15 +- .../Topics/Geometry/BrickTower/BrickTower.pde | 59 ---- .../Topics/Geometry/BrickTower/Cube.pde | 60 ---- .../Image Processing/Histogram/Histogram.pde | 3 +- .../PixelArray/PixelArray.pde | 2 - .../Topics/Interaction/Tickle/Tickle.pde | 7 +- java/examples/Topics/Motion/Bounce/Bounce.pde | 11 +- .../Motion/BouncyBubbles/BouncyBubbles.pde | 4 +- .../Topics/Motion/Collision/Collision.pde | 85 ----- java/examples/Topics/Motion/Linear/Linear.pde | 13 +- .../Topics/Motion/Reflection1/Reflection1.pde | 2 +- .../Topics/Motion/Reflection2/Reflection2.pde | 2 +- java/examples/Topics/Simulate/Fluid/Fluid.pde | 208 ------------ java/examples/Topics/Simulate/Smoke/Smoke.pde | 264 --------------- 30 files changed, 76 insertions(+), 1215 deletions(-) delete mode 100644 java/examples/Basics/Math/Modulo/Modulo.pde delete mode 100644 java/examples/Basics/Objects/Neighborhood/Neighborhood.pde delete mode 100644 java/examples/Topics/GUI/ImageButton/ImageButton.pde delete mode 100644 java/examples/Topics/GUI/ImageButton/data/base.gif delete mode 100644 java/examples/Topics/GUI/ImageButton/data/down.gif delete mode 100644 java/examples/Topics/GUI/ImageButton/data/roll.gif delete mode 100644 java/examples/Topics/Geometry/BrickTower/BrickTower.pde delete mode 100644 java/examples/Topics/Geometry/BrickTower/Cube.pde delete mode 100644 java/examples/Topics/Motion/Collision/Collision.pde delete mode 100644 java/examples/Topics/Simulate/Fluid/Fluid.pde delete mode 100644 java/examples/Topics/Simulate/Smoke/Smoke.pde diff --git a/java/examples/Basics/Math/Arctangent/Arctangent.pde b/java/examples/Basics/Math/Arctangent/Arctangent.pde index f321eba92..e299032e1 100644 --- a/java/examples/Basics/Math/Arctangent/Arctangent.pde +++ b/java/examples/Basics/Math/Arctangent/Arctangent.pde @@ -8,18 +8,16 @@ Eye e1, e2, e3; -void setup() -{ +void setup() { size(640, 360); smooth(); noStroke(); - e1 = new Eye( 190, 16, 120); + e1 = new Eye( 250, 16, 120); e2 = new Eye( 164, 185, 80); - e3 = new Eye( 390, 200, 220); + e3 = new Eye( 420, 230, 220); } -void draw() -{ +void draw() { background(102); e1.update(mouseX, mouseY); @@ -31,8 +29,7 @@ void draw() e3.display(); } -class Eye -{ +class Eye { int x, y; int size; float angle = 0.0; diff --git a/java/examples/Basics/Math/Modulo/Modulo.pde b/java/examples/Basics/Math/Modulo/Modulo.pde deleted file mode 100644 index 7ad1f5dc3..000000000 --- a/java/examples/Basics/Math/Modulo/Modulo.pde +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Modulo. - * - * The modulo operator (%) returns the remainder of a number - * divided by another. As in this example, it is often used - * to keep numerical values within a set range. - */ - -int num = 20; -float c; - -void setup() -{ - size(200,200); - fill(255); - frameRate(30); -} - -void draw() -{ - background(0); - c+=0.1; - for(int i=1; i= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; @@ -133,7 +123,6 @@ boolean overRect(int x, int y, int width, int height) } } -int lock(int val, int minv, int maxv) -{ +int lock(int val, int minv, int maxv) { return min(max(val, minv), maxv); } diff --git a/java/examples/Topics/GUI/ImageButton/ImageButton.pde b/java/examples/Topics/GUI/ImageButton/ImageButton.pde deleted file mode 100644 index 338cb3d1e..000000000 --- a/java/examples/Topics/GUI/ImageButton/ImageButton.pde +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Image button. - * - * Loading images and using them to create a button. - */ - - -ImageButtons button; - -void setup() -{ - size(200, 200); - background(102, 102, 102); - - // Define and create image button - PImage b = loadImage("base.gif"); - PImage r = loadImage("roll.gif"); - PImage d = loadImage("down.gif"); - int x = width/2 - b.width/2; - int y = height/2 - b.height/2; - int w = b.width; - int h = b.height; - button = new ImageButtons(x, y, w, h, b, r, d); -} - -void draw() -{ - button.update(); - button.display(); -} - -class Button -{ - int x, y; - int w, h; - color basecolor, highlightcolor; - color currentcolor; - boolean over = false; - boolean pressed = false; - - void pressed() { - if(over && mousePressed) { - pressed = true; - } else { - pressed = false; - } - } - - boolean overRect(int x, int y, int width, int height) { - if (mouseX >= x && mouseX <= x+width && - mouseY >= y && mouseY <= y+height) { - return true; - } else { - return false; - } -} -} - -class ImageButtons extends Button -{ - PImage base; - PImage roll; - PImage down; - PImage currentimage; - - ImageButtons(int ix, int iy, int iw, int ih, PImage ibase, PImage iroll, PImage idown) - { - x = ix; - y = iy; - w = iw; - h = ih; - base = ibase; - roll = iroll; - down = idown; - currentimage = base; - } - - void update() - { - over(); - pressed(); - if(pressed) { - currentimage = down; - } else if (over){ - currentimage = roll; - } else { - currentimage = base; - } - } - - void over() - { - if( overRect(x, y, w, h) ) { - over = true; - } else { - over = false; - } - } - - void display() - { - image(currentimage, x, y); - } -} - - - - diff --git a/java/examples/Topics/GUI/ImageButton/data/base.gif b/java/examples/Topics/GUI/ImageButton/data/base.gif deleted file mode 100644 index 8d7603a01811146e295889dfbbf6f2baa36ec215..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 774 zcmV+h1Nr<%Nk%w1VQ2tY0HOo{)X>QP|Nnr1fB*mh|Ns900000000000A^8LW000C4 zEC2ui0B8VM000C3IJ(^aFv>}*y*TU5yZ>M)j-(ZwXsWJk>%MR-tI%xUcz)M<@BcC$ za7g?K1AwG*$!t2G(5Q486<7sFs&>omQm@!Y%1bVrtJmy#&Gv%TZ7L+LeTz|a`6EBI zJH~ubbAeEP4SVcJN|y3fKW z07?QdgIy9+b!!!^J;a=wf#OBxlB2#j&Pd;1M;0e?hj~*|A59=Is)+!)6 zi~cYkDd?pC9kVn2LTbdtvC+hF6%}4onUUqjh=opa+ZSo1OPl&iGV#c2jmVooXT~#F z4O~j03mpbkI)LameMgx}jmFd|t%OKdW^K9kXHzLWX->gVL~B*BGTl8PTh^;pYg^bB zaf`Mn)VLSQay^U2EzE?9zUOqS)+d)DrzteC*lvX`N3->8=q{HySEY#o%;Ap zF0F~#0)ojLpx-Rr+Ec2AxAYUtSY(%+u` zxj6aDgY74teb&{IUt2JVHeOWVC5T>S@%1L)dkgw>pb-xK2BCrM0WqNx@U;=$4jFb4 zB7<|4s33vlfplRIDn1BT93$HBA%7d9=);Wz_Sc<@9lpRLg)AmgqmVIbI3piNx-cY& z6$a8IUuK+0$CT5oVI_?(Qd!29B6gYO8DKJErg1*rcjlU#9meLHeWh6-oOJeh1Q>Yc zspp=2_UY%Jfa-Z?poA7`=%IcNis+(@HoB*xjz%h}p(Rvm>7|%vs_CYjcIxS;4kQ2o EJ8f`&hyVZp diff --git a/java/examples/Topics/GUI/ImageButton/data/down.gif b/java/examples/Topics/GUI/ImageButton/data/down.gif deleted file mode 100644 index 7e4f4415532c840ee85251bc23dee5e04a76153c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 656 zcmV;B0&o3CNk%w1VQ2tY0FeU#|NsAhfPer10RR90A^8LW00093EC2ui0B8VM00092 zl#i*)?GK}zwAzca-n{z{O2J5$=82~2%C@e_yz)%fb8P4O?&ACp-1!24qVb4KDwoWr z^9cnEqtvSP`kZ37+%8k=4U4bfvH83#qt|FP`yF<}=U6$t$haTv_q-mzQ1X}L_s2(9 zsCP)Vuy>I5aJFcbhydvz8Ay_;;An8!z?mRuR{5v|A&NlSWr^DO`WY(_r#Vt9O9-o* zi{#pBOXT(IyIb7rNjn^jtIV4K8ojK*%0--fZIlhzyZyyH?R*S9E6pvQ1rCg?ZJcZ_ zbs9C9&VKHVFCTCJO}$yF?_IfB#JpiUP^}p}fzJvCB#7|en0)*wk~>##lteNA78kbb z^bs9I0|~=<#5nL-##I{?rW|*2pU8$0Zvm|M5T(kOpjg_Rm{VrVj!x)}40Us+(4y)n zO%N6HAjy_gC_v?TwB)>}Nu!4JDQqiFkcNUv6`-}B(nNjCeytf6ibaEL=-z`{Wv<&b zc4dOiyLaiFzGu^V)d`32+o?b023EXIX-~XW9|v|RR%2tp{00ej>~C}B&VwNPrOb$Q zS=HnI*13!b_Fcwtx0t?~*>z;k3_)wI{hIX~(?*-z?mGH6W<|1Fqqf$3IcMc2OGjUf zmTGFrb+6CPE_!!t;aRmqCog`xZjRoaqIXUkcjETN-E-gGY`uKx!Kw3MZGV_=`XL9@ zdy~aC-hIC1_uOy*hQuI(gFT3tZB037AXe%%*jNq(h;2~#nT4SNC!&HG qMF<{?yv_KXVKjPH-;Eghr{j$w{0L-_LJmn}kwzYgWReOL0029rWK6RF diff --git a/java/examples/Topics/GUI/ImageButton/data/roll.gif b/java/examples/Topics/GUI/ImageButton/data/roll.gif deleted file mode 100644 index 7e2a1bc2e3aa28fb61418115bdd01dd94ac73b70..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 774 zcmV+h1Nr<%Nk%w1VQ2tY0HOo{wz8`K|Nnr1fB*mh|Ns900000000000A^8LW000C4 zEC2ui0B8VM000C3IJ(^aFv>}*y*TU5yZ>M)j-(ZwXsWJk>%MR-tI%xUcz)M<@BcC$ za7g?K1AwG*$!t2G(5Q486<7sFs&>omQm@!Y%1bVrtJmy#&Gv%TZ7L+LeTz|a`6EBI zJH~ubbAeEP4SVcJN|y3fKW z07?QdgIy9+b!!!^J;a=wf#OBxlB2#j&Pd;1M;0e?hj~*|A59=Is)+!)6 zi~cYkDd?pC9kVn2LTbdtvC+hF6%}4onUUqjh=opa+ZSo1OPl&iGV#c2jmVooXT~#F z4O~j03mpbkI)LameMgx}jmFd|t%OKdW^K9kXHzLWX->gVL~B*BGTl8PTh^;pYg^bB zaf`Mn)VLSQay^U2EzE?9zUOqS)+d)DrzteC*lvX`N3->8=q{HySEY#o%;Ap zF0F~#0)ojLpx-Rr+Ec2AxAYUtSY(%+u` zxj6aDgY74teb&{IUt2JVHeOWVC5T>S@%1L)dkgw>pb-xK2BCrM0WqNx@U;=$4jFb4 zB7<|4s33vlfplRIDn1BT93$HBA%7d9=);Wz_Sc<@9lpRLg)AmgqmVIbI3piNx-cY& z6$a8IUuK+0$CT5oVI_?(Qd!29B6gYO8DKJErg1*rcjlU#9meLHeWh6-oOJeh1Q>Yc zspp=2_UY%Jfa-Z?poA7`=%IcNis+(@HoB*xjz%h}p(Rvm>7|%vs_CYjcIxS;4kQ2o EJ7O_@E&u=k diff --git a/java/examples/Topics/GUI/Rollover/Rollover.pde b/java/examples/Topics/GUI/Rollover/Rollover.pde index 4785ec9ac..4ad8d3238 100644 --- a/java/examples/Topics/GUI/Rollover/Rollover.pde +++ b/java/examples/Topics/GUI/Rollover/Rollover.pde @@ -8,8 +8,8 @@ int rectX, rectY; // Position of square button int circleX, circleY; // Position of circle button -int rectSize = 50; // Diameter of rect -int circleSize = 53; // Diameter of circle +int rectSize = 90; // Diameter of rect +int circleSize = 93; // Diameter of circle color rectColor; color circleColor; @@ -18,9 +18,8 @@ color baseColor; boolean rectOver = false; boolean circleOver = false; -void setup() -{ - size(200, 200); +void setup() { + size(640, 360); smooth(); rectColor = color(0); circleColor = color(255); @@ -32,8 +31,7 @@ void setup() ellipseMode(CENTER); } -void draw() -{ +void draw() { update(mouseX, mouseY); noStroke(); @@ -53,8 +51,7 @@ void draw() ellipse(circleX, circleY, circleSize, circleSize); } -void update(int x, int y) -{ +void update(int x, int y) { if( overCircle(circleX, circleY, circleSize) ) { circleOver = true; rectOver = false; @@ -66,8 +63,7 @@ void update(int x, int y) } } -boolean overRect(int x, int y, int width, int height) -{ +boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; @@ -76,8 +72,7 @@ boolean overRect(int x, int y, int width, int height) } } -boolean overCircle(int x, int y, int diameter) -{ +boolean overCircle(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) { diff --git a/java/examples/Topics/GUI/Scrollbar/Scrollbar.pde b/java/examples/Topics/GUI/Scrollbar/Scrollbar.pde index 4647b6095..8aa1d735d 100644 --- a/java/examples/Topics/GUI/Scrollbar/Scrollbar.pde +++ b/java/examples/Topics/GUI/Scrollbar/Scrollbar.pde @@ -10,20 +10,18 @@ PImage top, bottom; // Two image to load int topWidth, bottomWidth; // The width of the top and bottom images -void setup() -{ - size(200, 200); +void setup() { + size(640, 360); noStroke(); - hs1 = new HScrollbar(0, 20, width, 10, 3*5+1); - hs2 = new HScrollbar(0, height-20, width, 10, 3*5+1); + hs1 = new HScrollbar(0, 20, width, 20, 3*5+1); + hs2 = new HScrollbar(0, height-20, width, 20, 3*5+1); top = loadImage("seedTop.jpg"); topWidth = top.width; bottom = loadImage("seedBottom.jpg"); bottomWidth = bottom.width; } -void draw() -{ +void draw() { background(255); // Get the position of the top scrollbar @@ -45,8 +43,7 @@ void draw() } -class HScrollbar -{ +class HScrollbar { int swidth, sheight; // width and height of bar int xpos, ypos; // x and y position of bar float spos, newspos; // x position of slider diff --git a/java/examples/Topics/Geometry/BrickTower/BrickTower.pde b/java/examples/Topics/Geometry/BrickTower/BrickTower.pde deleted file mode 100644 index c40186498..000000000 --- a/java/examples/Topics/Geometry/BrickTower/BrickTower.pde +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Brick Tower - * by Ira Greenberg. - * - * 3D castle tower constructed out of individual bricks. - * Uses the PVector and Cube classes. - */ - -float bricksPerLayer = 16.0; -float brickLayers = 18.0; -Cube brick; -float brickWidth = 60, brickHeight = 25, brickDepth = 25; -float radius = 175.0; -float angle = 0; - -void setup(){ - size(640, 360, P3D); - brick = new Cube(brickWidth, brickHeight, brickDepth); -} - -void draw(){ - background(0); - float tempX = 0, tempY = 0, tempZ = 0; - fill(182, 62, 29); - noStroke(); - // Add basic light setup - lights(); - translate(width/2, height*1.2, -380); - // Tip tower to see inside - rotateX(radians(-45)); - // Slowly rotate tower - rotateY(frameCount * PI/600); - for (int i = 0; i < brickLayers; i++){ - // Increment rows - tempY-=brickHeight; - // Alternate brick seams - angle = 360.0 / bricksPerLayer * i/2; - for (int j = 0; j < bricksPerLayer; j++){ - tempZ = cos(radians(angle))*radius; - tempX = sin(radians(angle))*radius; - pushMatrix(); - translate(tempX, tempY, tempZ); - rotateY(radians(angle)); - // Add crenelation - if (i==brickLayers-1){ - if (j%2 == 0){ - brick.create(); - } - } - // Create main tower - else { - brick.create(); - } - popMatrix(); - angle += 360.0/bricksPerLayer; - } - } -} - diff --git a/java/examples/Topics/Geometry/BrickTower/Cube.pde b/java/examples/Topics/Geometry/BrickTower/Cube.pde deleted file mode 100644 index ba4fdb361..000000000 --- a/java/examples/Topics/Geometry/BrickTower/Cube.pde +++ /dev/null @@ -1,60 +0,0 @@ -class Cube { - - PVector[] vertices = new PVector[24]; - float w, h, d; - - Cube(){ } - - Cube(float w, float h, float d){ - this.w = w; - this.h = h; - this.d = d; - - // Cube composed of 6 quads - // Front - vertices[0] = new PVector(-w/2, -h/2, d/2); - vertices[1] = new PVector(w/2, -h/2, d/2); - vertices[2] = new PVector(w/2, h/2, d/2); - vertices[3] = new PVector(-w/2, h/2, d/2); - - // Left - vertices[4] = new PVector(-w/2, -h/2, d/2); - vertices[5] = new PVector(-w/2, -h/2, -d/2); - vertices[6] = new PVector(-w/2, h/2, -d/2); - vertices[7] = new PVector(-w/2, h/2, d/2); - - // Right - vertices[8] = new PVector(w/2, -h/2, d/2); - vertices[9] = new PVector(w/2, -h/2, -d/2); - vertices[10] = new PVector(w/2, h/2, -d/2); - vertices[11] = new PVector(w/2, h/2, d/2); - - // Back - vertices[12] = new PVector(-w/2, -h/2, -d/2); - vertices[13] = new PVector(w/2, -h/2, -d/2); - vertices[14] = new PVector(w/2, h/2, -d/2); - vertices[15] = new PVector(-w/2, h/2, -d/2); - - // Top - vertices[16] = new PVector(-w/2, -h/2, d/2); - vertices[17] = new PVector(-w/2, -h/2, -d/2); - vertices[18] = new PVector(w/2, -h/2, -d/2); - vertices[19] = new PVector(w/2, -h/2, d/2); - - // Bottom - vertices[20] = new PVector(-w/2, h/2, d/2); - vertices[21] = new PVector(-w/2, h/2, -d/2); - vertices[22] = new PVector(w/2, h/2, -d/2); - vertices[23] = new PVector(w/2, h/2, d/2); - } - - void create(){ - for (int i=0; i<6; i++){ - beginShape(QUADS); - for (int j = 0; j < 4; j++){ - vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z); - } - endShape(); - } - } -} diff --git a/java/examples/Topics/Image Processing/Histogram/Histogram.pde b/java/examples/Topics/Image Processing/Histogram/Histogram.pde index f5f7d49eb..7f4f89ecb 100644 --- a/java/examples/Topics/Image Processing/Histogram/Histogram.pde +++ b/java/examples/Topics/Image Processing/Histogram/Histogram.pde @@ -5,8 +5,7 @@ * A histogram is the frequency distribution * of the gray levels with the number of pure black values * displayed on the left and number of pure white values on the right. - * - * Updated 28 February, 2010. + * * Note that this sketch will behave differently on Android, * since most images will no longer be full 24-bit color. */ diff --git a/java/examples/Topics/Image Processing/PixelArray/PixelArray.pde b/java/examples/Topics/Image Processing/PixelArray/PixelArray.pde index cd133102a..6a96daee3 100644 --- a/java/examples/Topics/Image Processing/PixelArray/PixelArray.pde +++ b/java/examples/Topics/Image Processing/PixelArray/PixelArray.pde @@ -5,8 +5,6 @@ * press and hold any key to see the current pixel being read. * This program sequentially reads the color of every pixel of an image * and displays this color to fill the window. - * - * Updated 28 February 2010. */ PImage img; diff --git a/java/examples/Topics/Interaction/Tickle/Tickle.pde b/java/examples/Topics/Interaction/Tickle/Tickle.pde index b01794b1f..cf7a996dc 100644 --- a/java/examples/Topics/Interaction/Tickle/Tickle.pde +++ b/java/examples/Topics/Interaction/Tickle/Tickle.pde @@ -6,13 +6,14 @@ */ String message = "tickle"; +PFont f; float x, y; // X and Y coordinates of text float hr, vr; // horizontal and vertical radius of the text void setup() { - size(200, 200); - PFont font = loadFont("AmericanTypewriter-24.vlw"); - textFont(font); + size(640, 360); + f = createFont("Courier New", 36); + textFont(f); textAlign(CENTER, CENTER); hr = textWidth(message) / 2; vr = (textAscent() + textDescent()) / 2; diff --git a/java/examples/Topics/Motion/Bounce/Bounce.pde b/java/examples/Topics/Motion/Bounce/Bounce.pde index b6b7df531..2f5f000dc 100644 --- a/java/examples/Topics/Motion/Bounce/Bounce.pde +++ b/java/examples/Topics/Motion/Bounce/Bounce.pde @@ -4,7 +4,7 @@ * When the shape hits the edge of the window, it reverses its direction. */ -int size = 60; // Width of the shape +int rad = 60; // Width of the shape float xpos, ypos; // Starting position of shape float xspeed = 2.8; // Speed of the shape @@ -16,9 +16,10 @@ int ydirection = 1; // Top to Bottom void setup() { - size(640, 200); + size(640, 360); noStroke(); frameRate(30); + ellipseMode(RADIUS); smooth(); // Set the starting position of the shape xpos = width/2; @@ -35,13 +36,13 @@ void draw() // Test to see if the shape exceeds the boundaries of the screen // If it does, reverse its direction by multiplying by -1 - if (xpos > width-size || xpos < 0) { + if (xpos > width-rad || xpos < rad) { xdirection *= -1; } - if (ypos > height-size || ypos < 0) { + if (ypos > height-rad || ypos < rad) { ydirection *= -1; } // Draw the shape - ellipse(xpos+size/2, ypos+size/2, size, size); + ellipse(xpos, ypos, rad, rad); } diff --git a/java/examples/Topics/Motion/BouncyBubbles/BouncyBubbles.pde b/java/examples/Topics/Motion/BouncyBubbles/BouncyBubbles.pde index e9dc24f28..0757ef0d8 100644 --- a/java/examples/Topics/Motion/BouncyBubbles/BouncyBubbles.pde +++ b/java/examples/Topics/Motion/BouncyBubbles/BouncyBubbles.pde @@ -14,11 +14,11 @@ Ball[] balls = new Ball[numBalls]; void setup() { - size(640, 200); + size(640, 360); noStroke(); smooth(); for (int i = 0; i < numBalls; i++) { - balls[i] = new Ball(random(width), random(height), random(20, 40), i, balls); + balls[i] = new Ball(random(width), random(height), random(30, 70), i, balls); } } diff --git a/java/examples/Topics/Motion/Collision/Collision.pde b/java/examples/Topics/Motion/Collision/Collision.pde deleted file mode 100644 index 7d5b88c2b..000000000 --- a/java/examples/Topics/Motion/Collision/Collision.pde +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Collision (Pong). - * - * Move the mouse up and down to move the paddle. - */ - -// Global variables for the ball -float ball_x; -float ball_y; -float ball_dir = 1; -float ball_size = 15; // Radius -float dy = 0; // Direction - -// Global variables for the paddle -int paddle_width = 10; -int paddle_height = 60; - -int dist_wall = 15; - -void setup() -{ - size(640, 360); - rectMode(RADIUS); - ellipseMode(RADIUS); - noStroke(); - smooth(); - ball_y = height/2; - ball_x = 1; -} - -void draw() -{ - background(51); - - ball_x += ball_dir * 1.0; - ball_y += dy; - if(ball_x > width+ball_size) { - ball_x = -width/2 - ball_size; - ball_y = random(0, height); - dy = 0; - } - - // Constrain paddle to screen - float paddle_y = constrain(mouseY, paddle_height, height-paddle_height); - - // Test to see if the ball is touching the paddle - float py = width-dist_wall-paddle_width-ball_size; - if(ball_x == py - && ball_y > paddle_y - paddle_height - ball_size - && ball_y < paddle_y + paddle_height + ball_size) { - ball_dir *= -1; - if(mouseY != pmouseY) { - dy = (mouseY-pmouseY)/2.0; - if(dy > 5) { dy = 5; } - if(dy < -5) { dy = -5; } - } - } - - // If ball hits paddle or back wall, reverse direction - if(ball_x < ball_size && ball_dir == -1) { - ball_dir *= -1; - } - - // If the ball is touching top or bottom edge, reverse direction - if(ball_y > height-ball_size) { - dy = dy * -1; - } - if(ball_y < ball_size) { - dy = dy * -1; - } - - // Draw ball - fill(255); - ellipse(ball_x, ball_y, ball_size, ball_size); - - // Draw the paddle - fill(153); - rect(width-dist_wall, paddle_y, paddle_width, paddle_height); -} - - - - - - diff --git a/java/examples/Topics/Motion/Linear/Linear.pde b/java/examples/Topics/Motion/Linear/Linear.pde index 246b9b05e..914055b90 100644 --- a/java/examples/Topics/Motion/Linear/Linear.pde +++ b/java/examples/Topics/Motion/Linear/Linear.pde @@ -7,20 +7,19 @@ * back at the bottom of the screen. */ -float a = 100; +float a; -void setup() -{ - size(640, 200); +void setup() { + size(640, 360); stroke(255); + a = height/2; } -void draw() -{ +void draw() { background(51); + line(0, a, width, a); a = a - 0.5; if (a < 0) { a = height; } - line(0, a, width, a); } diff --git a/java/examples/Topics/Motion/Reflection1/Reflection1.pde b/java/examples/Topics/Motion/Reflection1/Reflection1.pde index 9f8434c93..c4d5be029 100644 --- a/java/examples/Topics/Motion/Reflection1/Reflection1.pde +++ b/java/examples/Topics/Motion/Reflection1/Reflection1.pde @@ -16,7 +16,7 @@ float ellipseSpeed = 3.5; float velocityX, velocityY; void setup(){ - size(640, 240); + size(640, 360); frameRate(30); fill(128); smooth(); diff --git a/java/examples/Topics/Motion/Reflection2/Reflection2.pde b/java/examples/Topics/Motion/Reflection2/Reflection2.pde index 05f135b7f..09a66016f 100644 --- a/java/examples/Topics/Motion/Reflection2/Reflection2.pde +++ b/java/examples/Topics/Motion/Reflection2/Reflection2.pde @@ -14,7 +14,7 @@ Ground[] ground = new Ground[segments]; float[] peakHeights = new float[segments+1]; void setup(){ - size(640, 200); + size(640, 360); smooth(); orb = new Orb(50, 50, 3); velocity = new PVector(.5, 0); diff --git a/java/examples/Topics/Simulate/Fluid/Fluid.pde b/java/examples/Topics/Simulate/Fluid/Fluid.pde deleted file mode 100644 index fd5f36bf6..000000000 --- a/java/examples/Topics/Simulate/Fluid/Fluid.pde +++ /dev/null @@ -1,208 +0,0 @@ -/** - * Fluid - * by Glen Murphy. - * - * Click and drag the mouse to move the simulated fluid. - * Adjust the "res" variable below to change resolution. - * Code has not been optimised, and will run fairly slowly. - */ - -int res = 2; -int penSize = 30; -int lwidth; -int lheight; -int pnum = 30000; -vsquare[][] v; -vbuffer[][] vbuf; -particle[] p = new particle[pnum]; -int pcount = 0; -int mouseXvel = 0; -int mouseYvel = 0; - -void setup() -{ - size(200, 200); - noStroke(); - frameRate(30); - lwidth = width/res; - lheight = height/res; - v = new vsquare[lwidth+1][lheight+1]; - vbuf = new vbuffer[lwidth+1][lheight+1]; - for (int i = 0; i < pnum; i++) { - p[i] = new particle(random(res,width-res),random(res,height-res)); - } - for (int i = 0; i <= lwidth; i++) { - for (int u = 0; u <= lheight; u++) { - v[i][u] = new vsquare(i*res,u*res); - vbuf[i][u] = new vbuffer(i*res,u*res); - } - } -} - -void draw() -{ - background(#666666); - - int axvel = mouseX-pmouseX; - int ayvel = mouseY-pmouseY; - - mouseXvel = (axvel != mouseXvel) ? axvel : 0; - mouseYvel = (ayvel != mouseYvel) ? ayvel : 0; - - for (int i = 0; i < lwidth; i++) { - for (int u = 0; u < lheight; u++) { - vbuf[i][u].updatebuf(i,u); - v[i][u].col = 32; - } - } - for (int i = 0; i < pnum-1; i++) { - p[i].updatepos(); - } - for (int i = 0; i < lwidth; i++) { - for (int u = 0; u < lheight; u++) { - v[i][u].addbuffer(i, u); - v[i][u].updatevels(mouseXvel, mouseYvel); - v[i][u].display(i, u); - } - } -} - -class particle { - float x; - float y; - float xvel; - float yvel; - int pos; - particle(float xIn, float yIn) { - x = xIn; - y = yIn; - } - - void updatepos() { - float col1; - if (x > 0 && x < width && y > 0 && y < height) { - int vi = (int)(x/res); - int vu = (int)(y/res); - vsquare o = v[vi][vu]; - - float ax = (x%res)/res; - float ay = (y%res)/res; - - xvel += (1-ax)*v[vi][vu].xvel*0.05; - yvel += (1-ay)*v[vi][vu].yvel*0.05; - - xvel += ax*v[vi+1][vu].xvel*0.05; - yvel += ax*v[vi+1][vu].yvel*0.05; - - xvel += ay*v[vi][vu+1].xvel*0.05; - yvel += ay*v[vi][vu+1].yvel*0.05; - - o.col += 4; - - x += xvel; - y += yvel; - } - else { - x = random(0,width); - y = random(0,height); - xvel = 0; - yvel = 0; - } - - xvel *= 0.5; - yvel *= 0.5; - } -} - -class vbuffer { - int x; - int y; - float xvel; - float yvel; - float pressurex = 0; - float pressurey = 0; - float pressure = 0; - - vbuffer(int xIn,int yIn) { - x = xIn; - y = yIn; - pressurex = 0; - pressurey = 0; - } - - void updatebuf(int i, int u) { - if (i>0 && i0 && u0 && i0 && u 255) col = 255; - if (i>0 && i0 && u width/2) { - randomGustXvel = random(-8,0); - } else { - randomGustXvel = random(0,8); - } - randomGustYvel = random(-2,1); - } - randomGust--; - } - - for(int i = 0; i < lwidth; i++) { - for(int u = 0; u < lheight; u++) { - vbuf[i][u].updatebuf(i,u); - v[i][u].col = 0; - } - } - for(int i = 0; i < pnum-1; i++) { - p[i].updatepos(); - } - for(int i = 0; i < lwidth; i++) { - for(int u = 0; u < lheight; u++) { - v[i][u].addbuffer(i, u); - v[i][u].updatevels(mouseXvel, mouseYvel); - v[i][u].display(i, u); - } - } - randomGust = 0; -} - -class particle -{ - float x; - float y; - float xvel; - float yvel; - float temp; - int pos; - - particle(float xIn, float yIn) { - x = xIn; - y = yIn; - } - - void reposition() { - x = width/2+random(-20,20); - y = random(height-10,height); - - xvel = random(-1,1); - yvel = random(-1,1); - } - - void updatepos() { - int vi = (int)(x/res); - int vu = (int)(y/res); - - if(vi > 0 && vi < lwidth && vu > 0 && vu < lheight) { - v[vi][vu].addcolour(2); - - float ax = (x%res)/res; - float ay = (y%res)/res; - - xvel += (1-ax)*v[vi][vu].xvel*0.05; - yvel += (1-ay)*v[vi][vu].yvel*0.05; - - xvel += ax*v[vi+1][vu].xvel*0.05; - yvel += ax*v[vi+1][vu].yvel*0.05; - - xvel += ay*v[vi][vu+1].xvel*0.05; - yvel += ay*v[vi][vu+1].yvel*0.05; - - v[vi][vu].yvel -= (1-ay)*0.003; - v[vi+1][vu].yvel -= ax*0.003; - - if(v[vi][vu].yvel < 0) v[vi][vu].yvel *= 1.00025; - - x += xvel; - y += yvel; - } - else { - reposition(); - } - if(random(0,400) < 1) { - reposition(); - } - xvel *= 0.6; - yvel *= 0.6; - } -} - -class vbuffer -{ - int x; - int y; - float xvel; - float yvel; - float pressurex = 0; - float pressurey = 0; - float pressure = 0; - - vbuffer(int xIn,int yIn) { - x = xIn; - y = yIn; - pressurex = 0; - pressurey = 0; - } - - void updatebuf(int i, int u) { - if(i>0 && i0 && u0 && i0 && u 0) { - adj = x - randomGustX; - opp = y - randomGustY; - dist = sqrt(opp*opp + adj*adj); - if(dist < randomGustSize) { - if(dist < res*2) dist = randomGustSize; - mod = randomGustSize/dist; - xvel += (randomGustMax-randomGust)*randomGustXvel*mod; - yvel += (randomGustMax-randomGust)*randomGustYvel*mod; - } - } - xvel *= 0.99; - yvel *= 0.98; - } - - void addcolour(int amt) { - col += amt; - if(col > 196) col = 196; - } - - void display(int i, int u) { - float tcol = 0; - if(i>0 && i0 && u