From 2b72e61ed32d2f3133002f28f9520d292ce95c5b Mon Sep 17 00:00:00 2001 From: benfry Date: Sat, 18 Jun 2011 15:38:31 +0000 Subject: [PATCH] adding the old examples to the new opengl lib --- java/libraries/opengl/build.xml | 8 +- .../opengl/examples/Esfera/Esfera.pde | 87 ++++++ .../examples/ExtrusionGL/ExtrusionGL.pde | 52 ++++ .../opengl/examples/Geometry/Geometry.pde | 165 +++++++++++ .../opengl/examples/LightsGL/LightsGL.pde | 48 ++++ .../opengl/examples/SpaceJunk/Cube.pde | 67 +++++ .../opengl/examples/SpaceJunk/SpaceJunk.pde | 65 +++++ .../TexturedSphere/TexturedSphere.pde | 174 ++++++++++++ .../opengl/examples/Yellowtail/Gesture.pde | 256 ++++++++++++++++++ .../opengl/examples/Yellowtail/Vec3f.pde | 19 ++ .../opengl/examples/Yellowtail/Yellowtail.pde | 190 +++++++++++++ java/libraries/opengl/library/export.txt | 4 +- 12 files changed, 1129 insertions(+), 6 deletions(-) create mode 100644 java/libraries/opengl/examples/Esfera/Esfera.pde create mode 100644 java/libraries/opengl/examples/ExtrusionGL/ExtrusionGL.pde create mode 100644 java/libraries/opengl/examples/Geometry/Geometry.pde create mode 100644 java/libraries/opengl/examples/LightsGL/LightsGL.pde create mode 100644 java/libraries/opengl/examples/SpaceJunk/Cube.pde create mode 100644 java/libraries/opengl/examples/SpaceJunk/SpaceJunk.pde create mode 100644 java/libraries/opengl/examples/TexturedSphere/TexturedSphere.pde create mode 100644 java/libraries/opengl/examples/Yellowtail/Gesture.pde create mode 100644 java/libraries/opengl/examples/Yellowtail/Vec3f.pde create mode 100644 java/libraries/opengl/examples/Yellowtail/Yellowtail.pde diff --git a/java/libraries/opengl/build.xml b/java/libraries/opengl/build.xml index e662fb045..87a4f24df 100644 --- a/java/libraries/opengl/build.xml +++ b/java/libraries/opengl/build.xml @@ -1,9 +1,9 @@ - + - + @@ -20,7 +20,7 @@ classpath="../../../core/core.jar; library/jogl.all.jar; library/nativewindow.all.jar;" /> - - + + diff --git a/java/libraries/opengl/examples/Esfera/Esfera.pde b/java/libraries/opengl/examples/Esfera/Esfera.pde new file mode 100644 index 000000000..168e0bcd2 --- /dev/null +++ b/java/libraries/opengl/examples/Esfera/Esfera.pde @@ -0,0 +1,87 @@ +/** + * Esfera + * by David Pena. + * + * Distribucion aleatoria uniforme sobre la superficie de una esfera. + */ + +import processing.opengl.*; + +int cuantos = 8000; +pelo[] lista ; +float[] z = new float[cuantos]; +float[] phi = new float[cuantos]; +float[] largos = new float[cuantos]; +float radio = 200; +float rx = 0; +float ry =0; + +void setup() { + size(1024, 768, OPENGL); + radio = height/3.5; + + lista = new pelo[cuantos]; + for (int i=0; i90) pt[index]=(int)random(8,27)*10; + + pt[index++] = int(random(2,50)*5); // Radius. Space them out nicely + + pt[index++] = random(4,32); // Width of band + if(random(100)>90) pt[index]=random(40,60); // Width of band + + pt[index++] = radians(random(5,30))/5; // Speed of rotation + + // get colors + prob = random(100); + if(prob<30) style[i*2]=colorBlended(random(1), 255,0,100, 255,0,0, 210); + else if(prob<70) style[i*2]=colorBlended(random(1), 0,153,255, 170,225,255, 210); + else if(prob<90) style[i*2]=colorBlended(random(1), 200,255,0, 150,255,0, 210); + else style[i*2]=color(255,255,255, 220); + + if(prob<50) style[i*2]=colorBlended(random(1), 200,255,0, 50,120,0, 210); + else if(prob<90) style[i*2]=colorBlended(random(1), 255,100,0, 255,255,0, 210); + else style[i*2]=color(255,255,255, 220); + + style[i*2+1]=(int)(random(100))%3; + } +} + +void draw() { + + background(0); + + int index=0; + translate(width/2, height/2, 0); + rotateX(PI/6); + rotateY(PI/6); + + for (int i = 0; i < num; i++) { + pushMatrix(); + + rotateX(pt[index++]); + rotateY(pt[index++]); + + if(style[i*2+1]==0) { + stroke(style[i*2]); + noFill(); + strokeWeight(1); + arcLine(0,0, pt[index++],pt[index++],pt[index++]); + } + else if(style[i*2+1]==1) { + fill(style[i*2]); + noStroke(); + arcLineBars(0,0, pt[index++],pt[index++],pt[index++]); + } + else { + fill(style[i*2]); + noStroke(); + arc(0,0, pt[index++],pt[index++],pt[index++]); + } + + // increase rotation + pt[index-5]+=pt[index]/10; + pt[index-4]+=pt[index++]/20; + + popMatrix(); + } +} + + +// Get blend of two colors +int colorBlended(float fract, +float r, float g, float b, +float r2, float g2, float b2, float a) { + + r2 = (r2 - r); + g2 = (g2 - g); + b2 = (b2 - b); + return color(r + r2 * fract, g + g2 * fract, b + b2 * fract, a); +} + + +// Draw arc line +void arcLine(float x,float y,float deg,float rad,float w) { + int a=(int)(min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1)); + int numlines=(int)(w/2); + + for (int j=0; j= capacity) { + // there are all sorts of possible solutions here, + // but for abject simplicity, I don't do anything. + } + else { + float v = distToLast(x, y); + float p = getPressureFromVelocity(v); + path[nPoints++].set(x,y,p); + + if (nPoints > 1) { + exists = true; + jumpDx = path[nPoints-1].x - path[0].x; + jumpDy = path[nPoints-1].y - path[0].y; + } + } + + } + + float getPressureFromVelocity(float v) { + final float scale = 18; + final float minP = 0.02; + final float oldP = (nPoints > 0) ? path[nPoints-1].p : 0; + return ((minP + max(0, 1.0 - v/scale)) + (damp1*oldP))*dampInv; + } + + void setPressures() { + // pressures vary from 0...1 + float pressure; + Vec3f tmp; + float t = 0; + float u = 1.0 / (nPoints - 1)*TWO_PI; + for (int i = 0; i < nPoints; i++) { + pressure = sqrt((1.0 - cos(t))*0.5); + path[i].p = pressure; + t += u; + } + } + + float distToLast(float ix, float iy) { + if (nPoints > 0) { + Vec3f v = path[nPoints-1]; + float dx = v.x - ix; + float dy = v.y - iy; + return mag(dx, dy); + } + else { + return 30; + } + } + + void compile() { + // compute the polygons from the path of Vec3f's + if (exists) { + clearPolys(); + + Vec3f p0, p1, p2; + float radius0, radius1; + float ax, bx, cx, dx; + float ay, by, cy, dy; + int axi, bxi, cxi, dxi, axip, axid; + int ayi, byi, cyi, dyi, ayip, ayid; + float p1x, p1y; + float dx01, dy01, hp01, si01, co01; + float dx02, dy02, hp02, si02, co02; + float dx13, dy13, hp13, si13, co13; + float taper = 1.0; + + int nPathPoints = nPoints - 1; + int lastPolyIndex = nPathPoints - 1; + float npm1finv = 1.0 / max(1, nPathPoints - 1); + + // handle the first point + p0 = path[0]; + p1 = path[1]; + radius0 = p0.p * thickness; + dx01 = p1.x - p0.x; + dy01 = p1.y - p0.y; + hp01 = sqrt(dx01*dx01 + dy01*dy01); + if (hp01 == 0) { + hp02 = 0.0001; + } + co01 = radius0 * dx01 / hp01; + si01 = radius0 * dy01 / hp01; + ax = p0.x - si01; + ay = p0.y + co01; + bx = p0.x + si01; + by = p0.y - co01; + + int xpts[]; + int ypts[]; + + int LC = 20; + int RC = w-LC; + int TC = 20; + int BC = h-TC; + float mint = 0.618; + float tapow = 0.4; + + // handle the middle points + int i = 1; + Polygon apoly; + for (i = 1; i < nPathPoints; i++) { + taper = pow((lastPolyIndex-i)*npm1finv,tapow); + + p0 = path[i-1]; + p1 = path[i ]; + p2 = path[i+1]; + p1x = p1.x; + p1y = p1.y; + radius1 = Math.max(mint,taper*p1.p*thickness); + + // assumes all segments are roughly the same length... + dx02 = p2.x - p0.x; + dy02 = p2.y - p0.y; + hp02 = (float) Math.sqrt(dx02*dx02 + dy02*dy02); + if (hp02 != 0) { + hp02 = radius1/hp02; + } + co02 = dx02 * hp02; + si02 = dy02 * hp02; + + // translate the integer coordinates to the viewing rectangle + axi = axip = (int)ax; + ayi = ayip = (int)ay; + axi=(axi<0)?(w-((-axi)%w)):axi%w; + axid = axi-axip; + ayi=(ayi<0)?(h-((-ayi)%h)):ayi%h; + ayid = ayi-ayip; + + // set the vertices of the polygon + apoly = polygons[nPolys++]; + xpts = apoly.xpoints; + ypts = apoly.ypoints; + xpts[0] = axi = axid + axip; + xpts[1] = bxi = axid + (int) bx; + xpts[2] = cxi = axid + (int)(cx = p1x + si02); + xpts[3] = dxi = axid + (int)(dx = p1x - si02); + ypts[0] = ayi = ayid + ayip; + ypts[1] = byi = ayid + (int) by; + ypts[2] = cyi = ayid + (int)(cy = p1y - co02); + ypts[3] = dyi = ayid + (int)(dy = p1y + co02); + + // keep a record of where we cross the edge of the screen + crosses[i] = 0; + if ((axi<=LC)||(bxi<=LC)||(cxi<=LC)||(dxi<=LC)) { + crosses[i]|=1; + } + if ((axi>=RC)||(bxi>=RC)||(cxi>=RC)||(dxi>=RC)) { + crosses[i]|=2; + } + if ((ayi<=TC)||(byi<=TC)||(cyi<=TC)||(dyi<=TC)) { + crosses[i]|=4; + } + if ((ayi>=BC)||(byi>=BC)||(cyi>=BC)||(dyi>=BC)) { + crosses[i]|=8; + } + + //swap data for next time + ax = dx; + ay = dy; + bx = cx; + by = cy; + } + + // handle the last point + p2 = path[nPathPoints]; + apoly = polygons[nPolys++]; + xpts = apoly.xpoints; + ypts = apoly.ypoints; + + xpts[0] = (int)ax; + xpts[1] = (int)bx; + xpts[2] = (int)(p2.x); + xpts[3] = (int)(p2.x); + + ypts[0] = (int)ay; + ypts[1] = (int)by; + ypts[2] = (int)(p2.y); + ypts[3] = (int)(p2.y); + + } + } + + void smooth() { + // average neighboring points + + final float weight = 18; + final float scale = 1.0 / (weight + 2); + int nPointsMinusTwo = nPoints - 2; + Vec3f lower, upper, center; + + for (int i = 1; i < nPointsMinusTwo; i++) { + lower = path[i-1]; + center = path[i]; + upper = path[i+1]; + + center.x = (lower.x + weight*center.x + upper.x)*scale; + center.y = (lower.y + weight*center.y + upper.y)*scale; + } + } +} + diff --git a/java/libraries/opengl/examples/Yellowtail/Vec3f.pde b/java/libraries/opengl/examples/Yellowtail/Vec3f.pde new file mode 100644 index 000000000..865d3c32f --- /dev/null +++ b/java/libraries/opengl/examples/Yellowtail/Vec3f.pde @@ -0,0 +1,19 @@ +class Vec3f { + float x; + float y; + float p; // Pressure + + Vec3f() { + set(0, 0, 0); + } + + Vec3f(float ix, float iy, float ip) { + set(ix, iy, ip); + } + + void set(float ix, float iy, float ip) { + x = ix; + y = iy; + p = ip; + } +} diff --git a/java/libraries/opengl/examples/Yellowtail/Yellowtail.pde b/java/libraries/opengl/examples/Yellowtail/Yellowtail.pde new file mode 100644 index 000000000..ad9182521 --- /dev/null +++ b/java/libraries/opengl/examples/Yellowtail/Yellowtail.pde @@ -0,0 +1,190 @@ +/** + * Yellowtail + * by Golan Levin (www.flong.com). + * + * Click, drag, and release to create a kinetic gesture. + * + * Yellowtail (1998-2000) is an interactive software system for the gestural + * creation and performance of real-time abstract animation. Yellowtail repeats + * a user's strokes end-over-end, enabling simultaneous specification of a + * line's shape and quality of movement. Each line repeats according to its + * own period, producing an ever-changing and responsive display of lively, + * worm-like textures. + */ + + +import processing.opengl.*; +import java.awt.Polygon; + +Gesture gestureArray[]; +final int nGestures = 36; // Number of gestures +final int minMove = 3; // Minimum travel for a new point +int currentGestureID; + +Polygon tempP; +int tmpXp[]; +int tmpYp[]; + + +void setup() { + size(1024, 768, OPENGL); + background(0, 0, 0); + noStroke(); + + currentGestureID = -1; + gestureArray = new Gesture[nGestures]; + for (int i = 0; i < nGestures; i++) { + gestureArray[i] = new Gesture(width, height); + } + clearGestures(); +} + + +void draw() { + background(0); + + updateGeometry(); + fill(255, 255, 245); + for (int i = 0; i < nGestures; i++) { + renderGesture(gestureArray[i], width, height); + } +} + +void mousePressed() { + currentGestureID = (currentGestureID+1) % nGestures; + Gesture G = gestureArray[currentGestureID]; + G.clear(); + G.clearPolys(); + G.addPoint(mouseX, mouseY); +} + + +void mouseDragged() { + if (currentGestureID >= 0) { + Gesture G = gestureArray[currentGestureID]; + if (G.distToLast(mouseX, mouseY) > minMove) { + G.addPoint(mouseX, mouseY); + G.smooth(); + G.compile(); + } + } +} + + +void keyPressed() { + if (key == '+' || key == '=') { + if (currentGestureID >= 0) { + float th = gestureArray[currentGestureID].thickness; + gestureArray[currentGestureID].thickness = min(96, th+1); + gestureArray[currentGestureID].compile(); + } + } else if (key == '-') { + if (currentGestureID >= 0) { + float th = gestureArray[currentGestureID].thickness; + gestureArray[currentGestureID].thickness = max(2, th-1); + gestureArray[currentGestureID].compile(); + } + } else if (key == ' ') { + clearGestures(); + } +} + + +void renderGesture(Gesture gesture, int w, int h) { + if (gesture.exists) { + if (gesture.nPolys > 0) { + Polygon polygons[] = gesture.polygons; + int crosses[] = gesture.crosses; + + int xpts[]; + int ypts[]; + Polygon p; + int cr; + + beginShape(QUADS); + int gnp = gesture.nPolys; + for (int i=0; i 0) { + if ((cr & 3)>0) { + vertex(xpts[0]+w, ypts[0]); + vertex(xpts[1]+w, ypts[1]); + vertex(xpts[2]+w, ypts[2]); + vertex(xpts[3]+w, ypts[3]); + + vertex(xpts[0]-w, ypts[0]); + vertex(xpts[1]-w, ypts[1]); + vertex(xpts[2]-w, ypts[2]); + vertex(xpts[3]-w, ypts[3]); + } + if ((cr & 12)>0) { + vertex(xpts[0], ypts[0]+h); + vertex(xpts[1], ypts[1]+h); + vertex(xpts[2], ypts[2]+h); + vertex(xpts[3], ypts[3]+h); + + vertex(xpts[0], ypts[0]-h); + vertex(xpts[1], ypts[1]-h); + vertex(xpts[2], ypts[2]-h); + vertex(xpts[3], ypts[3]-h); + } + + // I have knowingly retained the small flaw of not + // completely dealing with the corner conditions + // (the case in which both of the above are true). + } + } + endShape(); + } + } +} + +void updateGeometry() { + Gesture J; + for (int g=0; g 0) { + path = gesture.path; + for (int i = nPts1; i > 0; i--) { + path[i].x = path[i-1].x; + path[i].y = path[i-1].y; + } + path[0].x = path[nPts1].x - jx; + path[0].y = path[nPts1].y - jy; + gesture.compile(); + } + } +} + +void clearGestures() { + for (int i = 0; i < nGestures; i++) { + gestureArray[i].clear(); + } +} diff --git a/java/libraries/opengl/library/export.txt b/java/libraries/opengl/library/export.txt index abf9daf9c..bbbdbad5f 100755 --- a/java/libraries/opengl/library/export.txt +++ b/java/libraries/opengl/library/export.txt @@ -1,10 +1,10 @@ # If you want to support more platforms, see the jogl.dev.java.net to get the # natives libraries for the platform in question (i.e. Solaris). -name = OpenGL2 +name = OpenGL # In releases later than (but not including) 1.0.9, the applet JAR files # are downloaded directly from Sun, so that a single version is cached # on the user's computer, rather than increasing the download size with # the versions for each platform. -applet = opengl2.jar +applet = opengl.jar