Coder Social home page Coder Social logo

hexalattice's Introduction

hexalattice

Generate and plot hexagonal lattices in 2D, with fine control over spacing between hexagons, arbitrary rotation of the grid around central tile, etc. The module computes and returns the center point for each fo the tiles in the lattice.

Installation

PyPI version python version conda downloads_anaconda license

# Using pip
pip install hexalattice
# Using conda
conda install -c conda-forge hexalattice

Usage example

Create and plot 5x5 lattice of hexagons (as in first image):

from hexalattice.hexalattice import *
hex_centers, _ = create_hex_grid(nx=5,
                                 ny=5,
                                 do_plot=True)
                                 
plt.show()    # import matplotlib.pyplot as plt

Get central points of the hexagons:

tile_centers_x = hex_centers[:, 0]
tile_centers_y = hex_centers[:, 1]

Plot one grid over the other, second with spacing around the hexagons:

_, h_ax = create_hex_grid(nx=5, 
                          ny=7,
                          do_plot=True,
                          edge_color=(0.85, 0.85, 0.85))
                                    
create_hex_grid(nx=5,
                ny=7,
                do_plot=True,
                edge_color=(0.25,0.25, 0.25),
                h_ax=h_ax,
                plotting_gap=0.3)
plt.show()

Create Moiré pattern from two circularly cropped hexagrids:

hex_grid1, h_ax = create_hex_grid(nx=50,
                                  ny=50,
                                  rotate_deg=0,
                                  min_diam=1,
                                  crop_circ=20,
                                  do_plot=True)
    create_hex_grid(nx=50,
                    ny=50,
                    min_diam=1,
                    rotate_deg=5,
                    crop_circ=20,
                    do_plot=True,
                    h_ax=h_ax)

For API and additional examples see the wiki hexalattice API.

Release History

  • v1.0 - First version
  • v1.1 - Added the option to assign different colors to hexagons

About & License

Alex Kazakov – @bio_vs_silico[email protected]

Distributed under the MIT license. See LICENSE for more information.

https://github.com/alexkaz2/hexalattice

hexalattice's People

Contributors

alexkaz2 avatar

Watchers

James Cloos avatar  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.