How to make text be interpreted by Processing as *random* 3D values

edited May 2016 in How To...

Hi everyone,

I'm a code-illiterate graphic designer working on a project. The idea is to use text (made in worpad) as values to create random 3D volumes (or, if it not possible a 2D interpretation of such text - kind of the reverse effect of the JPEG-to-ASCII post) I want to thank you beforehand for your all help and patience!

Answers

  • Each character of a text is just a number: the Ascii code or Unicode code point value. How you exploit this number is another matter...
    You can also exploit other numbers, like the length of the word the char is in, the length of the paragraph, etc.

  • Hi PhiLho,

    Sorry for the incredibly late response. I was very intrigued by how deceptively easy the whole idea was, so I've been working with my teacher to improve upon the basis of the project. I told him about your toughts and he concurred. Every character is just a set of 1s and 0s. So now we're working on making those numbers transform into random 3d shapes (e.j Build would somehow be interpreted as a random shape, while Tear would constitute an entire different shape)

    I'm still learning the very basics, so I'm not sure if using something like the beginShape() endShape(); would be an appropiate workflow. Do you have any suggestions as to how exploit those numbers?

  • edited October 2014 Answer ✓

    you wrote

    (e.j Build would somehow be interpreted as a random shape, while Tear would constitute an entire different shape

    thus you would parse word by word, right?

    you could also parse letter by letter...

    so e would mean something, T would mean something else

    here... you need your file in the sketch folder named input.txt

    // 
    String lines[] ;
    
    void setup() {
      size(500, 500, P3D);
      //size(700, 700);
      lines = loadStrings("input.txt");
      println("there are " + lines.length 
        + " lines");
    }
    
    void draw() {
    
      for (int i = 0 ; i < lines.length; i++) {
    
        println(lines[i]);
    
        for (int i2 = 0 ; i2 < lines[i].length(); i2++) {
          println(lines[i].charAt(i2));
          eval(lines[i].charAt(i2));
        }
      }
    } // func 
    //
    void eval (char letter) {
      switch (letter) {
      case 'e':
        shapeE();
        break; 
      case ' ':
        // space
        shapeSpace();
        break; 
      case '.':
      case '-':
      case '!':
      case '?':
        // couple of others
        shapeE();
        break; 
      default:
        // all other
        break;
      } // switch
    }///func 
    //
    void shapeE() {
      // beginShape...................
    }
    //
    void shapeSpace() {
      // beginShape...................
    }
    //
    

    Best, Chrisir ;-)

  • edited October 2014

    also, you can work with the position, say you only draw spheres. Each sphere represents one character:

    • A sphere for a capital letter (E) is at y = 50, for a small letter (e) at 110

    • the chars ascii value gives the z value: z = int (lines[i].charAt(i2))

    • the x is how far you are in the text: x = i + i2;

      // 
      String lines[] ;
      
      void setup() {
        size(500, 500, P3D);
        lines = loadStrings("input.txt");
        println("there are " + lines.length 
          + " lines");
        background(0);
      }
      
      void draw() {
        background(0);
        lights();
        int x, y;
        float z; 
        noStroke();
        for (int i = 0 ; i < lines.length; i++) {
      
          println(lines[i]);
      
          for (int i2 = 0 ; i2 < lines[i].length(); i2++) {
            println(lines[i].charAt(i2)+
              "  " +  
              int (lines[i].charAt(i2)));
            int asciiValue = int (lines[i].charAt(i2)) ;
      
            // capital letter (E) is at y = ..., for a small letter (e) at y = ....
            if ( asciiValue > 90) {  
              y = 250;
            } 
            else 
            {
              y=510;
            }
      
            //the chars ascii value gives the z value: 
            z  = map (asciiValue, 17, 255, 0, -1900) ;
      
            //  the x is how far you are in the text:    
            x = i + i2 * 29 + 33;
      
            // draw sphere
            pushMatrix();
            fill(map(z, -1900, 0, 0, 255), 22, 22);
            fill(asciiValue*2, 22, 22);
            translate(x, y, z);
            sphere(22); 
            popMatrix();
          } // inner for
        }
      } // func 
      

    ;-)

  • you could write the letters at the bottom and connect the spheres with lines

  • Chrisir, you're a genious! with a little exploration and tweaking, I bet that little bit of code can do wonders. Thank you very much for taking the time and writing it. I was wondering, may I have your permission to post it on the class blog? (all credits due of course)

  • Sure, permission granted.

Sign In or Register to comment.