Giter VIP home page Giter VIP logo

quasi's Introduction

quasi-svg — SVG quasicrystals in JS

This is a port of Eric Weeks' quasi.c, which can still be found all the way back in 1995: http://www.physics.emory.edu/faculty/weeks/software/quasic.html.

I made a few modifications, including supporting SVG output in addition to PostScript, but overall the heart of the generator is a straight port. As such, it has a certain amount of undocumented magic (it also looks a lot more like C than the usual JS).

It should be relatively straightforward to add canvas support as well. If you're interested and have questions, don't hesitate to contact me.

Node Installation

Nothing but the usual:

npm install quasi-svg

In the browser

Just use one of the files (minified or not) from inside dist. Only the SVG module is provided, PostScript somehow seemed redundant in the browser. The file contains the minimal Browserify AMD code; if it's not loaded through a module system it makes itself available using the Quasi global. You can then call Quasi.svg() with some options.

API

If you require("quasi-svg") the following three methods are available. They can also be required individually as quasi-svg/svg for the SVG part, quasi-svg/ps to generate PostScript, and quasi-svg/quasi for the core engine.

  • svg([options]). Takes some options and generates an SVG string. Same options as ps().
  • ps([options]) Takes some options and generates a PostScript string. The options are an object with the following keys, all optional:
    • size (Number). A scaling factor.
    • fillPolygons (Boolean). Fills the polygons.
    • fillColor (Boolean). Fill colour is according to polygon type (also sets fillPolygons).
    • rotate (Boolean). Flip 90°.
    • magnify (Number). Magnification factor.
    • skinnyMidpoint (Enum) Midpoint type for skinny diamonds, takes enumerated values below.
    • fatMidpoint (Enum) Midpoint type for fat diamonds, takes enumerated values below.
      • 1: acute angle sides joined
      • 2: obtuse angle sides joined
      • 3: opposite sides joined to make cross
      • 4: all sides joined to make rectangle
      • 5: randomly choose 1 or 2
      • 6: randomly choose 1, 2, or 4
    • symmetry (Int). Degrees of symmetry.
    • lines (Int). Number of lines to use.
    • strokeWidth (Number). The stroke width for drawing.
    • color (Boolean). To be used with fillColor, if set will generate pretty-looking colours for the fills.
  • quasi(options, writer). This is the core engine that generates the quasicrystals. It takes the same options as the other two plus a writer. The writer is basically an object that quasi controls in order to tell it to produce the output. Look at the source of the svg and ps modules for details.

Examples

Here are a few examples (you can get a fair bit fancier). Note that they are also available as SVG, but GitHub will only let you embed PNG (for good reasons, too):

The default output

The default output

skinnyMidpoint=1, fatMidpoint=1

M1N1

skinnyMidpoint=1, fatMidpoint=2

M1N2

skinnyMidpoint=2, fatMidpoint=1

M2N1

skinnyMidpoint=2, fatMidpoint=2

M2N2

skinnyMidpoint=3, fatMidpoint=3

M3N3

skinnyMidpoint=5, fatMidpoint=5

M5N5

symmetry=14

S14

fillColor=true, magnify=0.6, symmetry=7

zm0.6S7

fillColor=true, lines=80, magnify=0.3

zn80m0.3

Several variants with color=true

S7n84M2N2zs03-colour zm0.6S7-colour zn80m0.3-colour

quasi's People

Contributors

darobin avatar

Stargazers

James Hart avatar  avatar foundartfactory avatar Venkatesh avatar  avatar Pixelomo avatar Zineb avatar Othman Alamoudi avatar Alex Capaldo avatar Steven Olsen avatar sonopictorial avatar jinho park avatar  avatar Lena Guerrero avatar Yann Di Serio avatar davay avatar Edouard SCHWEISGUTH avatar Pedro Simão avatar Ahmad Kiarostami avatar  avatar  avatar Bitluck avatar  avatar David Walsh avatar  avatar  avatar Vlad Dumitrescu avatar BethanyG avatar Joseph Kunin avatar  avatar Ondřej Tuček avatar undeadinu avatar Ja Sub Al avatar Morgan avatar  avatar  avatar hansen avatar Rhys avatar Manuel González avatar Kyle Cunningham avatar Dan Marshall avatar Boris Smirnov avatar Randy Pond avatar  avatar Thomas Jund avatar Ravi Varma Polakonda avatar M. C. DeMarco avatar Alex Ferreira avatar Simon Snow avatar pandecheng avatar imkarl avatar @printminion avatar Eko Adi Wijayanto avatar Andrew Starodubtsev avatar Juri Leino avatar 子龙 avatar Stéphane Klein avatar Billy Z Duke avatar Guillermo Greising avatar The Algebraist avatar James Hernandez avatar  avatar Stacey Reiman avatar Jeff French avatar Alan Kang avatar John-Michael Baldy avatar Philippe Lhoste avatar timelyportfolio avatar Joohun, Maeng avatar Andrea avatar Sam avatar Michael Anthony avatar Rasso Hilber avatar Jonathan Puckey avatar Innovimax avatar Jorge avatar Samy Rabih avatar

Watchers

 avatar timelyportfolio avatar James Cloos avatar Guillermo Greising avatar Michael Anthony avatar Mike 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.