Star Wars Text

edited July 2017 in How To...

Im going to apologize right off the start I'm very new to this and sorry about my code below, this is my first time posting in here and and i couldn't figure out how to copy my code and paste it in here with out looking like a mess and all in one paragraph so i typed it out with all the extra spacing. (If someone can tell how to do that on how to copy my code and paste it in the form that would be nice and helpful, save me some time instead of tying it out). Im trying to do the star wars text how in the opening credits of the movies it scrolls from the bottom to the top was wondering if anyone could help me, this is the code i have to start and can't figure out the next steps. Thanks in advance :)

// basic setup
final int COLOR_MAX = 255;
final char DELIMITER = ' '; // delimiter for words

// text setup
final int WORDS_PER_LINE = 5;
final int MAX_TEXT_SIZE = 40;
final int MIN_TEXT_SIZE = 0;

// where to draw the top of the text block
float textYOffset = 500+MAX_TEXT_SIZE; // 500 must match setup canvas size
 // start PAST the bottom of the screen so that the
// text comes in instead of just appearing

final float TEXT_SPEED = 0.9994; // try changing this to experiment

// story to tell!
final String STORY_TEXT = "A long time ago, in a galaxy far, far "+
  "away.... It is a period of civil war. Rebel spaceships, "+
  "striking from a hidden base, have won their first victory "+
  "against the evil Galactic Empire. During the battle, rebel "+
  "spies managed to steal secret plans to the Empire\'s " +
  "ultimate weapon, the DEATH STAR, an armored space station " +
  "with enough power to destroy an entire planet. Pursued by " +
  "the Empire\'s sinister agents, Princess Leia races home " +
  "aboard her starship, custodian of the stolen plans that " +
  "can save her people and restore freedom to the galaxy....";

String[] storyLines;

void setup()
 {
size(500, 500);
storyLines = splitToLines(STORY_TEXT, WORDS_PER_LINE, DELIMITER);
}

void draw()
{
  background(0);

  drawTextBlock(storyLines, textYOffset, MIN_TEXT_SIZE, MAX_TEXT_SIZE);
  // make the text slowly crawl up the screen
  // it has to slow down as it goes so that the big text looks
 // relatively to be the same speed
  textYOffset *= TEXT_SPEED;

}
Tagged:

Answers

  • Answer ✓

    Formatting code: Edit post (gear in upper right hand corner), mark the code you want to format, hit ctrl + o. Make sure there is a gap above and below the code.

  • Answer ✓

    @44Blue To format your code, follow these steps: Edit your post (gear icon in the top right corner of your post), select your code and hit ctrl+o. Make sure there is an empty line above and below your code.

    Check the code below.

    Kf

    final String delim = "\n"; // delimiter for words
    final int TEXT_SIZE = 20;
    
    
    // start PAST the bottom of the screen so that the
    // text comes in instead of just appearing
    
    final float TEXT_SPEED = 1;
    final String STORY_TEXT = "A long time ago, in a galaxy far, far"+delim+ "away.... It is a period of civil war. Rebel spaceships, "+delim+ "striking from a hidden base, have won their first victory "+delim+ "against the evil Galactic Empire. During the battle, rebel "+delim+ "spies managed to steal secret plans to the Empire\'s "+delim + "ultimate weapon, the DEATH STAR, an armored space station "+delim + "with enough power to destroy an entire planet. Pursued by "+delim + "the Empire\'s sinister agents, Princess Leia races home "+delim + "aboard her starship, custodian of the stolen plans that "+delim + "can save her people and restore freedom to the galaxy....";
    
    
    // where to draw the top of the text block
    float textYOffset;// 500 must match setup canvas size
    
    void setup() {
      size(500, 500, P3D);                           //3D is required to get the effect
      textYOffset = height; 
      //storyLines = splitTokens(STORY_TEXT, delim);
      fill(250, 250, 0);
      textAlign(CENTER, CENTER);
      textSize(TEXT_SIZE);
    }
    
    void draw() { 
      background(0);
      translate(width/2, height/2);
      //translate(width/2, height/2,-450);   //Playing with the depth aka. along the Z dimension
      rotateX(PI/3);
      text(STORY_TEXT, 0, textYOffset);
      textYOffset -= TEXT_SPEED;
    }
    
  • Awesome thanks so much guys! Appreciate it, i figured it out how to copy and paste the code @Eeyorelife, and thanks @kfrajer.

  • edited July 2017

    Another quick question @kfrajer I'm trying to get the text so that only 5 words only show up per line how would i go about to do that? Cant figure it out. Think i got something in the wrong spot.

        // basic setup
        final int COLOR_MAX = 255;
        final char DELIMITER = '\n'; // delimiter for words
    
        // text setup
        final int WORDS_PER_LINE = 5;
        final int MAX_TEXT_SIZE = 40;
        final int MIN_TEXT_SIZE = 0;
    
        // where to draw the top of the text block
        float textYOffset = 500+MAX_TEXT_SIZE; // 500 must match setup canvas size 
        // start PAST the bottom of the screen so that the
        // text comes in instead of just appearing
    
        final float TEXT_SPEED = 0.5; // try changing this to experiment
    
        // story to tell!
        final String STORY_TEXT = "A long time ago, in a galaxy far, far "+DELIMITER+
        "away.... It is a period of civil war. Rebel spaceships, "+DELIMITER+
        "striking from a hidden base, have won their first victory "+DELIMITER+
        "against the evil Galactic Empire. During the battle, rebel "+DELIMITER+
        "spies managed to steal secret plans to the Empire\'s " +DELIMITER+
        "ultimate weapon, the DEATH STAR, an armored space station " +DELIMITER+
        "with enough power to destroy an entire planet. Pursued by " +DELIMITER+
        "the Empire\'s sinister agents, Princess Leia races home " +DELIMITER+
        "aboard her starship, custodian of the stolen plans that " +DELIMITER+
        "can save her people and restore freedom to the galaxy....";
    
        String[] storyLines;
    
        void setup()
        {
          size(500, 500, P3D);
          textYOffset = height;
          //storyLines = splitToLines(STORY_TEXT, WORDS_PER_LINE, DELIMITER);
          fill(250,250,0);
          textAlign(CENTER,CENTER);
          textSize(MAX_TEXT_SIZE+MIN_TEXT_SIZE);
        }
    
        void draw()
        {
          background(0);
          translate(width/2,height/2);
          rotateX(PI/3);
          text(STORY_TEXT,0,textYOffset);
          //drawTextBlock(storyLines, textYOffset, MIN_TEXT_SIZE, MAX_TEXT_SIZE);
          // make the text slowly crawl up the screen
          // it has to slow down as it goes so that the big text looks
          // relatively to be the same speed
          textYOffset -= TEXT_SPEED;
        }
    
  • Answer ✓

    Check this sample code.

    Kf

    final char DELIMITER = ' ';
    final int WPL=5+1;  //Words per line plus 1 
    
    final String STORY_TEXT = "A long time ago, in a galaxy far, far "+DELIMITER+
    "away.... It is a period of civil war. Rebel spaceships, "+DELIMITER+
    "striking from a hidden base, have won their first victory "+DELIMITER+
    "against the evil Galactic Empire. During the battle, rebel "+DELIMITER+
    "spies managed to steal secret plans to the Empire\'s " +DELIMITER+
    "ultimate weapon, the DEATH STAR, an armored space station " +DELIMITER+
    "with enough power to destroy an entire planet. Pursued by " +DELIMITER+
    "the Empire\'s sinister agents, Princess Leia races home " +DELIMITER+
    "aboard her starship, custodian of the stolen plans that " +DELIMITER+
    "can save her people and restore freedom to the galaxy....";
    
    String[] lines = split(STORY_TEXT,' ');
    
    
    
    String msg ="";
    
    for(int i=0;i<lines.length;i++){
      if(i!=0 && i%WPL==0)
      msg+="\n";
    
      msg+=lines[i] + " ";
    }
    
    println(msg);
    
  • Works, thanks again!! @kfrajer

  • One way to create the Star Wars 3d text scroll effect:

    1. Create a P3D sketch
    2. ** Rotate the the 2D plane that you will be drawing on so that it is angled away from the camera.
    3. Draw that text on the plane.
    4. Change the y offset by a tiny amount each frame.

    That turns a normal vertical text crawl into a Star Wars text crawl.

Sign In or Register to comment.