Git Product home page Git Product logo

zig-dots's Introduction

[Dots]

A semigraphical drawing library made in Zig.

I created this library as a way to learn my way around the Zig programming language. It is a type of virtual dot matrix that can be either printed to the terminal, or returned as a string that consists of Unicode Braille characters.

Adding to your project.

Add the library either by importing the file, or as a package in build.zig (recommended)

const dots = .{
    .name = "dots",
    .path = .{.path = "zig-dots/dots.zig"}
};
...
exe.addPackage(dots);

Example code

A basic example showing how to use Dots. Explore the source code for more details.

/// helloworld.zig
/// Paperdev-code (c)
const std = @import("std");
const dots = @import("dots");

// Dots helloworld program.
pub fn main() !void {
    var stdout = std.io.getStdOut().writer();

    var gpa = std.heap.GeneralPurposeAllocator(.{}) {};
    defer _ = gpa.deinit();
    const allocator = &gpa.allocator;
    const config = dots.Config.init(64, 64, allocator);
    
    var buffer = try dots.Buffer.create(&config);
    defer buffer.destroy();
    
    var display = try dots.Display.create(&config);
    defer display.destroy();

    var context = try dots.Context.init(&buffer);

    // d
    context.line(-0.5,-0.2,-0.5, 0.9, .{.bitset = 1});
    context.circ(-0.65, 0.6, 3.14 - 0.56, 3.14 * 2.0 + 0.56, 0.25, 64, .{.bitset = 1});
    // o
    context.circ(-0.2, 0.65, 0, 3.14 * 2.0, 0.2, 64, .{.bitset = 1});
    // t
    context.circ( 0.25, 0.7, 3.14 * 1.5, 3.14 * 2.5, 0.15, 64, .{.bitset = 1});
    context.line( 0.11, 0.2, 0.11, 0.8, .{.bitset = 1});
    context.line( 0.0, 0.3, 0.25, 0.3, .{.bitset = 1});
    // s
    context.circ( 0.65, 0.4, 3.14 / 2.0, 3.14 * 2.0, 0.15, 64, .{.bitset = 1});
    context.circ( 0.65, 0.7, 3.14 * 2.0 + 3.14, 3.14 / 2.0 + 3.14, 0.15, 64, .{.bitset = 1});

    while (true) {
        context.rect(-1.0,-1.0, 1.0, 1.0, .{.bitxor = 1});
        std.time.sleep(std.time.ns_per_s * 0.5);
        try display.print(&buffer, 0, 0, &stdout);
    }
}

zig-dots's People

Contributors

paperdev-code avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.