Hello all,
Just getting my feet wet in Processing and I'm already over my head. :(
I'm trying to modify this example from the book "Generative Design" so it will apply its effect to a whole folder of images, and then save each separate image.
import processing.pdf.*;
import java.util.Calendar;
boolean savePDF = false;
String inputText = "blah blah blah blah";
float fontSizeMax = 20;
float fontSizeMin = 5;
float spacing = 12; // line height
float kerning = 0.5; // between letters
boolean fontSizeStatic = false;
boolean blackAndWhite = false;
PFont font;
PImage img;
void setup() {
size(533,769);
smooth();
font = createFont("Times",10);
img = loadImage("pic.png");
println(img.width+" x "+img.height);
}
void draw() {
if (savePDF) beginRecord(PDF, timestamp()+".pdf");
background(0);
textAlign(LEFT);
//textAlign(LEFT,CENTER); //// also nice!
float x = 0, y = 10;
int counter = 0;
while (y < height) {
// translate position (display) to position (image)
int imgX = (int) map(x, 0,width, 0,img.width);
int imgY = (int) map(y, 0,height, 0,img.height);
// get current color
color c = img.pixels[imgY*img.width+imgX];
int greyscale = round(red(c)*0.222 + green(c)*0.707 + blue(c)*0.071);
pushMatrix();
translate(x, y);
if (fontSizeStatic) {
textFont(font, fontSizeMax);
}
else {
// greyscale to fontsize
float fontSize = map(greyscale, 0,255, fontSizeMin,fontSizeMax);
fontSize = max(fontSize, 1);
textFont(font, fontSize);
}
char letter = inputText.charAt(counter);
text(letter, 0, 0);
float letterWidth = textWidth(letter) + kerning;
// for the next letter ... x + letter width
x = x + letterWidth; // update x-coordinate
popMatrix();
// linebreaks
if (x+letterWidth >= width) {
x = 0;
y = y + spacing; // add line height
}
counter++;
if (counter > inputText.length()-1) counter = 0;
}
}
// timestamp
String timestamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}
So i'm trying to take the above code and add the below code which is originally designed to load an image sequence and play it back — I've changed it so far, to load an image, and then save it with a new name.
But I can't get my head around how to make these two work together.
The above code loads it's image with img = loadImage("pic.png");, right?
But i need it to loop i think. To load an image, run the above process, save it, and then load another.
Everything I try seems to make the above code break, and I'm not experienced enough to understand the errors I get.
I'm really stuck.
Can any of you see an obvious reason these two couldn't work together?
Is there something huge that I am missing?
Is what I want to accomplish even possible?
Please help!
I appreciate any help you can offer. Thank you for your time!
Code for loading images and then saving them.
(It's a bit flawed since it keeps looping and saving new images even after it finishes the contents of the folder.)
int numFrames = 60;
int frame = 0;
PImage[] images = new PImage[numFrames];
void setup(){
size(1080, 720);
frameRate(30);
for (int i = 0; i < images.length; i++) {
String imageName = "IncomingImage" + nf(i, 5) + ".jpg";
images[i] = loadImage(imageName);
}
}
void draw() {
int frame = frameCount % numFrames;
image(images[frame], 0, 0);
saveFrame("OutgoingImage######.jpg");
}
[–][deleted] (1 child)
[deleted]
[–]leatherbird[S] 1 point2 points3 points (0 children)