flow: stuff

This commit is contained in:
cha0s 2021-02-11 15:11:09 -06:00
parent 009cee8926
commit 28caa55fc6

View File

@ -58,6 +58,7 @@ export const angleRange = (angle, delta) => ({
min: 360 + (angle - delta),
max: 360 + (angle + delta),
});
export const mod = (l, r) => ((l % r) + r) % r;
export const mul = (l, r) => l * r;
export const normalizeAngleRange = (min, max) => {
/* eslint-disable no-param-reassign */
@ -82,25 +83,28 @@ export const randomNumber = (min, max) => {
}
return min + Math.random() * (max - min);
};
export const spontaneous = (elapsed, period) => Math.random() < 1 / (period / elapsed);
export const sub = (l, r) => l - r;
export const toRad = (a) => (a % 360) * PI_180;
const binaryOp = (label) => ({
label,
type: 'number',
args: [
{
label: 'lhs',
type: 'number',
},
{
label: 'rhs',
type: 'number',
},
],
});
export function children() {
return {
add: {
label: 'Add',
type: 'number',
args: [
{
label: 'lhs',
type: 'number',
},
{
label: 'rhs',
type: 'number',
},
],
},
add: binaryOp('add'),
angleFromRad: {
label: 'Angle from radians',
type: 'number',
@ -125,6 +129,7 @@ export function children() {
},
],
},
div: binaryOp('divide'),
floor: {
label: 'Floor',
type: 'number',
@ -135,6 +140,12 @@ export function children() {
},
],
},
mod: binaryOp('mod'),
mul: binaryOp('multiply'),
random: {
type: 'number',
args: [],
},
randomNumber: {
label: 'Random number',
type: 'number',
@ -149,19 +160,20 @@ export function children() {
},
],
},
sub: {
label: 'Sub',
type: 'number',
spontaneous: {
type: 'bool',
args: [
{
label: 'lhs',
type: 'number',
},
{
label: 'rhs',
type: 'number',
},
],
},
sub: binaryOp('subtract'),
TWO_PI: {
type: 'number',
},
};
}