How to manipulate the string

edited December 2017 in Questions about Code

Hi guys I`m new here. I have a problem when trying to display a text file. How do I manipulate the string into the rectangle box as I want to display some information from a text file. Any help will be very appreciated. Thanks in advance!!!

` PFont f; PImage img, img1, img2, img3, img4, img5; PImage left, right;

String my_text = "CYRBORG"; String[] words; String entireplay;

float x = width/2; float y = 100; int index = 0;

void setup() { size(1200, 800, P3D); background(11, 39, 13); f = createFont("Arial", 32, true); img = loadImage("cyborg.png"); left = loadImage("arrow-left.png"); right = loadImage("arrow-right.png"); String[] lines = loadStrings("cyrborg.txt"); entireplay = join(lines, " "); println(entireplay); words = split(entireplay, " ");

}

void draw() {

fill(93, 142, 97);
stroke(10, 18, 11);
rect(50, 50, 500, 700);

//translate and rotate the image around its cyrcle
//pushMatrix();
  //translate(300, 200, 0);
  //rotateY(radians(r));
  img.resize(280,650);
  image(img,160,100);
  //r += 1;
//popMatrix();

image(left, 75, height/2 - 50 );
image(right, 480, height/2 - 50 );


line(width/2, 50, width/2, height-50);


line(width/2 + 50, 100, width- 50, 100);
fill(0);
noStroke();

textFont(f);
fill(255);
noStroke();
text(my_text,650,90);

fill(93, 142, 97);
stroke(10, 18, 11);
rect(width/2 + 50, 150, 500, 600);
for(int i = 0; i < words.length; i++)
{
  fill(255,127);
  textSize(28);
  text(words[i], 700+i, 200, 400, 400);
} // end form loop

}// end draw `

Answers

  • How to manipulate the string

    Manipulate in what way? Change its color? Combined fields under the same text element? Something similar to: https://processing.org/reference/concat_.html

    although there are other options:

    int ctr=100; 
    float number=100.0;
    String msg="A message from other planet";
    
    textAlign(CENTER,CENTER);
    text("This is my text ctr: " + ctr+
          "\n Here is my number: "+number+
          "\n Here is  my msg: "+msg,0,0,width,height);
    

    Kf

  • edited December 2017

    you don't need a for loop

    This

       text(entireplay , 700, 200, 400, 400);
    

    should do the job.

    Alternatively

    Alternatively with a for loop say

         text(lines[i], 700, 200+(i*24), 400, 400);
    

    before setup say

    String[] lines;
    

    in setup() change this

     String[] lines = loadStrings("cyrborg.txt");
    

    to

       lines = loadStrings("cyrborg.txt");
    

    Remark

    it's cyborg without the first "r"

  • edited December 2017

    How to post in the processing forum.

    Best is to hit ctrl-t in processing first before copy paste into the forum

    You can edit your post (click the small gear and the 'Edit').

    How to format Code:

    empty line before and after the code section
    
    select (highlight) entire code with the mouse
    
    hit ctrl-o OR click the small C in the command bar
    
  • thanks a million!!!

  • thanks kfrajer for the help. Chrisir solve the problem for me. Just wanted to text file and display it inside a box

  • Answer ✓

    Great!

Sign In or Register to comment.