Git Product home page Git Product logo

wang-tiles's Introduction

Wang Tiles

This Project is heavily (almost too much) inspired by Tsoding Daily's Project On Wang Tiles. It might be considered a port of the project to Golang.

Introduction

Wang tiles is a mathematical concept for procedural generation that was proposed by Hao Wang in 1961. Each tile has 4 sides. Each side can have one of 2 colors. Thus, each tile can be represented as a 4 bit number.

These tiles are stacked together with some specific rules.

  • all 4 edges of a tile must match with it's neighbour
  • All cells of the grid are filled, there is no overloap or empty cell.

This leads to very interesting patterns and visualisations.

Coming Up!

Grid Grid Grid

Usage

go run main.go {output-filename}

output-filename = must be a jpeg, default="./temp/atlas.jpeg"

Goals

  • To learn about procedural generation using wang-tiles.
  • To learn about GoLang's idiomatic way of doing things and exploring multiple solutions to the same problem.
  • To learn more about go-routines and generate graphics using nothing but the CPU.

Phases

This project is done in phases (again, very similar to Tsoding Daily's project) and each phase might add or remove stuff from the codebase. Please go through every phase to understand the journey.

Phase 1 - Atlas Rendering

A single struct named Tile is responsible for representing a single tile in the project. It embeds the image.Image type from golang. It's colors are dicided with a single uint8 called bltr. The method wangFragmentShader is analogus to fragment shaders in graphics libraries. It takes in normalized co-ordintaes and outputs a color for that particular coordinte. BLTR stands for Bottom, Left, Top, Right. It represents the order in which the bits represent the colors of a tile.

Doing This in a loop for each possible bltr results in an atlas of all posible wang tiles (kind of like a sprite sheet.).

Phase 2 - Grid Rendering

  • A grid is generated in the form of 2D slice of uint8 or [][]uint8 called bltrs. These are semi-randomly generated by following the basic rules.
  • Next, these are translated into a grid image using an atlas or tileSet which is a mapping of bltr to image.Image
  • Calculating Offsets from Rows and Cols, the following demo images were created (note: I have implemented 3 fragment shaders, there can be many more!!!)

Maze Like Demo

Atlas

Atlas

Generated Grid

Grid

Bokeh or Bubble like Demo

Atlas

Atlas

Generated Grid

Grid

Triangles Demo

Atlas

Atlas

Generated Grid

Grid

Things I learnt

  • I learnt about image.Image type and how to use it to manipulate images in golang. (It can be thought of as a wrapper around a 2D array which makes it easy to deal with images).
  • I learnt about vardiac functions which let you take a variable number of arguments e.g. the definition of fmt.Printf is
    func Printf(format string, a ...interface{}) (n int, err error)
  • I also learnt about go-routines and how they can help in parrellely processing individual tiles in of the wang-tiles set.
  • I implemented a basic linear algebra library to help in calculations
  • I learnt about the image.Image and draw.Draw interfaces and how the facilitate interacting and manipulating images

wang-tiles's People

Contributors

kaviisuri avatar

Stargazers

 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.