Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidchambers/orthogonal
DSL for describing simple vector graphics
https://github.com/davidchambers/orthogonal
Last synced: 3 months ago
JSON representation
DSL for describing simple vector graphics
- Host: GitHub
- URL: https://github.com/davidchambers/orthogonal
- Owner: davidchambers
- License: wtfpl
- Created: 2014-02-02T20:41:52.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2021-11-12T08:38:25.000Z (about 3 years ago)
- Last Synced: 2024-10-09T12:07:43.468Z (3 months ago)
- Language: CoffeeScript
- Size: 78.1 KB
- Stars: 14
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Orthogonal is a DSL for describing simple vector graphics. It can be used in
JavaScript or any compiles-to-JavaScript language. The following examples are
written in [CoffeeScript][1].Here’s “Hello, world” in Orthogonal:
```coffeescript
orthogonal = require 'orthogonal'square = (orthogonal.R 2)(orthogonal.D 2)(orthogonal.L 2)(orthogonal.U 2)
```Right two, down two, left two, up two. This “draws” a 2×2 square.
It’s possible to extend the global object to make the R, D, L, and U functions
(and their lower-case counterparts) easier to reference:```coffeescript
require('orthogonal').extend(global)square = (R 2)(D 2)(L 2)(U 2)
```Now for something a bit more advanced:
The source code is in [octocat.coffee][2].
### API
#### orthogonal.{R,D,L,U}(magnitude)
“Draw” a line in the direction determined by the function (e.g. right in the
case of orthogonal.R). A filled region can be described by “drawing” several
line segments in succession.#### orthogonal.{r,d,l,u}(magnitude)
Move in the direction determined by the function (e.g. right in the case of
orthogonal.r). These functions reposition the “pen”, making it possible to
describe multiple filled regions.#### orthogonal.extend(object)
Attach orthogonal.{R,D,L,U,r,d,l,u} to the provided object. Extending the
global object is recommended.#### orthogonal.bounds([[x0,y0],[x1,y1],...,[xN,yN]], scale = 1)
Determine the bounds — expressed as [left,top,right,bottom] — for
the provided array of coordinates.#### orthogonal.formatters.svg(path, scale = 1)
Get the SVG representation of the provided path.
```coffeescript
orthogonal.formatters.svg (r 8)(d 8)(R 2)(D 2)
# => 'm 8,8 l 2,0 l 0,2'
```[1]: http://coffeescript.org/
[2]: https://github.com/davidchambers/orthogonal/blob/master/src/svg/octocat.coffee