Skip to content

Latest commit

 

History

History

geom

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@thi.ng/geom

npm (scoped)

This project is part of the @thi.ng/umbrella monorepo.

About

This package is a partial WIP port of selected features of the Clojure/ClojureScript version of thi.ng/geom, as well as c.thi.ng. Currently only 2D shapes & operations are supported.

This package will soon be replaced by the currently still unreleased @thi.ng/geom2 package

Status

ALPHA - major breaking changes forthcoming...

Installation

yarn add @thi.ng/geom

Usage examples

Tessellations

sample output

import * as g from "@thi.ng/geom";
import * as v from "@thi.ng/vectors";
import * as h from "@thi.ng/hiccup";
import * as svg from "@thi.ng/hiccup-svg";
import * as fs from "fs";

const tintedPoly = (points) => {
    const p = g.polygon2(points);
    const c = p.centroid().toPolar();
    p.attribs = { fill: `hsl(${v.deg(c.y)},${c.x}%,${100-c.x/2}%)` };
    return p;
};

fs.writeFileSync(
    "tessel.svg",
    h.serialize(
        svg.svg(
            {
                width: 1000, height: 1000,
                viewBox: "-100 -100 200 200",
                fill: "none",
                stroke: "#000",
                "stroke-width": 0.5,
            },
            svg.convertTree(
                g.circle2(100)
                    .toPolygon(6)
                    .tessellate([g.quadFan, g.triFan, g.edgeSplit, g.quadFan])
                    .map((pts) => tintedPoly(pts).toHiccup())
            )
        )
    )
);

Subdivision curves

Chaikin (closed) Chaikin (open)
chaikin closed chaikin open
g.polygon2([-100,-100, 0,100, 100,-100, 0,0]).subdivide(g.CHAIKIN_CLOSED, 4);
g.polyline2([-100,100, -100,-100, 0,0, 100,-100, 100,100]).subdivide(g.CHAIKIN_OPEN, 4);

Authors

  • Karsten Schmidt

License

© 2013 - 2018 Karsten Schmidt // Apache Software License 2.0