Loading...
Logo
Processing Forum
epical's Profile
1 Posts
4 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hello,

    I'm using Wordookie with a lot of words, more than 20.000, my problem ist, that Processing stops rendering the snapshots/frames after various times. After 700 frames, after 1200 frames, after 900 frames. an so on.

    I dont why, and hope someone can help? And sorry for my bad english :-)

    1. import wordookie.*;
      import wordookie.util.ColorStuff;
      import wordookie.parsers.DumbParser;

      final String INPUT_FILE = "book.txt";
      final String FONT_NAME = "Times";
      final color BACKGROUND = color( 0 );
      final int MAX_FONTSIZE = 180;
      final int MIN_FONTSIZE = 30;
      final int FADE = 2;
      final boolean TAKE_SNAPSHOTS = true;

      java.util.List stringList;
      Iterator itr;
      Map wordMap;
      Layout layout;
      PFont font;
      boolean looping = false;

      void setup()
      {
        size( 1000, 500 );
        frameRate( 15 );

        DumbParser parser = new DumbParser();
        parser.load( createInput( INPUT_FILE ) );
        stringList = parser.getWords();
        itr = stringList.iterator();

        wordMap = new HashMap();

        font = createFont( FONT_NAME, 48 );
        layout = new Layout( this, BACKGROUND );
        //layout.setAngleType( Layout.ANYWAY );
        background( BACKGROUND );
      }

      void draw()
      {
        if ( itr.hasNext() )
        {
          String token = (String)itr.next();
          token.trim();
          token = token.toLowerCase();
          ColoredWord word = (ColoredWord)wordMap.get( token );

          // redraw the whole thing except for word
          background( BACKGROUND );
          for( Iterator witr = wordMap.values().iterator(); witr.hasNext(); )
          {
            ColoredWord w = (ColoredWord)witr.next();
            if ( w != word )
            {
              fill( w.col, w.life );
              layout.paintWord( w );
            }
          }

          if ( word == null )
          {
            word = new ColoredWord( token, 1f );
            word.font = font;
            word.col = ColorStuff.BlueIce[ (int)random(ColorStuff.BlueIce.length) ];
            wordMap.put( token, word );
            word.fontSize = (int)min( word.weight + MIN_FONTSIZE, MAX_FONTSIZE );
            layout.doLayout( word );
          }
          else
          {
            // fit word in
            word.weight += 1;
            word.fontSize = (int)min( word.weight + MIN_FONTSIZE, MAX_FONTSIZE );
            if ( layout.intersects( word ) )
              layout.doLayout( word );
          }
         
          word.life = 255;
          fill( word.col, word.life );
          layout.paintWord( word );

          // decrease life
          for( Iterator witr = wordMap.values().iterator(); witr.hasNext(); )
          {
            ColoredWord w = (ColoredWord)witr.next();
            w.life -= FADE;
            if ( w.life < 0 ) w.life = 0;
          }

          if ( TAKE_SNAPSHOTS )
            snap();
        }
        else
        {
          boolean anyleft = false;
          background( BACKGROUND );
          for( Iterator witr = wordMap.values().iterator(); witr.hasNext(); )
          {
            ColoredWord w = (ColoredWord)witr.next();
            if ( w.life > 0 )
            {
              anyleft = true;
              fill( w.col, w.life );
              layout.paintWord( w );
              w.life -= FADE;
              if ( w.life < 0 ) w.life = 0;
            }
          }
          if ( !anyleft )
          {
            println( "Done." );
            noLoop();
          }
        }
      }

      void snap()
      {
        saveFrame( "frames2/frame-######.png" );
      }

      void keyPressed()
      {
        switch( key )
        {
        case ' ':
          looping = !looping;
          break;
        }
      }