mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Added updated examples from branch
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
// Blending, by Andres Colubri
|
||||
// Images can be blended using one of the 10 blending modes
|
||||
// available in P3D.
|
||||
// Images by Kevin Bjorke.
|
||||
|
||||
PImage pic1, pic2;
|
||||
int selMode = REPLACE;
|
||||
String name = "replace";
|
||||
int picAlpha = 255;
|
||||
|
||||
void setup() {
|
||||
size(800, 480, P3D);
|
||||
orientation(LANDSCAPE);
|
||||
|
||||
PFont font = createFont(PFont.list()[0], 20);
|
||||
textFont(font, 20);
|
||||
|
||||
pic1 = loadImage("bjorke1.jpg");
|
||||
pic2 = loadImage("bjorke2.jpg");
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
tint(255, 255);
|
||||
image(pic1, 0, 0, pic1.width, pic1.height);
|
||||
|
||||
blendMode(selMode);
|
||||
tint(255, picAlpha);
|
||||
image(pic2, 0, 0, pic2.width, pic2.height);
|
||||
|
||||
blendMode(REPLACE);
|
||||
fill(200, 50, 50);
|
||||
rect(0, height - 50, map(picAlpha, 0, 255, 0, width), 50);
|
||||
fill(255);
|
||||
|
||||
text("Selected blend mode: " + name + ". Click to move to next", 10, pic1.height + 30);
|
||||
text("Drag this bar to change alpha of image", 10, height - 18);
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
if (height - 50 < mouseY) return;
|
||||
|
||||
if (selMode == REPLACE) {
|
||||
selMode = BLEND;
|
||||
name = "blend";
|
||||
} else if (selMode == BLEND) {
|
||||
selMode = ADD;
|
||||
name = "add";
|
||||
} else if (selMode == ADD) {
|
||||
selMode = SUBTRACT;
|
||||
name = "subtract";
|
||||
} else if (selMode == SUBTRACT) {
|
||||
selMode = LIGHTEST;
|
||||
name = "lightest";
|
||||
} else if (selMode == LIGHTEST) {
|
||||
selMode = DARKEST;
|
||||
name = "darkest";
|
||||
} else if (selMode == DARKEST) {
|
||||
selMode = DIFFERENCE;
|
||||
name = "difference";
|
||||
} else if (selMode == DIFFERENCE) {
|
||||
selMode = EXCLUSION;
|
||||
name = "exclusion";
|
||||
} else if (selMode == EXCLUSION) {
|
||||
selMode = MULTIPLY;
|
||||
name = "multiply";
|
||||
} else if (selMode == MULTIPLY) {
|
||||
selMode = SCREEN;
|
||||
name = "screen";
|
||||
} else if (selMode == SCREEN) {
|
||||
selMode = REPLACE;
|
||||
name = "replace";
|
||||
}
|
||||
}
|
||||
|
||||
void mouseDragged() {
|
||||
if (height - 50 < mouseY) {
|
||||
picAlpha = int(map(mouseX, 0, width, 0, 255));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Explode
|
||||
* by Daniel Shiffman.
|
||||
*
|
||||
* Mouse horizontal location controls breaking apart of image and
|
||||
* Maps pixels from a 2D image into 3D space. Pixel brightness controls
|
||||
* translation along z axis.
|
||||
*/
|
||||
|
||||
PImage img; // The source image
|
||||
int cellsize = 2; // Dimensions of each cell in the grid
|
||||
int columns, rows; // Number of columns and rows in our system
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
orientation(LANDSCAPE);
|
||||
img = loadImage("eames.jpg"); // Load the image
|
||||
columns = img.width / cellsize; // Calculate # of columns
|
||||
rows = img.height / cellsize; // Calculate # of rows
|
||||
img.loadPixels();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
// Begin loop for columns
|
||||
for ( int i = 0; i < columns; i++) {
|
||||
// Begin loop for rows
|
||||
for ( int j = 0; j < rows; j++) {
|
||||
int x = i*cellsize + cellsize/2; // x position
|
||||
int y = j*cellsize + cellsize/2; // y position
|
||||
int loc = x + y*img.width; // Pixel array location
|
||||
color c = img.pixels[loc]; // Grab the color
|
||||
// Calculate a z position as a function of mouseX and pixel brightness
|
||||
float z = (mouseX / float(width)) * brightness(img.pixels[loc]) - 20.0;
|
||||
// Translate to the location, set fill and stroke, and draw the rect
|
||||
pushMatrix();
|
||||
translate(x + 200, y + 100, z);
|
||||
fill(c, 204);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
rect(0, 0, cellsize, cellsize);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Extrusion.
|
||||
*
|
||||
* Converts a flat image into spatial data points and rotates the points
|
||||
* around the center.
|
||||
*/
|
||||
|
||||
PImage extrude;
|
||||
int[][] values;
|
||||
float angle = 0;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
orientation(LANDSCAPE);
|
||||
|
||||
// Load the image into a new array
|
||||
extrude = loadImage("ystone08.jpg");
|
||||
extrude.loadPixels();
|
||||
values = new int[extrude.width][extrude.height];
|
||||
for (int y = 0; y < extrude.height; y++) {
|
||||
for (int x = 0; x < extrude.width; x++) {
|
||||
color pixel = extrude.get(x, y);
|
||||
values[x][y] = int(brightness(pixel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
// Update the angle
|
||||
angle += 0.005;
|
||||
|
||||
// Rotate around the center axis
|
||||
translate(width/2, 0, +128);
|
||||
rotateY(angle);
|
||||
translate(-extrude.width/2, 100, +128);
|
||||
|
||||
// Display the image mass
|
||||
for (int y = 0; y < extrude.height; y++) {
|
||||
for (int x = 0; x < extrude.width; x++) {
|
||||
stroke(values[x][y]);
|
||||
point(x, y, -values[x][y]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Extrusion.
|
||||
*
|
||||
* Converts a flat image into spatial data points and rotates the points
|
||||
* around the center.
|
||||
*/
|
||||
|
||||
PImage a;
|
||||
boolean onetime = true;
|
||||
int[][] aPixels;
|
||||
int[][] values;
|
||||
float angle;
|
||||
|
||||
void setup() {
|
||||
size(displayWidth, displayHeight, P3D);
|
||||
|
||||
aPixels = new int[width][height];
|
||||
values = new int[width][height];
|
||||
noFill();
|
||||
|
||||
// Load the image into a new array
|
||||
// Extract the values and store in an array
|
||||
a = loadImage("ystone08.jpg");
|
||||
a.loadPixels();
|
||||
for (int i = 0; i < a.height; i++) {
|
||||
for (int j = 0; j < a.width; j++) {
|
||||
aPixels[j][i] = a.pixels[i*a.width + j];
|
||||
values[j][i] = int(blue(aPixels[j][i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
translate(width/2, height/2, 0);
|
||||
scale(2.0);
|
||||
|
||||
// Update and constrain the angle
|
||||
angle += 0.005;
|
||||
rotateY(angle);
|
||||
|
||||
// Display the image mass
|
||||
for (int i = 0; i < a.height; i += 2) {
|
||||
for (int j = 0; j < a.width; j += 2) {
|
||||
stroke(values[j][i], 153);
|
||||
line(j-a.width/2, i-a.height/2, -values[j][i], j-a.width/2, i-a.height/2, -values[j][i]-10);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Zoom.
|
||||
*
|
||||
* Move the cursor over the image to alter its position. Click and press
|
||||
* the mouse to zoom and set the density of the matrix by typing numbers 1-5.
|
||||
* This program displays a series of lines with their heights corresponding to
|
||||
* a color value read from an image.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
//boolean onetime = true;
|
||||
int[][] imgPixels;
|
||||
float sval = 1.0;
|
||||
float nmx, nmy;
|
||||
int res = 5;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
orientation(LANDSCAPE);
|
||||
noFill();
|
||||
stroke(255);
|
||||
img = loadImage("ystone08.jpg");
|
||||
imgPixels = new int[img.width][img.height];
|
||||
for (int i = 0; i < img.height; i++) {
|
||||
for (int j = 0; j < img.width; j++) {
|
||||
imgPixels[j][i] = img.get(j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
nmx = nmx + (mouseX-nmx)/20;
|
||||
nmy += (mouseY-nmy)/20;
|
||||
|
||||
if(mousePressed) {
|
||||
sval += 0.005;
|
||||
}
|
||||
else {
|
||||
sval -= 0.01;
|
||||
}
|
||||
|
||||
sval = constrain(sval, 1.0, 2.5);
|
||||
|
||||
translate(width/2 + nmx * sval-100, height/2 + nmy*sval - 200, -50);
|
||||
scale(sval);
|
||||
rotateZ(PI/9 - sval + 1.0);
|
||||
rotateX(PI/sval/8 - 0.125);
|
||||
rotateY(sval/8 - 0.125);
|
||||
|
||||
translate(-width/2, -height/2, 0);
|
||||
|
||||
for (int i = 0; i < img.height; i += res) {
|
||||
for (int j = 0; j < img.width; j += res) {
|
||||
float rr = red(imgPixels[j][i]);
|
||||
float gg = green(imgPixels[j][i]);
|
||||
float bb = blue(imgPixels[j][i]);
|
||||
float tt = rr+gg+bb;
|
||||
stroke(rr, gg, gg);
|
||||
line(i, j, tt/10-20, i, j, tt/10 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if(key == '1') {
|
||||
res = 1;
|
||||
}
|
||||
else if (key == '2') {
|
||||
res = 2;
|
||||
}
|
||||
else if (key == '3') {
|
||||
res = 3;
|
||||
}
|
||||
else if (key == '4') {
|
||||
res = 4;
|
||||
}
|
||||
else if (key == '5') {
|
||||
res = 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user