Examples updated accordingly

This commit is contained in:
codeanticode
2012-12-30 22:51:11 +00:00
parent a4a0369e90
commit 5ecea76597
18 changed files with 125 additions and 112 deletions
@@ -11,7 +11,8 @@ class Particle {
Particle() {
partSize = random(10,60);
part = createShape(QUAD);
part = createShape();
part.beginShape(QUAD);
part.noStroke();
part.texture(sprite);
part.normal(0, 0, 1);
@@ -19,7 +20,7 @@ class Particle {
part.vertex(+partSize/2, -partSize/2, sprite.width, 0);
part.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height);
part.vertex(-partSize/2, +partSize/2, 0, sprite.height);
part.end();
part.endShape();
rebirth(width/2,height/2);
lifespan = random(255);
@@ -52,7 +53,7 @@ class Particle {
lifespan = lifespan - 1;
velocity.add(gravity);
part.tint(255,lifespan);
part.setTint(color(255,lifespan));
part.translate(velocity.x, velocity.y);
}
}
@@ -50,6 +50,7 @@ void createRibbonModel(ArrayList residues, PShape model, ArrayList trj) {
if (renderMode == 0) {
model = createShape();
model.beginShape();
model.stroke(ribbonColor);
model.noFill();
model.beginContour();
@@ -70,12 +71,13 @@ void createRibbonModel(ArrayList residues, PShape model, ArrayList trj) {
model.vertex(posVec.x, posVec.y, posVec.z);
}
model.endContour();
model.end(OPEN);
model.endShape(OPEN);
} else {
// The ribbon construction is fairly inneficient here, since
// it could use triangle strips instead to avoid duplicating
// shared vertices...
model = createShape(TRIANGLES);
model = createShape();
model.beginShape(TRIANGLES);
model.noStroke();
model.fill(ribbonColor);
for (int i = 0; i < vertices.size(); i++) {
@@ -84,7 +86,7 @@ void createRibbonModel(ArrayList residues, PShape model, ArrayList trj) {
model.normal(-normVec.x, -normVec.y, -normVec.z);
model.vertex(posVec.x, posVec.y, posVec.z);
}
model.end();
model.endShape();
}
trj.add(model);
@@ -10,7 +10,8 @@ PShape createTrefoil(float s, int ny, int nx, PImage tex) {
PVector n0, n1, n2;
float u0, u1, v0, v1;
PShape obj = createShape(TRIANGLES);
PShape obj = createShape();
obj.beginShape(TRIANGLES);
obj.texture(tex);
for (int j = 0; j < nx; j++) {
@@ -49,7 +50,7 @@ PShape createTrefoil(float s, int ny, int nx, PImage tex) {
obj.vertex(s * p1.x, s * p1.y, s * p1.z, u1, v0);
}
}
obj.end();
obj.endShape();
return obj;
}
@@ -47,11 +47,11 @@ public void keyPressed() {
} else if (key == ' ') {
restoreCube();
} else if (key == '1') {
cube.strokeWeight(1);
cube.setStrokeWeight(1);
} else if (key == '2') {
cube.strokeWeight(5);
cube.setStrokeWeight(5);
} else if (key == '3') {
cube.strokeWeight(10);
cube.setStrokeWeight(10);
}
}
@@ -61,9 +61,10 @@ void createCube() {
PShape face;
// Front face
face = createShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face = createShape();
face.beginShape(POLYGON);
face.stroke(color(255, 0, 0));
face.fill(color(255));
face.beginContour();
face.vertex(-cubeSize/2, -cubeSize/2, +cubeSize/2);
face.vertex(+cubeSize/2, -cubeSize/2, +cubeSize/2);
@@ -79,13 +80,14 @@ void createCube() {
face.vertex(x, y, z);
}
face.endContour();
face.end(CLOSE);
face.endShape(CLOSE);
cube.addChild(face);
// Back face
face = createShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face = createShape();
face.beginShape(POLYGON);
face.stroke(color(255, 0, 0));
face.fill(color(255));
face.beginContour();
face.vertex(+cubeSize/2, -cubeSize/2, -cubeSize/2);
face.vertex(-cubeSize/2, -cubeSize/2, -cubeSize/2);
@@ -101,13 +103,14 @@ void createCube() {
face.vertex(x, y, z);
}
face.endContour();
face.end(CLOSE);
face.endShape(CLOSE);
cube.addChild(face);
// Right face
face = createShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face = createShape();
face.beginShape(POLYGON);
face.stroke(color(255, 0, 0));
face.fill(color(255));
face.beginContour();
face.vertex(+cubeSize/2, -cubeSize/2, +cubeSize/2);
face.vertex(+cubeSize/2, -cubeSize/2, -cubeSize/2);
@@ -123,13 +126,14 @@ void createCube() {
face.vertex(x, y, z);
}
face.endContour();
face.end(CLOSE);
face.endShape(CLOSE);
cube.addChild(face);
// Left face
face = createShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face = createShape();
face.beginShape(POLYGON);
face.stroke(color(255, 0, 0));
face.fill(color(255));
face.beginContour();
face.vertex(-cubeSize/2, -cubeSize/2, -cubeSize/2);
face.vertex(-cubeSize/2, -cubeSize/2, +cubeSize/2);
@@ -145,13 +149,14 @@ void createCube() {
face.vertex(x, y, z);
}
face.endContour();
face.end(CLOSE);
face.endShape(CLOSE);
cube.addChild(face);
// Top face
face = createShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face = createShape();
face.beginShape(POLYGON);
face.stroke(color(255, 0, 0));
face.fill(color(255));
face.beginContour();
face.vertex(-cubeSize/2, +cubeSize/2, +cubeSize/2);
face.vertex(+cubeSize/2, +cubeSize/2, +cubeSize/2);
@@ -167,13 +172,14 @@ void createCube() {
face.vertex(x, y, z);
}
face.endContour();
face.end(CLOSE);
face.endShape(CLOSE);
cube.addChild(face);
// Bottom face
face = createShape(POLYGON);
face.stroke(255, 0, 0);
face.fill(255);
face = createShape();
face.beginShape(POLYGON);
face.stroke(color(255, 0, 0));
face.fill(color(255));
face.beginContour();
face.vertex(+cubeSize/2, -cubeSize/2, +cubeSize/2);
face.vertex(-cubeSize/2, -cubeSize/2, +cubeSize/2);
@@ -189,7 +195,7 @@ void createCube() {
face.vertex(x, y, z);
}
face.endContour();
face.end(CLOSE);
face.endShape(CLOSE);
cube.addChild(face);
}
@@ -15,7 +15,7 @@ void setup() {
noSmooth();
noStroke();
grid = createShape(PShape.GROUP);
grid = createShape(GROUP);
// Build grid using multiple translations
for (float i =- depth/2+margin; i <= depth/2-margin; i += boxSize){
@@ -25,7 +25,7 @@ void setup() {
// ensures values stay within legal range
boxFill = color(abs(i), abs(j), abs(k), 50);
PShape cube = createShape(BOX, boxSize, boxSize, boxSize);
cube.fill(boxFill);
cube.setFill(boxFill);
cube.translate(k, j, i);
grid.addChild(cube);
}
@@ -23,7 +23,8 @@ void setup() {
sprite = loadImage("sprite.png");
for (int n = 0; n < npartTotal; n++) {
PShape part = createShape(QUAD);
PShape part = createShape();
part.beginShape(QUAD);
part.noStroke();
part.texture(sprite);
part.normal(0, 0, 1);
@@ -31,7 +32,7 @@ void setup() {
part.vertex(+partSize/2, -partSize/2, sprite.width, 0);
part.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height);
part.vertex(-partSize/2, +partSize/2, 0, sprite.height);
part.end();
part.endShape();
particles.addChild(part);
}
@@ -58,7 +59,7 @@ void draw () {
if (0 <= lifetimes[n]) {
float opacity = 1.0 - float(lifetimes[n]) / partLifetime;
part.tint(255, opacity * 255);
part.setTint(color(255, opacity * 255));
if (lifetimes[n] == 0) {
// Re-spawn dead particle
@@ -73,7 +74,7 @@ void draw () {
velocities[n].y += gravity;
}
} else {
part.tint(0, 0);
part.setTint(color(0));
}
}
@@ -20,16 +20,17 @@ void setup() {
float cy = random(-500, +500);
float cz = random(-500, +500);
PShape part = createShape(QUAD);
PShape part = createShape();
part.beginShape(QUAD);
part.noStroke();
part.tint(255);
part.tint(color(255));
part.texture(sprite);
part.normal(0, 0, 1);
part.vertex(cx - partSize/2, cy - partSize/2, cz, 0, 0);
part.vertex(cx + partSize/2, cy - partSize/2, cz, sprite.width, 0);
part.vertex(cx + partSize/2, cy + partSize/2, cz, sprite.width, sprite.height);
part.vertex(cx - partSize/2, cy + partSize/2, cz, 0, sprite.height);
part.end();
part.endShape();
particles.addChild(part);
}
@@ -11,8 +11,9 @@ void setup() {
smooth();
// Make a shape
s = createShape();
s.fill(0);
s.stroke(255);
s.beginShape();
s.fill(0xFF000000);
s.stroke(0xFFFFFFFF);
s.strokeWeight(2);
// Exterior part of shape
s.vertex(-100,-100);
@@ -29,7 +30,7 @@ void setup() {
s.endContour();
// Finishing off shape
s.end(CLOSE);
s.endShape(CLOSE);
}
void draw() {
@@ -16,8 +16,9 @@ void setup() {
// Make a polygon PShape
PShape star = createShape();
star.beginShape();
star.noFill();
star.stroke(255);
star.stroke(0xFFFFFFFF);
star.vertex(0, -50);
star.vertex(14, -20);
star.vertex(47, -15);
@@ -28,23 +29,23 @@ void setup() {
star.vertex(-23, 7);
star.vertex(-47, -15);
star.vertex(-14, -20);
star.end(CLOSE);
star.endShape(CLOSE);
// Make a path PShape
PShape path = createShape();
path = createShape();
path.beginShape();
path.noFill();
path.stroke(255);
path.stroke(0xFFFFFFFF);
for (float a = -PI; a < 0; a += 0.1) {
float r = random(60, 70);
path.vertex(r*cos(a), r*sin(a));
}
path.end();
path.endShape();
// Make a primitive (Rectangle) PShape
PShape rectangle = createShape(RECT,-10,-10,20,20);
rectangle.noFill();
rectangle.stroke(255);
rectangle.setFill(false);
rectangle.setStroke(0xFFFFFFFF);
// Add them all to the group
group.addChild(star);
@@ -19,7 +19,8 @@ class Particle {
Particle() {
partSize = random(10, 60);
// The particle is a textured quad
part = createShape(QUAD);
part = createShape();
part.beginShape(QUAD);
part.noStroke();
part.texture(sprite);
part.normal(0, 0, 1);
@@ -27,7 +28,7 @@ class Particle {
part.vertex(+partSize/2, -partSize/2, sprite.width, 0);
part.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height);
part.vertex(-partSize/2, +partSize/2, 0, sprite.height);
part.end();
part.endShape();
// Initialize center vector
center = new PVector();
@@ -72,7 +73,7 @@ class Particle {
lifespan = lifespan - 1;
// Apply gravity
velocity.add(gravity);
part.tint(255, lifespan);
part.setTint(color(255, lifespan));
// Move the particle according to its velocity
part.translate(velocity.x, velocity.y);
// and also update the center
@@ -12,9 +12,10 @@ void setup() {
smooth();
// Create the shape
path = createShape();
path.beginShape();
// Set fill and stroke
path.noFill();
path.stroke(255);
path.stroke(color(255));
path.strokeWeight(2);
float x = 0;
@@ -24,7 +25,7 @@ void setup() {
x+= 5;
}
// The path is complete
path.end();
path.endShape();
}
@@ -13,9 +13,10 @@ void setup() {
smooth();
// First create the shape
star = createShape();
star.beginShape();
// You can set fill and stroke
star.fill(102);
star.stroke(255);
star.fill(color(102));
star.stroke(color(255));
star.strokeWeight(2);
// Here, we are hardcoding a series of vertices
star.vertex(0, -50);
@@ -28,7 +29,7 @@ void setup() {
star.vertex(-23, 7);
star.vertex(-47, -15);
star.vertex(-14, -20);
star.end(CLOSE);
star.endShape(CLOSE);
}
void draw() {
@@ -14,8 +14,9 @@ class Star {
speed = random(0.5, 3);
// First create the shape
s = createShape();
s.beginShape();
// You can set fill and stroke
s.fill(255, 204);
s.fill(color(255, 204));
s.noStroke();
// Here, we are hardcoding a series of vertices
s.vertex(0, -50);
@@ -29,7 +30,7 @@ class Star {
s.vertex(-47, -15);
s.vertex(-14, -20);
// The shape is complete
s.end(CLOSE);
s.endShape(CLOSE);
}
void move() {
@@ -15,8 +15,9 @@ void setup() {
smooth();
// Make a PShape
PShape star = createShape();
star.beginShape();
star.noStroke();
star.fill(0,127);
star.fill(color(0,127));
star.vertex(0, -50);
star.vertex(14, -20);
star.vertex(47, -15);
@@ -27,7 +28,7 @@ void setup() {
star.vertex(-23, 7);
star.vertex(-47, -15);
star.vertex(-14, -20);
star.end(CLOSE);
star.endShape(CLOSE);
// Make an ArrayList
polygons = new ArrayList<Polygon>();
@@ -18,13 +18,14 @@ void setup() {
smooth();
shapes[0] = createShape(ELLIPSE,0,0,100,100);
shapes[0].fill(255,127);
shapes[0].noStroke();
shapes[0].setFill(color(255,127));
shapes[0].setStroke(false);
shapes[1] = createShape(RECT,0,0,100,100);
shapes[1].fill(255,127);
shapes[1].noStroke();
shapes[2] = createShape();
shapes[2].fill(0,127);
shapes[1].setFill(color(255,127));
shapes[1].setStroke(false);
shapes[2] = createShape();
shapes[2].beginShape();
shapes[2].fill(color(0,127));
shapes[2].noStroke();
shapes[2].vertex(0, -50);
shapes[2].vertex(14, -20);
@@ -36,7 +37,7 @@ void setup() {
shapes[2].vertex(-23, 7);
shapes[2].vertex(-47, -15);
shapes[2].vertex(-14, -20);
shapes[2].end(CLOSE);
shapes[2].endShape(CLOSE);
// Make an ArrayList
polygons = new ArrayList<Polygon>();
@@ -19,9 +19,9 @@ void setup() {
void draw() {
background(51);
// We can dynamically set the stroke and fill of the shape
circle.stroke(255);
circle.strokeWeight(4);
circle.fill(map(mouseX, 0, width, 0, 255));
circle.setStroke(color(255));
circle.setStrokeWeight(4);
circle.setFill(color(map(mouseX, 0, width, 0, 255)));
// We can use translate to move the PShape
translate(mouseX, mouseY);
// Drawing the PShape
@@ -28,13 +28,14 @@ class Wiggler {
// Now make the PShape with those vertices
s = createShape();
s.fill(127);
s.stroke(0);
s.beginShape();
s.setFill(color(127));
s.stroke(color(0));
s.strokeWeight(2);
for (PVector v : original) {
s.vertex(v.x, v.y);
}
s.end(CLOSE);
s.endShape(CLOSE);
}
void wiggle() {
@@ -9,40 +9,32 @@ uniform vec2 texcoordOffset;
varying vec4 vertColor;
varying vec4 vertTexcoord;
#define KERNEL_SIZE 9
// Gaussian kernel
// 1 2 1
// 2 4 2
// 1 2 1
float kernel[KERNEL_SIZE];
vec2 offset[KERNEL_SIZE];
void main(void) {
int i = 0;
vec4 sum = vec4(0.0);
offset[0] = vec2(-texcoordOffset.s, -texcoordOffset.t);
offset[1] = vec2(0.0, -texcoordOffset.t);
offset[2] = vec2(texcoordOffset.s, -texcoordOffset.t);
offset[3] = vec2(-texcoordOffset.s, 0.0);
offset[4] = vec2(0.0, 0.0);
offset[5] = vec2(texcoordOffset.s, 0.0);
offset[6] = vec2(-texcoordOffset.s, texcoordOffset.t);
offset[7] = vec2(0.0, texcoordOffset.t);
offset[8] = vec2(texcoordOffset.s, texcoordOffset.t);
kernel[0] = 1.0/16.0; kernel[1] = 2.0/16.0; kernel[2] = 1.0/16.0;
kernel[3] = 2.0/16.0; kernel[4] = 4.0/16.0; kernel[5] = 2.0/16.0;
kernel[6] = 1.0/16.0; kernel[7] = 2.0/16.0; kernel[8] = 1.0/16.0;
for(i = 0; i < KERNEL_SIZE; i++) {
vec4 tmp = texture2D(textureSampler, vertTexcoord.st + offset[i]);
sum += tmp * kernel[i];
}
// Grouping texcoord variables in order to make it work in the GMA 950. See post #13
// in this thread:
// http://www.idevgames.com/forums/thread-3467.html
vec2 tc0 = vertTexcoord.st + vec2(-texcoordOffset.s, -texcoordOffset.t);
vec2 tc1 = vertTexcoord.st + vec2( 0.0, -texcoordOffset.t);
vec2 tc2 = vertTexcoord.st + vec2(+texcoordOffset.s, -texcoordOffset.t);
vec2 tc3 = vertTexcoord.st + vec2(-texcoordOffset.s, 0.0);
vec2 tc4 = vertTexcoord.st + vec2( 0.0, 0.0);
vec2 tc5 = vertTexcoord.st + vec2(+texcoordOffset.s, 0.0);
vec2 tc6 = vertTexcoord.st + vec2(-texcoordOffset.s, +texcoordOffset.t);
vec2 tc7 = vertTexcoord.st + vec2( 0.0, +texcoordOffset.t);
vec2 tc8 = vertTexcoord.st + vec2(+texcoordOffset.s, +texcoordOffset.t);
vec4 col0 = texture2D(textureSampler, tc0);
vec4 col1 = texture2D(textureSampler, tc1);
vec4 col2 = texture2D(textureSampler, tc2);
vec4 col3 = texture2D(textureSampler, tc3);
vec4 col4 = texture2D(textureSampler, tc4);
vec4 col5 = texture2D(textureSampler, tc5);
vec4 col6 = texture2D(textureSampler, tc6);
vec4 col7 = texture2D(textureSampler, tc7);
vec4 col8 = texture2D(textureSampler, tc8);
vec4 sum = (1.0 * col0 + 2.0 * col1 + 1.0 * col2 +
2.0 * col3 + 4.0 * col4 + 2.0 * col4 +
1.0 * col5 + 2.0 * col6 + 1.0 * col7) / 16.0;
gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
}