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,16 @@
|
||||
// Example 08-01 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
println("Ready to roll!");
|
||||
rollDice(20);
|
||||
rollDice(20);
|
||||
rollDice(6);
|
||||
println("Finished.");
|
||||
}
|
||||
|
||||
void rollDice(int numSides) {
|
||||
int d = 1 + int(random(numSides));
|
||||
println("Rolling... " + d);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Example 08-02 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
println("Ready to roll!");
|
||||
int d1 = 1 + int(random(20));
|
||||
println("Rolling... " + d1);
|
||||
int d2 = 1 + int(random(20));
|
||||
println("Rolling... " + d2);
|
||||
int d3 = 1 + int(random(6));
|
||||
println("Rolling... " + d3);
|
||||
println("Finished.");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Example 08-03 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
translate(110, 110);
|
||||
stroke(0);
|
||||
strokeWeight(70);
|
||||
line(0, -35, 0, -65); // Body
|
||||
noStroke();
|
||||
fill(255);
|
||||
ellipse(-17.5, -65, 35, 35); // Left eye dome
|
||||
ellipse(17.5, -65, 35, 35); // Right eye dome
|
||||
arc(0, -65, 70, 70, 0, PI); // Chin
|
||||
fill(0);
|
||||
ellipse(-14, -65, 8, 8); // Left eye
|
||||
ellipse(14, -65, 8, 8); // Right eye
|
||||
quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// Example 08-04 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
|
||||
// Left owl
|
||||
translate(110, 110);
|
||||
stroke(0);
|
||||
strokeWeight(70);
|
||||
line(0, -35, 0, -65); // Body
|
||||
noStroke();
|
||||
fill(255);
|
||||
ellipse(-17.5, -65, 35, 35); // Left eye dome
|
||||
ellipse(17.5, -65, 35, 35); // Right eye dome
|
||||
arc(0, -65, 70, 70, 0, PI); // Chin
|
||||
fill(0);
|
||||
ellipse(-14, -65, 8, 8); // Left eye
|
||||
ellipse(14, -65, 8, 8); // Right eye
|
||||
quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
|
||||
|
||||
// Right owl
|
||||
translate(70, 0);
|
||||
stroke(0);
|
||||
strokeWeight(70);
|
||||
line(0, -35, 0, -65); // Body
|
||||
noStroke();
|
||||
fill(255);
|
||||
ellipse(-17.5, -65, 35, 35); // Left eye dome
|
||||
ellipse(17.5, -65, 35, 35); // Right eye dome
|
||||
arc(0, -65, 70, 70, 0, PI); // Chin
|
||||
fill(0);
|
||||
ellipse(-14, -65, 8, 8); // Left eye
|
||||
ellipse(14, -65, 8, 8); // Right eye
|
||||
quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Example 08-05 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
owl(110, 110);
|
||||
owl(180, 110);
|
||||
}
|
||||
|
||||
void owl(int x, int y) {
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
stroke(0);
|
||||
strokeWeight(70);
|
||||
line(0, -35, 0, -65); // Body
|
||||
noStroke();
|
||||
fill(255);
|
||||
ellipse(-17.5, -65, 35, 35); // Left eye dome
|
||||
ellipse(17.5, -65, 35, 35); // Right eye dome
|
||||
arc(0, -65, 70, 70, 0, PI); // Chin
|
||||
fill(0);
|
||||
ellipse(-14, -65, 8, 8); // Left eye
|
||||
ellipse(14, -65, 8, 8); // Right eye
|
||||
quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Example 08-06 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
for (int x = 35; x < width + 70; x += 70) {
|
||||
owl(x, 110);
|
||||
}
|
||||
}
|
||||
|
||||
void owl(int x, int y) {
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
stroke(0);
|
||||
strokeWeight(70);
|
||||
line(0, -35, 0, -65); // Body
|
||||
noStroke();
|
||||
fill(255);
|
||||
ellipse(-17.5, -65, 35, 35); // Left eye dome
|
||||
ellipse(17.5, -65, 35, 35); // Right eye dome
|
||||
arc(0, -65, 70, 70, 0, PI); // Chin
|
||||
fill(0);
|
||||
ellipse(-14, -65, 8, 8); // Left eye
|
||||
ellipse(14, -65, 8, 8); // Right eye
|
||||
quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// Example 08-07 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
size(480, 120);
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
randomSeed(0);
|
||||
for (int i = 35; i < width + 40; i += 40) {
|
||||
int gray = int(random(0, 102));
|
||||
float scalar = random(0.25, 1.0);
|
||||
owl(i, 110, gray, scalar);
|
||||
}
|
||||
}
|
||||
|
||||
void owl(int x, int y, int g, float s) {
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
scale(s); // Set the size
|
||||
stroke(g); // Set the gray value
|
||||
strokeWeight(70);
|
||||
line(0, -35, 0, -65); // Body
|
||||
noStroke();
|
||||
fill(255-g);
|
||||
ellipse(-17.5, -65, 35, 35); // Left eye dome
|
||||
ellipse(17.5, -65, 35, 35); // Right eye dome
|
||||
arc(0, -65, 70, 70, 0, PI); // Chin
|
||||
fill(g);
|
||||
ellipse(-14, -65, 8, 8); // Left eye
|
||||
ellipse(14, -65, 8, 8); // Right eye
|
||||
quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Example 08-08 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
void setup() {
|
||||
float yourWeight = 132;
|
||||
float marsWeight = calculateMars(yourWeight);
|
||||
println(marsWeight);
|
||||
}
|
||||
|
||||
float calculateMars(float w) {
|
||||
float newWeight = w * 0.38;
|
||||
return newWeight;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user