Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Demos/Graphics/GetTessGroups/GetTessGroups.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// GetTessGroups, by Andres Colubri
// The getTessellation() function in Processing 4 returns a group shape
// where the first shape contains only the fill geometry, the second,
// the stroke lines, and third, only the points (if any).

PShape box;
PShape tess;

boolean onlyStrokeLines = false;

void setup() {
size(600, 600, P3D);

strokeWeight(5);
box = createShape(BOX, 200);

tess = box.getTessellation();
}

void draw() {
background(180);
lights();

translate(width/2, height/2);
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
for (int i = 0; i < tess.getChildCount(); i++) {
if (!onlyStrokeLines || i == 1) {
shape(tess.getChild(i));
}
}
}

void keyPressed() {
onlyStrokeLines = !onlyStrokeLines;
}
88 changes: 88 additions & 0 deletions Demos/Graphics/MultipleWindows/MultipleWindows.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// MultipleWindows, by Andres Colubri
// Adapted from a PixelFlow example by Thomas Diewald
// Demonstration of a multiple window sketch with OpenGL
// (P2D or P3D) renderers, including resource sharing
// across windows.

ChildApplet childA;
ChildApplet childB;
ChildApplet childC;

PShape pointer;

void setup() {
size(400, 300, P2D);
println("Creating window 1");

// This PShape can be shared across all windows
pointer = createShape(ELLIPSE, 0, 0, 20, 20);

childA = new ChildApplet(2, 500, 0, 400, 300);
childA.bckColor = color(227, 173, 37);

// Change location of parent window after creating child window.
surface.setLocation(100, 0);
}

void draw() {
background(32);

fill(160);
textAlign(CENTER, CENTER);
text("MAIN window", width/2, height/2);

translate(mouseX, mouseY);
shape(pointer);

String txt = String.format("Window 1 %6.2fps", frameRate);
surface.setTitle(txt);
}

public void keyPressed() {
if (childB == null) {
childB = new ChildApplet(3, 500, 353, 400, 300);
childB.bckColor = color(137, 227, 37);
} else if (childC == null) {
childC = new ChildApplet(4, 100, 353, 400, 300);
childC.bckColor = color(51, 157, 209);
}
}

class ChildApplet extends PApplet {
int id, vx, vy, vw, vh;
int bckColor;

ChildApplet(int id, int vx, int vy, int vw, int vh) {
super();
this.id = id;
this.vx = vx;
this.vy = vy;
this.vw = vw;
this.vh = vh;

PApplet.runSketch(new String[] { this.getClass().getName() }, this);
}

void settings() {
size(vw, vh, P2D);
smooth(0);
println("Creating window "+ id);
}

void setup() {
surface.setLocation(vx, vy);
surface.setResizable(true);
}

void draw() {
background(bckColor);
textAlign(CENTER, CENTER);
text("CHILD window "+ id, width/2, height/2);

translate(mouseX, mouseY);
shape(pointer);

String txt = String.format("Window %d %6.2fps", id, frameRate);
surface.setTitle(txt);
}
}
64 changes: 64 additions & 0 deletions Demos/Graphics/TessUpdate/TessUpdate.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// TessUpdate, by Andres Colubri
// The begin/endTessallation API in Processing 4
// enables dynamic modification of PShape objects.

PShape group;

int numBoxes = 100000;
float boxSize = 2;

PMatrix3D mat = new PMatrix3D();

int fcount, lastm;
float frate;
int fint = 3;

void setup() {
size(600, 600, P3D);
noSmooth();

noStroke();
group = createShape(GROUP);

for (int i = 0; i < numBoxes; i++) {
PShape s = createShape(BOX, boxSize, boxSize, boxSize);
s.setFill(#F5CB40);
s.translate(random(-width/2, width/2), random(-height/2, height/2), random(-1000, 1000));
group.addChild(s);
}
}

void draw() {
background(0);
lights();
PVector v = new PVector();

// PShape.set*() calls between beginTessellation() and endTessellation
// will modify the tessellated geometry directly, so this should result
// better performance for shapes that change dynamically during drawing
group.beginTessellation(TRIANGLES);
// getChildCount() returns number of vertices in the tessellated geometry,
// which could be different from the original number of vertices in the shape.
for (int ci = 0; ci < group.getChildCount(); ci++) {
PShape child = group.getChild(ci);
float rx = random(-1, 1);
float ry = random(-1, 1);
float rz = random(-1, 1);
for (int vi = 0; vi < child.getVertexCount(); vi++) {
child.getVertex(vi, v);
v.x += rx;
v.y += ry;
v.z += rz;
child.setVertex(vi, v.x, v.y, v.z);
}
}
group.endTessellation();

translate(width/2, height/2, 0);
rotateY(frameCount * 0.001);
rotateX(frameCount * 0.001);
shape(group);

String txt = String.format("FPS: %6.2fps", frameRate);
surface.setTitle(txt);
}