@code-not-art/core
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -0,0 +0,0 @@ export declare enum BlendMode { |
@@ -0,0 +0,0 @@ export var BlendMode; |
@@ -0,0 +0,0 @@ import { Path } from '../structures'; |
export {}; | ||
//# sourceMappingURL=Brush.js.map |
@@ -0,0 +0,0 @@ import Vec2 from '../math/Vec2'; |
@@ -1,145 +0,11 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import Vec2 from '../math/Vec2'; | ||
import { Draw } from './Draw'; | ||
var Canvas = /** @class */ (function () { | ||
function Canvas(canvas) { | ||
var _this = this; | ||
this._transforms = []; | ||
this.get = { | ||
// Canvas size | ||
/** | ||
* Canvas width (in pixels) | ||
* @returns {number} | ||
*/ | ||
width: function () { return _this.canvas.width; }, | ||
/** | ||
* Canvas Height (in pixels) | ||
* @returns {number} | ||
*/ | ||
height: function () { return _this.canvas.height; }, | ||
/** | ||
* Minimum dimension, the lesser of width and height | ||
* @returns {number} | ||
*/ | ||
minDim: function () { return Math.min(_this.canvas.width, _this.canvas.height); }, | ||
/** | ||
* Maximum dimension, the greater of width and height | ||
* @returns {number} | ||
*/ | ||
maxDim: function () { return Math.max(_this.canvas.width, _this.canvas.height); }, | ||
/** | ||
* The ratio of width to height | ||
* @returns {number} | ||
*/ | ||
aspectRatio: function () { return _this.canvas.width / _this.canvas.height; }, | ||
size: function () { return new Vec2(_this.canvas.width, _this.canvas.height); }, | ||
/** | ||
* Center of the canvas (width/2, height/2) | ||
* @returns {Vec2} | ||
*/ | ||
center: function () { return new Vec2(_this.canvas.width / 2, _this.canvas.height / 2); }, | ||
// context state | ||
blendMode: function () { return _this.context.globalCompositeOperation; }, | ||
transform: function () { return _this.context.getTransform(); }, | ||
}; | ||
this.set = { | ||
size: function (width, height) { | ||
_this.canvas.height = height; | ||
_this.canvas.width = width; | ||
}, | ||
blendMode: function (mode) { | ||
_this.context.globalCompositeOperation = mode; | ||
}, | ||
transform: function (transform) { | ||
_this.context.setTransform(transform); | ||
}, | ||
}; | ||
// TODO: Both clear and fill need to have code that resets all context translate/rotations and then restore the previous | ||
/** | ||
* Reset the content on the canvas. Will clear all current marks and return to full transparent. | ||
*/ | ||
this.clear = function () { | ||
_this.context.clearRect(0, 0, _this.get.width(), _this.get.height()); | ||
}; | ||
/** | ||
* Fill the entire canvas with a single color | ||
* @param fill | ||
*/ | ||
this.fill = function (fill) { | ||
var storedTransform = _this.context.getTransform(); | ||
_this.context.resetTransform(); | ||
_this.draw.rect({ | ||
point: Vec2.origin(), | ||
height: _this.get.height(), | ||
width: _this.get.width(), | ||
fill: fill, | ||
}); | ||
_this.context.setTransform(storedTransform); | ||
}; | ||
this.transform = { | ||
push: function () { | ||
_this._transforms.push(_this.context.getTransform()); | ||
return _this.transform; | ||
}, | ||
pop: function () { | ||
var storedTransform = _this._transforms.pop(); | ||
if (storedTransform) { | ||
_this.context.setTransform(storedTransform); | ||
} | ||
else { | ||
_this.context.resetTransform(); | ||
} | ||
return _this.transform; | ||
}, | ||
reset: function () { | ||
_this.context.resetTransform(); | ||
return _this.transform; | ||
}, | ||
set: function (transform) { | ||
_this.context.setTransform(transform); | ||
return _this.transform; | ||
}, | ||
// ===== Move the draw position | ||
translate: function (vector) { | ||
_this.context.translate(vector.x, vector.y); | ||
return _this.transform; | ||
}, | ||
scale: function (factor) { | ||
_this.context.scale(factor.x, factor.y); | ||
return _this.transform; | ||
}, | ||
rotate: function (radians) { | ||
_this.context.rotate(radians); | ||
return _this.transform; | ||
}, | ||
flipHorizontal: function () { | ||
_this.context.scale(-1, 1); | ||
return _this.transform; | ||
}, | ||
flipVertical: function () { | ||
_this.context.scale(1, -1); | ||
return _this.transform; | ||
}, | ||
}; | ||
// ===== Get and Merge layers | ||
this.layer = function () { | ||
// probably dont need to get doc from the canvas, could probably just use `document` but maybe there is some edge condition where this matters. | ||
var doc = _this.canvas.ownerDocument; | ||
var layer = doc.createElement('canvas'); | ||
layer.width = _this.canvas.width; | ||
layer.height = _this.canvas.height; | ||
return new Canvas(layer); | ||
}; | ||
export class Canvas { | ||
canvas; | ||
context; | ||
draw; | ||
_transforms = []; | ||
constructor(canvas) { | ||
this.canvas = canvas; | ||
var maybeContext = canvas.getContext('2d'); | ||
const maybeContext = canvas.getContext('2d'); | ||
if (!maybeContext) { | ||
@@ -159,16 +25,138 @@ // Handling potential return of `undefined` - Don't ever expect this but we're playing nice with TypeScript | ||
*/ | ||
Canvas.fromId = function (canvasId) { | ||
var canvas = document.getElementById(canvasId); | ||
static fromId(canvasId) { | ||
const canvas = document.getElementById(canvasId); | ||
if (!canvas) { | ||
throw new Error("Could not find canvas element with id ".concat(canvasId)); | ||
throw new Error(`Could not find canvas element with id ${canvasId}`); | ||
} | ||
return new Canvas(canvas); | ||
} | ||
get = { | ||
// Canvas size | ||
/** | ||
* Canvas width (in pixels) | ||
* @returns {number} | ||
*/ | ||
width: () => this.canvas.width, | ||
/** | ||
* Canvas Height (in pixels) | ||
* @returns {number} | ||
*/ | ||
height: () => this.canvas.height, | ||
/** | ||
* Minimum dimension, the lesser of width and height | ||
* @returns {number} | ||
*/ | ||
minDim: () => Math.min(this.canvas.width, this.canvas.height), | ||
/** | ||
* Maximum dimension, the greater of width and height | ||
* @returns {number} | ||
*/ | ||
maxDim: () => Math.max(this.canvas.width, this.canvas.height), | ||
/** | ||
* The ratio of width to height | ||
* @returns {number} | ||
*/ | ||
aspectRatio: () => this.canvas.width / this.canvas.height, | ||
size: () => new Vec2(this.canvas.width, this.canvas.height), | ||
/** | ||
* Center of the canvas (width/2, height/2) | ||
* @returns {Vec2} | ||
*/ | ||
center: () => new Vec2(this.canvas.width / 2, this.canvas.height / 2), | ||
// context state | ||
blendMode: () => this.context.globalCompositeOperation, | ||
transform: () => this.context.getTransform(), | ||
}; | ||
Canvas.prototype.apply = function (layer, options) { | ||
if (options === void 0) { options = {}; } | ||
this.draw.stamp(__assign({ source: layer }, options)); | ||
set = { | ||
size: (width, height) => { | ||
this.canvas.height = height; | ||
this.canvas.width = width; | ||
}, | ||
blendMode: (mode) => { | ||
this.context.globalCompositeOperation = mode; | ||
}, | ||
transform: (transform) => { | ||
this.context.setTransform(transform); | ||
}, | ||
}; | ||
return Canvas; | ||
}()); | ||
export { Canvas }; | ||
// TODO: Both clear and fill need to have code that resets all context translate/rotations and then restore the previous | ||
/** | ||
* Reset the content on the canvas. Will clear all current marks and return to full transparent. | ||
*/ | ||
clear = () => { | ||
this.context.clearRect(0, 0, this.get.width(), this.get.height()); | ||
}; | ||
/** | ||
* Fill the entire canvas with a single color | ||
* @param fill | ||
*/ | ||
fill = (fill) => { | ||
const storedTransform = this.context.getTransform(); | ||
this.context.resetTransform(); | ||
this.draw.rect({ | ||
point: Vec2.origin(), | ||
height: this.get.height(), | ||
width: this.get.width(), | ||
fill: fill, | ||
}); | ||
this.context.setTransform(storedTransform); | ||
}; | ||
transform = { | ||
push: () => { | ||
this._transforms.push(this.context.getTransform()); | ||
return this.transform; | ||
}, | ||
pop: () => { | ||
const storedTransform = this._transforms.pop(); | ||
if (storedTransform) { | ||
this.context.setTransform(storedTransform); | ||
} | ||
else { | ||
this.context.resetTransform(); | ||
} | ||
return this.transform; | ||
}, | ||
reset: () => { | ||
this.context.resetTransform(); | ||
return this.transform; | ||
}, | ||
set: (transform) => { | ||
this.context.setTransform(transform); | ||
return this.transform; | ||
}, | ||
// ===== Move the draw position | ||
translate: (vector) => { | ||
this.context.translate(vector.x, vector.y); | ||
return this.transform; | ||
}, | ||
scale: (factor) => { | ||
this.context.scale(factor.x, factor.y); | ||
return this.transform; | ||
}, | ||
rotate: (radians) => { | ||
this.context.rotate(radians); | ||
return this.transform; | ||
}, | ||
flipHorizontal: () => { | ||
this.context.scale(-1, 1); | ||
return this.transform; | ||
}, | ||
flipVertical: () => { | ||
this.context.scale(1, -1); | ||
return this.transform; | ||
}, | ||
}; | ||
// ===== Get and Merge layers | ||
layer = () => { | ||
// probably dont need to get doc from the canvas, could probably just use `document` but maybe there is some edge condition where this matters. | ||
const doc = this.canvas.ownerDocument; | ||
const layer = doc.createElement('canvas'); | ||
layer.width = this.canvas.width; | ||
layer.height = this.canvas.height; | ||
return new Canvas(layer); | ||
}; | ||
apply(layer, options = {}) { | ||
this.draw.stamp({ source: layer, ...options }); | ||
} | ||
} | ||
//# sourceMappingURL=Canvas.js.map |
@@ -0,0 +0,0 @@ import Vec2 from '../math/Vec2'; |
@@ -1,12 +0,1 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import Vec2 from '../math/Vec2'; | ||
@@ -35,4 +24,5 @@ import Color from '../color'; | ||
} | ||
var Draw = /** @class */ (function () { | ||
function Draw(context) { | ||
export class Draw { | ||
context; | ||
constructor(context) { | ||
this.context = context; | ||
@@ -46,7 +36,7 @@ } | ||
*/ | ||
Draw.prototype.draw = function (stroke, fill) { | ||
draw(stroke, fill) { | ||
this.fill(fill); | ||
this.stroke(stroke); | ||
}; | ||
Draw.prototype.fill = function (fill) { | ||
} | ||
fill(fill) { | ||
if (fill) { | ||
@@ -56,6 +46,6 @@ this.context.fillStyle = resolveFillStyle(fill); | ||
} | ||
}; | ||
Draw.prototype.stroke = function (stroke) { | ||
} | ||
stroke(stroke) { | ||
if (stroke) { | ||
var color = resolveColorSelection(stroke.color); | ||
const color = resolveColorSelection(stroke.color); | ||
this.context.lineWidth = stroke.width; | ||
@@ -68,5 +58,5 @@ this.context.strokeStyle = color.rgb(); | ||
} | ||
}; | ||
} | ||
// -- Different geometries below | ||
Draw.prototype.circle = function (inputs) { | ||
circle(inputs) { | ||
this.context.beginPath(); | ||
@@ -77,8 +67,7 @@ this.context.arc(inputs.center.x, inputs.center.y, inputs.radius, 0, TAU); | ||
inputs.brush && inputs.brush({ path: Path.fromCircle(inputs), draw: this }); | ||
}; | ||
} | ||
// TODO: Expand rect to also handle rounded corners. Probably want to take advantage of Path API once written. | ||
Draw.prototype.rect = function (inputs) { | ||
var _this = this; | ||
rect(inputs) { | ||
// Map all corners except the start | ||
var corners = [ | ||
const corners = [ | ||
inputs.point.add(new Vec2(inputs.width, 0)), | ||
@@ -90,5 +79,5 @@ inputs.point.add(new Vec2(inputs.width, inputs.height)), | ||
this.context.moveTo(inputs.point.x, inputs.point.y); | ||
corners.forEach(function (corner) { | ||
corners.forEach((corner) => { | ||
// Move to each corner | ||
_this.context.lineTo(corner.x, corner.y); | ||
this.context.lineTo(corner.x, corner.y); | ||
}); | ||
@@ -98,5 +87,5 @@ this.context.closePath(); | ||
inputs.brush && inputs.brush({ path: Path.fromRect(inputs), draw: this }); | ||
}; | ||
Draw.prototype.line = function (inputs) { | ||
var start = inputs.start, end = inputs.end, stroke = inputs.stroke, fill = inputs.fill; | ||
} | ||
line(inputs) { | ||
const { start, end, stroke, fill } = inputs; | ||
this.context.beginPath(); | ||
@@ -107,5 +96,5 @@ this.context.moveTo(start.x, start.y); | ||
inputs.brush && inputs.brush({ path: Path.fromLine(inputs), draw: this }); | ||
}; | ||
Draw.prototype.bezier2 = function (inputs) { | ||
var start = inputs.start, control = inputs.control, end = inputs.end, stroke = inputs.stroke, fill = inputs.fill; | ||
} | ||
bezier2(inputs) { | ||
const { start, control, end, stroke, fill } = inputs; | ||
this.context.beginPath(); | ||
@@ -116,5 +105,5 @@ this.context.moveTo(start.x, start.y); | ||
inputs.brush && inputs.brush({ path: Path.fromBez2(inputs), draw: this }); | ||
}; | ||
Draw.prototype.bezier3 = function (inputs) { | ||
var start = inputs.start, control1 = inputs.control1, control2 = inputs.control2, end = inputs.end, stroke = inputs.stroke, fill = inputs.fill; | ||
} | ||
bezier3(inputs) { | ||
const { start, control1, control2, end, stroke, fill } = inputs; | ||
this.context.beginPath(); | ||
@@ -125,30 +114,29 @@ this.context.moveTo(start.x, start.y); | ||
inputs.brush && inputs.brush({ path: Path.fromBez3(inputs), draw: this }); | ||
}; | ||
Draw.prototype.path = function (inputs) { | ||
var _this = this; | ||
var path = inputs.path, fill = inputs.fill, stroke = inputs.stroke, _a = inputs.close, close = _a === void 0 ? false : _a; | ||
} | ||
path(inputs) { | ||
const { path, fill, stroke, close = false } = inputs; | ||
this.context.beginPath(); | ||
this.context.moveTo(path.start.x, path.start.y); | ||
path.segments.forEach(function (segment) { | ||
path.segments.forEach((segment) => { | ||
switch (segment.type) { | ||
case SegmentType.Move: | ||
_this.context.moveTo(segment.point.x, segment.point.y); | ||
this.context.moveTo(segment.point.x, segment.point.y); | ||
break; | ||
case SegmentType.Line: | ||
_this.context.lineTo(segment.point.x, segment.point.y); | ||
this.context.lineTo(segment.point.x, segment.point.y); | ||
break; | ||
case SegmentType.Arc: | ||
var startAngle = segment.start.diff(segment.center).angle(); | ||
var endAngle = startAngle - segment.angle; | ||
var counterClockwise = segment.angle >= 0; | ||
_this.context.arc(segment.center.x, segment.center.y, segment.radius, startAngle, endAngle, counterClockwise); | ||
const startAngle = segment.start.diff(segment.center).angle(); | ||
const endAngle = startAngle - segment.angle; | ||
const counterClockwise = segment.angle >= 0; | ||
this.context.arc(segment.center.x, segment.center.y, segment.radius, startAngle, endAngle, counterClockwise); | ||
break; | ||
case SegmentType.Bezier2: | ||
_this.context.quadraticCurveTo(segment.control.x, segment.control.y, segment.point.x, segment.point.y); | ||
this.context.quadraticCurveTo(segment.control.x, segment.control.y, segment.point.x, segment.point.y); | ||
break; | ||
case SegmentType.Bezier3: | ||
_this.context.bezierCurveTo(segment.control1.x, segment.control1.y, segment.control2.x, segment.control2.y, segment.point.x, segment.point.y); | ||
this.context.bezierCurveTo(segment.control1.x, segment.control1.y, segment.control2.x, segment.control2.y, segment.point.x, segment.point.y); | ||
break; | ||
default: | ||
console.warn("core.draw.path", "segment switch hit default due to unhandled segment type:", segment); | ||
console.warn(`core.draw.path`, `segment switch hit default due to unhandled segment type:`, segment); | ||
} | ||
@@ -161,25 +149,24 @@ }); | ||
inputs.brush && inputs.brush({ path: inputs.path, draw: this }); | ||
}; | ||
Draw.prototype.points = function (inputs) { | ||
var points = inputs.points; | ||
var path = new Path(points[0]); | ||
points.slice(1).forEach(function (point) { return path.line(point); }); | ||
this.path(__assign(__assign({}, inputs), { path: path })); | ||
}; | ||
Draw.prototype.layer = function (options) { | ||
if (options === void 0) { options = {}; } | ||
var doc = this.context.canvas.ownerDocument; | ||
var transform = this.context.getTransform(); | ||
var element = doc.createElement('canvas'); | ||
} | ||
points(inputs) { | ||
const { points } = inputs; | ||
const path = new Path(points[0]); | ||
points.slice(1).forEach((point) => path.line(point)); | ||
this.path({ ...inputs, path }); | ||
} | ||
layer(options = {}) { | ||
const doc = this.context.canvas.ownerDocument; | ||
const transform = this.context.getTransform(); | ||
const element = doc.createElement('canvas'); | ||
element.width = options.size ? options.size.x : this.context.canvas.width; | ||
element.height = options.size ? options.size.y : this.context.canvas.height; | ||
var output = new Canvas(element); | ||
const output = new Canvas(element); | ||
output.context.setTransform(transform); | ||
return output; | ||
}; | ||
Draw.prototype.stamp = function (inputs) { | ||
var source = inputs.source, blendMode = inputs.blendMode, position = inputs.position, rotation = inputs.rotation; | ||
var tempBlend = this.context.globalCompositeOperation; | ||
} | ||
stamp(inputs) { | ||
const { source, blendMode, position, rotation } = inputs; | ||
const tempBlend = this.context.globalCompositeOperation; | ||
this.context.globalCompositeOperation = blendMode || BlendMode.default; | ||
var storedTransform = this.context.getTransform(); | ||
const storedTransform = this.context.getTransform(); | ||
this.context.resetTransform(); | ||
@@ -189,11 +176,9 @@ if (rotation) { | ||
} | ||
var x = position ? position.x : 0; | ||
var y = position ? position.y : 0; | ||
const x = position ? position.x : 0; | ||
const y = position ? position.y : 0; | ||
this.context.drawImage(source.canvas, x, y, source.get.width(), source.get.height()); | ||
this.context.setTransform(storedTransform); | ||
this.context.globalCompositeOperation = tempBlend; | ||
}; | ||
return Draw; | ||
}()); | ||
export { Draw }; | ||
} | ||
} | ||
//# sourceMappingURL=Draw.js.map |
@@ -0,0 +0,0 @@ export * from './Brush'; |
@@ -0,0 +0,0 @@ export * from './Brush'; |
@@ -0,0 +0,0 @@ import Color from './'; |
@@ -10,20 +10,17 @@ import { clamp, repeat } from '../utils'; | ||
*/ | ||
var Gradient = /** @class */ (function () { | ||
function Gradient() { | ||
var colors = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
colors[_i] = arguments[_i]; | ||
} | ||
var _this = this; | ||
class Gradient { | ||
colors; | ||
cache; | ||
constructor(...colors) { | ||
this.colors = new Map(); | ||
this.cache = new Map(); | ||
var divisions = colors.length - 1; | ||
colors.forEach(function (color, index) { | ||
var position = index / divisions; | ||
_this.colors.set(position, color); | ||
const divisions = colors.length - 1; | ||
colors.forEach((color, index) => { | ||
const position = index / divisions; | ||
this.colors.set(position, color); | ||
}); | ||
} | ||
Gradient.prototype.clearCache = function () { | ||
clearCache() { | ||
this.cache = new Map(); | ||
}; | ||
} | ||
/** | ||
@@ -34,4 +31,4 @@ * Retrieve the color from the gradient from the provided position. | ||
*/ | ||
Gradient.prototype.at = function (position) { | ||
var clampedPosition = clamp(position); | ||
at(position) { | ||
const clampedPosition = clamp(position); | ||
switch (this.colors.size) { | ||
@@ -48,40 +45,39 @@ case 0: | ||
if (this.colors.has(clampedPosition)) { | ||
var output_1 = this.colors.get(clampedPosition); | ||
this.cache.set(clampedPosition, output_1); | ||
return output_1; | ||
const output = this.colors.get(clampedPosition); | ||
this.cache.set(clampedPosition, output); | ||
return output; | ||
} | ||
// No exact match found, need to calculate a mix from the boundary colours | ||
var values = Array.from(this.colors.keys()).sort(); | ||
var upperBound = values.find(function (i) { return i > clampedPosition; }); | ||
const values = Array.from(this.colors.keys()).sort(); | ||
const upperBound = values.find((i) => i > clampedPosition); | ||
if (upperBound === undefined || !this.colors.has(upperBound)) { | ||
console.error("[@code-not-art/core.Gradient.at] Impossible situation! Shouldn't be here in normal operation. Returning the last color in gradient."); | ||
var selection = Math.max.apply(Math, values); | ||
console.error(`[@code-not-art/core.Gradient.at] Impossible situation! Shouldn't be here in normal operation. Returning the last color in gradient.`); | ||
const selection = Math.max(...values); | ||
return this.colors.get(selection); | ||
} | ||
var lowerBoundIndex = values.indexOf(upperBound) - 1; | ||
const lowerBoundIndex = values.indexOf(upperBound) - 1; | ||
if (lowerBoundIndex < 0 || lowerBoundIndex >= values.length) { | ||
console.error("[@code-not-art/core.Gradient.at] Impossible situation! Shouldn't be here in normal operation. Lower bound index out of range. Returning the color identified as upper bound for this position."); | ||
console.error(`[@code-not-art/core.Gradient.at] Impossible situation! Shouldn't be here in normal operation. Lower bound index out of range. Returning the color identified as upper bound for this position.`); | ||
return this.colors.get(upperBound); | ||
} | ||
var lowerBound = values[lowerBoundIndex]; | ||
const lowerBound = values[lowerBoundIndex]; | ||
if (!this.colors.has(lowerBound)) { | ||
console.error("[@code-not-art/core.Gradient.at] Impossible situation! Shouldn't be here in normal operation. lowerBound value not found in color map. Returning the color identified as upper bound for this position."); | ||
console.error(`[@code-not-art/core.Gradient.at] Impossible situation! Shouldn't be here in normal operation. lowerBound value not found in color map. Returning the color identified as upper bound for this position.`); | ||
return this.colors.get(upperBound); | ||
} | ||
var ratio = (clampedPosition - lowerBound) / (upperBound - lowerBound); | ||
var upperColor = this.colors.get(upperBound); | ||
var lowerColor = this.colors.get(lowerBound); | ||
var output = Color.mix(upperColor, lowerColor, ratio); | ||
const ratio = (clampedPosition - lowerBound) / (upperBound - lowerBound); | ||
const upperColor = this.colors.get(upperBound); | ||
const lowerColor = this.colors.get(lowerBound); | ||
const output = Color.mix(upperColor, lowerColor, ratio); | ||
this.cache.set(clampedPosition, output); | ||
return output; | ||
} | ||
}; | ||
Gradient.prototype.list = function (length) { | ||
var _this = this; | ||
var output = []; | ||
repeat(length, function (i) { | ||
output[i] = _this.at(i / (length - 1)); | ||
} | ||
list(length) { | ||
const output = []; | ||
repeat(length, (i) => { | ||
output[i] = this.at(i / (length - 1)); | ||
}); | ||
return output; | ||
}; | ||
} | ||
/** | ||
@@ -94,7 +90,7 @@ * Add a color to the gradient at the provided position (0 to 1). | ||
*/ | ||
Gradient.prototype.set = function (position, color) { | ||
var clampedPosition = clamp(position); | ||
set(position, color) { | ||
const clampedPosition = clamp(position); | ||
this.colors.set(clampedPosition, color); | ||
this.clearCache(); | ||
}; | ||
} | ||
/** | ||
@@ -107,14 +103,13 @@ * Add a new color to the gradient at the end of the gradient (position = 1) | ||
*/ | ||
Gradient.prototype.add = function (color) { | ||
var _this = this; | ||
var values = Array.from(this.colors.keys()).sort(); | ||
add(color) { | ||
const values = Array.from(this.colors.keys()).sort(); | ||
// The original gradient will be restricted to a range of positions based on the number of colours in the gradient, | ||
// with the new colour getting an equal division of space at the end of the gradient. | ||
var newDivisions = values.length; | ||
var valuesRange = newDivisions - 1 / newDivisions; | ||
const newDivisions = values.length; | ||
const valuesRange = newDivisions - 1 / newDivisions; | ||
// Add the existing gradient to the new color map at proportional positions within the new valuesRange | ||
var newColors = new Map(); | ||
values.forEach(function (originalValue) { | ||
var newValue = valuesRange * originalValue; | ||
var color = _this.colors.get(originalValue); | ||
const newColors = new Map(); | ||
values.forEach((originalValue) => { | ||
const newValue = valuesRange * originalValue; | ||
const color = this.colors.get(originalValue); | ||
newColors.set(newValue, color); | ||
@@ -127,3 +122,3 @@ }); | ||
this.colors = newColors; | ||
}; | ||
} | ||
/** | ||
@@ -135,3 +130,3 @@ * Remove color at the specific position. | ||
*/ | ||
Gradient.prototype.remove = function (position) { | ||
remove(position) { | ||
// TODO: Handle case where color at 0 or 1 is removed, need to rescale the whole gradient. | ||
@@ -143,5 +138,5 @@ if (this.colors.has(position)) { | ||
else { | ||
console.warn("[@code-not-art/core.Gradient.remove] No Color at the provided position to remove."); | ||
console.warn(`[@code-not-art/core.Gradient.remove] No Color at the provided position to remove.`); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -154,7 +149,7 @@ * Returns a new gradient built from this gradient that repeats all the colours in the gradient to form a loop. | ||
*/ | ||
Gradient.prototype.loop = function () { | ||
var loopGradient = new Gradient(); | ||
this.colors.forEach(function (entry, key) { | ||
var firstPosition = key / 2; | ||
var secondPosition = 1 - firstPosition; | ||
loop() { | ||
const loopGradient = new Gradient(); | ||
this.colors.forEach((entry, key) => { | ||
const firstPosition = key / 2; | ||
const secondPosition = 1 - firstPosition; | ||
loopGradient.set(firstPosition, entry); | ||
@@ -164,6 +159,5 @@ loopGradient.set(secondPosition, entry); | ||
return loopGradient; | ||
}; | ||
return Gradient; | ||
}()); | ||
} | ||
} | ||
export default Gradient; | ||
//# sourceMappingURL=Gradient.js.map |
@@ -0,0 +0,0 @@ import tinycolor from 'tinycolor2'; |
@@ -1,16 +0,7 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import tinycolor from 'tinycolor2'; | ||
import { Random } from '../'; | ||
import { clamp } from '../utils'; | ||
var Color = /** @class */ (function () { | ||
class Color { | ||
seed; | ||
_color; | ||
/** | ||
@@ -23,66 +14,7 @@ * h = hue, is 0 to 360, default random | ||
*/ | ||
function Color(options) { | ||
var _this = this; | ||
this.get = { | ||
alpha: function () { return _this._color.getAlpha(); }, | ||
rgb: function () { return _this._color.toRgb(); }, | ||
hex: function () { return _this._color.toHex(); }, | ||
hsv: function () { return _this._color.toHsv(); }, | ||
}; | ||
this.set = { | ||
rgb: function (r, g, b) { | ||
_this._color = tinycolor({ a: _this._color.getAlpha(), r: r, g: g, b: b }); | ||
return _this; | ||
}, | ||
hex: function (value) { | ||
var alpha = _this._color.getAlpha(); | ||
_this._color = tinycolor(value); | ||
_this._color.setAlpha(alpha); | ||
return _this; | ||
}, | ||
hsv: function (h, s, v) { | ||
var hsva = _this._color.toHsv(); | ||
_this._color = tinycolor({ a: hsva.a, h: h, s: s, v: v }); | ||
return _this; | ||
}, | ||
alpha: function (a) { | ||
var rgba = _this._color.toRgb(); | ||
_this._color = tinycolor(__assign(__assign({}, rgba), { a: a })); | ||
return _this; | ||
}, | ||
red: function (r) { | ||
var rgba = _this._color.toRgb(); | ||
_this._color = tinycolor(__assign(__assign({}, rgba), { r: r })); | ||
return _this; | ||
}, | ||
green: function (g) { | ||
var rgba = _this._color.toRgb(); | ||
_this._color = tinycolor(__assign(__assign({}, rgba), { g: g })); | ||
return _this; | ||
}, | ||
blue: function (b) { | ||
var rgba = _this._color.toRgb(); | ||
_this._color = tinycolor(__assign(__assign({}, rgba), { b: b })); | ||
return _this; | ||
}, | ||
hue: function (h) { | ||
var hsva = _this._color.toHsv(); | ||
_this._color = tinycolor(__assign(__assign({}, hsva), { h: h })); | ||
return _this; | ||
}, | ||
saturation: function (s) { | ||
var hsva = _this._color.toHsv(); | ||
_this._color = tinycolor(__assign(__assign({}, hsva), { s: s })); | ||
return _this; | ||
}, | ||
value: function (v) { | ||
var hsva = _this._color.toHsv(); | ||
_this._color = tinycolor(__assign(__assign({}, hsva), { v: v })); | ||
return _this; | ||
}, | ||
}; | ||
constructor(options) { | ||
if (options === undefined) { | ||
this.seed = new Random("Random Color Seed").next().toString(); | ||
var _rng = new Random("Color ".concat(this.seed), this.seed); | ||
var hsv = "hsva(".concat(_rng.float(0, 360), ", ").concat(_rng.float(0, 100), "%, ").concat(_rng.float(0, 100), "%, 1)"); | ||
this.seed = new Random(`Random Color Seed`).next().toString(); | ||
const _rng = new Random(`Color ${this.seed}`, this.seed); | ||
const hsv = `hsva(${_rng.float(0, 360)}, ${_rng.float(0, 100)}%, ${_rng.float(0, 100)}%, 1)`; | ||
this._color = tinycolor(hsv); | ||
@@ -95,21 +27,79 @@ } | ||
this.seed = | ||
options.seed || new Random("Random Color Seed").next().toString(); | ||
var _rng = options.rng || new Random("Color ".concat(this.seed), this.seed); | ||
var _h = options.h || _rng.float(0, 360); | ||
var _s = options.s || _rng.float(0, 100); | ||
var _v = options.v || _rng.float(0, 100); | ||
var _a = options.a || 1; | ||
var hsv = "hsva(".concat(clamp(_h, { min: 0, max: 360 }), ", ").concat(clamp(_s, { | ||
options.seed || new Random(`Random Color Seed`).next().toString(); | ||
const _rng = options.rng || new Random(`Color ${this.seed}`, this.seed); | ||
const _h = options.h || _rng.float(0, 360); | ||
const _s = options.s || _rng.float(0, 100); | ||
const _v = options.v || _rng.float(0, 100); | ||
const _a = options.a || 1; | ||
const hsv = `hsva(${clamp(_h, { min: 0, max: 360 })}, ${clamp(_s, { | ||
min: 0, | ||
max: 100, | ||
}), "%, ").concat(clamp(_v, { min: 0, max: 100 }), "%, ").concat(clamp(_a), ")"); | ||
})}%, ${clamp(_v, { min: 0, max: 100 })}%, ${clamp(_a)})`; | ||
this._color = tinycolor(hsv); | ||
} | ||
} | ||
Color.prototype.rgb = function () { | ||
rgb() { | ||
return this._color.toRgbString(); | ||
} | ||
get = { | ||
alpha: () => this._color.getAlpha(), | ||
rgb: () => this._color.toRgb(), | ||
hex: () => this._color.toHex(), | ||
hsv: () => this._color.toHsv(), | ||
}; | ||
Color.prototype.color = function () { | ||
set = { | ||
rgb: (r, g, b) => { | ||
this._color = tinycolor({ a: this._color.getAlpha(), r, g, b }); | ||
return this; | ||
}, | ||
hex: (value) => { | ||
const alpha = this._color.getAlpha(); | ||
this._color = tinycolor(value); | ||
this._color.setAlpha(alpha); | ||
return this; | ||
}, | ||
hsv: (h, s, v) => { | ||
const hsva = this._color.toHsv(); | ||
this._color = tinycolor({ a: hsva.a, h, s, v }); | ||
return this; | ||
}, | ||
alpha: (a) => { | ||
const rgba = this._color.toRgb(); | ||
this._color = tinycolor({ ...rgba, a }); | ||
return this; | ||
}, | ||
red: (r) => { | ||
const rgba = this._color.toRgb(); | ||
this._color = tinycolor({ ...rgba, r }); | ||
return this; | ||
}, | ||
green: (g) => { | ||
const rgba = this._color.toRgb(); | ||
this._color = tinycolor({ ...rgba, g }); | ||
return this; | ||
}, | ||
blue: (b) => { | ||
const rgba = this._color.toRgb(); | ||
this._color = tinycolor({ ...rgba, b }); | ||
return this; | ||
}, | ||
hue: (h) => { | ||
const hsva = this._color.toHsv(); | ||
this._color = tinycolor({ ...hsva, h }); | ||
return this; | ||
}, | ||
saturation: (s) => { | ||
const hsva = this._color.toHsv(); | ||
this._color = tinycolor({ ...hsva, s }); | ||
return this; | ||
}, | ||
value: (v) => { | ||
const hsva = this._color.toHsv(); | ||
this._color = tinycolor({ ...hsva, v }); | ||
return this; | ||
}, | ||
}; | ||
color() { | ||
return tinycolor(this._color.toRgb()); | ||
}; | ||
} | ||
/** | ||
@@ -124,15 +114,14 @@ * Return a color that mixes the two provided colors. | ||
*/ | ||
Color.mix = function (c1, c2, ratio) { | ||
if (ratio === void 0) { ratio = 0.5; } | ||
var clampedRatio = clamp(ratio); | ||
var rgba1 = c1.get.rgb(); | ||
var rgb2 = c2.get.rgb(); | ||
var r = rgba1.r * clampedRatio + rgb2.r * (1 - clampedRatio); | ||
var g = rgba1.g * clampedRatio + rgb2.g * (1 - clampedRatio); | ||
var b = rgba1.b * clampedRatio + rgb2.b * (1 - clampedRatio); | ||
var a = rgba1.a * clampedRatio + rgb2.a * (1 - clampedRatio); | ||
var color = tinycolor({ r: r, g: g, b: b, a: a }); | ||
var _b = color.toHsv(), h = _b.h, s = _b.s, v = _b.v; | ||
return new Color({ h: h, s: s * 100, v: v * 100, a: a }); // saturation and value are in the 1-100 range on color input, but are returned as 0 to 1 by tinycolor.hsv() | ||
}; | ||
static mix(c1, c2, ratio = 0.5) { | ||
const clampedRatio = clamp(ratio); | ||
const rgba1 = c1.get.rgb(); | ||
const rgb2 = c2.get.rgb(); | ||
const r = rgba1.r * clampedRatio + rgb2.r * (1 - clampedRatio); | ||
const g = rgba1.g * clampedRatio + rgb2.g * (1 - clampedRatio); | ||
const b = rgba1.b * clampedRatio + rgb2.b * (1 - clampedRatio); | ||
const a = rgba1.a * clampedRatio + rgb2.a * (1 - clampedRatio); | ||
const color = tinycolor({ r, g, b, a }); | ||
const { h, s, v } = color.toHsv(); | ||
return new Color({ h, s: s * 100, v: v * 100, a }); // saturation and value are in the 1-100 range on color input, but are returned as 0 to 1 by tinycolor.hsv() | ||
} | ||
/** | ||
@@ -148,16 +137,14 @@ * Same as mix() but averages values along the HSV axis, so this can result in some crazy hue shifts | ||
*/ | ||
Color.mixHsv = function (c1, c2, ratio) { | ||
if (ratio === void 0) { ratio = 0.5; } | ||
var clampedRatio = clamp(ratio); | ||
var hsva1 = c1.get.hsv(); | ||
var hsva2 = c2.get.hsv(); | ||
var h = hsva1.h * clampedRatio + hsva2.h * (1 - clampedRatio); | ||
var s = (hsva1.s * clampedRatio + hsva2.s * (1 - clampedRatio)) * 100; // saturation and value are in the 1-100 range on color input, but are returned as 0 to 1 by tinycolor.hsv() | ||
var v = (hsva1.v * clampedRatio + hsva2.v * (1 - clampedRatio)) * 100; | ||
var a = hsva1.a * clampedRatio + hsva2.a * (1 - clampedRatio); | ||
return new Color({ h: h, s: s, v: v, a: a }); | ||
}; | ||
return Color; | ||
}()); | ||
static mixHsv(c1, c2, ratio = 0.5) { | ||
const clampedRatio = clamp(ratio); | ||
const hsva1 = c1.get.hsv(); | ||
const hsva2 = c2.get.hsv(); | ||
const h = hsva1.h * clampedRatio + hsva2.h * (1 - clampedRatio); | ||
const s = (hsva1.s * clampedRatio + hsva2.s * (1 - clampedRatio)) * 100; // saturation and value are in the 1-100 range on color input, but are returned as 0 to 1 by tinycolor.hsv() | ||
const v = (hsva1.v * clampedRatio + hsva2.v * (1 - clampedRatio)) * 100; | ||
const a = hsva1.a * clampedRatio + hsva2.a * (1 - clampedRatio); | ||
return new Color({ h, s, v, a }); | ||
} | ||
} | ||
export default Color; | ||
//# sourceMappingURL=index.js.map |
@@ -0,0 +0,0 @@ import Color from '.'; |
@@ -10,13 +10,12 @@ import Color from '.'; | ||
*/ | ||
export function mix(c1, c2, ratio) { | ||
if (ratio === void 0) { ratio = 0.5; } | ||
var clampedRatio = clamp(ratio); | ||
var hsva1 = c1.get.hsv(); | ||
var hsva2 = c2.get.hsv(); | ||
var h = hsva1.h * ratio + hsva2.h * (1 - clampedRatio); | ||
var s = hsva1.s * ratio + hsva2.s * (1 - clampedRatio); | ||
var v = hsva1.v * ratio + hsva2.v * (1 - clampedRatio); | ||
var a = hsva1.a * ratio + hsva2.a * (1 - clampedRatio); | ||
return new Color({ h: h, s: s, v: v, a: a }); | ||
export function mix(c1, c2, ratio = 0.5) { | ||
const clampedRatio = clamp(ratio); | ||
const hsva1 = c1.get.hsv(); | ||
const hsva2 = c2.get.hsv(); | ||
const h = hsva1.h * ratio + hsva2.h * (1 - clampedRatio); | ||
const s = hsva1.s * ratio + hsva2.s * (1 - clampedRatio); | ||
const v = hsva1.v * ratio + hsva2.v * (1 - clampedRatio); | ||
const a = hsva1.a * ratio + hsva2.a * (1 - clampedRatio); | ||
return new Color({ h, s, v, a }); | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -0,0 +0,0 @@ export declare const PI: number; |
@@ -1,4 +0,4 @@ | ||
export var PI = Math.PI; | ||
export var TWOPI = Math.PI * 2; | ||
export var TAU = Math.PI * 2; | ||
export const PI = Math.PI; | ||
export const TWOPI = Math.PI * 2; | ||
export const TAU = Math.PI * 2; | ||
//# sourceMappingURL=constants.js.map |
@@ -6,3 +6,4 @@ export * from './canvas'; | ||
export { default as Vec2 } from './math/Vec2'; | ||
export { default as Random, RandomContext } from './random'; | ||
export { default as Random } from './random'; | ||
export type { RandomContext } from './random'; | ||
export * as Noise from './random/noise'; | ||
@@ -9,0 +10,0 @@ export * from './structures'; |
@@ -0,0 +0,0 @@ export * from './canvas'; |
@@ -0,0 +0,0 @@ /** |
@@ -5,3 +5,5 @@ /** | ||
*/ | ||
var Vec2 = /** @class */ (function () { | ||
class Vec2 { | ||
x; | ||
y; | ||
/** | ||
@@ -15,10 +17,3 @@ * Vec2 constructor. If only one number is passed in, the class property y will be set to the same value as x. | ||
*/ | ||
function Vec2(x, y) { | ||
var _this = this; | ||
this.withMagnitude = function (magnitude) { | ||
return _this.normalize().scale(magnitude); | ||
}; | ||
this.withAngle = function (angle) { | ||
return Vec2.unit().rotate(angle).scale(_this.magnitude()); | ||
}; | ||
constructor(x, y) { | ||
this.x = x; | ||
@@ -28,5 +23,5 @@ this.y = y === undefined ? x : y; | ||
/* ===== Properties ===== */ | ||
Vec2.prototype.magnitude = function () { | ||
magnitude() { | ||
return Math.sqrt(this.x * this.x + this.y * this.y); | ||
}; | ||
} | ||
/** | ||
@@ -36,7 +31,7 @@ * | ||
*/ | ||
Vec2.prototype.angle = function () { | ||
angle() { | ||
return Math.atan2(this.y, this.x); | ||
}; | ||
} | ||
/* ===== Base Maths ===== */ | ||
Vec2.prototype.add = function (value) { | ||
add(value) { | ||
if (value instanceof Vec2) { | ||
@@ -48,4 +43,4 @@ return new Vec2(this.x + value.x, this.y + value.y); | ||
} | ||
}; | ||
Vec2.prototype.diff = function (value) { | ||
} | ||
diff(value) { | ||
if (value instanceof Vec2) { | ||
@@ -57,4 +52,4 @@ return new Vec2(this.x - value.x, this.y - value.y); | ||
} | ||
}; | ||
Vec2.prototype.scale = function (value) { | ||
} | ||
scale(value) { | ||
if (typeof value === 'object') { | ||
@@ -66,6 +61,6 @@ return new Vec2(this.x * value.x, this.y * value.y); | ||
} | ||
}; | ||
Vec2.prototype.dot = function (vector) { | ||
} | ||
dot(vector) { | ||
return this.x * vector.x + this.y * vector.y; | ||
}; | ||
} | ||
/** | ||
@@ -76,17 +71,17 @@ * Equivalent to the determinant between two Vec2's, not exactly the 3D vector cross product. | ||
*/ | ||
Vec2.prototype.cross = function (vector) { | ||
cross(vector) { | ||
return this.x * vector.y - this.y * vector.x; | ||
}; | ||
Vec2.prototype.within = function (max, min) { | ||
var _min = min || Vec2.origin(); | ||
} | ||
within(max, min) { | ||
const _min = min || Vec2.origin(); | ||
return (this.x < max.x && this.y < max.y && this.x > _min.x && this.y > _min.y); | ||
}; | ||
Vec2.prototype.distance = function (value) { | ||
} | ||
distance(value) { | ||
return this.diff(value).magnitude(); | ||
}; | ||
} | ||
/* ===== Modify ===== */ | ||
Vec2.prototype.normalize = function () { | ||
var M = this.magnitude(); | ||
normalize() { | ||
const M = this.magnitude(); | ||
return new Vec2(this.x / M, this.y / M); | ||
}; | ||
} | ||
/** | ||
@@ -97,5 +92,11 @@ * | ||
*/ | ||
Vec2.prototype.rotate = function (angle) { | ||
rotate(angle) { | ||
return this.toPolar().add(new Vec2(0, angle)).toCoords(); | ||
} | ||
withMagnitude = (magnitude) => { | ||
return this.normalize().scale(magnitude); | ||
}; | ||
withAngle = (angle) => { | ||
return Vec2.unit().rotate(angle).scale(this.magnitude()); | ||
}; | ||
/* ===== Convert ===== */ | ||
@@ -106,11 +107,11 @@ /** | ||
*/ | ||
Vec2.prototype.toPolar = function () { | ||
toPolar() { | ||
return new Vec2(this.magnitude(), this.angle()); | ||
}; | ||
} | ||
/** | ||
* Converts a polar vector (radius, theta) to cartesian (x, y) | ||
*/ | ||
Vec2.prototype.toCoords = function () { | ||
toCoords() { | ||
return new Vec2(Math.cos(this.y) * this.x, Math.sin(this.y) * this.x); | ||
}; | ||
} | ||
// ===== Static generators for common simple vectors | ||
@@ -121,5 +122,5 @@ /** | ||
*/ | ||
Vec2.origin = function () { | ||
static origin() { | ||
return new Vec2(0, 0); | ||
}; | ||
} | ||
/** | ||
@@ -129,5 +130,5 @@ * Alias for `Vec2.origin`. Shortcut for `new Vec2(0, 0)` | ||
*/ | ||
Vec2.zero = function () { | ||
static zero() { | ||
return Vec2.origin(); | ||
}; | ||
} | ||
/** | ||
@@ -137,5 +138,5 @@ * Vec2 of size 1 along the first (x) axis. Shortcut for `new Vec2(1, 0)`. | ||
*/ | ||
Vec2.unit = function () { | ||
static unit() { | ||
return new Vec2(1, 0); | ||
}; | ||
} | ||
/** | ||
@@ -145,5 +146,5 @@ * Vec2 of all 1's. Shortcut for `new Vec2(1, 1)` | ||
*/ | ||
Vec2.ones = function () { | ||
static ones() { | ||
return new Vec2(1, 1); | ||
}; | ||
} | ||
/** | ||
@@ -155,3 +156,3 @@ * Create a new Vec2 based on another Vec2 or a single number. | ||
*/ | ||
Vec2.from = function (prototype) { | ||
static from(prototype) { | ||
if (prototype instanceof Vec2) { | ||
@@ -163,6 +164,5 @@ return new Vec2(prototype.x, prototype.y); | ||
} | ||
}; | ||
return Vec2; | ||
}()); | ||
} | ||
} | ||
export default Vec2; | ||
//# sourceMappingURL=Vec2.js.map |
type Distribution = (x: number) => number; | ||
export default Distribution; | ||
//# sourceMappingURL=Distribution.d.ts.map |
export {}; | ||
//# sourceMappingURL=Distribution.js.map |
@@ -0,0 +0,0 @@ import Distribution from './Distribution'; |
@@ -0,0 +0,0 @@ export { default as Uniform } from './Uniform'; |
@@ -0,0 +0,0 @@ import Distribution from '.'; |
@@ -9,6 +9,4 @@ /** | ||
*/ | ||
var Power = function (power) { return function (x) { | ||
return Math.pow(x, power <= 0 ? 1 : power); | ||
}; }; | ||
const Power = (power) => (x) => Math.pow(x, power <= 0 ? 1 : power); | ||
export default Power; | ||
//# sourceMappingURL=Power.js.map |
@@ -0,0 +0,0 @@ import Distribution from '.'; |
@@ -12,6 +12,4 @@ /** | ||
*/ | ||
var Sin = function (phase, period) { return function (x) { | ||
return (Math.sin(x * Math.PI * 2 * period + phase) + 1) / 2; | ||
}; }; | ||
const Sin = (phase, period) => (x) => (Math.sin(x * Math.PI * 2 * period + phase) + 1) / 2; | ||
export default Sin; | ||
//# sourceMappingURL=Sin.js.map |
@@ -0,0 +0,0 @@ import Distribution from '.'; |
@@ -1,3 +0,3 @@ | ||
var Uniform = function (x) { return x; }; | ||
const Uniform = (x) => x; | ||
export default Uniform; | ||
//# sourceMappingURL=Uniform.js.map |
@@ -0,0 +0,0 @@ import { Color, Vec2 } from '..'; |
@@ -7,17 +7,17 @@ import srng from 'seed-random'; | ||
import * as Words from './words'; | ||
var Random = /** @class */ (function () { | ||
function Random(context, seed) { | ||
this._contexts = []; | ||
var _seed = "".concat(seed ? seed : Math.random()); | ||
class Random { | ||
_contexts = []; | ||
constructor(context, seed) { | ||
const _seed = `${seed ? seed : Math.random()}`; | ||
this._contexts.push(this.createContext(context, _seed, Uniform)); | ||
} | ||
Random.prototype.createContext = function (context, seed, distribution) { | ||
createContext(context, seed, distribution) { | ||
return { | ||
context: context, | ||
context, | ||
count: 0, | ||
distribution: distribution, | ||
seed: seed, | ||
distribution, | ||
seed, | ||
rng: srng(seed), | ||
}; | ||
}; | ||
} | ||
/* *** | ||
@@ -27,25 +27,23 @@ * Context Management | ||
// Get Data about current active context | ||
Random.prototype.getContext = function () { | ||
getContext() { | ||
return this._contexts[this._contexts.length - 1]; | ||
}; | ||
Random.prototype.getCount = function () { | ||
} | ||
getCount() { | ||
return this.getContext().count; | ||
}; | ||
Random.prototype.getSeed = function () { | ||
} | ||
getSeed() { | ||
return this.getContext().seed; | ||
}; | ||
Random.prototype.getContextByLabel = function (context) { | ||
return this._contexts.find(function (i) { return i.context === context; }); | ||
}; | ||
Random.prototype.getCountByLabel = function (context) { | ||
var _a; | ||
return (_a = this.getContextByLabel(context)) === null || _a === void 0 ? void 0 : _a.count; | ||
}; | ||
Random.prototype.getSeedByLabel = function (context) { | ||
var _a; | ||
return (_a = this.getContextByLabel(context)) === null || _a === void 0 ? void 0 : _a.seed; | ||
}; | ||
Random.prototype.getContexts = function () { | ||
} | ||
getContextByLabel(context) { | ||
return this._contexts.find((i) => i.context === context); | ||
} | ||
getCountByLabel(context) { | ||
return this.getContextByLabel(context)?.count; | ||
} | ||
getSeedByLabel(context) { | ||
return this.getContextByLabel(context)?.seed; | ||
} | ||
getContexts() { | ||
return this._contexts; | ||
}; | ||
} | ||
/** | ||
@@ -58,15 +56,14 @@ * Create a new random context. Contexts provide a new seeded RNG, | ||
*/ | ||
Random.prototype.push = function (context, options) { | ||
if (options === void 0) { options = {}; } | ||
var _seed = options.seed === undefined ? this.next().toString() : options.seed; | ||
var _distribution = options.distribution === undefined ? Uniform : options.distribution; | ||
push(context, options = {}) { | ||
const _seed = options.seed === undefined ? this.next().toString() : options.seed; | ||
const _distribution = options.distribution === undefined ? Uniform : options.distribution; | ||
this._contexts.push(this.createContext(context, _seed, _distribution)); | ||
}; | ||
Random.prototype.pop = function () { | ||
} | ||
pop() { | ||
this._contexts.pop(); | ||
}; | ||
Random.prototype.reset = function () { | ||
var context = this.getContext(); | ||
} | ||
reset() { | ||
const context = this.getContext(); | ||
context.rng = srng(context.seed); | ||
}; | ||
} | ||
/* *** | ||
@@ -80,24 +77,23 @@ * Make Random Stuff | ||
*/ | ||
Random.prototype.next = function (distribution) { | ||
var _distribution = distribution | ||
next(distribution) { | ||
const _distribution = distribution | ||
? distribution | ||
: this.getContext().distribution; | ||
var _context = this.getContext(); | ||
const _context = this.getContext(); | ||
_context.count++; | ||
var x = _context.rng(); | ||
const x = _context.rng(); | ||
return _distribution(x); | ||
}; | ||
Random.prototype.bool = function (chance, distribution) { | ||
if (chance === void 0) { chance = 0.5; } | ||
} | ||
bool(chance = 0.5, distribution) { | ||
return this.next(distribution) <= chance; | ||
}; | ||
Random.prototype.int = function (min, max, distribution) { | ||
} | ||
int(min, max, distribution) { | ||
return Math.floor(this.next(distribution) * (max - min + 1) + min); | ||
}; | ||
Random.prototype.float = function (min, max, distribution) { | ||
} | ||
float(min, max, distribution) { | ||
return this.next(distribution) * (max - min) + min; | ||
}; | ||
Random.prototype.angle = function (distribution) { | ||
} | ||
angle(distribution) { | ||
return this.next(distribution) * TAU; | ||
}; | ||
} | ||
/** | ||
@@ -108,7 +104,6 @@ * Randomize a color. Options allow control over the range of output values. | ||
*/ | ||
Random.prototype.color = function (options) { | ||
if (options === void 0) { options = {}; } | ||
var h; | ||
var s; | ||
var v; | ||
color(options = {}) { | ||
let h; | ||
let s; | ||
let v; | ||
// Choice of options will change the number of random calls, so execute this within a new random context | ||
@@ -118,4 +113,4 @@ this.push('random color'); | ||
if (options.h instanceof Object) { | ||
var min = options.h.min === undefined ? 0 : Math.max(0, options.h.min); | ||
var max = options.h.max === undefined ? 360 : options.h.max; | ||
const min = options.h.min === undefined ? 0 : Math.max(0, options.h.min); | ||
const max = options.h.max === undefined ? 360 : options.h.max; | ||
h = this.float(min, max) % 360; | ||
@@ -129,4 +124,4 @@ } | ||
if (options.s instanceof Object) { | ||
var min = options.s.min === undefined ? 0 : Math.max(0, options.s.min); | ||
var max = options.s.max === undefined ? 100 : options.s.max; | ||
const min = options.s.min === undefined ? 0 : Math.max(0, options.s.min); | ||
const max = options.s.max === undefined ? 100 : options.s.max; | ||
s = this.float(min, max) % 100; | ||
@@ -140,4 +135,4 @@ } | ||
if (options.v instanceof Object) { | ||
var min = options.v.min === undefined ? 0 : Math.max(0, options.v.min); | ||
var max = options.v.max === undefined ? 0 : options.v.max; | ||
const min = options.v.min === undefined ? 0 : Math.max(0, options.v.min); | ||
const max = options.v.max === undefined ? 0 : options.v.max; | ||
v = this.float(min, max) % 100; | ||
@@ -149,8 +144,8 @@ } | ||
} | ||
var seed = this.next().toString(); | ||
var output = new Color({ seed: seed, h: h, s: s, v: v }); | ||
const seed = this.next().toString(); | ||
const output = new Color({ seed, h, s, v }); | ||
// Return to original random context | ||
this.pop(); | ||
return output; | ||
}; | ||
} | ||
/** | ||
@@ -161,6 +156,6 @@ * Random unit vector | ||
*/ | ||
Random.prototype.vec2 = function (distribution) { | ||
vec2(distribution) { | ||
return Vec2.unit().rotate(this.angle(distribution)); | ||
}; | ||
Random.prototype.word = function (type) { | ||
} | ||
word(type) { | ||
switch (type) { | ||
@@ -177,29 +172,22 @@ case 'noun': | ||
} | ||
}; | ||
Random.prototype.fuzzy = function (base, distribution) { | ||
var _this = this; | ||
} | ||
fuzzy(base, distribution) { | ||
return { | ||
// The checks for range === 0 are done to ensure that the same number of calls to the rng are occurring, even if the fuzzy range is 0 | ||
int: function (range) { | ||
return range === 0 | ||
? _this.next(distribution) * 0 + base | ||
: Math.round(_this.int(-range, range, distribution) + base); | ||
}, | ||
float: function (range) { | ||
return range === 0 | ||
? _this.next(distribution) * 0 + base | ||
: _this.float(-range * 100, range * 100, distribution) / 100 + base; | ||
}, // awkward 100 stuff because if range is small (like 0.1 or less) then the near zero values deal with float rounding issues. | ||
int: (range) => range === 0 | ||
? this.next(distribution) * 0 + base | ||
: Math.round(this.int(-range, range, distribution) + base), | ||
float: (range) => range === 0 | ||
? this.next(distribution) * 0 + base | ||
: this.float(-range * 100, range * 100, distribution) / 100 + base, // awkward 100 stuff because if range is small (like 0.1 or less) then the near zero values deal with float rounding issues. | ||
}; | ||
}; | ||
Random.prototype.chooseOne = function (items) { | ||
} | ||
chooseOne(items) { | ||
return items[this.int(0, items.length - 1)]; | ||
}; | ||
Random.prototype.choose = function (items, count, allowDuplicates) { | ||
var _this = this; | ||
if (allowDuplicates === void 0) { allowDuplicates = true; } | ||
var output = []; | ||
} | ||
choose(items, count, allowDuplicates = true) { | ||
const output = []; | ||
if (allowDuplicates) { | ||
repeat(count, function () { | ||
output.push(_this.chooseOne(items)); | ||
repeat(count, () => { | ||
output.push(this.chooseOne(items)); | ||
}); | ||
@@ -209,21 +197,20 @@ } | ||
// No Duplicates version | ||
var _count = count > items.length ? items.length : count; | ||
var options_1 = array(_count); | ||
repeat(_count, function () { | ||
var selection = _this.int(0, options_1.length); | ||
const _count = count > items.length ? items.length : count; | ||
let options = array(_count); | ||
repeat(_count, () => { | ||
const selection = this.int(0, options.length); | ||
output.push(items[selection]); | ||
// Remove selection from options list | ||
options_1 = options_1 | ||
options = options | ||
.slice(0, selection) | ||
.concat(options_1.splice(selection + 1)); | ||
.concat(options.splice(selection + 1)); | ||
}); | ||
} | ||
return output; | ||
}; | ||
Random.prototype.shuffle = function (items) { | ||
var _this = this; | ||
var output = items.map(function (i) { return i; }); | ||
repeat(output.length, function (i) { | ||
var swap = _this.int(i, output.length - 1); | ||
var temp = output[i]; | ||
} | ||
shuffle(items) { | ||
const output = items.map((i) => i); | ||
repeat(output.length, (i) => { | ||
const swap = this.int(i, output.length - 1); | ||
const temp = output[i]; | ||
output[i] = output[swap]; | ||
@@ -233,6 +220,5 @@ output[swap] = temp; | ||
return output; | ||
}; | ||
return Random; | ||
}()); | ||
} | ||
} | ||
export default Random; | ||
//# sourceMappingURL=index.js.map |
@@ -0,0 +0,0 @@ import { Noise2D, Noise3D, Noise4D } from '.'; |
@@ -6,11 +6,11 @@ import Vec2 from '../../math/Vec2'; | ||
function curl(position, noise, config) { | ||
var delta = config.resolution || 0.01; | ||
var x0 = position.x; | ||
var x1 = position.x + delta; | ||
var y0 = position.y; | ||
var y1 = position.y + delta; | ||
var z = config.z === undefined ? 0 : config.z; | ||
var w = config.w === undefined ? 0 : config.w; | ||
var dx = (noise(x1, y0, z, w) - noise(x0, y0, z, w)) / delta; | ||
var dy = (noise(x0, y1, z, w) - noise(x0, y0, z, w)) / delta; | ||
const delta = config.resolution || 0.01; | ||
const x0 = position.x; | ||
const x1 = position.x + delta; | ||
const y0 = position.y; | ||
const y1 = position.y + delta; | ||
const z = config.z === undefined ? 0 : config.z; | ||
const w = config.w === undefined ? 0 : config.w; | ||
const dx = (noise(x1, y0, z, w) - noise(x0, y0, z, w)) / delta; | ||
const dy = (noise(x0, y1, z, w) - noise(x0, y0, z, w)) / delta; | ||
return new Vec2(dy, dx).angle(); | ||
@@ -17,0 +17,0 @@ } |
@@ -0,0 +0,0 @@ export { default as curl } from './curl'; |
@@ -1,15 +0,4 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as openSimplex from 'open-simplex-noise'; | ||
export { default as curl } from './curl'; | ||
var defaultOptions = { | ||
const defaultOptions = { | ||
amplitude: 1, | ||
@@ -20,13 +9,15 @@ frequency: 1, | ||
}; | ||
export var simplex2 = function (integerSeed, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = __assign(__assign({}, defaultOptions), options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves; | ||
var noise = openSimplex.makeNoise2D(integerSeed); | ||
return function (x, y) { | ||
var output = octaves | ||
.map(function (octave) { | ||
var freq = frequency * Math.pow(2, octave); | ||
export const simplex2 = (integerSeed, options = {}) => { | ||
const { amplitude, frequency, octaves } = { | ||
...defaultOptions, | ||
...options, | ||
}; | ||
const noise = openSimplex.makeNoise2D(integerSeed); | ||
return (x, y) => { | ||
const output = octaves | ||
.map((octave) => { | ||
const freq = frequency * Math.pow(2, octave); | ||
return noise(x * freq, y * freq); | ||
}) | ||
.reduce(function (acc, value) { return acc + value; }, 0) * | ||
.reduce((acc, value) => acc + value, 0) * | ||
(amplitude / octaves.length); | ||
@@ -36,13 +27,15 @@ return output; | ||
}; | ||
export var simplex3 = function (integerSeed, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = __assign(__assign({}, defaultOptions), options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves; | ||
var noise = openSimplex.makeNoise3D(integerSeed); | ||
return function (x, y, z) { | ||
var output = octaves | ||
.map(function (octave) { | ||
var freq = frequency * Math.pow(2, octave); | ||
export const simplex3 = (integerSeed, options = {}) => { | ||
const { amplitude, frequency, octaves } = { | ||
...defaultOptions, | ||
...options, | ||
}; | ||
const noise = openSimplex.makeNoise3D(integerSeed); | ||
return (x, y, z) => { | ||
const output = octaves | ||
.map((octave) => { | ||
const freq = frequency * Math.pow(2, octave); | ||
return noise(x * freq, y * freq, z * freq); | ||
}) | ||
.reduce(function (acc, value) { return acc + value; }, 0) * | ||
.reduce((acc, value) => acc + value, 0) * | ||
(amplitude / octaves.length); | ||
@@ -52,13 +45,15 @@ return output; | ||
}; | ||
export var simplex4 = function (integerSeed, options) { | ||
if (options === void 0) { options = {}; } | ||
var _a = __assign(__assign({}, defaultOptions), options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves; | ||
var noise = openSimplex.makeNoise4D(integerSeed); | ||
return function (x, y, z, w) { | ||
var output = octaves | ||
.map(function (octave) { | ||
var freq = frequency * Math.pow(2, octave); | ||
export const simplex4 = (integerSeed, options = {}) => { | ||
const { amplitude, frequency, octaves } = { | ||
...defaultOptions, | ||
...options, | ||
}; | ||
const noise = openSimplex.makeNoise4D(integerSeed); | ||
return (x, y, z, w) => { | ||
const output = octaves | ||
.map((octave) => { | ||
const freq = frequency * Math.pow(2, octave); | ||
return noise(x * freq, y * freq, z * freq, w * freq); | ||
}) | ||
.reduce(function (acc, value) { return acc + value; }, 0) * | ||
.reduce((acc, value) => acc + value, 0) * | ||
(amplitude / octaves.length); | ||
@@ -65,0 +60,0 @@ return output; |
@@ -0,0 +0,0 @@ export declare function getWord(ratio: number): string; |
@@ -1,7 +0,7 @@ | ||
var words = require('a-set-of-english-words'); | ||
var wordList = Array.from(words); | ||
var tagger = require('wink-pos-tagger')(); | ||
var nounSymbols = ['NN', 'NNP', 'NNS', 'NNPS']; | ||
var adverbSymbols = ['RB']; // Removing awkward comparor adverbs (-er and -est): [, 'RBS', 'RBR'] | ||
var adjectiveSymbols = ['JJ', 'JJS', 'JJR']; | ||
const words = require('a-set-of-english-words'); | ||
const wordList = Array.from(words); | ||
const tagger = require('wink-pos-tagger')(); | ||
const nounSymbols = ['NN', 'NNP', 'NNS', 'NNPS']; | ||
const adverbSymbols = ['RB']; // Removing awkward comparor adverbs (-er and -est): [, 'RBS', 'RBR'] | ||
const adjectiveSymbols = ['JJ', 'JJS', 'JJR']; | ||
export function getWord(ratio) { | ||
@@ -11,5 +11,5 @@ return wordList[Math.floor(ratio * wordList.length)]; | ||
export function getWordOfPosType(ratio, types) { | ||
var index = Math.floor(ratio * wordList.length); | ||
let index = Math.floor(ratio * wordList.length); | ||
while (true) { | ||
var word = tagger.tagRawTokens([wordList[index]])[0]; | ||
const word = tagger.tagRawTokens([wordList[index]])[0]; | ||
if (types.includes(word.pos)) { | ||
@@ -16,0 +16,0 @@ return word.value; |
@@ -0,0 +0,0 @@ import Vec2 from '../math/Vec2'; |
import Vec2 from '../math/Vec2'; | ||
import { repeat } from '../utils'; | ||
export var grid = function (options) { | ||
var output = []; | ||
var tileSize = Vec2.ones() | ||
export const grid = (options) => { | ||
const output = []; | ||
const tileSize = Vec2.ones() | ||
.scale(options.size || 1) | ||
.scale(new Vec2(1 / options.columns, 1 / options.rows)); | ||
repeat(options.rows, function (row) { | ||
repeat(options.columns, function (column) { | ||
var uv = new Vec2(column / options.columns, row / options.rows); | ||
var origin = uv.scale(options.size || 1); | ||
repeat(options.rows, (row) => { | ||
repeat(options.columns, (column) => { | ||
const uv = new Vec2(column / options.columns, row / options.rows); | ||
const origin = uv.scale(options.size || 1); | ||
output.push({ | ||
uv: uv, | ||
origin: origin, | ||
uv, | ||
origin, | ||
center: origin.add(tileSize.scale(0.5)), | ||
size: tileSize, | ||
row: row, | ||
column: column, | ||
row, | ||
column, | ||
firstRow: row === 0, | ||
@@ -20,0 +20,0 @@ lastRow: row === options.rows - 1, |
export * from './grid'; | ||
export * from './Path'; | ||
//# sourceMappingURL=index.d.ts.map |
export * from './grid'; | ||
export * from './Path'; | ||
//# sourceMappingURL=index.js.map |
@@ -0,0 +0,0 @@ import { Bezier2, Bezier3, Circle, Line, Rect } from '../canvas'; |
@@ -1,12 +0,1 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import { TAU } from '../constants'; | ||
@@ -22,64 +11,66 @@ import Vec2 from '../math/Vec2'; | ||
})(SegmentType || (SegmentType = {})); | ||
var Path = /** @class */ (function () { | ||
function Path(start) { | ||
export class Path { | ||
start; | ||
segments; | ||
constructor(start) { | ||
this.start = start; | ||
this.segments = []; | ||
} | ||
Path.prototype.getEnd = function () { | ||
getEnd() { | ||
return this.segments.length | ||
? this.segments[this.segments.length - 1].end | ||
: this.start; | ||
}; | ||
Path.prototype.arc = function (angle, center) { | ||
var start = this.getEnd(); | ||
var radius = start.distance(center); | ||
var end = center.diff(start).rotate(angle); | ||
var segment = { | ||
} | ||
arc(angle, center) { | ||
const start = this.getEnd(); | ||
const radius = start.distance(center); | ||
const end = center.diff(start).rotate(angle); | ||
const segment = { | ||
type: SegmentType.Arc, | ||
angle: angle, | ||
radius: radius, | ||
center: center, | ||
angle, | ||
radius, | ||
center, | ||
}; | ||
this.segments.push(__assign(__assign({}, segment), { start: start, end: end })); | ||
this.segments.push({ ...segment, start, end }); | ||
return this; | ||
}; | ||
Path.prototype.move = function (destination) { | ||
var segment = { | ||
} | ||
move(destination) { | ||
const segment = { | ||
type: SegmentType.Move, | ||
point: destination, | ||
}; | ||
this.segments.push(__assign(__assign({}, segment), { start: this.getEnd(), end: destination })); | ||
this.segments.push({ ...segment, start: this.getEnd(), end: destination }); | ||
return this; | ||
}; | ||
Path.prototype.line = function (destination) { | ||
var segment = { | ||
} | ||
line(destination) { | ||
const segment = { | ||
type: SegmentType.Line, | ||
point: destination, | ||
}; | ||
this.segments.push(__assign(__assign({}, segment), { start: this.getEnd(), end: destination })); | ||
this.segments.push({ ...segment, start: this.getEnd(), end: destination }); | ||
return this; | ||
}; | ||
Path.prototype.bez2 = function (destination, control) { | ||
var segment = { | ||
} | ||
bez2(destination, control) { | ||
const segment = { | ||
type: SegmentType.Bezier2, | ||
point: destination, | ||
control: control, | ||
control, | ||
}; | ||
this.segments.push(__assign(__assign({}, segment), { start: this.getEnd(), end: destination })); | ||
this.segments.push({ ...segment, start: this.getEnd(), end: destination }); | ||
return this; | ||
}; | ||
Path.prototype.bez3 = function (destination, control1, control2) { | ||
var segment = { | ||
} | ||
bez3(destination, control1, control2) { | ||
const segment = { | ||
type: SegmentType.Bezier3, | ||
point: destination, | ||
control1: control1, | ||
control2: control2, | ||
control1, | ||
control2, | ||
}; | ||
this.segments.push(__assign(__assign({}, segment), { start: this.getEnd(), end: destination })); | ||
this.segments.push({ ...segment, start: this.getEnd(), end: destination }); | ||
return this; | ||
}; | ||
Path.prototype.getBounds = function () { | ||
var min = Vec2.from(this.start); | ||
var max = Vec2.from(this.start); | ||
this.segments.forEach(function (point) { | ||
} | ||
getBounds() { | ||
let min = Vec2.from(this.start); | ||
let max = Vec2.from(this.start); | ||
this.segments.forEach((point) => { | ||
if (point.end.x < min.x) { | ||
@@ -98,7 +89,7 @@ min.x = point.end.x; | ||
}); | ||
return { min: min, max: max }; | ||
}; | ||
Path.prototype.getLength = function () { | ||
var length = 0; | ||
this.segments.forEach(function (segment) { | ||
return { min, max }; | ||
} | ||
getLength() { | ||
let length = 0; | ||
this.segments.forEach((segment) => { | ||
switch (segment.type) { | ||
@@ -125,12 +116,12 @@ case SegmentType.Line: | ||
return length; | ||
}; | ||
Path.fromCircle = function (circle) { | ||
var startPos = circle.center.add(Vec2.unit().scale(circle.radius)); | ||
} | ||
static fromCircle(circle) { | ||
const startPos = circle.center.add(Vec2.unit().scale(circle.radius)); | ||
return new Path(startPos).arc(TAU, circle.center); | ||
}; | ||
Path.fromLine = function (line) { | ||
} | ||
static fromLine(line) { | ||
return new Path(line.start).line(line.end); | ||
}; | ||
Path.fromRect = function (rect) { | ||
var corners = [ | ||
} | ||
static fromRect(rect) { | ||
const corners = [ | ||
rect.point.add(new Vec2(rect.width, 0)), | ||
@@ -145,12 +136,10 @@ rect.point.add(new Vec2(rect.width, rect.height)), | ||
.line(rect.point); | ||
}; | ||
Path.fromBez2 = function (bez2) { | ||
} | ||
static fromBez2(bez2) { | ||
return new Path(bez2.start).bez2(bez2.end, bez2.control); | ||
}; | ||
Path.fromBez3 = function (bez3) { | ||
} | ||
static fromBez3(bez3) { | ||
return new Path(bez3.start).bez3(bez3.end, bez3.control1, bez3.control2); | ||
}; | ||
return Path; | ||
}()); | ||
export { Path }; | ||
} | ||
} | ||
//# sourceMappingURL=Path.js.map |
export declare function toDegrees(rads: number): number; | ||
export declare function toRadians(degrees: number): number; | ||
//# sourceMappingURL=angles.d.ts.map |
@@ -0,0 +0,0 @@ import { TAU } from '../constants'; |
@@ -0,0 +0,0 @@ export declare function array(length: number): number[]; |
export function array(length) { | ||
return Array.from({ length: length }, function (_v, k) { return k; }); | ||
return Array.from({ length: length }, (_v, k) => k); | ||
} | ||
export function range(start, end) { | ||
return array(end - start).map(function (i) { return i + start; }); | ||
return array(end - start).map((i) => i + start); | ||
} | ||
export function sequence(count, method) { | ||
return array(count).map(function (i) { return method(i); }); | ||
return array(count).map((i) => method(i)); | ||
} | ||
export function repeat(count, action) { | ||
var _loop_1 = function (i) { | ||
var stopRequested = false; | ||
var stopLoop = function () { return (stopRequested = true); }; | ||
for (let i = 0; i < count; i++) { | ||
let stopRequested = false; | ||
const stopLoop = () => (stopRequested = true); | ||
action(i, stopLoop); | ||
if (stopRequested) { | ||
return "break"; | ||
break; | ||
} | ||
}; | ||
for (var i = 0; i < count; i++) { | ||
var state_1 = _loop_1(i); | ||
if (state_1 === "break") | ||
break; | ||
} | ||
} | ||
//# sourceMappingURL=arrays.js.map |
@@ -0,0 +0,0 @@ export { toDegrees, toRadians } from './angles'; |
@@ -0,0 +0,0 @@ export { toDegrees, toRadians } from './angles'; |
@@ -0,0 +0,0 @@ /** |
@@ -10,8 +10,7 @@ /** | ||
*/ | ||
export function clamp(value, options) { | ||
if (options === void 0) { options = {}; } | ||
var min = options.min === undefined ? 0 : options.min; | ||
var max = options.max === undefined ? 1 : options.max; | ||
export function clamp(value, options = {}) { | ||
const min = options.min === undefined ? 0 : options.min; | ||
const max = options.max === undefined ? 1 : options.max; | ||
return Math.max(min, Math.min(max, value)); | ||
} | ||
//# sourceMappingURL=numeric.js.map |
{ | ||
"name": "@code-not-art/core", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "HTML 5 Canvas Drawing Library", | ||
@@ -8,4 +8,3 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "tsc" | ||
}, | ||
@@ -36,3 +35,3 @@ "repository": { | ||
"ts-node": "^10.2.1", | ||
"typescript": "^4.3.5" | ||
"typescript": "^5" | ||
}, | ||
@@ -39,0 +38,0 @@ "dependencies": { |
@@ -6,5 +6,6 @@ export * from './canvas'; | ||
export { default as Vec2 } from './math/Vec2'; | ||
export { default as Random, RandomContext } from './random'; | ||
export { default as Random } from './random'; | ||
export type { RandomContext } from './random'; | ||
export * as Noise from './random/noise'; | ||
export * from './structures'; | ||
export * as Utils from './utils'; |
@@ -7,3 +7,3 @@ { | ||
// "incremental": true, /* Enable incremental compilation */ | ||
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */, | ||
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */, | ||
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, | ||
@@ -29,3 +29,3 @@ "lib": [ | ||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ | ||
"isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */, | ||
@@ -32,0 +32,0 @@ /* Strict Type-Checking Options */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
1
243525
3804