npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

archaic

v2.0.1

Published

Reproduce images from geometric primitives.

Downloads

27

Readme

archaic

Reproduce images from geometric primitives (Node.js + browser port of primitive), forked from transitive-bullshit/primitive.

Table of Contents

Install

npm install --save archaic
# or
yarn add archaic
# or
bun install archaic

Usage

Archaic is usable from both Node.js and browser environments. Most of the API options between the two are the same, with minor differences in input and output configurations.

Available shape types:

  • triangle
  • circle
  • ellipse
  • rotated-ellipse
  • rectangle
  • rotated-rectangle
  • random (will use all the shape types)

How It Works

A target image is provided as input. The algorithm tries to find the single most optimal shape that can be drawn to minimize the error between the target image and the drawn image. It repeats this process, adding one shape at a time. Around 50 to 200 shapes are needed to reach a result that is recognizable yet artistic and abstract.

This GIF demonstrates the iterative nature of the algorithm, attempting to minimize the mean squared error by adding one shape at a time (use a ".gif" output file to generate one yourself).

Demo

Node API

Reproduces the given input image using geometric primitives.

Returns a Promise for the generated model.

Available output formats:

  • png
  • jpg
  • svg
  • gif

Type: function (opts): Promise

  • opts Object Configuration options
    • opts.input string Input image to process (can be a local path, http url, or data url)
    • opts.output string? Path to generate output image
    • opts.numSteps number Number of steps to process [1, 1000] (optional, default 200)
    • opts.minEnergy number? Minimum energy to stop processing early [0, 1]
    • opts.shapeAlpha number Alpha opacity of shapes [0, 255] (optional, default 128)
    • opts.shapeType string Type of shapes to use (optional, default traingle)
    • opts.numCandidates number Number of top-level candidates per step [1, 32] (optional, default 1)
    • opts.numCandidateShapes number Number of random candidate shapes per step [10, 1000] (optional, default 50)
    • opts.numCandidateMutations number Number of candidate mutations per step [10, 500] (optional, default 100)
    • opts.numCandidateExtras number Number of extra candidate shapes per step [0, 16] (optional, default 0)
    • opts.onStep function? Optional async function taking in the model and step index
    • opts.log function Optional logging function (console.log to enable logging) (optional, default noop)

Browser API

Reproduces the given input image using geometric primitives.

Optionally draws the results to an HTML canvas.

Returns a Promise for the generated model.

Type: function (opts): Promise

  • opts Object Configuration options
    • opts.input (string | Image | ImageData) URL, Image, or ImageData of input image to process
    • opts.output (string | HTMLCanvasElement)? Selector or DOM Element of HTMLCanvas to draw results
    • opts.numSteps number Number of steps to process [1, 1000] (optional, default 200)
    • opts.minEnergy number? Minimum energy to stop processing early [0, 1]
    • opts.shapeAlpha number Alpha opacity of shapes [0, 255] (optional, default 128)
    • opts.shapeType string Type of shapes to use (optional, default traingle)
    • opts.numCandidates number Number of top-level candidates per step [1, 32] (optional, default 1)
    • opts.numCandidateShapes number Number of random candidate shapes per step [10, 1000] (optional, default 50)
    • opts.numCandidateMutations number Number of candidate mutations per step [10, 500] (optional, default 100)
    • opts.numCandidateExtras number Number of extra candidate shapes per step [0, 16] (optional, default 0)
    • opts.onStep function? Optional async function taking in the model and step index
    • opts.log function Optional logging function (console.log to enable logging) (optional, default noop)

Related

There are several other ports of the primitive algorithm, including at least two JavaScript ports that I'm aware of. This module isn't necessarily better; I created it out of pure fascination.

Examples

alekzan-powell

atikh-bana

caleb-woods

glauco-zuccaccia

jessica-weiller

nicolas-picard

stefanus-martanto

timothy-paul-smith

umanoide

License

MIT © Giorgio Garasto

Original project by Travis Fischer.

All images are provided by Unsplash via a CC0 license.