output stills using keyPress and saveFrame functions

edited October 2015 in Questions about Code

Hi all, I'm a complete beginner trying to get into it. This is my first little doodle. I'd like to be able to hit "enter" in order to export the current frame into a folder in the sketch folder (script folder) and I've hit my first brick wall. What have I done wrong here. Can anyone explain to me what I'm failing to grasp?

good old stupid circle

Tagged:

Answers

  • edited October 2015 Answer ✓

    the } of the function draw() must close after the ellipse() command

    void setup() { 
      size(600, 600); 
      background(160); 
      frameRate(24);
      smooth();
    }
    
    void draw() { 
      ellipse(mouseX, mouseY, 80, 20);
    }
    
    void keyPressed() { 
      if (keyCode==ENTER) { 
        saveFrame("screen-####.jpg");
      }
    }
    
  • edited October 2015

    thanks!

    but also, I thought the keypress function had to be coded into "draw"s function block?

  • edited October 2015 Answer ✓

    Java language doesn't allow functions inside another function. :-B
    Although it does allow classes & interfaces inside another class or function! ;)

  • edited October 2015

    Alright that clears things up for now. Rule-Keep my functions separate from each other. As for class/interfaces not sure what that means in this particular scenario, butthat's some higher level stuff I'll have to research, in the meantime thank you for your help!.

  • Answer ✓

    As for class/interfaces not sure what that means in this particular scenario, ...

    Just mentioned those for completeness' sake! L-)

Sign In or Register to comment.