Giter VIP home page Giter VIP logo

emojivision's Introduction

✨👯‍♀️emojivision👁👄👁👯‍♀️✨

A 200 something line Swift Playground for rendering images as emojis.

emojivision

At the top of the file are a few constants:

  • imageFileName - The input image
  • colorMapName - The palette to sample from
  • emojiFileName - The file to generate the palette from
  • resolution - EmojiDensity™

Included in the source is a dump of all iOS12 emojis (sourced from EmojiDump). The function generateColorMap reads that file and exports a newline-separated text file containing the dominant color in each emoji to ~/Documents/Shared Playground Data/colormap.txt. You can replace that file if you want to populate your palette with more emojis, but you'll need to update the file specified by colorMapName if you want it to be used.

You'll notice that the included color map has far fewer entries than the comprehensive emoji dump, which is a performance requirement. Here's how it works:

  1. Go through every few pixels of the image (specified by resolution) and get the color of that pixel
  2. Treating each color's rgb as a 3d vector, compare the euclidian distance of that color with every color in the provided palette, and get the color with the nearest distance
  3. Get the emoji associated with that color value from a precomputed dictionary of colors to emojis
  4. Draw the emoji in the rect occupied by the current pixel with dimension specified by resolution

For your convenience, code at the end of the file outputs your artwork to ~/Documents/Shared Playground Data/out.png. Note that this directory needs to exist beforehand 🙄.

PS: this was done as a proof of concept and the right way to do things would be to offload more to the GPU, such as finding nearest colors and rendering of emojis 🤷‍♂️

emojivision's People

Contributors

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