trying to combine 2 codes but come out with unexpected token void
in
Core Library Questions
•
1 years ago
I am new to processing. I tried to combine two codes which is fractale and the pdf exporter
the code for fractale works when I move the mouse in X direction and i tried to record the movement of the fractale with the pdf exporter code so I can get the vector of it's movement of it. However, after I combined the two I get this error message saying "unexpected token void". help is appreciated. thank you
here's the code
import processing.pdf.*;
boolean record;
float theta;
void setup() {
size(640, 900);
smooth();
}
void draw() {
if (record) {
// Note that #### will be replaced with the frame number. Fancy!
beginRecord(PDF, "frame-####.pdf");
}
// Draw something good here
background(0);
frameRate(30);
stroke(255);
// Let's pick an angle 0 to 90 degrees based on the mouse position
float a = (mouseX / (float) width) * 90f;
// Convert it to radians
theta = radians(a);
// Start the tree from the bottom of the screen
translate(width/2,height);
// Draw a line 120 pixels
line(450,0,0,0);
// Move to the end of that line
translate(0,-450);
// Start the recursive branching!
branch(200);
}
void branch(float h) {
// Each branch will be 2/3rds the size of the previous one
h *= 0.66;
// All recursive functions must have an exit condition!!!!
// Here, ours is when the length of the branch is 2 pixels or less
if (h > 2) {
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotate(theta); // Rotate by theta
line(0, 0, 0, -h); // Draw the branch
translate(0, -h); // Move to the end of the branch
branch(h); // Ok, now call myself to draw two new branches!!
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
// Repeat the same thing, only branch off to the "left" this time!
pushMatrix();
rotate(-theta);
line(0, 0, 0, h);
translate(0, h);
branch(h);
popMatrix();
if (record) {
endRecord();
record = false;
}
// Use a keypress so thousands of files aren't created
void mousePressed() {
record = true;
}
}
the code for fractale works when I move the mouse in X direction and i tried to record the movement of the fractale with the pdf exporter code so I can get the vector of it's movement of it. However, after I combined the two I get this error message saying "unexpected token void". help is appreciated. thank you
here's the code
import processing.pdf.*;
boolean record;
float theta;
void setup() {
size(640, 900);
smooth();
}
void draw() {
if (record) {
// Note that #### will be replaced with the frame number. Fancy!
beginRecord(PDF, "frame-####.pdf");
}
// Draw something good here
background(0);
frameRate(30);
stroke(255);
// Let's pick an angle 0 to 90 degrees based on the mouse position
float a = (mouseX / (float) width) * 90f;
// Convert it to radians
theta = radians(a);
// Start the tree from the bottom of the screen
translate(width/2,height);
// Draw a line 120 pixels
line(450,0,0,0);
// Move to the end of that line
translate(0,-450);
// Start the recursive branching!
branch(200);
}
void branch(float h) {
// Each branch will be 2/3rds the size of the previous one
h *= 0.66;
// All recursive functions must have an exit condition!!!!
// Here, ours is when the length of the branch is 2 pixels or less
if (h > 2) {
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotate(theta); // Rotate by theta
line(0, 0, 0, -h); // Draw the branch
translate(0, -h); // Move to the end of the branch
branch(h); // Ok, now call myself to draw two new branches!!
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
// Repeat the same thing, only branch off to the "left" this time!
pushMatrix();
rotate(-theta);
line(0, 0, 0, h);
translate(0, h);
branch(h);
popMatrix();
if (record) {
endRecord();
record = false;
}
// Use a keypress so thousands of files aren't created
void mousePressed() {
record = true;
}
}
1