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

@davepagurek/p5.csg

v0.0.3

Published

This is a library for doing <a href="https://en.wikipedia.org/wiki/Constructive_solid_geometry">constructive solid geometry (CSG)</a> in p5.js. It is powered under the hood by <a href="https://github.com/evanw/csg.js/">csg.js</a> by Evan Wallace, augmente

Downloads

76

Readme

p5.csg

This is a library for doing constructive solid geometry (CSG) in p5.js. It is powered under the hood by csg.js by Evan Wallace, augmented to accept and return p5.Geometry.

Usage

Adding the library

Add the library in a script tag:

<script src="https://cdn.jsdelivr.net/npm/@davepagurek/[email protected]"></script>

Or on OpenProcessing, add the CDN link as a library:

https://cdn.jsdelivr.net/npm/@davepagurek/[email protected]

If you're using p5 without importing it globally, you can manually set up p5.csg:

import P5 from 'p5'
import { setupCSG } from '@davepagurek/p5.csg'
setupCSG(P5)

Example

let deathStar

function setup() {
  createCanvas(400, 400, WEBGL)

  deathStar = csg(() => sphere(50))
    .subtract(() => {
      translate(40, -40)
      sphere(25)
    })
    .union(() => sphere(40))
    .done()
}

function draw() {
  clear()
  orbitControl()
  noStroke()
  lights()
  model(deathStar)
}

Live: https://editor.p5js.org/davepagurek/sketches/f5QmdBoVI

Reference

Create a new CSG wrapper object with the csg function. It takes one of the following two inputs:

// Pass in an existing p5.Geometry
csg(geometry: p5.Geometry): CSGWrapper

// Pass in an input to `buildGeometry()`, which we will automatically
// convert into a new p5.Geometry under the hood
csg(buildGeometryCallback: Function): CSGWrapper

Once a CSG wrapper object has been created, you can apply a Boolean operation to create a new CSG object, or call done() on it to get a p5.Geometry you can draw:

// Take the boundary of both shapes
myCSG.union(other: CSGInput, options?: BooleanOptions): CSGWrapper

// Take a bite out of the current geometry, in the shape of the other
myCSG.subtract(other: CSGInput, options?: BooleanOptions): CSGWrapper

// Take just the region that overlaps between two shapes
myCSG.intersect(other: CSGInput, options?: BooleanOptions): CSGWrapper

// Flip the inside and outside of the current shape
myCSG.invert(): CSGWrapper

myCSG.done(): p5.Geometry

// Inputs to CSG methods can be either another CSG wrapper object,
// a p5.Geometry, or a `buildGeometry` callback function.
type CSGInput = CSGWrapper | p5.Geometry | Function

// Optionally specify whether or not to include faces from one input
// or another in the end result. By default, both are included, so
// if you subtract one shape from another, you will still get a closed
// shape as a result. If you do not include the other shape's faces,
// the subtraction will leave a hole.
type BooleanOptions = {
  includeSelfFaces?: boolean;
  includeOtherFaces?: boolean;
}