griddle 0.1.0 copy "griddle: ^0.1.0" to clipboard
griddle: ^0.1.0 copied to clipboard

Creating terminal-based UIs and games in Dart should be accessible and fun!

example/example.dart

import 'dart:math' as math;

import 'package:griddle/griddle.dart';

/// A sample application, similar to the one provided in [termpixels][].
///
/// [termpixels]: https://github.com/loganzartman/termpixels
void main() {
  run(Screen.terminal(Terminal.usingAnsiStdio()));
}

void run(Screen screen) {
  const string = 'Hello World, from Griddle for Dart!';

  screen.onFrame.listen((elapsed) {
    screen.clear();

    for (var i = 0; i < string.length; i++) {
      final t = DateTime.now().millisecondsSinceEpoch / 1000;
      final f = i / string.length;
      final c = Color.fromHSL(f * 300 + t, 1, 0.5);
      final x = screen.width ~/ 2 - string.length ~/ 2;
      final o = math.sin(t * 3 + f * 5) * 2;
      final y = (screen.height / 2 + o).round();

      screen.print(string[i], x + i, y, foreground: c);
    }

    screen
      ..print('${elapsed.inMilliseconds}ms', 0, screen.height ~/ 2 - 2)
      ..update();
  });
}
8
likes
0
pub points
0%
popularity

Publisher

verified publisherlurey.dev

Creating terminal-based UIs and games in Dart should be accessible and fun!

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta, neoansi, neocolor

More

Packages that depend on griddle