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

gen-city

v1.4.4

Published

Procedural generation city

Downloads

32

Readme

⚡ Gen City

Version Small size Build

Procedural city generation

.

Demo

Documentation

.

Install

npm i gen-city

.

Generation

Create city

const city = new City(params)

| Param | Description | Default | | ------|-------------|---------| | width | Map width | - | | height | Map height | - |

Generate

await city.generate(params?)

| Param | Description | Default | | ------|-------------|---------| | mode | Generation mode.* Runtime - Random generation in runtime* Seed - Generation follows the specified seed | Runtime | | seed | Generation seed array for seed mode | - | | startPosition | Position of the first node. | Center of map | | startDirections | Start generation directions | Left, Right, Top, Bottom | | streetMinLength | Street length before generating an intersection or turn | 10 | | probabilityIntersection | Probability of generating intersection | 0.1 | | probabilityTurn | Probability of generating turn | 0.05 | | probabilityStreetEnd | Probability of generating street end | 0.001 | | buildingMinSize | Minimum building size | 3 | | buildingMaxSize | Maximum building size | 6 | | buildingMinSpace | Minimum distance between buildings | 1 | | buildingMaxSpace | Maximum distance between buildings | 3 | | buildingOffset | Distance between building and path | 0 |

.

General

Get size

const width = city.width
const height = city.height

Get seed

Return seed if city was generated with runtime mode

const seed = city.getSeed(): number[] | null

.

Nodes

Get all nodes

const nodes = city.getAllNodes(): Node[]

Get node paths

const inputPaths = node.getInputPaths(): Path[]
const outputPaths = node.getOutputPaths(): Path[]
const allPaths = node.getAllPaths(): Path[]

Get node type

Get type by count of input and output paths (Turn, Cross, End)

const type = node.getType(): NodeType

.

Paths

Get all paths

const paths = city.getAllPaths(): Path[]

Get path positions

const positions = path.getPositions(): { 
  beg: Position
  end: Position
}

Get path nodes

const nodeBeg = path.getNodeBeg(): Node
const nodeEnd = path.getNodeEnd(): Node

Get path length

const length = path.getLength(): number

Each path positions

path.each(callback: (position: Position) => void)

Remove path from nodes

path.remove()

Get path buildings

const buildings = path.getBuildings(): Building[]

Get path direction

Get direction in degrees

const direction: number = path.direction

.

Buildings

Get all buildings

const buildings = city.getAllBuildings(): Building[]

Get building vertices

Array of rectangle corners positions

const vertices: Position[] = building.vertices

Get building position

Get top left corner position

const position: Position = building.position

Get building size

const width: number = building.width
const height: number = building.height

Each building positions

building.each(callback: (position: Position) => void)

Remove building from path

building.remove()

.

Example

const city = new City({
  width: 200,
  height: 200,
});

city.generate({
  streetMinLength: 15,
}).then(() => {
  // Draw roads
  ctx.beginPath();
  city.getAllPaths().forEach((path) => {
    const positions = path.getPositions();
    ctx.moveTo(positions.beg.x, positions.beg.y);
    ctx.lineTo(positions.end.x, positions.end.y);
  });
  ctx.stroke();

  // Draw buildings
  city.getAllBuildings().forEach((building) => {
    ctx.fillRect(
      building.position.x,
      building.position.y,
      building.width,
      building.height
    );
  });
});