// Animation for the "L" and "a" in "Der Lauf Der Dinge". // David A. Mellis // 22 October 2004 int the_frame = 0; void setup() { size(500, 500); framerate(30); } void loop() { if (the_frame >= 0 && the_frame < 300) letter2(the_frame, "La"); the_frame++; } BFont font; Text[] texts; Text[] a; int[] starts; Text big; int frame = 0; int fountain_frame = 0; boolean show_big = false; boolean bounce = true; boolean fountain = false; boolean bounce_big = true; final static float ay = 1; void mellis_setup() { font = loadFont("Bodoni.vlw.gz"); texts = new Text[100]; starts = new int[texts.length]; for (int i = 0; i < texts.length; i++) { texts[i] = new Text(font, (int) random(10) + 12, "l", random(width), -random(height / 5), random(20) - 10, 0, 0); starts[i] = (int) random(25); } a = new Text[20]; for (int i = 0; i < a.length; i++) a[i] = new Text(font, 18, "a", random(width), height + 18, random(8) - 4, -random(15) - 10, 0); big = new Text(font, 96, "L", width / 2, 0, 0, 80, 0); } void letter2(int frame, String s) { frame = frame % 300; if (frame == 0) mellis_setup(); background(255); fill(0); stroke(0); if (frame > 125 && fountain == false) show_big = true; if (big.y < 0 && big.word.equals("L")) big.word = "A"; for (int i = 0; i < texts.length; i++) if (frame > starts[i]) texts[i].draw(); if (show_big) big.draw(); if (fountain) for (int i = 0; i < a.length; i++) if (frame - fountain_frame > i) a[i].draw(); for (int i = 0; i < texts.length; i++) if (frame > starts[i]) move(texts[i], bounce); if (show_big) move(big, bounce_big); if (fountain) for (int i = 0; i < a.length; i++) if (frame - fountain_frame > i) move(a[i], false); if (big.y == height && big.word.equals("L")) { for (int i = 0; i < texts.length; i++) texts[i].vy = -15 - random(100) / (abs(big.x - texts[i].x) + 2); bounce = false; } if (big.y == height && big.vy < 0 && big.word.equals("A") && bounce_big) { fountain = true; fountain_frame = frame; bounce_big = false; } noFill(); stroke(0); rect(0, 0, width - 1, height - 1); } void move(Text t, boolean bounce) { t.x += t.vx; t.y += t.vy; t.vy += ay; if (t.y > height && t.vy > 0 && bounce) { t.vy *= -0.5; t.y = height; } if (t.x < 0 && bounce) { t.vx *= -0.6; t.x = 0; } if (t.x > width - font.width("l") && bounce) { t.vx *= -0.6; t.x = width - font.width("l"); } } class Text { public BFont font; public int font_size; public String word; public float x, y; public float vx, vy; public float angle; public Text(BFont font, int font_size, String word, float x, float y, float vx, float vy, float angle) { this.font = font; this.font_size = font_size; this.word = word; this.x = x; this.y = y; this.vx = vx; this.vy = vy; this.angle = angle; } public void draw() { push(); translate(x, y); rotateZ(angle); textFont(font, font_size); font.text(word.charAt(0), 0.0, 0.0, g); pop(); } }