Initial Commit

This commit is contained in:
plane000
2018-04-20 10:15:15 +01:00
parent 49150ccfe4
commit 62101e8e61
2870 changed files with 520122 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/**
* Arm.
*
* The angle of each segment is controlled with the mouseX and
* mouseY position. The transformations applied to the first segment
* are also applied to the second segment because they are inside
* the same pushMatrix() and popMatrix() group.
*/
float x, y;
float angle1 = 0.0;
float angle2 = 0.0;
float segLength = 100;
void setup() {
size(640, 360);
strokeWeight(30);
stroke(255, 160);
x = width * 0.3;
y = height * 0.5;
}
void draw() {
background(0);
angle1 = (mouseX/float(width) - 0.5) * -PI;
angle2 = (mouseY/float(height) - 0.5) * PI;
pushMatrix();
segment(x, y, angle1);
segment(segLength, 0, angle2);
popMatrix();
}
void segment(float x, float y, float a) {
translate(x, y);
rotate(a);
line(0, 0, segLength, 0);
}

View File

@@ -0,0 +1,34 @@
/**
* Rotate.
*
* Rotating a square around the Z axis. To get the results
* you expect, send the rotate function angle parameters that are
* values between 0 and PI*2 (TWO_PI which is roughly 6.28). If you prefer to
* think about angles as degrees (0-360), you can use the radians()
* method to convert your values. For example: scale(radians(90))
* is identical to the statement scale(PI/2).
*/
float angle;
float jitter;
void setup() {
size(640, 360);
noStroke();
fill(255);
rectMode(CENTER);
}
void draw() {
background(51);
// during even-numbered seconds (0, 2, 4, 6...)
if (second() % 2 == 0) {
jitter = random(-0.1, 0.1);
}
angle = angle + jitter;
float c = cos(angle);
translate(width/2, height/2);
rotate(c);
rect(0, 0, 180, 180);
}

View File

@@ -0,0 +1,37 @@
/**
* Rotate Push Pop.
*
* The push() and pop() functions allow for more control over transformations.
* The push function saves the current coordinate system to the stack
* and pop() restores the prior coordinate system.
*/
float a; // Angle of rotation
float offset = PI/24.0; // Angle offset between boxes
int num = 12; // Number of boxes
void setup() {
size(640, 360, P3D);
noStroke();
}
void draw() {
lights();
background(0, 0, 26);
translate(width/2, height/2);
for(int i = 0; i < num; i++) {
float gray = map(i, 0, num-1, 0, 255);
pushMatrix();
fill(gray);
rotateY(a + offset*i);
rotateX(a/2 + offset*i);
box(200);
popMatrix();
}
a += 0.01;
}

View File

@@ -0,0 +1,40 @@
/**
* Rotate 1.
*
* Rotating simultaneously in the X and Y axis.
* Transformation functions such as rotate() are additive.
* Successively calling rotate(1.0) and rotate(2.0)
* is equivalent to calling rotate(3.0).
*/
float a = 0.0;
float rSize; // rectangle size
void setup() {
size(640, 360, P3D);
rSize = width / 6;
noStroke();
fill(204, 204);
}
void draw() {
background(126);
a += 0.005;
if(a > TWO_PI) {
a = 0.0;
}
translate(width/2, height/2);
rotateX(a);
rotateY(a * 2.0);
fill(255);
rect(-rSize, -rSize, rSize*2, rSize*2);
rotateX(a * 1.001);
rotateY(a * 2.002);
fill(0);
rect(-rSize, -rSize, rSize*2, rSize*2);
}

View File

@@ -0,0 +1,37 @@
/**
* Scale
* by Denis Grutze.
*
* Paramenters for the scale() function are values specified
* as decimal percentages. For example, the method call scale(2.0)
* will increase the dimension of the shape by 200 percent.
* Objects always scale from the origin.
*/
float a = 0.0;
float s = 0.0;
void setup() {
size(640, 360);
noStroke();
rectMode(CENTER);
frameRate(30);
}
void draw() {
background(102);
a = a + 0.04;
s = cos(a)*2;
translate(width/2, height/2);
scale(s);
fill(51);
rect(0, 0, 50, 50);
translate(75, 0);
fill(255);
scale(s);
rect(0, 0, 50, 50);
}

View File

@@ -0,0 +1,37 @@
/**
* Translate.
*
* The translate() function allows objects to be moved
* to any location within the window. The first parameter
* sets the x-axis offset and the second parameter sets the
* y-axis offset.
*/
float x, y;
float dim = 80.0;
void setup() {
size(640, 360);
noStroke();
}
void draw() {
background(102);
x = x + 0.8;
if (x > width + dim) {
x = -dim;
}
translate(x, height/2-dim/2);
fill(255);
rect(-dim/2, -dim/2, dim, dim);
// Transforms accumulate. Notice how this rect moves
// twice as fast as the other, but it has the same
// parameter for the x-axis value
translate(x, dim);
fill(0);
rect(-dim/2, -dim/2, dim, dim);
}