This commit is contained in:
benfry
2011-01-26 19:22:19 +00:00
parent d3a18c7964
commit eb64b2d4fc
1234 changed files with 96518 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
// Example 07-01 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
void draw() {
println(frameRate);
}

View File

@@ -0,0 +1,15 @@
// Example 07-02 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
void setup() {
frameRate(30); // Thirty frames each second
//frameRate(12); // Twelve frames each second
//frameRate(2); // Two frames each second
//frameRate(0.5); // One frame every two seconds
}
void draw() {
println(frameRate);
}

View File

@@ -0,0 +1,19 @@
// Example 07-03 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
int radius = 40;
float x = -radius;
float speed = 0.5;
void setup() {
size(240, 120);
smooth();
ellipseMode(RADIUS);
}
void draw() {
background(0);
x += speed; // Increase the value of x
arc(x, 60, radius, radius, 0.52, 5.76);
}

View File

@@ -0,0 +1,22 @@
// Example 07-04 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
int radius = 40;
float x = -radius;
float speed = 0.5;
void setup() {
size(240, 120);
smooth();
ellipseMode(RADIUS);
}
void draw() {
background(0);
x += speed; // Increase the value of x
if (x > width+radius) { // If the shape is off screen
x = -radius; // move to the left edge
}
arc(x, 60, radius, radius, 0.52, 5.76);
}

View File

@@ -0,0 +1,27 @@
// Example 07-05 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
int radius = 40;
float x = 110;
float speed = 0.5;
int direction = 1;
void setup() {
size(240, 120);
smooth();
ellipseMode(RADIUS);
}
void draw() {
background(0);
x += speed * direction;
if ((x > width-radius) || (x < radius)) {
direction = -direction; // Flip direction
}
if (direction == 1) {
arc(x, 60, radius, radius, 0.52, 5.76); // Face right
} else {
arc(x, 60, radius, radius, 3.67, 8.9); // Face left
}
}

View File

@@ -0,0 +1,27 @@
// Example 07-06 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
int startX = 20; // Initial x-coordinate
int stopX = 160; // Final x-coordinate
int startY = 30; // Initial y-coordinate
int stopY = 80; // Final y-coordinate
float x = startX; // Current x-coordinate
float y = startY; // Current y-coordinate
float step = 0.005; // Size of each step (0.0 to 1.0)
float pct = 0.0; // Percentage traveled (0.0 to 1.0)
void setup() {
size(240, 120);
smooth();
}
void draw() {
background(0);
if (pct < 1.0) {
x = startX + ((stopX-startX) * pct);
y = startY + ((stopY-startY) * pct);
pct += step;
}
ellipse(x, y, 20, 20);
}

View File

@@ -0,0 +1,8 @@
// Example 07-07 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
void draw() {
float r = random(0, mouseX);
println(r);
}

View File

@@ -0,0 +1,18 @@
// Example 07-08 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
void setup() {
size(240, 120);
smooth();
}
void draw() {
background(204);
for (int x = 20; x < width; x += 20) {
float mx = mouseX / 10;
float offsetA = random(-mx, mx);
float offsetB = random(-mx, mx);
line(x + offsetA, 20, x - offsetB, 100);
}
}

View File

@@ -0,0 +1,21 @@
// Example 07-09 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float speed = 2.5;
int diameter = 20;
float x;
float y;
void setup() {
size(240, 120);
smooth();
x = width/2;
y = height/2;
}
void draw() {
x += random(-speed, speed);
y += random(-speed, speed);
ellipse(x, y, diameter, diameter);
}

View File

@@ -0,0 +1,8 @@
// Example 07-10 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
void draw() {
int timer = millis();
println(timer);
}

View File

@@ -0,0 +1,23 @@
// Example 07-11 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
int time1 = 2000;
int time2 = 4000;
float x = 0;
void setup() {
size(480, 120);
smooth();
}
void draw() {
int currentTime = millis();
background(204);
if (currentTime > time2) {
x -= 0.5;
} else if (currentTime > time1) {
x += 2;
}
ellipse(x, 60, 90, 90);
}

View File

@@ -0,0 +1,13 @@
// Example 07-12 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float angle = 0.0;
void draw() {
float sinval = sin(angle);
println(sinval);
float gray = map(sinval, -1, 1, 0, 255);
background(gray);
angle += 0.1;
}

View File

@@ -0,0 +1,24 @@
// Example 07-13 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float angle = 0.0;
float offset = 60;
float scalar = 40;
float speed = 0.05;
void setup() {
size(240, 120);
smooth();
}
void draw() {
background(0);
float y1 = offset + sin(angle) * scalar;
float y2 = offset + sin(angle + 0.4) * scalar;
float y3 = offset + sin(angle + 0.8) * scalar;
ellipse( 80, y1, 40, 40);
ellipse(120, y2, 40, 40);
ellipse(160, y3, 40, 40);
angle += speed;
}

View File

@@ -0,0 +1,20 @@
// Example 07-14 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float angle = 0.0;
float offset = 60;
float scalar = 30;
float speed = 0.05;
void setup() {
size(120, 120);
smooth();
}
void draw() {
float x = offset + cos(angle) * scalar;
float y = offset + sin(angle) * scalar;
ellipse( x, y, 40, 40);
angle += speed;
}

View File

@@ -0,0 +1,22 @@
// Example 07-15 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float angle = 0.0;
float offset = 60;
float scalar = 2;
float speed = 0.05;
void setup() {
size(120, 120);
fill(0);
smooth();
}
void draw() {
float x = offset + cos(angle) * scalar;
float y = offset + sin(angle) * scalar;
ellipse( x, y, 2, 2);
angle += speed;
scalar += speed;
}

View File

@@ -0,0 +1,12 @@
// Example 07-16 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
void setup() {
size(120, 120);
}
void draw() {
translate(mouseX, mouseY);
rect(0, 0, 30, 30);
}

View File

@@ -0,0 +1,14 @@
// Example 07-17 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
void setup() {
size(120, 120);
}
void draw() {
translate(mouseX, mouseY);
rect(0, 0, 30, 30);
translate(35, 10);
rect(0, 0, 15, 15);
}

View File

@@ -0,0 +1,16 @@
// Example 07-18 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
void setup() {
size(120, 120);
}
void draw() {
pushMatrix();
translate(mouseX, mouseY);
rect(0, 0, 30, 30);
popMatrix();
translate(35, 10);
rect(0, 0, 15, 15);
}

View File

@@ -0,0 +1,17 @@
// Example 07-19 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float angle = 0.0;
void setup() {
size(120, 120);
smooth();
}
void draw() {
translate(mouseX, mouseY);
rotate(angle);
rect(-15, -15, 30, 30);
angle += 0.1;
}

View File

@@ -0,0 +1,17 @@
// Example 07-20 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float angle = 0.0;
void setup() {
size(120, 120);
smooth();
}
void draw() {
rotate(angle);
translate(mouseX, mouseY);
rect(-15, -15, 30, 30);
angle += 0.1;
}

View File

@@ -0,0 +1,17 @@
// Example 07-21 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float angle = 0.0;
void setup() {
size(120, 120);
smooth();
}
void draw() {
translate(mouseX, mouseY);
scale(sin(angle) + 2);
rect(-15, -15, 30, 30);
angle += 0.1;
}

View File

@@ -0,0 +1,19 @@
// Example 07-22 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float angle = 0.0;
void setup() {
size(120, 120);
smooth();
}
void draw() {
translate(mouseX, mouseY);
float scalar = sin(angle) + 2;
scale(scalar);
strokeWeight(1.0 / scalar);
rect(-15, -15, 30, 30);
angle += 0.1;
}

View File

@@ -0,0 +1,33 @@
// Example 07-23 from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
float angle = 0.0;
float angleDirection = 1;
float speed = 0.005;
void setup() {
size(120, 120);
smooth();
}
void draw() {
background(204);
translate(20, 25); // Move to start position
rotate(angle);
strokeWeight(12);
line(0, 0, 40, 0);
translate(40, 0); // Move to next joint
rotate(angle * 2.0);
strokeWeight(6);
line(0, 0, 30, 0);
translate(30, 0); // Move the next joint
rotate(angle * 2.5);
strokeWeight(3);
line(0, 0, 20, 0);
angle += speed * angleDirection;
if ((angle > QUARTER_PI) || (angle < 0)) {
angleDirection *= -1;
}
}