log.console("test_text starting") var time = use('time') var core = use('core') var text2d = use('text2d') var compositor = use('compositor') var film2d = use('film2d') var math = use('math/radians') var texts = [] var t = 0 var camera = { pos: {x: 250, y: 250}, width: 500, height: 500, anchor: {x: 0.5, y: 0.5} } var compositor_config = { clear: {r: 0.1, g: 0.1, b: 0.15, a: 1}, planes: [ { name: 'main', plane: 'main', camera: camera, resolution: {width: 500, height: 500}, presentation: 'stretch', clear: {r: 0.1, g: 0.1, b: 0.15, a: 1} } ] } function init() { // Row 1: Normal text texts[] = text2d({ plane: 'main', layer: 0, text: "Normal Text", pos: {x: 20, y: 470}, font: 'examples/fonts/dos', size: 24, color: {r: 1, g: 1, b: 1, a: 1} }) // Row 2: Opacity variations texts[] = text2d({ plane: 'main', layer: 0, text: "Opacity 0.25", pos: {x: 20, y: 420}, font: 'examples/fonts/dos', size: 20, color: {r: 1, g: 1, b: 1, a: 1}, opacity: 0.25 }) texts[] = text2d({ plane: 'main', layer: 0, text: "Opacity 0.5", pos: {x: 200, y: 420}, font: 'examples/fonts/dos', size: 20, color: {r: 1, g: 1, b: 1, a: 1}, opacity: 0.5 }) texts[] = text2d({ plane: 'main', layer: 0, text: "Opacity 0.75", pos: {x: 360, y: 420}, font: 'examples/fonts/dos', size: 20, color: {r: 1, g: 1, b: 1, a: 1}, opacity: 0.75 }) // Row 3: Tint colors texts[] = text2d({ plane: 'main', layer: 0, text: "Red Tint", pos: {x: 20, y: 360}, font: 'examples/fonts/dos', size: 24, color: {r: 1, g: 1, b: 1, a: 1}, tint: {r: 1, g: 0.2, b: 0.2, a: 1} }) texts[] = text2d({ plane: 'main', layer: 0, text: "Green Tint", pos: {x: 180, y: 360}, font: 'examples/fonts/dos', size: 24, color: {r: 1, g: 1, b: 1, a: 1}, tint: {r: 0.2, g: 1, b: 0.2, a: 1} }) texts[] = text2d({ plane: 'main', layer: 0, text: "Blue Tint", pos: {x: 360, y: 360}, font: 'examples/fonts/dos', size: 24, color: {r: 1, g: 1, b: 1, a: 1}, tint: {r: 0.2, g: 0.2, b: 1, a: 1} }) // Row 4: Combined tint + opacity texts[] = text2d({ plane: 'main', layer: 0, text: "Yellow + 50% Opacity", pos: {x: 20, y: 300}, font: 'examples/fonts/dos', size: 20, color: {r: 1, g: 1, b: 1, a: 1}, tint: {r: 1, g: 1, b: 0, a: 1}, opacity: 0.5 }) texts[] = text2d({ plane: 'main', layer: 0, text: "Cyan + 75% Opacity", pos: {x: 280, y: 300}, font: 'examples/fonts/dos', size: 20, color: {r: 1, g: 1, b: 1, a: 1}, tint: {r: 0, g: 1, b: 1, a: 1}, opacity: 0.75 }) // Row 5: Different sizes texts[] = text2d({ plane: 'main', layer: 0, text: "Small", pos: {x: 20, y: 240}, font: 'examples/fonts/dos', size: 12, color: {r: 1, g: 1, b: 1, a: 1} }) texts[] = text2d({ plane: 'main', layer: 0, text: "Medium", pos: {x: 100, y: 240}, font: 'examples/fonts/dos', size: 20, color: {r: 1, g: 1, b: 1, a: 1} }) texts[] = text2d({ plane: 'main', layer: 0, text: "Large", pos: {x: 220, y: 240}, font: 'examples/fonts/dos', size: 32, color: {r: 1, g: 1, b: 1, a: 1} }) texts[] = text2d({ plane: 'main', layer: 0, text: "XL", pos: {x: 360, y: 240}, font: 'examples/fonts/dos', size: 48, color: {r: 1, g: 1, b: 1, a: 1} }) // Row 6: Animated text (pulsing opacity) texts[] = text2d({ plane: 'main', layer: 0, text: "Pulsing Opacity", pos: {x: 150, y: 150}, font: 'examples/fonts/dos', size: 28, color: {r: 1, g: 1, b: 1, a: 1}, opacity: 1 }) // Row 7: Animated tint (rainbow cycle) texts[] = text2d({ plane: 'main', layer: 0, text: "Rainbow Tint", pos: {x: 150, y: 100}, font: 'examples/fonts/dos', size: 28, color: {r: 1, g: 1, b: 1, a: 1}, tint: {r: 1, g: 0, b: 0, a: 1} }) // Row 8: Typewriter effect simulation texts[] = text2d({ plane: 'main', layer: 0, text: "", pos: {x: 20, y: 50}, font: 'examples/fonts/dos', size: 20, color: {r: 0.8, g: 1, b: 0.8, a: 1} }) log.console("test_text initialized with " + text(length(texts)) + " text elements") } var typewriter_text = "Hello, this is a typewriter effect demo..." var typewriter_index = 0 var typewriter_timer = 0 function update(dt) { t += dt // Animate pulsing opacity var pulsing_text = texts[length(texts) - 3] pulsing_text.opacity = 0.3 + 0.7 * abs(math.sine(t * 2)) // Animate rainbow tint var rainbow_text = texts[length(texts) - 2] rainbow_text.tint.r = 0.5 + 0.5 * math.sine(t * 2) rainbow_text.tint.g = 0.5 + 0.5 * math.sine(t * 2 + 2.094) rainbow_text.tint.b = 0.5 + 0.5 * math.sine(t * 2 + 4.188) // Typewriter effect typewriter_timer += dt var typewriter = null if (typewriter_timer > 0.08) { typewriter_timer = 0 typewriter_index++ if (typewriter_index > length(typewriter_text)) { typewriter_index = 0 } typewriter = texts[length(texts) - 1] typewriter.text = text(typewriter_text, 0, typewriter_index) } } function render() { var plan = compositor.compile(compositor_config) return compositor.execute(plan) } init() core.start({ width: 500, height: 500, title: "Test Text Features", framerate: 60, update: update, render: render })