/* A little meandering textlet */ /* Fonts have to be loaded later, so just declare for now. */ PFont fonts[]; static final int PLAIN = 0; static final int ITALIC = 1; Word[] words = { new Word ( "iÕm", -70, 60, 160, 0, 270, 250, PLAIN, -1, 100 ), new Word ( "their", 100, 120, 240, 3 * PI / 2, 0, 0, PLAIN, 0, 70 ), new Word ( "writing", -100, 50, 80, PI / 2, 0, 0, PLAIN, 0, 100 ), new Word ( "words", 70, 80, 80, 3 * PI / 2, 0, 0, PLAIN, 1, 0 ), new Word ( "meaning", -50, 40, 480, PI / 2, 0, 0, ITALIC, 1, 100 ), new Word ( "lose", 30, 40, 240, PI / 2, 0, 0, PLAIN, 3, 40 ), new Word ( "when", -60, 40, 120, PI / 2, 0, 0, PLAIN, 4, 120 ), new Word ( "not", 50, 40, 160, 3 * PI / 2, 0, 0, PLAIN, 2, 120 ), new Word ( "for", 70, 80, 80, PI / 2, 0, 0, PLAIN, 2, 40 ), new Word ( "them", 70, 40, 120, 3 * PI / 2, 0, 0, PLAIN, 8, 70 ), new Word ( "you", -50, 40, 160, PI / 2, 0, 0, ITALIC, 8, 0 ) }; void setup () { size ( 700, 500, JAVA2D ); /* load fonts */ PFont plain = loadFont("Bembo-48.vlw"); PFont italic = loadFont("Bembo-Italic-48.vlw"); PFont[] tmpF = { plain, italic }; fonts = tmpF; } void draw () { background(255); for ( int i = 0; i < words.length; ++i ) { words[i].step(); words[i].draw(); } } class Word { String word; float x = 0; float y = 0; float rx; float ry; float period; // not literally, since we don't use 2*PI, but serving the same purpose float baseAngle; float xbase; float ybase; int fontIndex; int ownerIndex; int grey; Word ( String word, float rx, float ry, float period, float baseAngle, float xbase, float ybase, int fontIndex, int ownerIndex, int grey ) { this.word = word; this.x = x; this.y = y; this.rx = rx; this.ry = ry; this.period = period; this.baseAngle = baseAngle; this.xbase = xbase; this.ybase = ybase; this.fontIndex = fontIndex; this.ownerIndex = ownerIndex; this.grey = grey; } void step () { if ( ownerIndex < 0 ) { x = xbase + rx * cos ( baseAngle + frameCount * PI / period ) * sin ( frameCount * PI / (1.01 * period) ); y = ybase + ry * sin ( baseAngle + frameCount * PI / period ); } else { x = words[ownerIndex].x + rx * cos ( baseAngle + frameCount * PI / period ); y = words[ownerIndex].y + ry * sin ( baseAngle + frameCount * PI / period ); } } void draw () { textFont ( fonts[fontIndex] ); fill ( grey ); text ( word, x, y ); } }