We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › BABEL FISH TOWER 2
Page Index Toggle Pages: 1
BABEL FISH TOWER 2 (Read 631 times)
BABEL FISH TOWER 2
May 23rd, 2007, 4:06am
 
dear people/

trying to get babel fish tower 2 code running on processing beta 0124, but it just wouldn't work... I adapted a few things (font) and with that maybe screwed up the whole thing? for any hints very grateful! thanks in advance--- harald

http://chronotext.org/bits/018/index.htm

code:

// BABEL FISH TOWER 2
// by arielm, May 2003
// http://www.chronotext.org

float fovy, aspect;
float elevation, azimuth, distance;

Tower tower;

BFont f;

void setup()
{
 size(300, 300);
 background(255);
 framerate(20);
 //hint(SMOOTH_IMAGES);

 fovy = 60.0f;
 aspect = (float)width / (float)height;

 distance = 160.0f;
 elevation = radians(15.0f);
 azimuth = radians(-45.0f);

 String[] lines =
 {
   "long text string"
 };

 color[] colors =
 {
   color(204, 0, 0),
   color(204, 204, 0),
   color(0, 204, 0),
   color(127, 0, 0),
   color(127, 127, 0),
   color(0, 127, 0)
 };

 f = loadFont("dialog48.vlw");  // I created that font and then put the file in "data" folder...

 tower = new Tower(0.0f, 30.0f, 0.0f, 3.0f, 75.0f, 25.0f, 100.0f, lines, colors, f, 10.0f, 2.0f);
}

void loop()
{
 beginCamera();
 perspective(fovy, aspect, 1.0f, 1000.0f);
 translate(0.0f, 0.0f, -distance);
 rotateX(-elevation);
 rotateY(-azimuth);
 endCamera();

 tower.run();
}

class Helix
{
 float x, y, z, turns, r1, r2, h;

 Text txt;
 float offset, speed;
 boolean sliding;

 float d, D, r, l, L, dy, dr;
 boolean conical;
 int index;
 char ch;
 float w;
 float rouge, vert, bleu;

 Helix(float x, float y, float z, float turns, float r1, float r2, float h, Text txt, float speed)
 {
   this.x = x;
   this.y = y;
   this.z = z;
   this.turns = turns;
   this.r1 = r1;
   this.r2 = r2;
   this.h = h;

   this.txt = txt;
   this.speed = speed;
 }

 boolean run()
 {
   if (sliding)
   {
     draw();

     if (offset >= L)
     {
       stop();
     }
     else
     {
       offset += speed;
       return true;
     }
   }

   return false;
 }

 void draw()
 {
   D = offset;

   l = TWO_PI * turns;
   L = PI * turns * (r1 + r2);
   dy = -h / l;

   conical = (abs(r1 - r2) > 0.5);  // avoids infinity and divisions by zero with cylindrical helices (r1 = r2)
   if (conical)
   {
     dr = (r2 - r1) / l;
   }
   else
   {
     r = r1;
   }

   index = txt.line.length();
   char ch;

   txt.font.setSize(txt.sz);

   colorMode(RGB, 255, 255, 255, 1);
   rouge = red(txt.col);
   vert = green(txt.col);
   bleu = blue(txt.col);

   while(index > 0)
   {
     ch = txt.line.charAt(--index);
     w = txt.font.charWidth(ch);
     D += w;

     if (D + w > L)
     {
       break;
     }

     if (D >= w)
     {
       if (conical)
       {
         r = sqrt(r1 * r1 + 2.0 * dr * D);
         d = (r - r1) / dr;
       }
       else
       {
         d = D / r;
       }

       fill(rouge, vert, bleu, 0.6 + 0.4 * cos(azimuth + d));  // simple depth effect...

       push();
       translate(x - sin(d) * r, y + d * dy, z + cos(d) * r);
       rotateY(-d);
       rotateZ(atan2(h , l * r));  // banking...
       txt.font.drawChar(ch, 0.0f, 0.0f);
       pop();
     }
   }
 }

 void rewind(boolean invisible, float indent)
 {
   offset = indent;

   if (invisible)
   {
     offset -= txt.getWidth();
   }
 }

 void start()
 {
   sliding = true;
 }

 void stop()
 {
   sliding = false;
 }
}

class Text
{
 String line;
 BFont font;
 color col;
 float sz;

 Text(String line, BFont font, color col, float sz)
 {
   this.line = line;
   this.font = font;
   this.col = col;
   this.sz = sz;
 }

 float getWidth()
 {
   font.setSize(sz);
   return font.stringWidth(line);  // once kerning is implemented in P5, this one won't be accurate!
 }
}

class Tower
{
 float x, y, z, turns, r1, r2, h;

 String[] lines;
 color[] colors;
 BFont font;
 float sz;

 float speed;

 Helix[] helices;

 Tower(float x, float y, float z, float turns, float r1, float r2, float h, String[] lines, color[] colors, BFont font, float sz, float speed)
 {
   this.x = x;
   this.y = y;
   this.z = z;
   this.turns = turns;
   this.r1 = r1;
   this.r2 = r2;
   this.h = h;

   this.lines = lines;
   this.colors = colors;
   this.font = font;
   this.sz = sz;

   this.speed = speed;

   build();
   rewind();
 }

 void run()
 {
   boolean sliding = false;
   for (int i = 0; i < lines.length; i++)
   {
     sliding |= helices[i].run();
   }
   if (!sliding)
   {
     rewind();
   }
 }

 void build()
 {
   helices = new Helix[lines.length];
   for (int i = 0; i < lines.length; i++)
   {
     helices[i] = new Helix(x, y, z, turns, r1, r2, h, new Text(lines[i], font, colors[i], sz), speed);
   }
 }

 void rewind()
 {
   float l = 0.0f;
   for (int i = 0; i < lines.length; i++)
   {
     helices[i].rewind(true, l);
     helices[i].start();

     l -= helices[i].txt.getWidth() + sz;  // the queued lines are separated by a gap equals to the font size...
   }
 }
}


Re: BABEL FISH TOWER 2
Reply #1 - Jun 1st, 2007, 4:56am
 
I've found (quick view) these "old keywords":

BFont < PFont
framerate < frameRate
push() < pushMatrix()
...

I think you'd have to actualize it using the new language reference.
Re: BABEL FISH TOWER 2
Reply #2 - Jun 1st, 2007, 3:30pm
 
You were using an old processing syntax scheme which is not working with 124.

I've have managed to modify it and make it start but it is still a little buggy.

hope this will help. ;)


Quote:
// BABEL FISH TOWER 2
// by arielm, May 2003
// http://www.chronotext.org

float fovy, aspect;
float elevation, azimuth, distance;

Tower tower;

PFont f;

void setup()
{
 size(640, 480,P3D);
 background(0);
 frameRate(30);
 //hint(SMOOTH_IMAGES);

 fovy = 60.0f;
 aspect = (float)width / (float)height;

 distance = 160.0f;
 elevation = radians(15.0f);
 azimuth = radians(-45.0f);

 String[] lines =
 {
   "long text string"
 };

 color[] colors =
 {
   color(204, 0, 0),
   color(204, 204, 0),
   color(0, 204, 0),
   color(127, 0, 0),
   color(127, 127, 0),
   color(0, 127, 0)
 };

 f = loadFont("Arial-Black-48.vlw");  // I created that font and then put the file in "data" folder...

 tower = new Tower(0.0f, 30.0f, 0.0f, 3.0f, 75.0f, 25.0f, 100.0f, lines, colors, f, 10.0f, 2.0f);
}

void draw()
{
 beginCamera();
 perspective(fovy, aspect, 1.0f, 1000.0f);
 translate(0.0f, 0.0f, -distance);
 rotateX(-elevation);
 rotateY(-azimuth);
 endCamera();

 tower.run();
}

class Helix
{
 float x, y, z, turns, r1, r2, h;

 Text txt;
 float offset, speed;
 boolean sliding;

 float d, D, r, l, L, dy, dr;
 boolean conical;
 int index;
 char ch;
 float w;
 float rouge, vert, bleu;

 Helix(float x, float y, float z, float turns, float r1, float r2, float h, Text txt, float speed)
 {
   this.x = x;
   this.y = y;
   this.z = z;
   this.turns = turns;
   this.r1 = r1;
   this.r2 = r2;
   this.h = h;

   this.txt = txt;
   this.speed = speed;
 }

 boolean run()
 {
   if (sliding)
   {
draw();

if (offset >= L)
{
  stop();
}
else
{
  offset += speed;
  return true;
}
   }

   return false;
 }

 void draw()
 {
   D = offset;

   l = TWO_PI * turns;
   L = PI * turns * (r1 + r2);
   dy = -h / l;

   conical = (abs(r1 - r2) > 0.5);  // avoids infinity and divisions by zero with cylindrical helices (r1 = r2)
   if (conical)
   {
dr = (r2 - r1) / l;
   }
   else
   {
r = r1;
   }

   index = txt.line.length();
   char ch;

   textSize(32);

   colorMode(RGB, 255, 255, 255, 1);
   rouge = red(txt.col);
   vert = green(txt.col);
   bleu = blue(txt.col);

   while(index > 0)
   {
ch = txt.line.charAt(--index);
w = textWidth(ch);
D += w;

if (D + w > L)
{
  break;
}

if (D >= w)
{
  if (conical)
  {
    r = sqrt(r1 * r1 + 2.0 * dr * D);
    d = (r - r1) / dr;
  }
  else
  {
    d = D / r;
  }

  fill(rouge, vert, bleu, 0.6 + 0.4 * cos(azimuth + d));  // simple depth effect...

  pushMatrix();
  translate(x - sin(d) * r, y + d * dy, z + cos(d) * r);
  rotateY(-d);
  rotateZ(atan2(h , l * r));  // banking...
  text(ch, 0.0f, 0.0f);
  popMatrix();
}
   }
 }

 void rewind(boolean invisible, float indent)
 {
   offset = indent;

   if (invisible)
   {
offset -= txt.getWidth();
   }
 }

 void start()
 {
   sliding = true;
 }

 void stop()
 {
   sliding = false;
 }
}

class Text
{
 String line;
 PFont font;
 color col;
 float sz;

 Text(String line, PFont font, color col, float sz)
 {
   this.line = line;
   this.font = font;
   this.col = col;
   this.sz = sz;
 }

 float getWidth()
 {
   textFont(f, 32);
   textSize(sz);
   return textWidth(line);  // once kerning is implemented in P5, this one won't be accurate!
 }
}

class Tower
{
 float x, y, z, turns, r1, r2, h;

 String[] lines;
 color[] colors;
 PFont font;
 float sz;

 float speed;

 Helix[] helices;

 Tower(float x, float y, float z, float turns, float r1, float r2, float h, String[] lines, color[] colors, PFont font, float sz, float speed)
 {
   this.x = x;
   this.y = y;
   this.z = z;
   this.turns = turns;
   this.r1 = r1;
   this.r2 = r2;
   this.h = h;

   this.lines = lines;
   this.colors = colors;
   this.font = font;
   this.sz = sz;

   this.speed = speed;

   build();
   rewind();
 }

 void run()
 {
   boolean sliding = false;
   for (int i = 0; i < lines.length; i++)
   {
sliding |= helices[i].run();
   }
   if (!sliding)
   {
rewind();
   }
 }

 void build()
 {
   helices = new Helix[lines.length];
   for (int i = 0; i < lines.length; i++)
   {
helices[i] = new Helix(x, y, z, turns, r1, r2, h, new Text(lines[i], font, colors[i], sz), speed);
   }
 }

 void rewind()
 {
   float l = 0.0f;
   for (int i = 0; i < lines.length; i++)
   {
helices[i].rewind(true, l);
helices[i].start();

l -= helices[i].txt.getWidth() + sz;  // the queued lines are separated by a gap equals to the font size...
   }
 }
}
Re: BABEL FISH TOWER 2
Reply #3 - Jun 2nd, 2007, 3:44pm
 
Hello and thanks for the hints & code!

I was trying around with some of the new expressions (popMatrix PFont etc.) but I am not aware of all of the ones that need to be changed. Anyway the babel fish still won't work. Thanks to jaylfk it does at least show me a graphical thing... but to be honest it doesn't look like what I actually want to realize which is the following, maybe this makes it even "easier":

a never ending string of the word "samesame" (white letters on black) should be animated from the bottom right of the screen... then the string heads towards the center following a 3d spiral path, similar to babel fish tower 2. the string should become smaller and smaller towards the center and disappear in the center... sounds "easy"? but isn't of course...

hmm any further hints very much appreciated and thanked for in advance! maybe the babel fish 2 isn't the best basis for what I want to do?

anyway! greetings from semi sunny vienna,

harald

x
Page Index Toggle Pages: 1