expecting EOF, found 'it' error - can someone help?

Hi,

I'm trying to add a 'save as PDF' feature to my script, but I keep getting this "expecting EOF, found 'it' error". I read somewhere that the if should be within the draw, but I tried that.

Can someone help me with this error? Where should I place the if then? Or do I have too many }?

Thanks in advance!

Cheers, Sander

/*
 * Simply a visual variant of the main FlowField example! :-)
 * See the main example for more information on the used techniques.
 * 
 * USAGE:
 * - click the mouse to restart the sketch  
 */

import processing.pdf.*;

int maxParticles = 1000; // the maximum number of active particles
ArrayList <Particle> particles = new ArrayList <Particle> (); // the list of particles
color BACKGROUND_COLOR = color(0);
color PGRAPHICS_COLOR = color(0);
float globalRotation;
PGraphics pg;

boolean saveOneFrame = false;          // variable used to save a single frame as a PDF page

void setup() {
  size(2560, 1380, P2D);
  smooth(10000); // higher smooth setting = higher quality rendering
  // create the offscreen PGraphics with the text 
  pg = createGraphics(width, height, JAVA2D);
  pg.beginDraw();
  pg.textSize(700);
  pg.textAlign(CENTER, CENTER);
  pg.fill(PGRAPHICS_COLOR);
  pg.text("L&M", pg.width/2, pg.height/2); 
  pg.endDraw();
  background(BACKGROUND_COLOR);
}

void draw() {
  // begin recording to PDF
  if (saveOneFrame == true) {
    beginRecord(PDF, "Waves-" + timestamp() + ".pdf");
  }

  // set colorMode for the sketch to Hue-Saturation-Brightness (HSB)
  // must be called after beginRecord to work for the exported PDF!
  colorMode(HSB, 360, 100, 100);


  addRemoveParticles();
  // update and display each particle in the list
  for (Particle p : particles) {
    p.update();
    p.display();
  }
}

void mousePressed() {
  background(BACKGROUND_COLOR); // clear the screen
  particles.clear(); // remove all particles
  globalRotation = random(TWO_PI); // randomly set the global rotation/direction of the Particles
}

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());
  }
}


// end recording to PDF
if (saveOneFrame) {
  endRecord();
  saveOneFrame = false;
  }
}


void keyPressed() {
  if (key == 'P') {
    saveOneFrame = true; // set the variable to true to save a single frame as a PDF file / page
  }
}

String timestamp() {
  return year() + nf(month(), 2) + nf(day(), 2) + "-"  + nf(hour(), 2) + nf(minute(), 2) + nf(second(), 2);
}

Answers

  • EOF means End Of File

    It probably means that it has found { without a matching }

    Since your code is not all here it is difficult to be more precise.

  • edited September 2015

    Thanks for the fast reaction. You're right, here is the complete code.

    [mod edit: duplicate code posting deleted]

  • Since your code is not all here it is difficult to be more precise.

    the pre markup that some people use when quoting code seems to break on lessthan and greater than signs. which is odd.

    this forum's various quirks are many and confusing.

  • edited September 2015

    the 'if' (not 'it') on line 75 is outside of a method.

    deleting line 71 should fix this.

  • // end recording to PDF
    if (saveOneFrame) {
      endRecord();
      saveOneFrame = false;
    }
    }
    

    The problem is the extra }

  • edited September 2015

    You mean the second } in line 71? If I delete the } the whole animation (draw) doesn't work anymore...

  • edited September 2015

    @quark You mean in line 78 or 79 (after 'saveOneFrame')? If I delete one of them I still have the same error...

  • this is a mess. i've been fixing up the formatting and people have been referring to and reposting unfixed code. i'm trying to tidy it up. sorry for any confusion.

    ctrl-t in the processing editor will indent the code properly and make it easier to see broken brackets.

    the problem here is as i posted, that if block is outside of a method. but the fix i mentioned is no good. that code needs to be inside draw(). plus there's an extra bracket.

  • Yes! It works now.

    However, when I make a PDF export, it only shows dots instead of the longer 'hairs' you'll get when you start it.

    Do you have any clue why it only saves dots and not the visual exactly on the moment you press to export (in this case shift+P)

  • Move this code from its current position

    // end recording to PDF
    if (saveOneFrame) {
      endRecord();
      saveOneFrame = false;
    }
    

    to the end of the draw method. At the moment it is executed BEFORE the particles are updated and displayed

  • edited September 2015

    But I have it after the 'particle updating'... And it still only saves dots.

    See my current code:

    /**
     * Simply a visual variant of the main FlowField example!
     * See the main example for more information on the used techniques.
     * 
     * USAGE:
     * - click the mouse to restart the sketch  
     */
    
    import processing.pdf.*;
    
    int maxParticles = 1000; // the maximum number of active particles
    ArrayList <Particle> particles = new ArrayList <Particle> (); // the list of particles
    color BACKGROUND_COLOR = color(000);
    color PGRAPHICS_COLOR = color(0);
    float globalRotation;
    PGraphics pg;
    
    boolean saveOneFrame = false;          // variable used to save a single frame as a PDF page
    
    void setup() {
      size(1280, 750, P2D);
      smooth(10); // higher smooth setting = higher quality rendering
      // create the offscreen PGraphics with the text 
      pg = createGraphics(width, height, JAVA2D);
      pg.beginDraw();
      pg.textSize(550);
      pg.textAlign(CENTER, CENTER);
      pg.fill(PGRAPHICS_COLOR);
      pg.text("L&M", pg.width/2, pg.height/2); 
      pg.endDraw();
      background(BACKGROUND_COLOR);
    }
    
    void draw() {
      // begin recording to PDF
      if (saveOneFrame == true) {
        beginRecord(PDF, "lucas-" + timestamp() + ".pdf");
      }
    
      // set colorMode for the sketch to Hue-Saturation-Brightness (HSB)
      // must be called after beginRecord to work for the exported PDF!
      colorMode(HSB, 338, 0, 100);
    
      addRemoveParticles();
      // update and display each particle in the list
      for (Particle p : particles) {
        p.update();
        p.display();
      }
    
    // end recording to PDF
    if (saveOneFrame) {
      endRecord();
      saveOneFrame = false;
      }
    }
    
    void mousePressed() {
      background(BACKGROUND_COLOR); // clear the screen
      particles.clear(); // remove all particles
      globalRotation = random(TWO_PI); // randomly set the global rotation/direction of the Particles
    }
    
    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());
      }
    }
    
    void keyPressed() {
      if (key == 'P') {
        saveOneFrame = true; // set the variable to true to save a single frame as a PDF file / page
      }
    }
    
    String timestamp() {
      return year() + nf(month(), 2) + nf(day(), 2) + "-"  + nf(hour(), 2) + nf(minute(), 2) + nf(second(), 2);
    }
    
  • edited September 2015

    please don't use PRE to format code.

    highlight it and press ctrl-o.

    (i have fixed it.)

  • yes, you will only get one lot of dots. this is because you only draw one lot of dots between starting and ending your pdf. the rest are visible on screen but were there before you started.

  • I can see your code but I can't test it because I don't have the Particle class

  • With this script I can make letters which consists of growing particle which look like hairs when growing. And I would love it if I could save it as a pdf with the hair and all, not just the dots... But if it's not possible, then that's really a shame.

    Thanks you guys for reacting on such a short notice! Really appreciate it!

  • have two flags, one for starting, one for ending, both set using a different key.

    that way you'll get multiple frames in your pdf rather than just one.

  • Tnx. I really would want to be able to do this, but I'm afraid I'm not Processing pro enough (yet) to rewrite this by myself unfortunately... If you could help with rewriting it I would be very thankful!

  • Answer ✓

    ok, the flag is now two flags, startSave and endSave, one to start recording, one to end it, keys S and E respectively.

    (i can't test this due to lack of Particle class but...)

    /**
     * Simply a visual variant of the main FlowField example!
     * See the main example for more information on the used techniques.
     * 
     * USAGE:
     * - click the mouse to restart the sketch  
     */
    
    import processing.pdf.*;
    
    int maxParticles = 1000; // the maximum number of active particles
    ArrayList <Particle> particles = new ArrayList <Particle> (); // the list of particles
    color BACKGROUND_COLOR = color(000);
    color PGRAPHICS_COLOR = color(0);
    float globalRotation;
    PGraphics pg;
    
    boolean startSave = false;
    boolean endSave = false;
    
    void setup() {
      size(1280, 750, P2D);
      smooth(10); // higher smooth setting = higher quality rendering
      // create the offscreen PGraphics with the text 
      pg = createGraphics(width, height, JAVA2D);
      pg.beginDraw();
      pg.textSize(550);
      pg.textAlign(CENTER, CENTER);
      pg.fill(PGRAPHICS_COLOR);
      pg.text("L&M", pg.width/2, pg.height/2); 
      pg.endDraw();
      background(BACKGROUND_COLOR);
    }
    
    void draw() {
      // begin recording to PDF
      if (startSave) {
        beginRecord(PDF, "lucas-" + timestamp() + ".pdf");
        startSave = false;
      }
    
      // set colorMode for the sketch to Hue-Saturation-Brightness (HSB)
      // must be called after beginRecord to work for the exported PDF!
      colorMode(HSB, 338, 0, 100);
    
      addRemoveParticles();
      // update and display each particle in the list
      for (Particle p : particles) {
        p.update();
        p.display();
      }
    
      // end recording to PDF
      if (endSave) {
        endRecord();
        endSave = false;
      }
    }
    
    void mousePressed() {
      background(BACKGROUND_COLOR); // clear the screen
      particles.clear(); // remove all particles
      globalRotation = random(TWO_PI); // randomly set the global rotation/direction of the Particles
    }
    
    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());
      }
    }
    
    void keyPressed() {
      if (key == 'S') {
        startSave = true; // start saving
      }
      if (key == 'E') {
        endSave = true; // end saving
      }
    }
    
    String timestamp() {
      return year() + nf(month(), 2) + nf(day(), 2) + "-"  + nf(hour(), 2) + nf(minute(), 2) + nf(second(), 2);
    }
    
  • You, my friend, are a true hero!!! It works! They should make a statue for you :). Thanks a million. Now I can save them in vector. Whoehoew!

Sign In or Register to comment.