artsupply
v1.2.1
Published
A utility library for creative coding.
Readme
artsupply
A utility library for creative coding.
Usage
Install
npm
npm i artsupplyunpkg
<script src="https://unpkg.com/artsupply"></script>Use
import _supply from 'artsupply';
const foobar = _supply.functionName()API
Calculation
clamp
Keep a number within a range of numbers.
@param {Number} numberThe number to check.@param {Number} minThe min of the range.@param {Number} maxThe max of the range.@return {Number}The number within the range.
map
Map a number from one range to another range. The code is derived from: https://gist.github.com/xposedbones/75ebaef3c10060a3ee3b246166caab56.
@param {Number} numberThe number to convert.@param {Number} inMinThe min of the range for the input number.@param {Number} inMaxThe max of the range for the input number.@param {Number} outMinThe min of the range for the output number.@param {Number} outMaxThe max of the range for the output number.@return {Number}The number within the output range.
polarToCartesian
Convert polar coordinates to cartesian coordinates. Polar Coordinates Explainer.
@param {Number} xPolar x coordinate.@param {Number} yPolar y coordinate.@param {Number} radiusThe distance from the polar point.@param {Number} angleInDegreesThe angle from the polar point.@return {Object} pointThe cartesian point.@return {Object} point.xCartesian x coordinate.@return {Object} point.yCartesian y coordinate.
toDegrees
Convert an angle in radians to degrees. The code is derived from: https://stackoverflow.com/questions/9705123/how-can-i-get-sin-cos-and-tan-to-use-degrees-instead-of-radians.
@param {Number} angleAn angle in radians.@return {Number}An angle in degrees.
toRadians
Convert an angle in degrees to radians. The code is derived from: https://stackoverflow.com/questions/9705123/how-can-i-get-sin-cos-and-tan-to-use-degrees-instead-of-radians.
@param {Number} angleAn angle in degrees.@return {Number}An angle in radians.
Grids
grid
Create a grid and run a function for each item it has.
@param {Object} gridAn object containing information about the grid.@param {Number} grid.columnsThe number of columns in the grid.@param {Number} grid.rowsThe number of rows in the grid.@param {Number} grid.widthThe width of the grid.@param {Number} grid.heightThe height of the grid.@param {Function} callbackThe function to run. The function contains information about each item in the grid.@return {Void}Returns nothing.
times
Run a function x number of times.
@param {Number} numberThe number of times to run the function.@param {Function} callbackThe function to run. The function contains the current index of the loop.@return {Void}Returns nothing.
Interpolation
lerp
Interpolate the number between a set of numbers.
@param {Number} startThe number to start at.@param {Number} endThe number to end at.@return {Number}Returns the interpolated number.
lerpColor
A linear interpolator for hexadecimal colors. The code is derived from: https://gist.github.com/rosszurowski/67f04465c424a9bc0dae.
@param {String} colorAThe hexadecimal color to start at.@param {String} colorBThe hexadecimal color to end at.@return {String}Returns the interpolated hex color.
linearInterpolation
Compute an object full of interpolations.
@param {Number} numberThe number of times to interpolate.@param {Object} valuesAn object containing the start and end numbers in an array.@return {Array}Returns the list of interpolations.
smoothstep
Smoothstep performs Hermite interpolation between two values.
@param {Number} numberThe number to interpolate.@param {Number} minThe min of the range.@param {Number} maxThe max of the range.@return {Number}Returns a value between 0.0 to 1.0.
Noise
The noise functions are built on top of simplex-noise. You can read an exapliner about noise by Varun Vachhar called Noise in Creative Coding. A quick note, frequency controls how quickly or slowly the noise function is "evolving over time". A low frequency would produce values that are very close to each other for close values of x, while a high frequency would have more volatility, and probably look more similar to the random function. amplitude controls the range of values we get from the noise function. Random.noise1D will return numbers between -amplitude and amplitude. This is very similar to the parameters of Random.range(minValue, maxValue), but compressed in a single parameter.
noise1D
Created noise in 1 dimension.
@param {Number} xx dimension.@param {Number} frequencyHow often to change. Usually a number between0and1@param {Number} amplitudeThe amplitude of the wave, how much to change in each direction.
noise2D
Created noise in 2 dimensions.
@param {Number} xx dimension.@param {Number} yy dimension.@param {Number} frequencyHow often to change. Usually a number between0and1@param {Number} amplitudeThe amplitude of the wave, how much to change in each direction.
noise3D
Created noise in 3 dimensions.
@param {Number} xx dimension.@param {Number} yy dimension.@param {Number} zz dimension.@param {Number} frequencyHow often to change. Usually a number between0and1@param {Number} amplitudeThe amplitude of the wave, how much to change in each direction.
noise4D
Created noise in 4 dimensions.
@param {Number} xx dimension.@param {Number} yy dimension.@param {Number} zz dimension.@param {Number} timetime dimension.@param {Number} frequencyHow often to change. Usually a number between0and1@param {Number} amplitudeThe amplitude of the wave, how much to change in each direction.
Contributing
All contributors and all contributions both big and small are welcome in this project.
