mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 05:39:18 +01:00
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// Example 10-01 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
float x1 = -20;
|
||||
float x2 = 20;
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
x1 += 0.5;
|
||||
x2 += 0.5;
|
||||
arc(x1, 30, 40, 40, 0.52, 5.76);
|
||||
arc(x2, 90, 40, 40, 0.52, 5.76);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// Example 10-02 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
float x1 = -10;
|
||||
float x2 = 10;
|
||||
float x3 = 35;
|
||||
float x4 = 18;
|
||||
float x5 = 30;
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
x1 += 0.5;
|
||||
x2 += 0.5;
|
||||
x3 += 0.5;
|
||||
x4 += 0.5;
|
||||
x5 += 0.5;
|
||||
arc(x1, 20, 20, 20, 0.52, 5.76);
|
||||
arc(x2, 40, 20, 20, 0.52, 5.76);
|
||||
arc(x3, 60, 20, 20, 0.52, 5.76);
|
||||
arc(x4, 80, 20, 20, 0.52, 5.76);
|
||||
arc(x5, 100, 20, 20, 0.52, 5.76);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Example 10-03 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
float[] x = new float[3000];
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
noStroke();
|
||||
fill(255, 200);
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] = random(-1000, 200);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] += 0.5;
|
||||
float y = i * 0.4;
|
||||
arc(x[i], y, 12, 12, 0.52, 5.76);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Example 10-04 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
int[] x; // Declare the array
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
x = new int[2]; // Create the array
|
||||
x[0] = 12; // Assign the first value
|
||||
x[1] = 2; // Assign the second value
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// Example 10-05 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
int[] x = new int[2]; // Declare and create the array
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
x[0] = 12; // Assign the first value
|
||||
x[1] = 2; // Assign the second value
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Example 10-06 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
int[] x = { 12, 2 }; // Declare, create, and assign
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Example 10-07 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
float[] x = {-20, 20};
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
x[0] += 0.5; // Increase the first element
|
||||
x[1] += 0.5; // Increase the second element
|
||||
arc(x[0], 30, 40, 40, 0.52, 5.76);
|
||||
arc(x[1], 90, 40, 40, 0.52, 5.76);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Example 10-08 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
float[] gray;
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
gray = new float[width];
|
||||
for (int i = 0; i < gray.length; i++) {
|
||||
gray[i] = random(0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
for (int i = 0; i < gray.length; i++) {
|
||||
stroke(gray[i]);
|
||||
line(i, 0, i, height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Example 10-09 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
int num = 60;
|
||||
int[] x = new int[num];
|
||||
int[] y = new int[num];
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
// Copy array values from back to front
|
||||
for (int i = x.length-1; i > 0; i--) {
|
||||
x[i] = x[i-1];
|
||||
y[i] = y[i-1];
|
||||
}
|
||||
x[0] = mouseX; // Set the first element
|
||||
y[0] = mouseY; // Set the first element
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
fill(i * 4);
|
||||
ellipse(x[i], y[i], 40, 40);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Example 10-10 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
JitterBug[] bugs = new JitterBug[33];
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
smooth();
|
||||
for (int i = 0; i < bugs.length; i++) {
|
||||
float x = random(width);
|
||||
float y = random(height);
|
||||
int r = i + 2;
|
||||
bugs[i] = new JitterBug(x, y, r);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
for (int i = 0; i < bugs.length; i++) {
|
||||
bugs[i].move();
|
||||
bugs[i].display();
|
||||
}
|
||||
}
|
||||
|
||||
class JitterBug {
|
||||
|
||||
float x;
|
||||
float y;
|
||||
int diameter;
|
||||
float speed = 2.5;
|
||||
|
||||
JitterBug(float tempX, float tempY, int tempDiameter) {
|
||||
x = tempX;
|
||||
y = tempY;
|
||||
diameter = tempDiameter;
|
||||
}
|
||||
|
||||
void move() {
|
||||
x += random(-speed, speed);
|
||||
y += random(-speed, speed);
|
||||
}
|
||||
|
||||
void display() {
|
||||
ellipse(x, y, diameter, diameter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Example 10-11 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
int numFrames = 12; // The number of frames
|
||||
PImage[] images = new PImage[numFrames]; // Make the array
|
||||
int currentFrame = 1;
|
||||
|
||||
void setup() {
|
||||
size(240, 120);
|
||||
for (int i = 1; i < images.length; i++) {
|
||||
String imageName = "frame-" + nf(i, 4) + ".png";
|
||||
images[i] = loadImage(imageName); // Load each image
|
||||
}
|
||||
frameRate(24);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
image(images[currentFrame], 0, 0);
|
||||
currentFrame++; // Next frame
|
||||
if (currentFrame >= images.length) {
|
||||
currentFrame = 1; // Return to first frame
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user