mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
// Example 05-01 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void draw() {
|
||||
// Displays the frame count to the Console
|
||||
println("I’m drawing");
|
||||
println(frameCount);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// Example 05-02 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
println("I’m starting");
|
||||
}
|
||||
|
||||
void draw() {
|
||||
println("I’m running");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Example 05-03 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
int x = 280;
|
||||
int y = -100;
|
||||
int diameter = 380;
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
smooth();
|
||||
fill(102);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
ellipse(x, y, diameter, diameter);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Example 05-04 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
fill(0, 102);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
ellipse(mouseX, mouseY, 9, 9);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Example 05-05 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
fill(0, 102);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
ellipse(mouseX, mouseY, 9, 9);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Example 05-06 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
strokeWeight(4);
|
||||
smooth();
|
||||
stroke(0, 102);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
line(mouseX, mouseY, pmouseX, pmouseY);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Example 05-07 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
smooth();
|
||||
stroke(0, 102);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
float weight = dist(mouseX, mouseY, pmouseX, pmouseY);
|
||||
strokeWeight(weight);
|
||||
line(mouseX, mouseY, pmouseX, pmouseY);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Example 05-08 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
float x;
|
||||
float easing = 0.01;
|
||||
|
||||
void setup() {
|
||||
size(220, 120);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
float targetX = mouseX;
|
||||
x += (targetX - x) * easing;
|
||||
ellipse(x, 40, 12, 12);
|
||||
println(targetX + " : " + x);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Example 05-09 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float px;
|
||||
float py;
|
||||
float easing = 0.05;
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
smooth();
|
||||
stroke(0, 102);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
float targetX = mouseX;
|
||||
x += (targetX - x) * easing;
|
||||
float targetY = mouseY;
|
||||
y += (targetY - y) * easing;
|
||||
float weight = dist(x, y, px, py);
|
||||
strokeWeight(weight);
|
||||
line(x, y, px, py);
|
||||
py = y;
|
||||
px = x;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Example 05-10 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
strokeWeight(12);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
stroke(255);
|
||||
line(120, 60, mouseX, mouseY); // White line
|
||||
stroke(0);
|
||||
float mx = mouseX/2 + 60;
|
||||
line(120, 60, mx, mouseY); // Black line
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Example 05-11 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
strokeWeight(12);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
stroke(255);
|
||||
line(120, 60, mouseX, mouseY); // White line
|
||||
stroke(0);
|
||||
float mx = map(mouseX, 0, width, 60, 180);
|
||||
line(120, 60, mx, mouseY); // Black line
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Example 05-12 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
strokeWeight(30);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
stroke(102);
|
||||
line(40, 0, 70, height);
|
||||
if (mousePressed == true) {
|
||||
stroke(0);
|
||||
}
|
||||
line(0, 70, width, 50);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Example 05-13 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
strokeWeight(30);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
stroke(102);
|
||||
line(40, 0, 70, height);
|
||||
if (mousePressed) {
|
||||
stroke(0);
|
||||
} else {
|
||||
stroke(255);
|
||||
}
|
||||
line(0, 70, width, 50);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Example 05-14 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(120, 120);
|
||||
smooth();
|
||||
strokeWeight(30);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
stroke(102);
|
||||
line(40, 0, 70, height);
|
||||
if (mousePressed) {
|
||||
if (mouseButton == LEFT) {
|
||||
stroke(255);
|
||||
} else {
|
||||
stroke(0);
|
||||
}
|
||||
line(0, 70, width, 50);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Example 05-15 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
float x;
|
||||
int offset = 10;
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
x = width/2;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
if (mouseX > x) {
|
||||
x += 0.5;
|
||||
offset = -10;
|
||||
}
|
||||
if (mouseX < x) {
|
||||
x -= 0.5;
|
||||
offset = 10;
|
||||
}
|
||||
line(x, 0, x, height);
|
||||
line(mouseX, mouseY, mouseX + offset, mouseY - 10);
|
||||
line(mouseX, mouseY, mouseX + offset, mouseY + 10);
|
||||
line(mouseX, mouseY, mouseX + offset*3, mouseY);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Example 05-16 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
int x = 120;
|
||||
int y = 60;
|
||||
int radius = 12;
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
ellipseMode(RADIUS);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
float d = dist(mouseX, mouseY, x, y);
|
||||
if (d < radius) {
|
||||
radius++;
|
||||
fill(0);
|
||||
} else {
|
||||
fill(255);
|
||||
}
|
||||
ellipse(x, y, radius, radius);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Example 05-17 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
int x = 80;
|
||||
int y = 30;
|
||||
int w = 80;
|
||||
int h = 60;
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
if ((mouseX > x) && (mouseX < x+w) &&
|
||||
(mouseY > y) && (mouseY < y+h)) {
|
||||
fill(0);
|
||||
}
|
||||
else {
|
||||
fill(255);
|
||||
}
|
||||
rect(x, y, w, h);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// Example 05-18 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
line(20, 20, 220, 100);
|
||||
if (keyPressed) {
|
||||
line(220, 20, 20, 100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Example 05-19 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(120, 120);
|
||||
textSize(64);
|
||||
textAlign(CENTER);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
text(key, 60, 80);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Example 05-20 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(120, 120);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
if (keyPressed) {
|
||||
if ((key == 'h') || (key == 'H')) {
|
||||
line(30, 60, 90, 60);
|
||||
}
|
||||
if ((key == 'n') || (key == 'N')) {
|
||||
line(30, 20, 90, 100);
|
||||
}
|
||||
}
|
||||
line(30, 20, 30, 100);
|
||||
line(90, 20, 90, 100);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Example 05-21 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
int x = 215;
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if (keyPressed && (key == CODED)) { // If it's a coded key
|
||||
if (keyCode == LEFT) { // If it's the left arrow
|
||||
x--;
|
||||
}
|
||||
else if (keyCode == RIGHT) { // If it's the right arrow
|
||||
x++;
|
||||
}
|
||||
}
|
||||
rect(x, 45, 50, 50);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user