Giter Site home page Giter Site logo

chisel's Introduction

Chisel

GitHub Workflow Status github.com Hex version Hex docs

Chisel is a library that uses bitmap fonts to sculpt text on any device that can handle pixels.

Setup

Add Chisel to your mix.exs deps:

{:chisel, "~> 0.2.0"},

Run mix deps.get to download the new dependency.

Usage

  1. Take a function to draw pixels...
  put_pixel = fn x, y ->
    YourDisplay.draw_pixel(x, y, ...)
  end
  1. Pick a BDF font (Look for one on the Internet or take one from the fixtures folder on this project)
  {:ok, font} = Chisel.Font.load("foo/bar/font.bdf")
  1. Use Chisel to sculpt the text using the provided function and font
  Chisel.Renderer.draw_text("Hello World!", x, y, font, put_pixel)
  1. Enjoy!

Demo

(Thanks to lawik for the picture)

General purpose

Chisel is a general purpose library that can be used to render text on any target based on pixels (LCD, Led matrixs, image files, ...).

Render on an image with :egd

  img = :egd.create(200, 50)
  color = :egd.color({0, 0, 0})

  put_pixel = fn x, y ->
    :egd.line(img, {x, y}, {x, y}, color)
  end

  {:ok, font} = Chisel.Font.load("font.bdf")

  Chisel.Renderer.draw_text("Hello World!", 0, 0, font, put_pixel)

  :egd.save(:egd.render(img, :png), "test.png")

Render ASCII art

  put_pixel = fn x, y, pixels ->
    [{x, y} | pixels]
  end

  {:ok, font} = Chisel.Font.load("c64.bdf")

  {pixels, _, _} = Chisel.Renderer.reduce_draw_text("Hello World!", 0, 0, font, [], put_pixel)

  for y <- 0..10 do
    for x <- 0..100 do
      if Enum.member?(pixels, {x, y}) do
        "%"
      else
        " "
      end
    end
    |> IO.puts()
  end

Result:

                                                                                                     
                                                                                                     
 %%  %%                                          %%   %%                                   %%        
 %%  %%           %%%     %%%                    %%   %%                  %%%        %%    %%        
 %%  %%   %%%%     %%      %%     %%%%           %%   %%  %%%%   %%%%%     %%        %%    %%        
 %%%%%%  %%  %%    %%      %%    %%  %%          %% % %% %%  %%  %%  %%    %%     %%%%%    %%        
 %%  %%  %%%%%%    %%      %%    %%  %%          %%%%%%% %%  %%  %%        %%    %%  %%              
 %%  %%  %%        %%      %%    %%  %%          %%% %%% %%  %%  %%        %%    %%  %%              
 %%  %%   %%%%    %%%%    %%%%    %%%%           %%   %%  %%%%   %%       %%%%    %%%%%    %%        
                                                                                                     
                                                                                                     

Samples using OLED

OLED Demo

Using the right font it is even possible to render unicode strings.

Many good BDF fonts are available here on the U8g2 library repo.

Check fonts licenses here.

chisel's People

Contributors

luisgabrielroldan avatar ream88 avatar fstiewitz avatar xosdy avatar feng19 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.