GithubHelp home page GithubHelp logo

polygen's Introduction

PolyGen

A demo application for procedural generation of 2D polygons

Video

Watch the video

Description

Polygon Generation Script

I needed some polygons for a game I’m working on so I spent a week developing a procedural polygon generator script that can generate polygons based on a few parameters that I can control in real-time.

Iteration 1: Randomness

Randomly create a few points in 2d space and connect them to each other.

This creates a polygon, but it does not always work. This is because with this approach, some lines can intersect, and then it's no longer a simple polygon.

Iteration 2: Simple Polygons

Make sure that no lines are intersecting. Generate some random points, but instead of connecting them right away, first sort them based on angle and THEN connect them.

This works much better but it looks too random and there is no control over what shape you get (except for how many sides it has).

Iteration 3: Regular Polygons

To generate a square, or a hexagon, or any other regular polygon, we need a polygon where all sides are equal in length.

We have the angle and the radius and we can use that calculate the corresponding x,y vectors

Iteration 4: Irregular Polygons

If we make the angles between the points random we bring back some randomness to our regular polygons,

Iteration 5: Concave Polygons

So far, we can generate convex polygons which means that all of its points are pointing outwards. A concave polygon has at least one point pointing inward. So I take a few points and move them in or out by adding a random value to the radius.

Iteration 6: Greyscale Mode

A “greyscale mode”

Download

Version 1.0.0

polygen's People

Contributors

hackenshaw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.