Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fauna

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fauna - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

.travis.yml

21

package.json
{
"name": "fauna",
"version": "0.2.0",
"version": "0.3.0",
"description": "Generate and render animated L-Systems",
"main": "src/index.js",
"scripts": {
"test": "mocha src/*.spec.js -w"
"commit": "git-cz",
"test": "mocha src/*.spec.js -w",
"test:single": "mocha src/*.spec.js",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},

@@ -21,4 +24,14 @@ "repository": {

"chai": "^3.5.0",
"mocha": "^2.5.3"
"commitizen": "^2.8.6",
"cz-conventional-changelog": "^1.2.0",
"mocha": "^2.5.3",
"rewire": "^2.5.2",
"semantic-release": "^4.3.5"
},
"czConfig": {
"path": "node_modules/cz-conventional-changelog"
},
"dependencies": {
"xml": "^1.0.1"
}
}
}
# fauna
Javascript library for generating L-Systems
[![Build Status][build]][link]
[![semantic-release][semantic-image] ][semantic-url]
[build]: https://travis-ci.org/bradleybossard/fauna.svg?branch=master
[link]: https://travis-ci.org/bradleybossard/fauna
[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[semantic-url]: https://github.com/semantic-release/semantic-release
### Publish a new version

@@ -6,0 +13,0 @@

@@ -0,1 +1,24 @@

function pathString(stack) {
let path = [];
stack.forEach(function(p) {
path.push(`${p.c} ${p.x} ${p.y}`);
});
return path.join(' ');
}
function boundingBox(stack) {
let x = y = 0;
let minX = minY = Infinity;
let maxX = maxY = -Infinity;
stack.forEach(function(p) {
x = (p.c === 'M') ? p.x : x + p.x;
y = (p.c === 'M') ? p.y : x + p.y;
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
});
return {'minX': minX, 'minY': minY, 'maxX': maxX, 'maxY': maxY};
}
exports.iterate = function(axiom, rules, iterations) {

@@ -9,1 +32,60 @@ for (var i = 0; i < iterations; i++) {

}
exports.toCommands = function(length, alpha, lengthGrowth, alphaGrowth, stream) {
let point = {'x': 0, 'y': 0};
let angle = -90;
let pathLength = 0;
let lineLength = length;
let tempStack = [];
let stack = [{'c': 'M', 'x': 0, 'y': 0}];
for(var i = 0, c =''; c = stream.charAt(i); i++){
switch(c) {
case '(':
alpha *= 1 - angleGrowth;
break;
case ')':
alpha *= 1 + angleGrowth;
break;
case '<':
lineLength *= 1 - lengthGrowth;
break;
case '>':
lineLength *= 1 + lengthGrowth;
break;
case 'F':
const deltaX = lineLength * Math.cos(Math.PI / 180 * angle)
const deltaY = lineLength * Math.sin(Math.PI / 180 * angle)
stack.push({'c': 'l', 'x': 0, 'y': 0});
point.x += deltaX;
point.y += deltaY;
break;
case '+':
angle += alpha;
break;
case '-':
angle -= alpha;
break;
case '[':
tempStack.push({'angle': angle, 'point': point, 'alpha': alpha});
break;
case ']':
angle, point, alpha = tempStack.pop()
break;
case '!':
angle *= -1.0;
break;
case '|':
angle += 180;
break;
}
}
return stack;
}
exports.toPaths = function(stack) {
const xml = require('xml');
return pathString(stack);
}

@@ -1,9 +0,62 @@

var expect = require('chai').expect;
var fauna = require('./index.js');
const expect = require('chai').expect;
const rewire = require('rewire');
const fauna = rewire('./index.js');
const pathString = fauna.__get__('pathString');
const boundingBox = fauna.__get__('boundingBox');
describe('iterate test', function() {
it('simple iteration', function() {
const expandedString = fauna.iterate('a', {'a': 'bab'}, 2);
expect(expandedString).to.be.equal('bbabb');
it('simple iteration', function(done) {
const expandedString = fauna.iterate('L', {'L': 'LFLR+'}, 2);
expect(expandedString).to.be.equal('LFLR+FLFLR+R+');
done();
});
it('simple iteration', function(done) {
const expandedString = fauna.iterate('a', {'a': 'bac', 'c': 'ddd'}, 4);
expect(expandedString).to.be.equal('bbbbacddddddddd');
done();
});
});
describe('toCommands test', function() {
it('covert stream', function(done) {
const expected = [{ c: 'M', x: 0, y: 0 },
{ c: 'l', x: 0, y: 0 },
{ c: 'l', x: 0, y: 0 },
{ c: 'l', x: 0, y: 0 }];
const commands = fauna.toCommands(1, 30, 0.1, 0.1, 'LFLR+FLFLR+R+');
expect(commands).to.be.deep.equal(expected);
done();
});
});
describe('pathString test', function() {
it('should compose the pathString', function(done) {
const stack = [{ c: 'M', x: 0, y: 0 },
{ c: 'l', x: 0, y: 0 },
{ c: 'l', x: 0, y: 0 },
{ c: 'l', x: 0, y: 0 }];
const expected = 'M 0 0 l 0 0 l 0 0 l 0 0';
const path = pathString(stack);
expect(path).to.be.equal(expected);
done();
});
});
describe('boundingBox test', function() {
it('should calculate the bounding box properly', function(done) {
const stack = [{ c: 'M', x: -4, y: 0 },
{ c: 'M', x: 0, y: -4 },
{ c: 'M', x: 4, y: 0 },
{ c: 'M', x: 0, y: 4 }];
const expected = {'minX': -4, 'minY': -4, 'maxX': 4, 'maxY': 4};
const box = boundingBox(stack);
expect(box).to.be.deep.equal(expected);
done();
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc