Git Product home page Git Product logo

wang-tiles's Introduction

Wang Tiles Grid generator

thumbnail

Quick Start

The project is using nobuild build system.

$ cc -o nobuild nobuild.c
$ ./nobuild
$ ./wang -live

Goal

Trying to generate a random grid of 2-colored Wang Tiles based on a single function definition:

typedef struct { float c[2]; } Vec2f;
typedef struct { float c[3]; } Vec3f;
typedef Vec2f UV;
typedef Vec3f RGB;
typedef uint32_t BLTR;

RGB wang(BLTR bltr, UV uv);

where

  • bltr is a 4 bit mask encoding the specific Wang Tile. Each bit represents a side of the tile in the following order: Bottom, Left, Top, Right. 0 is the first color, 1 is the second one.
  • uv is a 2D vector that represents a point on the tile. Top-Left corner is [0.0, 0.0], Bottom-Right corner is [1.0, 1.0]. Coordinates are normalized and resolution-independant.
  • The result of the function is a 3D vector that represents an RGB color of a pixel on the tile bltr at uv.

Think of it as a Fragment Shader that generates a Texture for a Wang Tile based on its bitmask description.

Phases

The whole rendering is split into roughly 3 phases and done entirely on CPU.

Phase 1. Atlas Rendering

Given the "Shader" function described in the Goal section we generate an atlas (spritesheet) of all 16 Wang Tiles. (4 sides, 2 colors, 2โด = 16)

atlas-00 atlas-01

Phase 2. Grid Generation

Given the size of the grid in tiles we generate 2D array of BLTR-s (defined in the Goal section) satisfying the Wang Tile constraints between the tiles (the adjacent side of the tiles must have the same color).

Phase 3. Grid Rendering

After the Atlas and the Grid are generated we iterate over each BLTR in the Grid and copy the corresponding tiles from the Atlas into the final Grid image.

grid-00 grid-01

Screencasts

The development was streamed on Twitch. Here is an archive of screencasts: https://www.youtube.com/playlist?list=PLpM-Dvs8t0VYgJXZyQzWjfYUm3MxcvqR0

wang-tiles's People

Contributors

kolumb avatar rexim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kolumb pdwilso

wang-tiles's Issues

wang-tiles -live runs choppy

wang-tiles -live runs choppy, even though the rendering takes about 3 ms according to the builtin profiler.

We shipped this shit, and the customer is really mad. Do you even have QA?!

1 star.

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.