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,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;
}