1.0.6 • Published 2 years ago

image-tessellator v1.0.6

Weekly downloads
2
License
ISC
Repository
github
Last release
2 years ago

Tessellations

This project is a cute little program that loads up a random image and draws triangles over it. It is meant to be nothing more than a simple screen saver like application.

Available as an npm package

Live Demo

Navigate to https://edricy.github.io/Tessellations/demo (tested in Google Chrome)

Download

npm install image-tessellator

File include

<script src="tessellator.js"></script>

ES6 Module

import ImageTessellator from path/to/tessellator.es.js';

CommonJS

require("image-tesselator");

Basic Usage

See the demo code

Setup your canvas like you want it.

<style>
#c {
	width: 50vw;
	height: 50vh;
}
</style>
<canvas id="c"></canvas>

include the script <script src="/path/to/tessellator.js"></script>

call the constructor

let c = document.getElementById("c");
let src = "path/to/img.png"
let tess = new  ImageTessellator(c, src, {loadCallback: "playAnimation"});

Options

PropertyDefaultNotes
imgSampleRatio.010 to 1. smaller value means less color accuracy but faster processing
fitMethodFitOptions.FITSpecifies how the canvas is fit to the container
traversalModeTraversalOptions.LARGEST_FIRSTSpecifies what order triangles are processed
splitModeSplitOptions.HALVESpecifies how the triangles are split
loadCallbacknullcalled after the image loads
backgroundColor#567
strokeColor#555
doStroketrue
minColorArea50
itersPerTick200
areaPerTick10000
tickMinDuration0
renderImgPiecesfalseset to true to draw pieces of the actual image when triangles are tiny
doFadeAfterfalsefade the actual image on top when finished. renderImgPieces must be false
fadeDelay500,number of ms to wait before doing the after fade

An example with different options specified: https://edricy.github.io/Tessellations/demo?splitMode=1&traversalMode=1&doStroke=false&doFadeAfter=true

FitOptions:
FIT: 0      // largest possible size while still fitting inside canvas
FILL: 1     // fill canvas completely while keeping aspect ratio
SAME: 2     // draw at original image size
STRETCH: 3  // stretch to canvas dimensions

TraversalOptions:
LARGEST_FIRST: 0
IN_ORDER: 1
RANDOM_ORDER: 2

SplitOptions:
HALVE: 0
SIERPINSKI: 1
CENTROID: 2