~ashn/braille-pattern-graphics-sunder

ce5fa17103ef6b3567971fbf8c739a427873f7e1 — ashn 7 months ago 396ad5a main
Update to Sunder version 2022.02.01
3 files changed, 16 insertions(+), 26 deletions(-)

M README.md
M bpgfx.sunder
M example.sunder
M README.md => README.md +3 -10
@@ 4,7 4,7 @@ Block](https://en.wikipedia.org/wiki/Braille_Patterns). Ported from the Braille
Pattern Graphics [Python 3
library](https://github.com/ashn-dot-dev/braille-pattern-graphics) for
[Sunder](https://github.com/ashn-dot-dev/sunder) version
[2022.12.01](https://github.com/ashn-dot-dev/sunder/releases/tag/2022.12.01).
[2023.02.01](https://github.com/ashn-dot-dev/sunder/releases/tag/2023.02.01).

## Example Usage
```


@@ 12,19 12,12 @@ import "std";
import "bpgfx.sunder";

func main() void {
    var allocator = std::general_allocator::init();
    defer {
        allocator.fini();
    }

    # Create a 40 x 30 canvas of virtual dot pixels.
    #
    # Virtual dot-pixels are mapped onto a grid of braille characters when the
    # canvas is rendered via its format member function.
    var canvas = bpgfx::canvas::init(std::allocator::init[[typeof(allocator)]](&allocator), 40, 30);
    defer {
        canvas.fini();
    }
    var canvas = bpgfx::canvas::init(40, 30);
    defer canvas.fini();

    # Draw a rectangle around the border of the canvas.
    for x in canvas.width() {

M bpgfx.sunder => bpgfx.sunder +11 -7
@@ 5,7 5,7 @@ import "std";
# Printing this escape sequence to the terminal will clear the screen and
# reposition the cursor on the top-left of the terminal in terminal emulators
# with support for ANSI escape codes.
const CLEAR = "\x1B[H\x1B[2J";
let CLEAR = "\x1B[H\x1B[2J";

struct drawable_itable {
    var draw: func(*any, *canvas) void;


@@ 16,7 16,7 @@ struct drawable {
    var object: *any;

    func init[[T]](object: *T) bpgfx::drawable {
        const itable = (:bpgfx::drawable_itable){
        let itable = (:bpgfx::drawable_itable){
            .draw = T::draw
        };
        return (:bpgfx::drawable){


@@ 40,7 40,11 @@ struct canvas {
    var _height: usize;
    var _dots: [][]bool;

    func init(allocator: std::allocator, width: usize, height: usize) canvas {
    func init(width: usize, height: usize) canvas {
        return canvas::init_with_allocator(std::global_allocator(), width, height);
    }

    func init_with_allocator(allocator: std::allocator, width: usize, height: usize) canvas {
        var dots_w = width;
        for dots_w % 2 != 0 {
            dots_w = dots_w + 1;


@@ 51,9 55,9 @@ struct canvas {
            dots_h = dots_h + 1;
        }

        var dots = std::slice[[[]bool]]::new(allocator, dots_h);
        var dots = std::slice[[[]bool]]::new_with_allocator(allocator, dots_h);
        for i in countof(dots) {
            dots[i] = std::slice[[bool]]::new(allocator, dots_w);
            dots[i] = std::slice[[bool]]::new_with_allocator(allocator, dots_w);
            std::slice[[bool]]::fill(dots[i], false);
        }



@@ 67,9 71,9 @@ struct canvas {

    func fini(self: *canvas) void {
        for i in countof(self.*._dots) {
            std::slice[[bool]]::delete(self.*._allocator, self.*._dots[i]);
            std::slice[[bool]]::delete_with_allocator(self.*._allocator, self.*._dots[i]);
        }
        std::slice[[[]bool]]::delete(self.*._allocator, self.*._dots);
        std::slice[[[]bool]]::delete_with_allocator(self.*._allocator, self.*._dots);
    }

    func width(self: *canvas) usize {

M example.sunder => example.sunder +2 -9
@@ 2,19 2,12 @@ import "std";
import "bpgfx.sunder";

func main() void {
    var allocator = std::general_allocator::init();
    defer {
        allocator.fini();
    }

    # Create a 40 x 30 canvas of virtual dot pixels.
    #
    # Virtual dot-pixels are mapped onto a grid of braille characters when the
    # canvas is rendered via its format member function.
    var canvas = bpgfx::canvas::init(std::allocator::init[[typeof(allocator)]](&allocator), 40, 30);
    defer {
        canvas.fini();
    }
    var canvas = bpgfx::canvas::init(40, 30);
    defer canvas.fini();

    # Draw a rectangle around the border of the canvas.
    for x in canvas.width() {