Git Product home page Git Product logo

bit-packed-map's Introduction

BitPackedMap

On-chain 8x8 bitmap svg packed into a single 32 byte storage slot. By packing the bitmap into a single storage slot, we can dramatically reduce gas consumption.

How it works

Each bitmap has 64 squares, with each square corresponding to a 4 bit color.

Color pallet

color pallet

Example

Consider the following bitmap: 0x7624778dedc75f8b322b9fa1632a610d40b85e106c7d9bf0e743a9ce291b9c63. We can see how each 4 bit value is assigned to a square according to the above color pallet.

7 6 2 4 7 7 8 d
e d c 7 5 f 8 b
3 2 2 b 9 f a 1
6 2 3 a 6 1 0 d
4 0 b 8 5 e 1 0
6 c 7 d 9 b f 0
e 7 4 3 a 9 c e
2 9 1 b 9 c 6 3

bitmap1

And a more intentionally arranged bitmap: 0x000000000dd0bb000dd2bb20002202200ff077000ff277200022022000000000

bitmap2

Variations

For the initial implementation we went with an 8x8 grid of 4 bit colors, but we can do this with different grid sizes and color profiles as long as they are inversely related. For example, we can do the following variations:

  • 4x4 grid of 8 bit colors (256 different colors)
  • 8x8 grid of 4 bit colors (16 different colors)
  • 16x16 grid of 2 bit colors (4 different colors)
  • 32x32 grid of 1 bit colors (2 different colors)

We can also play around with various color pallets, use an additional slot, etc..

Wanna implement a different variation? Submit a PR!

bit-packed-map's People

Contributors

kadenzipfel 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.