Default text for new sketches? (like a template)

edited October 2015 in Using Processing

Hi all, I was wondering if there is any way one can set some default text for his new sketches. For example the setup() draw() functions so that it is not necessary to write them every time. I've looked at the preferences.txt and the different files in java mode etc but no luck...

Tagged:

Answers

  • https://GitHub.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L6099

    // forum.processing.org/two/discussion/13073/
    // default-text-for-new-sketches-like-a-template
    
    // GoToLoop (2015-Oct-17)
    
    //static final String MY_FONT = "Lucida Sans";
    static final String MY_FONT = "Trebuchet MS Italic";
    
    @ Override PFont createDefaultFont(float size) {
      return createFont(MY_FONT, size, true, null);
    }
    
    void setup() {
      size(800, 300);
      smooth(4);
      noLoop();
    
      fill(#0000FF);
      background(-1);
    
      textAlign(CENTER, BASELINE);
      textSize(050);
      text("Testing overridden default font...", width>>1, height>>1);
    
      println(PFont.list());
    }
    
  • edited October 2015

    Hi, I can't really understand your answer.

    I don't know if my question is clear enough, but I'm just trying to find a way to open new sketches that will always include the following code

    void setup(){
        size(700, 400);
    }
    
    void draw(){
    
    }
    
  • If you had opened the link I've posted, you'd realize "Lucida Sans" is hardcoded inside createDefaultFont(). [-(

  • :( Sorry but I don't understand how I can use the createDefaultFont() in order to achieve what I want... can you explain please?

  • Since it's hardcoded, you can't have what you want unless you recompile the whole PApplet library on your own!
    Most we can do is @Override the original createDefaultFont() like I did in my example. 3:-O

  • Or you can ask "them" to add in that option for ya: ~:>
    https://GitHub.com/processing/processing/issues

  • I'm afraid I might seem impolite.... but I believe there is a misunderstanding on the subject of my question. I'm just trying to make the IDE to open every new sketch with the setup and draw functions already included as code.

    Nothing to do with the fonts.

  • edited October 2015 Answer ✓
    • Oops! When I saw "default text" I've understood it as "default font". X_X
    • What you're looking for is a "default template".
    • Processing used to have these 2 "Tools": "Templater" & "Bootstrap" by Jonathan Acosta.
    • Dunno why but it seems they're not available anymore. Sorry... :(
  • edited October 2015

    Well i found this thread forum.processing.org/one/topic/initsketch-extension-tool.html but none of the links work, as far as I can tell the developer abandoned the tools. Sad. At least if anyone knows what has to be tweaked and where ... :\

    Anyway, thank's a lot for your help!

  • edited October 2015

    I've found their updated version to Processing 2.2.1 in his GitHub:
    https://GitHub.com/poifox/processing-tools/releases

    But it's in source code form and still needs to be manually built & compiled as a ".jar". 8-X

  • You could do something close enough with system wide text substitution tools like texter. These allow you to define shortcuts that are automatically expanded to any string. So for example you might just type }sketch to get the boiler plate...

  • I have a little post-it notes app an my laptop, useful for holding code snippets. Would be ideal for this. Easier than digging around in the filesystem for a file.

    (But yes, it's a pain. I understand immediate mode was more common in earlier versions so not everything had a setup and a draw but surely it's easier to delete something you don't want than add something you do)

    (Could easily also be a menu option)

Sign In or Register to comment.