Skip to content

Commit

Permalink
adding polyline and random
Browse files Browse the repository at this point in the history
  • Loading branch information
romellogoodman committed Jan 19, 2021
1 parent 5d7e2df commit 2e5e55e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ A library for creating svgs. Learn more at [goodgraphics.xyz/about](https://good
Pros

- chainable api
- zero dependencies
- made with ❤️

Cons
Expand Down Expand Up @@ -110,15 +109,43 @@ Re-draws the svg.
- `@param {String | Number} y2` The y position of the end of the line.
- `@param {String | Number} opts` tk.

### `polyline()`
### `polyline(points, opts)`

tk
- `@param {Array [Strings]} points` Series of points on the line.
- `@param {String | Number} opts` tk.

### `group(draw, opts)`

- `@param {Function} draw` The draw function. Called with the arguments tk.
- `@param {String | Number} opts` tk.

```js
// TODO: how to use tk
```

### `times(number, draw)`

Runs the draw function x number of times.

- `@param {Number} number` The number of times to run the loop.
- `@param {Function} draw` The draw function. Called with the arguments tk.

```js
// TODO: how to use tk
```

### `grid(cols, rows, draw)`

tk

```js
// TODO: how to use tk
```

## Non-Chainable Utils

The following are not chainable

### `map(number, inMin, inMax, outMin, outMax)`

Maps a value from one range to another.
Expand All @@ -129,18 +156,14 @@ Maps a value from one range to another.
- `@param {Number} outMin` The min for the second range.
- `@param {Number} outMax` The max for the second range.

### `spline()`
### `random(min, max)`

tk
Get a random number between two numbers.

### `times(number, draw)`

Runs the draw function x number of times.

- `@param {Number} number` The number of times to run the loop.
- `@param {Function} draw` The draw function. Called with the arguments tk.
- `@param {Number} min` The min of the range.
- `@param {Number} max` The max of the range.

### `grid(cols, rows, draw)`
### `spline()`

tk

Expand Down
41 changes: 23 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ export default class Graphic {
return this;
}

polyline() {
console.log('polyline');
this.add('polyline');
polyline(points, opts = {}) {
this.add(`<polyline points="${points}" ${convertAttributes(opts)} />`);

return this;
}
Expand All @@ -170,22 +169,8 @@ export default class Graphic {
}

/**
* Helper Functions
*/

/**
* Map a number from one range to another range
* https://gist.github.com/xposedbones/75ebaef3c10060a3ee3b246166caab56
* "Series" Functions (TBD on the name)
*/
map(number, inMin, inMax, outMin, outMax) {
return ((number - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
}

spline() {
console.log('spline tk');

return this;
}

times(number, draw) {
for (let x = 0; x < number; x++) {
Expand All @@ -211,4 +196,24 @@ export default class Graphic {

return this;
}

/**
* Helper Functions
*/

/**
* Map a number from one range to another range
* https://gist.github.com/xposedbones/75ebaef3c10060a3ee3b246166caab56
*/
map(number, inMin, inMax, outMin, outMax) {
return ((number - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
}

spline() {
return [];
}

random(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
}

0 comments on commit 2e5e55e

Please sign in to comment.