1 /** 2 A few example programs using texit. Just run `dub build` with one of the follwing versions to see them 3 $(LIST 4 * HelloWorld 5 * RandomCharacters 6 * ScrollingZooming 7 * AudioExample 8 ) 9 */ 10 module texit.app; 11 12 import texit; 13 14 version = ImageExample; 15 16 version(HelloWorld) { 17 // Texit will automatically add a main to your program 18 // charmap file, char size, scale, world width, world height, screen width, screen height, title 19 mixin Texit!("qbicfeet_10x10.png", 10, 2, 64, 32, 64, 32, "Hello World"); 20 21 void setup() { 22 // create a new "event", events have a start and end time both in seconds. 23 // TextEvent draws text to the screen at the start and removes it at the end 24 // using infinity here tells it to never disappear 25 // start, end, location, string 26 queue(new TextEvent(0, float.infinity, Point(0, 0), "Hello, World!")); 27 } 28 } 29 30 version(RandomCharacters) { 31 mixin Texit!("qbicfeet_10x10.png", 10, 2, 64, 32, 64, 32, "Random Characters"); 32 33 void setup() { 34 import std.random; 35 float[3] randColor() { 36 return [uniform01, uniform01, uniform01]; 37 } 38 // loop over all characters in the world 39 for(int i = 0; i < WORLD_WIDTH; i++) { 40 for(int j = 0; j < WORLD_HEIGHT; j++) { 41 // add a textevent for each of them 42 float start = uniform01*2; 43 float end = start+2+uniform01*2; 44 // textevent has another constructor, allowing you to specify foreground and background colors 45 // colors are represented as a float[3] 46 // these text events have a non-infinity end time, so they'll disappear a bit after they appear 47 queue(new TextEvent(start, end, Point(i, j), randColor, randColor, ""~cast(char)uniform(0, 255))); 48 } 49 } 50 } 51 } 52 53 version(ScrollingZooming) { 54 mixin Texit!("qbicfeet_10x10.png", 10, 2, 128, 64, 64, 32, "Scrolling & Zooming"); 55 56 void setup() { 57 import std.random; 58 // colors are represented by float[3] 59 float[3] randColor() { 60 return [uniform01, uniform01, uniform01]; 61 } 62 // random string the size of WORLD_WIDTH 63 string randString() { 64 string s = ""; 65 for(int i = 0; i < WORLD_WIDTH; i++) { 66 char c = cast(char)uniform(0, 255); 67 s ~= c == '\n' ? ' ' : c; 68 } 69 return s; 70 } 71 Vector start = Vector(0, 0); 72 translation = start; // set initial translation without an event 73 // create rows 74 for(int i = 0; i < WORLD_HEIGHT; i++) 75 queue(new TextEvent(0, float.infinity, Point(0, i), randColor, randColor, randString)); 76 // start translating & zooming at time 1 77 queue(new TranslationEvent(1, 10, start, Vector(WIDTH*1.5, HEIGHT*1.5, 0), easing!"easeOutBack")); 78 queue(new ZoomEvent(1, 10, 1, 4, easing!"easeInOutCubic")); 79 } 80 } 81 82 version(AudioExample) { 83 mixin Texit!("qbicfeet_10x10.png", 10, 2, 128, 64, 64, 32, "Audio Example"); 84 85 float beat(float v) { 86 enum ms = 60f/140f; // song is at 140bpm 87 return v*ms; 88 } 89 90 void setup() { 91 import std.random; 92 float[3] randColor() { 93 return [uniform01, uniform01, uniform01]; 94 } 95 offset = 0; // set offset /before/ you play the audio (here it's 0 so it doesn't matter but important to remember) 96 audio("hello_world.ogg"); 97 string s = "Hello, World!"; 98 for(int i = 0; i < WORLD_WIDTH/s.length; i++) { 99 for(int j = 0; j < WORLD_HEIGHT; j++) { 100 queue(new FlashingTextEvent(uniform(0, 24).beat, float.infinity, Point(i*cast(int)s.length, j), randColor, randColor, randColor, randColor, s, 4.beat)); 101 } 102 } 103 for(int i = 0; i < 50; i++) { 104 float a = (i*16).beat; 105 float b = a+(8.beat); 106 float c = b+(8.beat); 107 queue(new TranslationEvent(a, b, Vector(0, WORLD_HEIGHT/2), Vector(WORLD_WIDTH, WORLD_HEIGHT/2), easing!"easeInOutBack")); 108 queue(new TranslationEvent(b, c, Vector(WORLD_WIDTH, WORLD_HEIGHT/2), Vector(0, WORLD_HEIGHT/2), easing!"easeInOutBack")); 109 queue(new ZoomEvent(a, b, 2, 4, easing!"easeInBack")); 110 queue(new ZoomEvent(b, c, 4, 2, easing!"easeOutBack")); 111 } 112 } 113 } 114 115 version(ImageExample) { 116 mixin Texit!("qbicfeet_10x10.png", 10, 2, 64, 32, 64, 32, "Image Example"); 117 118 void setup() { 119 120 } 121 }