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 11 // for some reason this file needs to be in source/ directly, and not in source/texit. Otherwise I get complaints about core.sys.posix stuff... strange. 12 // I'm guessing it's a linux-specific bug since I didn't get it when I was originally creating this library on Windows. 13 14 module texit.app; 15 16 import texit; 17 18 version(HelloWorld) { 19 // Texit will automatically add a main to your program 20 // charmap file, char size, scale, world width, world height, screen width, screen height, title 21 mixin Texit!("assets/qbicfeet_10x10.png", 10, 2, 64, 32, 64, 32, "Hello World"); 22 23 void setup() { 24 // create a new "event", events have a start and end time both in seconds. 25 // TextEvent draws text to the screen at the start and removes it at the end 26 // using infinity here tells it to never disappear 27 // start, end, location, string 28 queue(new TextEvent(0, float.infinity, Point(0, 0), "Hello, World!")); 29 } 30 } 31 32 version(RandomCharacters) { 33 mixin Texit!("assets/qbicfeet_10x10.png", 10, 2, 64, 32, 64, 32, "Random Characters"); 34 35 void setup() { 36 import std.random; 37 float[3] randColor() { 38 return [uniform01, uniform01, uniform01]; 39 } 40 // loop over all characters in the world 41 for(int i = 0; i < WORLD_WIDTH; i++) { 42 for(int j = 0; j < WORLD_HEIGHT; j++) { 43 // add a textevent for each of them 44 float start = uniform01*2; 45 float end = start+2+uniform01*2; 46 // textevent has another constructor, allowing you to specify foreground and background colors 47 // colors are represented as a float[3] 48 // these text events have a non-infinity end time, so they'll disappear a bit after they appear 49 queue(new TextEvent(start, end, Point(i, j), randColor, randColor, ""~cast(char)uniform(0, 255))); 50 } 51 } 52 } 53 } 54 55 version(ScrollingZooming) { 56 mixin Texit!("assets/qbicfeet_10x10.png", 10, 2, 128, 64, 64, 32, "Scrolling & Zooming"); 57 58 void setup() { 59 import std.random; 60 // set an end time 61 endTime = 14; 62 // colors are represented by float[3] 63 float[3] randColor() { 64 return [uniform01, uniform01, uniform01]; 65 } 66 // random string the size of WORLD_WIDTH 67 string randString() { 68 string s = ""; 69 for(int i = 0; i < WORLD_WIDTH; i++) { 70 char c = cast(char)uniform(0, 255); 71 s ~= c == '\n' ? ' ' : c; 72 } 73 return s; 74 } 75 Vector start = Vector(0, 0); 76 translation = start; // set initial translation without an event 77 // create rows 78 for(int i = 0; i < WORLD_HEIGHT; i++) 79 queue(new TextEvent(0, float.infinity, Point(0, i), randColor, randColor, randString)); 80 // start translating & zooming at time 1 81 queue( 82 new TranslationEvent(1, 10, start, Vector(WIDTH*1.5, HEIGHT*1.5, 0), easing!"easeOutBack"), 83 new ZoomEvent(1, 10, 1, 4, easing!"easeInOutCubic") 84 ); 85 } 86 } 87 88 version(AudioExample) { 89 mixin Texit!("assets/qbicfeet_10x10.png", 10, 2, 128, 64, 64, 32, "Audio Example"); 90 91 float beat(float v) { 92 enum ms = 60f/140f; // song is at 140bpm 93 return v*ms; 94 } 95 96 void setup() { 97 import std.random; 98 float[3] randColor() { 99 return [uniform01, uniform01, uniform01]; 100 } 101 offset = 0; // set offset /before/ you play the audio (here it's 0 so it doesn't matter but important to remember) 102 audio("assets/hello_world.ogg"); 103 string s = "Hello, World!"; 104 for(int i = 0; i < WORLD_WIDTH/s.length; i++) { 105 for(int j = 0; j < WORLD_HEIGHT; j++) { 106 queue(new FlashingTextEvent(uniform(0, 24).beat, float.infinity, Point(i*cast(int)s.length, j), randColor, randColor, randColor, randColor, s, 4.beat)); 107 } 108 } 109 for(int i = 0; i < 50; i++) { 110 float a = (i*16).beat; 111 float b = a+(8.beat); 112 float c = b+(8.beat); 113 queue( 114 new TranslationEvent(a, b, Vector(0, WORLD_HEIGHT/2), Vector(WORLD_WIDTH, WORLD_HEIGHT/2), easing!"easeInOutBack"), 115 new TranslationEvent(b, c, Vector(WORLD_WIDTH, WORLD_HEIGHT/2), Vector(0, WORLD_HEIGHT/2), easing!"easeInOutBack"), 116 new ZoomEvent(a, b, 2, 4, easing!"easeInBack"), 117 new ZoomEvent(b, c, 4, 2, easing!"easeOutBack") 118 ); 119 } 120 } 121 } 122 123 version(ImageExample) { 124 mixin Texit!("assets/qbicfeet_10x10.png", 10, 2, 64, 32, 64, 32, "Image Example"); 125 126 void setup() { 127 queue( 128 new EntityEvent(0, float.infinity, new ImageEntity(Vector(1, 0), Vector(6, 6), "image", "./assets/image.png")), 129 new TextEvent(0, float.infinity, Point(1, 10), "Text appears ontop of entities"), 130 new EntityTranslationEvent(0, 1, "image", Vector(1, 0), Vector(1, 7.5), easing!"easeOutBounce"), 131 new EntityResizeEvent(1, 2, "image", Vector(6, 6), Vector(30, 6), easing!"easeOutCubic"), 132 ); 133 } 134 }