Added new P3D examples

This commit is contained in:
codeanticode
2011-12-12 04:20:41 +00:00
parent 63e688f79a
commit ffbf9af5ed
74 changed files with 4885 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
/**
* Bezier.
*
* The first two parameters for the bezier() function specify the
* first point in the curve and the last two parameters specify
* the last point. The middle parameters set the control points
* that define the shape of the curve.
*/
void setup() {
size(640, 360, P3D);
stroke(255);
noFill();
}
void draw() {
background(0);
for (int i = 0; i < 200; i += 20) {
bezier(mouseX-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0));
}
}
@@ -0,0 +1,41 @@
// Robot 1: Draw from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
size(720, 480, P3D);
smooth();
strokeWeight(2);
background(204);
ellipseMode(RADIUS);
// Neck
stroke(102); // Set stroke to gray
line(266, 257, 266, 162); // Left
line(276, 257, 276, 162); // Middle
line(286, 257, 286, 162); // Right
// Antennae
line(276, 155, 246, 112); // Small
line(276, 155, 306, 56); // Tall
line(276, 155, 342, 170); // Medium
// Body
noStroke(); // Disable stroke
fill(102); // Set fill to gray
ellipse(264, 377, 33, 33); // Antigravity orb
fill(0); // Set fill to black
rect(219, 257, 90, 120); // Main body
fill(102); // Set fill to gray
rect(219, 274, 90, 6); // Gray stripe
// Head
fill(0); // Set fill to black
ellipse(276, 155, 45, 45); // Head
fill(255); // Set fill to white
ellipse(288, 150, 14, 14); // Large eye
fill(0); // Set fill to black
ellipse(288, 150, 3, 3); // Pupil
fill(153); // Set fill to light gray
ellipse(263, 148, 5, 5); // Small eye 1
ellipse(296, 130, 4, 4); // Small eye 2
ellipse(305, 162, 3, 3); // Small eye 3
@@ -0,0 +1,32 @@
/**
* Shape Primitives.
*
* The basic shape primitive functions are triangle(),
* rect(), quad(), ellipse(), and arc(). Squares are made
* with rect() and circles are made with ellipse(). Each
* of these functions requires a number of parameters to
* determine the shape's position and size.
*/
size(640, 360, P3D);
background(0);
noStroke();
fill(204);
triangle(18, 18, 18, 360, 81, 360);
fill(102);
rect(81, 81, 63, 63);
fill(204);
quad(189, 18, 216, 18, 216, 360, 144, 360);
fill(255);
ellipse(252, 144, 72, 72);
fill(204);
triangle(288, 18, 351, 360, 288, 360);
fill(255);
arc(479, 300, 280, 280, PI, TWO_PI);
@@ -0,0 +1,44 @@
/**
* TRIANGLE_STRIP Mode
* by Ira Greenberg.
*
* Generate a closed ring using the vertex() function and
* beginShape(TRIANGLE_STRIP) mode. The outerRad and innerRad
* variables control ring's radii respectively.
*/
int x;
int y;
float outerRad;
float innerRad;
void setup() {
size(640, 360, P3D);
background(204);
x = width/2;
y = height/2;
outerRad = min(width, height) * 0.4;
innerRad = outerRad * 0.6;
}
void draw() {
background(204);
int pts = int(map(mouseX, 0, width, 6, 60));
float rot = 180.0/pts;
float angle = 0;
beginShape(TRIANGLE_STRIP);
for (int i = 0; i <= pts; i++) {
float px = x + cos(radians(angle)) * outerRad;
float py = y + sin(radians(angle)) * outerRad;
angle += rot;
vertex(px, py);
px = x + cos(radians(angle)) * innerRad;
py = y + sin(radians(angle)) * innerRad;
vertex(px, py);
angle += rot;
}
endShape();
}