All Projects → dumbmatter → Facesjs

dumbmatter / Facesjs

Licence: apache-2.0
A JavaScript library for generating vector-based cartoon faces

Labels

Projects that are alternatives of or similar to Facesjs

Bgrabitmap
📜 BGRABitmap graphics library made with Lazarus (Free Pascal).
Stars: ✭ 112 (-5.88%)
Mutual labels:  svg
Elemental2
Type checked access to browser APIs for Java code.
Stars: ✭ 115 (-3.36%)
Mutual labels:  svg
Teenyicons
Tiny minimal 1px icons designed to fit in the smallest places.
Stars: ✭ 1,631 (+1270.59%)
Mutual labels:  svg
Svg Icon
👻 A lightweight library that makes it easier to use SVG icons in your Angular Application
Stars: ✭ 112 (-5.88%)
Mutual labels:  svg
Mocodo
Modélisation Conceptuelle de Données. Nickel. Ni souris.
Stars: ✭ 113 (-5.04%)
Mutual labels:  svg
X6
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
Stars: ✭ 2,686 (+2157.14%)
Mutual labels:  svg
Tyxml
Build valid HTML and SVG documents
Stars: ✭ 111 (-6.72%)
Mutual labels:  svg
Snap.svg.zpd
A zoom/pan/drag/rotate plugin for Snap.svg (useful for view only)
Stars: ✭ 119 (+0%)
Mutual labels:  svg
Vue Graph
⚡️ Vue components based on the JUI chart available in Vue.js
Stars: ✭ 114 (-4.2%)
Mutual labels:  svg
React Native Svg Animations
SVG Animations wrapper for react-native.
Stars: ✭ 117 (-1.68%)
Mutual labels:  svg
React Fast Charts
Blazing Fast Charting Library in React with loading time less than 50ms
Stars: ✭ 113 (-5.04%)
Mutual labels:  svg
Svgdragtree
一个可以通过拖放 SVG 图标,来生成拥有树状结构的视图与数据的前端组件。 SDT example:
Stars: ✭ 113 (-5.04%)
Mutual labels:  svg
Tabler Icons
A set of over 1400 free MIT-licensed high-quality SVG icons for you to use in your web projects.
Stars: ✭ 10,858 (+9024.37%)
Mutual labels:  svg
Python Altium
Altium schematic format documentation, SVG converter and TK viewer
Stars: ✭ 112 (-5.88%)
Mutual labels:  svg
Geojson2svg
Converts geojson to svg string given svg viewport size and maps extent.
Stars: ✭ 117 (-1.68%)
Mutual labels:  svg
Warp Svg
Warp and distort SVG files online
Stars: ✭ 112 (-5.88%)
Mutual labels:  svg
Vue Weather
基于vue.js 2.0的天气应用demo
Stars: ✭ 116 (-2.52%)
Mutual labels:  svg
Svg Pathdata
Parse SVG PathDatas
Stars: ✭ 119 (+0%)
Mutual labels:  svg
Blazor.diagrams
A fully customizable and extensible all-purpose diagrams library for Blazor
Stars: ✭ 119 (+0%)
Mutual labels:  svg
Apexcharts.js
📊 Interactive JavaScript Charts built on SVG
Stars: ✭ 10,991 (+9136.13%)
Mutual labels:  svg

faces.js

A JavaScript library for generating vector-based cartoon faces

See a live demo here.

Why?

I wrote this to generate random cartoon faces for players in Basketball GM and Football GM. You can use it for similar purposes, or other purposes.

Help wanted!

I am not an artist! The faces look kind of shitty! If you would like to help, please keep reading. With version 2 of faces.js, it will hopefully be easier for people to contribute. Even if you're new to programming or to JavaScript, I am happy to help you.

Installation

npm install --save facesjs

or

yarn add facesjs

Use

Import it with ES modules:

import * as faces from "facesjs";

or CommonJS:

const faces = require("facesjs");

Then, generate a random face:

const face = faces.generate();

And display it:

// Display in a div with id "my-div-id"
faces.display("my-div-id", face);

// Display in a div you already have a reference to
const element = document.getElementById("my-div-id");
faces.display(element, face);

If you'd like a non-random face, look inside the face variable and you'll see all the available options for a manually constructed face.

Overrides

Both display and generate accept an optional final argument, specifying values to override either the randomly generated face (for generate) or the supplied face (for display). For instance:

# Generate a random face that always has blue skin
const face = faces.generate({ body: { color: "blue" } });

# Display a face, but impose that it has blue skin
faces.display("my-div-id", face, { body: { color: "blue" } });

Options

The generate function takes a second optional arguement, which takes in extra parameters for player creation, in the form of an object. Currently, you can assign a race attribute that can be white, black, asian, or brown.

# Generates a random player who will be white
const face = faces.generate(null, {race: "white"});

Development

Running yarn run start will do a few things:

  1. Open a face viewer UI in your browser
  2. Watch for changes to the code
  3. Watch for changes to the facial feature SVG files
  4. Update the face viewer UI when any code or SVG changes

This lets you immediately see your changes as you work.

Adding new facial features

Each face is assembled from multiple SVGs. You can see them within the "svg" folder. If you want to add another feature, just create an SVG (using a vector graphics editor like Inkscape) and put it in the appropriate folder. It should automatically work. If not, it's a bug, please let me know!

When creating SVGs, assume the size of the canvas is 400x600. For most features, it doesn't mater where you draw on the canvas because it will automatically identify your object and position it in the appropriate place. But for head and hair SVGs, position does matter. For those you do need to make sure they are in the correct place on a 400x600 canvas, same as the existing head and hair SVGs. Otherwise it won't know where to place the other facial features relative to the head and hair.

If you find it not quite placing a facial feature exactly where you want, it's because by default it finds the center of the eye/eyebrow/mouth/nose SVG and places that in a specific location. If that's not good for a certain facial feature, that behavior can be overridden in code. For instance, see how it's done in display.js for the "pinocchio" nose which uses the left side of the SVG rather than the center to place it.

If you want a brand new "class" of facial features (like facial hair, or earrings, or hats) you'll have to create a new subfolder within the "svg" folder and edit the code to recognize your new feature.

If you find any of this confusing, feel free to reach out to me for help! I would love for someone to help me make better looking faces :)

Technical details

Minimizing import size

If you generate and display faces in separate bundles, you can decrease file size by only including the display or generate function in each bundle. You can import the display and generate functions individually and rely on tree shaking from your bundler. ES modules:

import { display } from "facesjs";

or CommonJS:

const { generate } = require("facesjs");

Or, import them directly if you don't trust your bundler :). ES modules:

import generate from "facesjs/build/esmodules/generate";

or CommonJS:

const display = require("facesjs/build/commonjs/display");

Credits

dumbmatter wrote most of the code and TravisJB89 made most of the graphics.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].