Skip to content

Commit 49d773d

Browse files
committed
First commit, old Processing 3 examples without changes
1 parent c2e1a11 commit 49d773d

File tree

539 files changed

+75159
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

539 files changed

+75159
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore this stuff
2+
.DS_Store

Basics/Arrays/Array/Array.pde

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Array.
3+
*
4+
* An array is a list of data. Each piece of data in an array
5+
* is identified by an index number representing its position in
6+
* the array. Arrays are zero based, which means that the first
7+
* element in the array is [0], the second element is [1], and so on.
8+
* In this example, an array named "coswave" is created and
9+
* filled with the cosine values. This data is displayed three
10+
* separate ways on the screen.
11+
*/
12+
13+
14+
float[] coswave;
15+
16+
void setup() {
17+
size(640, 360);
18+
coswave = new float[width];
19+
for (int i = 0; i < width; i++) {
20+
float amount = map(i, 0, width, 0, PI);
21+
coswave[i] = abs(cos(amount));
22+
}
23+
background(255);
24+
noLoop();
25+
}
26+
27+
void draw() {
28+
29+
int y1 = 0;
30+
int y2 = height/3;
31+
for (int i = 0; i < width; i++) {
32+
stroke(coswave[i]*255);
33+
line(i, y1, i, y2);
34+
}
35+
36+
y1 = y2;
37+
y2 = y1 + y1;
38+
for (int i = 0; i < width; i++) {
39+
stroke(coswave[i]*255 / 4);
40+
line(i, y1, i, y2);
41+
}
42+
43+
y1 = y2;
44+
y2 = height;
45+
for (int i = 0; i < width; i++) {
46+
stroke(255 - coswave[i]*255);
47+
line(i, y1, i, y2);
48+
}
49+
50+
}

Basics/Arrays/Array2D/Array2D.pde

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Array 2D.
3+
*
4+
* Demonstrates the syntax for creating a two-dimensional (2D) array.
5+
* Values in a 2D array are accessed through two index values.
6+
* 2D arrays are useful for storing images. In this example, each dot
7+
* is colored in relation to its distance from the center of the image.
8+
*/
9+
10+
float[][] distances;
11+
float maxDistance;
12+
int spacer;
13+
14+
void setup() {
15+
size(640, 360);
16+
maxDistance = dist(width/2, height/2, width, height);
17+
distances = new float[width][height];
18+
for (int y = 0; y < height; y++) {
19+
for (int x = 0; x < width; x++) {
20+
float distance = dist(width/2, height/2, x, y);
21+
distances[x][y] = distance/maxDistance * 255;
22+
}
23+
}
24+
spacer = 10;
25+
strokeWeight(6);
26+
noLoop(); // Run once and stop
27+
}
28+
29+
void draw() {
30+
background(0);
31+
// This embedded loop skips over values in the arrays based on
32+
// the spacer variable, so there are more values in the array
33+
// than are drawn here. Change the value of the spacer variable
34+
// to change the density of the points
35+
for (int y = 0; y < height; y += spacer) {
36+
for (int x = 0; x < width; x += spacer) {
37+
stroke(distances[x][y]);
38+
point(x + spacer/2, y + spacer/2);
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Array Objects.
3+
*
4+
* Demonstrates the syntax for creating an array of custom objects.
5+
*/
6+
7+
int unit = 40;
8+
int count;
9+
Module[] mods;
10+
11+
void setup() {
12+
size(640, 360);
13+
noStroke();
14+
int wideCount = width / unit;
15+
int highCount = height / unit;
16+
count = wideCount * highCount;
17+
mods = new Module[count];
18+
19+
int index = 0;
20+
for (int y = 0; y < highCount; y++) {
21+
for (int x = 0; x < wideCount; x++) {
22+
mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8), unit);
23+
}
24+
}
25+
}
26+
27+
void draw() {
28+
background(0);
29+
for (Module mod : mods) {
30+
mod.update();
31+
mod.display();
32+
}
33+
}

Basics/Arrays/ArrayObjects/Module.pde

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Module {
2+
int xOffset;
3+
int yOffset;
4+
float x, y;
5+
int unit;
6+
int xDirection = 1;
7+
int yDirection = 1;
8+
float speed;
9+
10+
// Contructor
11+
Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit) {
12+
xOffset = xOffsetTemp;
13+
yOffset = yOffsetTemp;
14+
x = xTemp;
15+
y = yTemp;
16+
speed = speedTemp;
17+
unit = tempUnit;
18+
}
19+
20+
// Custom method for updating the variables
21+
void update() {
22+
x = x + (speed * xDirection);
23+
if (x >= unit || x <= 0) {
24+
xDirection *= -1;
25+
x = x + (1 * xDirection);
26+
y = y + (1 * yDirection);
27+
}
28+
if (y >= unit || y <= 0) {
29+
yDirection *= -1;
30+
y = y + (1 * yDirection);
31+
}
32+
}
33+
34+
// Custom method for drawing the object
35+
void display() {
36+
fill(255);
37+
ellipse(xOffset + x, yOffset + y, 6, 6);
38+
}
39+
}

Basics/Camera/MoveEye/MoveEye.pde

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Move Eye.
3+
* by Simon Greenwold.
4+
*
5+
* The camera lifts up (controlled by mouseY) while looking at the same point.
6+
*/
7+
8+
void setup() {
9+
size(640, 360, P3D);
10+
fill(204);
11+
}
12+
13+
void draw() {
14+
lights();
15+
background(0);
16+
17+
// Change height of the camera with mouseY
18+
camera(30.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
19+
0.0, 0.0, 0.0, // centerX, centerY, centerZ
20+
0.0, 1.0, 0.0); // upX, upY, upZ
21+
22+
noStroke();
23+
box(90);
24+
stroke(255);
25+
line(-100, 0, 0, 100, 0, 0);
26+
line(0, -100, 0, 0, 100, 0);
27+
line(0, 0, -100, 0, 0, 100);
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Perspective vs. Ortho
3+
*
4+
* Move the mouse left to right to change the "far"
5+
* parameter for the perspective() and ortho() functions.
6+
* This parameter sets the maximum distance from the
7+
* origin away from the viewer and will clip the geometry.
8+
* Click a mouse button to switch between the perspective and
9+
* orthographic projections.
10+
*/
11+
12+
13+
boolean showPerspective = false;
14+
15+
void setup() {
16+
size(600, 360, P3D);
17+
noFill();
18+
fill(255);
19+
noStroke();
20+
}
21+
22+
void draw() {
23+
lights();
24+
background(0);
25+
float far = map(mouseX, 0, width, 120, 400);
26+
if (showPerspective == true) {
27+
perspective(PI/3.0, float(width)/float(height), 10, far);
28+
} else {
29+
ortho(-width/2.0, width/2.0, -height/2.0, height/2.0, 10, far);
30+
}
31+
translate(width/2, height/2, 0);
32+
rotateX(-PI/6);
33+
rotateY(PI/3);
34+
box(180);
35+
}
36+
37+
void mousePressed() {
38+
showPerspective = !showPerspective;
39+
}
40+
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Perspective.
3+
*
4+
* Move the mouse left and right to change the field of view (fov).
5+
* Click to modify the aspect ratio. The perspective() function
6+
* sets a perspective projection applying foreshortening, making
7+
* distant objects appear smaller than closer ones. The parameters
8+
* define a viewing volume with the shape of truncated pyramid.
9+
* Objects near to the front of the volume appear their actual size,
10+
* while farther objects appear smaller. This projection simulates
11+
* the perspective of the world more accurately than orthographic projection.
12+
* The version of perspective without parameters sets the default
13+
* perspective and the version with four parameters allows the programmer
14+
* to set the area precisely.
15+
*/
16+
17+
void setup() {
18+
size(640, 360, P3D);
19+
noStroke();
20+
}
21+
22+
void draw() {
23+
lights();
24+
background(0);
25+
float cameraY = height/2.0;
26+
float fov = mouseX/float(width) * PI/2;
27+
float cameraZ = cameraY / tan(fov / 2.0);
28+
float aspect = float(width)/float(height);
29+
if (mousePressed) {
30+
aspect = aspect / 2.0;
31+
}
32+
perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
33+
34+
translate(width/2+30, height/2, 0);
35+
rotateX(-PI/6);
36+
rotateY(PI/3 + mouseY/float(height) * PI);
37+
box(45);
38+
translate(0, 0, -50);
39+
box(30);
40+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Brightness
3+
* by Rusty Robison.
4+
*
5+
* Brightness is the relative lightness or darkness of a color.
6+
* Move the cursor vertically over each bar to alter its brightness.
7+
*/
8+
9+
int barWidth = 20;
10+
int lastBar = -1;
11+
12+
void setup() {
13+
size(640, 360);
14+
colorMode(HSB, width, 100, height);
15+
noStroke();
16+
background(0);
17+
}
18+
19+
void draw() {
20+
int whichBar = mouseX / barWidth;
21+
if (whichBar != lastBar) {
22+
int barX = whichBar * barWidth;
23+
fill(barX, 100, mouseY);
24+
rect(barX, 0, barWidth, height);
25+
lastBar = whichBar;
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Color Variables (Homage to Albers).
3+
*
4+
* This example creates variables for colors that may be referred to
5+
* in the program by a name, rather than a number.
6+
*/
7+
8+
size(640, 360);
9+
noStroke();
10+
background(51, 0, 0);
11+
12+
color inside = color(204, 102, 0);
13+
color middle = color(204, 153, 0);
14+
color outside = color(153, 51, 0);
15+
16+
// These statements are equivalent to the statements above.
17+
// Programmers may use the format they prefer.
18+
//color inside = #CC6600;
19+
//color middle = #CC9900;
20+
//color outside = #993300;
21+
22+
pushMatrix();
23+
translate(80, 80);
24+
fill(outside);
25+
rect(0, 0, 200, 200);
26+
fill(middle);
27+
rect(40, 60, 120, 120);
28+
fill(inside);
29+
rect(60, 90, 80, 80);
30+
popMatrix();
31+
32+
pushMatrix();
33+
translate(360, 80);
34+
fill(inside);
35+
rect(0, 0, 200, 200);
36+
fill(outside);
37+
rect(40, 60, 120, 120);
38+
fill(middle);
39+
rect(60, 90, 80, 80);
40+
popMatrix();

Basics/Color/Hue/Hue.pde

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Hue.
3+
*
4+
* Hue is the color reflected from or transmitted through an object
5+
* and is typically referred to as the name of the color (red, blue, yellow, etc.)
6+
* Move the cursor vertically over each bar to alter its hue.
7+
*/
8+
9+
int barWidth = 20;
10+
int lastBar = -1;
11+
12+
void setup()
13+
{
14+
size(640, 360);
15+
colorMode(HSB, height, height, height);
16+
noStroke();
17+
background(0);
18+
}
19+
20+
void draw()
21+
{
22+
int whichBar = mouseX / barWidth;
23+
if (whichBar != lastBar) {
24+
int barX = whichBar * barWidth;
25+
fill(mouseY, height, height);
26+
rect(barX, 0, barWidth, height);
27+
lastBar = whichBar;
28+
}
29+
}
30+

0 commit comments

Comments
 (0)