How to make my radom text scroll

Hi ! I have an issue trying to make my text scroll. So I instead I have been trying to make the process reload when the text hit the bottom of the page. I tried to make my own setup fonction, to loop, to redraw, to insert the code inside another one it works but I don't know how to make the draw fonction resart from the top of the screen.

Could you help me for either the first or the second, or both options ?

Thanks a lot !

PFont typo;

String house = "A HOUSE OF"; 
String using = "USING"; 
String inhabited = "INHABITED";


String [] of = { 
  "SEAWEED AND HEMP BRICKS", "VEGETABLE FIBERS PANEL"
};

String [] where = {
  "IN A STANDARDIZED SUBDIVISION", "IN A OVERPOPULATED BUILDING",

};

String [] light = {
  "STREETLIGHTS NIGHT AND DAY ", "NO LIGHT",
};

String [] who = { 
  "BY PEOPLE ALWAYS HAVE THEIR EYES ON THEIR SCREEN", "BY IDLERS WHO DO NOTHING"
};

float y;


void setup() {


  size(793, 1122); 
   //fullScreen();
  smooth();
  frameRate(0.9);
  background(255);
  fill(50);
  // typo = loadFont("Dot Matrix.vlw");
  typo = createFont("Dot Matrix", 10);
  textFont(typo, 15);


}

void draw() {

  y = y + 110;

  translate(0, y);
  text(house, 60, -70);
  text(using, 120, -23); 
  text(inhabited, 150, 0);
  text( of[int(random(0, of.length))], 156, -70);
  text( where[int(random(0, where.length))], 90, -47);
  text( light[int(random(0, light.length))], 175, -23); 
  text(who[int(random(0, who.length))], 236, 0);


}



  void keyPressed() {
  saveFrame("HouseofDust-##.jpg");

    }
Tagged:

Answers

  • Answer ✓

    I'm not sure if this is exactly what you wanted, but this is a sketch that scrolls automatically when the text reaches the line. It's also possible to scroll maually with the mouseWheel.

    If this isn't exactly what you were looking for, then hopefully it gives you an idea of what you can do and what the mouseWheel function does and also other functions that exists that relates to text and displaying text.

    String scrollableText = "Hi there! Press the mouse button to add another line of text!\n";
    int lineNumber = 0;
    int limit = 15, lineHeight = 15, push = 0;
    
    void setup () {
      size(400, 500);
    }
    
    void draw() {
      background(100, 50, 50);
      fill(230);
      line(0, 255, width, 255);
      pushMatrix();
      translate(10, push*lineHeight);
      textSize(12);
      textLeading(lineHeight);
      text (scrollableText, 0, 12);
      popMatrix();
    }
    
    void mouseClicked() {
      if (mouseButton == LEFT) addline("Woohoo!");
      if (mouseButton == RIGHT) addline("Wiihii!");
    }
    
    void addline(String l) {
      scrollableText += l + "\n";
      if (lineNumber>limit) push = (lineNumber-limit)*-1; 
      else push = 0;
      lineNumber += 1;
    }
    
    void mouseWheel(MouseEvent event) {
      float e = event.getCount();
      push += e;
    }
    
  • Answer ✓

    Notice that when you add another line, the text jumps into position so the bottom (most recent) line of text is visible at the black line across the screen. I find that this is quite useful because then the new text is right there in front of you. Besides, as it is now, the text might be lost outside the screen because there is no limit to how far you can spin the wheel.

    You could also limit the push variable so that you can't scroll more than 20 lines away from the text, but I'm a little unsure of how you could do that. You can probably figure it out if you really want to :)

  • hi ! Thank you so much for answering me and sorry for the late reply, so this is not exactly what I wanted because I need to respect a really strict page setting as for example to have a space each for lines and some other stuff that I am not sure to be able to setup with this code. Anyway I figured out another way that suits me but I have an another project with electronic pad and random words and I thinks this is going to be perfect for what I want to do :) ! thanks !

Sign In or Register to comment.