We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey everybody, i am totally new to processing and i was playing around with this generative Typography Tutorial. My Problem is that the pdf export that i tried to add to it won't work. Well, it just shows the regular Text in de PDF File but i want to have the particles. I guess that i am overlocking the class of particles somehow. Can anybody please help me out?
This is the Code which consists of two tabs.
FIRST TAB
import processing.pdf.*;
boolean dosave=false;
int maxParticles = 1000;
ArrayList <Particle> particles = new ArrayList <Particle> ();
color BACKGROUND_COLOR = color(255);
color PGRAPHICS_COLOR = color(0);
float globalRotation;
PGraphics pg;
void setup() {
size(1280, 700, P2D);
smooth(16);
pg = createGraphics(width, height, JAVA2D);
pg.beginDraw();
pg.textSize(200);
pg.textAlign(CENTER, CENTER);
pg.fill(PGRAPHICS_COLOR);
pg.text("Test", pg.width/2, pg.height/2);
pg.endDraw();
background(BACKGROUND_COLOR);
}
void draw() {
if(dosave) {
PGraphicsPDF pdf = (PGraphicsPDF)beginRaw(PDF, "pdf_complex_out.pdf");
pdf.beginDraw();
pdf.textSize(200);
pdf.textAlign(CENTER, CENTER);
pdf.fill(PGRAPHICS_COLOR);
pdf.endDraw();
}
addRemoveParticles();
// update and display each particle in the list
for (Particle p : particles) {
p.update();
p.display();
}
if(dosave) {
endRaw();
}
}
void mousePressed() {
particles.clear(); // remove all particles
globalRotation = random(TWO_PI); // randomly set the global rotation/direction of the Particles
}
void keyPressed() {
if (key == 'd') {
dosave=false;
}
}
void addRemoveParticles() {
// remove particles with no life left
for (int i=particles.size()-1; i>=0; i--) {
Particle p = particles.get(i);
if (p.life <= 0) {
particles.remove(i);
}
}
// add particles until the maximum
while (particles.size () < maxParticles) {
particles.add(new Particle());
}
}
SECOND TAB
class Particle {
PVector loc;
float life, lifeRate;
Particle() {
getPosition();
life = random(0.9, 1.25);
lifeRate = random(0.07, 0.08);
}
void update() {
float angle = noise(loc.x * 0.01, loc.y * 0.01) * TWO_PI;
PVector vel = PVector.fromAngle(angle + globalRotation);
loc.add(vel);
life -= lifeRate;
}
void display() {
boolean special = random(1) < 0.001;
strokeWeight(special ? random(0.75, 3) : 0.75);
stroke(0, special ? random(175, 255) : 65);
point(loc.x, loc.y);
}
// get a random position inside the text
void getPosition() {
while (loc == null || !isInText (loc)) loc = new PVector(random(width), random(height));
}
// return if point is inside the text
boolean isInText(PVector v) {
return pg.get(int(v.x), int(v.y)) == PGRAPHICS_COLOR;
}
}
Answers
Let see...
pdf.
(the created PDF object) will go in the PDF file.