mirror of
https://github.com/processing/processing4.git
synced 2026-02-02 21:29:17 +01:00
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
// Example 07-01 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void draw() {
|
||||
println(frameRate);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user