mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Example 11-01 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
import processing.opengl.*;
|
||||
|
||||
void setup() {
|
||||
size(440, 220, OPENGL);
|
||||
noStroke();
|
||||
fill(255, 190);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(mouseX / 200.0);
|
||||
rotateY(mouseY / 100.0);
|
||||
int dim = 18;
|
||||
for (int i = -height/2; i < height/2; i += dim*1.2) {
|
||||
for (int j = -height/2; j < height/2; j += dim*1.2) {
|
||||
beginShape();
|
||||
vertex(i, j, 0);
|
||||
vertex(i+dim, j, 0);
|
||||
vertex(i+dim, j+dim, -dim);
|
||||
vertex(i, j+dim, -dim);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Example 11-02 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
import processing.opengl.*;
|
||||
|
||||
void setup() {
|
||||
size(420, 220, OPENGL);
|
||||
noStroke();
|
||||
fill(255);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
//ambientLight(102, 102, 102);
|
||||
//directionalLight(255, 255, 255, // Color
|
||||
// -1, 0, 0); // Direction XYZ
|
||||
//pointLight(255, 255, 255, // Color
|
||||
// mouseX, 110, 50); // Position
|
||||
//spotLight(255, 255, 255, // Color
|
||||
// mouseX, 0, 200, // Position
|
||||
// 0, 0, -1, // Direction XYZ
|
||||
// PI, 2); // Concentration
|
||||
rotateY(PI/24);
|
||||
background(0);
|
||||
translate(width/2, height/2, -20);
|
||||
int dim = 18;
|
||||
for (int i = -height/2; i < height/2; i += dim*1.4) {
|
||||
for (int j = -height/2; j < height/2; j += dim*1.4) {
|
||||
pushMatrix();
|
||||
translate(i, j, -j);
|
||||
box(dim, dim, dim);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// Example 11-03 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
import processing.opengl.*;
|
||||
|
||||
void setup() {
|
||||
size(420, 220, OPENGL);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
background(0);
|
||||
float camZ = (height/2.0) / tan(PI*60.0 / 360.0);
|
||||
camera(mouseX, mouseY, camZ, // Camera location
|
||||
width/2.0, height/2.0, 0, // Camera target
|
||||
0, 1, 0); // Camera orientation
|
||||
translate(width/2, height/2, -20);
|
||||
int dim = 18;
|
||||
for (int i = -height/2; i < height/2; i += dim*1.4) {
|
||||
for (int j = -height/2; j < height/2; j += dim*1.4) {
|
||||
pushMatrix();
|
||||
translate(i, j, -j);
|
||||
box(dim, dim, dim);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Example 11-04 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
float x = 0;
|
||||
|
||||
void setup() {
|
||||
size(720, 480);
|
||||
smooth();
|
||||
noFill();
|
||||
strokeCap(SQUARE);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
translate(x, 0);
|
||||
for (int y = 40; y < 280; y += 20) {
|
||||
line(-260, y, 0, y + 200);
|
||||
line(0, y + 200, 260, y);
|
||||
}
|
||||
if (frameCount < 60) {
|
||||
saveFrame("frames/SaveExample-####.tif");
|
||||
} else {
|
||||
exit();
|
||||
}
|
||||
x += 2.5;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Example 11-05 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
import processing.pdf.*;
|
||||
|
||||
void setup() {
|
||||
size(600, 800, PDF, "Ex-11-5.pdf");
|
||||
noFill();
|
||||
strokeCap(SQUARE);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
for (int y = 100; y < height - 300; y+=20) {
|
||||
float r = random(0, 102);
|
||||
strokeWeight(r / 10);
|
||||
beginShape();
|
||||
vertex(100, y);
|
||||
vertex(width/2, y + 200);
|
||||
vertex(width-100, y);
|
||||
endShape();
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Example 11-06 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
// Note: This is code for an Arduino board, not Processing
|
||||
|
||||
int sensorPin = 0; // Select input pin
|
||||
int val = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // Open serial port
|
||||
}
|
||||
|
||||
void loop() {
|
||||
val = analogRead(sensorPin) / 4; // Read value from sensor
|
||||
Serial.print(val, BYTE); // Print variable to serial port
|
||||
delay(100); // Wait 100 milliseconds
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Example 11-07 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
Serial port; // Create object from Serial class
|
||||
float val; // Data received from the serial port
|
||||
|
||||
void setup() {
|
||||
size(440, 220);
|
||||
// IMPORTANT NOTE:
|
||||
// The first serial port retrieved by Serial.list()
|
||||
// should be your Arduino. If not, uncomment the next
|
||||
// line by deleting the // before it. Run the sketch
|
||||
// again to see a list of serial ports. Then, change
|
||||
// the 0 in between [ and ] to the number of the port
|
||||
// that your Arduino is connected to.
|
||||
//println(Serial.list());
|
||||
String arduinoPort = Serial.list()[0];
|
||||
port = new Serial(this, arduinoPort, 9600);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if (port.available() > 0) { // If data is available,
|
||||
val = port.read(); // read it and store it in val
|
||||
val = map(val, 0, 255, 0, height); // Convert the value
|
||||
}
|
||||
rect(40, val-10, 360, 20);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// Example 11-08 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
Serial port; // Create object from Serial class
|
||||
float val; // Data received from the serial port
|
||||
int x;
|
||||
float easing = 0.05;
|
||||
float easedVal;
|
||||
|
||||
void setup() {
|
||||
size(440, 440);
|
||||
frameRate(30);
|
||||
smooth();
|
||||
String arduinoPort = Serial.list()[0];
|
||||
port = new Serial(this, arduinoPort, 9600);
|
||||
background(0);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if ( port.available() > 0) { // If data is available,
|
||||
val = port.read(); // read it and store it in val
|
||||
val = map(val, 0, 255, 0, height); // Convert the values
|
||||
}
|
||||
|
||||
float targetVal = val;
|
||||
easedVal += (targetVal - easedVal) * easing;
|
||||
|
||||
stroke(0);
|
||||
line(x, 0, x, height); // Black line
|
||||
stroke(255);
|
||||
line(x+1, 0, x+1, height); // White line
|
||||
line(x, 220, x, val); // Raw value
|
||||
line(x, 440, x, easedVal + 220); // Averaged value
|
||||
|
||||
x++;
|
||||
if (x > width) {
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// Example 11-09 from "Getting Started with Processing"
|
||||
// by Reas & Fry. O'Reilly / Make 2010
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
Serial port; // Create object from Serial class
|
||||
float val; // Data received from the serial port
|
||||
float angle;
|
||||
float radius;
|
||||
|
||||
void setup() {
|
||||
size(440, 440);
|
||||
frameRate(30);
|
||||
strokeWeight(2);
|
||||
smooth();
|
||||
String arduinoPort = Serial.list()[0];
|
||||
port = new Serial(this, arduinoPort, 9600);
|
||||
background(0);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if ( port.available() > 0) { // If data is available,
|
||||
val = port.read(); // read it and store it in val
|
||||
// Convert the values to set the radius
|
||||
radius = map(val, 0, 255, 0, height * 0.45);
|
||||
}
|
||||
|
||||
int middleX = width/2;
|
||||
int middleY = height/2;
|
||||
float x = middleX + cos(angle) * height/2;
|
||||
float y = middleY + sin(angle) * height/2;
|
||||
stroke(0);
|
||||
line(middleX, middleY, x, y);
|
||||
|
||||
x = middleX + cos(angle) * radius;
|
||||
y = middleY + sin(angle) * radius;
|
||||
stroke(255);
|
||||
line(middleX, middleY, x, y);
|
||||
|
||||
angle += 0.01;
|
||||
}
|
||||
Reference in New Issue
Block a user