mirror of
https://github.com/litruv/picoGraph.git
synced 2026-07-24 10:46:06 +10:00
Initial commit
moved from private version control
This commit is contained in:
25
scripts/nodes/library/math/abs.js
Normal file
25
scripts/nodes/library/math/abs.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Computes the absolute value using abs.
|
||||
*/
|
||||
export const mathAbsNode = createNodeModule(
|
||||
{
|
||||
id: "math_abs",
|
||||
title: "Abs",
|
||||
category: "Math",
|
||||
description: "Return the absolute value of a number.",
|
||||
searchTags: ["abs", "absolute", "math"],
|
||||
inputs: [{ id: "value", name: "Value", direction: "input", kind: "number" }],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
return `abs(${value})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
30
scripts/nodes/library/math/atan2.js
Normal file
30
scripts/nodes/library/math/atan2.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Computes an angle from delta components using atan2.
|
||||
*/
|
||||
export const mathAtan2Node = createNodeModule(
|
||||
{
|
||||
id: "math_atan2",
|
||||
title: "Atan2",
|
||||
category: "Math",
|
||||
description:
|
||||
"Return the screenspace angle for a delta X and Y pair.",
|
||||
searchTags: ["atan2", "angle", "math", "trig"],
|
||||
inputs: [
|
||||
{ id: "dx", name: "DX", direction: "input", kind: "number" },
|
||||
{ id: "dy", name: "DY", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const dx = resolveValueInput("dx", "0");
|
||||
const dy = resolveValueInput("dy", "0");
|
||||
return `atan2(${dx}, ${dy})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/band.js
Normal file
29
scripts/nodes/library/math/band.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs bitwise and using band.
|
||||
*/
|
||||
export const mathBandNode = createNodeModule(
|
||||
{
|
||||
id: "math_band",
|
||||
title: "Bitwise AND",
|
||||
category: "Math",
|
||||
description: "Return bits set in both operands using BAND().",
|
||||
searchTags: ["band", "bitwise", "and", "math"],
|
||||
inputs: [
|
||||
{ id: "a", name: "A", direction: "input", kind: "number" },
|
||||
{ id: "b", name: "B", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const a = resolveValueInput("a", "0");
|
||||
const b = resolveValueInput("b", "0");
|
||||
return `band(${a}, ${b})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
25
scripts/nodes/library/math/bnot.js
Normal file
25
scripts/nodes/library/math/bnot.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs bitwise not using bnot.
|
||||
*/
|
||||
export const mathBnotNode = createNodeModule(
|
||||
{
|
||||
id: "math_bnot",
|
||||
title: "Bitwise NOT",
|
||||
category: "Math",
|
||||
description: "Invert every bit in a value using BNOT().",
|
||||
searchTags: ["bnot", "bitwise", "not", "math"],
|
||||
inputs: [{ id: "value", name: "Value", direction: "input", kind: "number" }],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
return `bnot(${value})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/bor.js
Normal file
29
scripts/nodes/library/math/bor.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs bitwise or using bor.
|
||||
*/
|
||||
export const mathBorNode = createNodeModule(
|
||||
{
|
||||
id: "math_bor",
|
||||
title: "Bitwise OR",
|
||||
category: "Math",
|
||||
description: "Return bits set in either operand using BOR().",
|
||||
searchTags: ["bor", "bitwise", "or", "math"],
|
||||
inputs: [
|
||||
{ id: "a", name: "A", direction: "input", kind: "number" },
|
||||
{ id: "b", name: "B", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const a = resolveValueInput("a", "0");
|
||||
const b = resolveValueInput("b", "0");
|
||||
return `bor(${a}, ${b})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/bxor.js
Normal file
29
scripts/nodes/library/math/bxor.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs bitwise exclusive-or using bxor.
|
||||
*/
|
||||
export const mathBxorNode = createNodeModule(
|
||||
{
|
||||
id: "math_bxor",
|
||||
title: "Bitwise XOR",
|
||||
category: "Math",
|
||||
description: "Return bits set in exactly one operand using BXOR().",
|
||||
searchTags: ["bxor", "bitwise", "xor", "math"],
|
||||
inputs: [
|
||||
{ id: "a", name: "A", direction: "input", kind: "number" },
|
||||
{ id: "b", name: "B", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const a = resolveValueInput("a", "0");
|
||||
const b = resolveValueInput("b", "0");
|
||||
return `bxor(${a}, ${b})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
25
scripts/nodes/library/math/ceil.js
Normal file
25
scripts/nodes/library/math/ceil.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Ceils a numeric value using ceil.
|
||||
*/
|
||||
export const mathCeilNode = createNodeModule(
|
||||
{
|
||||
id: "math_ceil",
|
||||
title: "Ceil",
|
||||
category: "Math",
|
||||
description: "Round a value up to the nearest integer.",
|
||||
searchTags: ["ceil", "ceiling", "math", "round"],
|
||||
inputs: [{ id: "value", name: "Value", direction: "input", kind: "number" }],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
return `ceil(${value})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
26
scripts/nodes/library/math/cos.js
Normal file
26
scripts/nodes/library/math/cos.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Computes the cosine of a value using cos.
|
||||
*/
|
||||
export const mathCosNode = createNodeModule(
|
||||
{
|
||||
id: "math_cos",
|
||||
title: "Cos",
|
||||
category: "Math",
|
||||
description:
|
||||
"Return the cosine of an angle where 1.0 represents a full turn.",
|
||||
searchTags: ["cos", "cosine", "math", "trig"],
|
||||
inputs: [{ id: "value", name: "Value", direction: "input", kind: "number" }],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
return `cos(${value})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/div.js
Normal file
29
scripts/nodes/library/math/div.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs integer division using the floor operation.
|
||||
*/
|
||||
export const mathDivNode = createNodeModule(
|
||||
{
|
||||
id: "math_div",
|
||||
title: "Integer Divide",
|
||||
category: "Math",
|
||||
description: "Return the floored quotient of two numbers (A \\ B).",
|
||||
searchTags: ["div", "integer", "divide", "math"],
|
||||
inputs: [
|
||||
{ id: "a", name: "A", direction: "input", kind: "number" },
|
||||
{ id: "b", name: "B", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const a = resolveValueInput("a", "0");
|
||||
const b = resolveValueInput("b", "1");
|
||||
return `(${a}) \\ (${b})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
25
scripts/nodes/library/math/flr.js
Normal file
25
scripts/nodes/library/math/flr.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Floors a numeric value using flr.
|
||||
*/
|
||||
export const mathFlrNode = createNodeModule(
|
||||
{
|
||||
id: "math_flr",
|
||||
title: "Floor",
|
||||
category: "Math",
|
||||
description: "Round a value down to the nearest integer.",
|
||||
searchTags: ["flr", "floor", "math", "round"],
|
||||
inputs: [{ id: "value", name: "Value", direction: "input", kind: "number" }],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
return `flr(${value})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
79
scripts/nodes/library/math/index.js
Normal file
79
scripts/nodes/library/math/index.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import { mathMaxNode } from "./max.js";
|
||||
import { mathMinNode } from "./min.js";
|
||||
import { mathMidNode } from "./mid.js";
|
||||
import { mathFlrNode } from "./flr.js";
|
||||
import { mathCeilNode } from "./ceil.js";
|
||||
import { mathCosNode } from "./cos.js";
|
||||
import { mathSinNode } from "./sin.js";
|
||||
import { mathAtan2Node } from "./atan2.js";
|
||||
import { mathSqrtNode } from "./sqrt.js";
|
||||
import { mathAbsNode } from "./abs.js";
|
||||
import { mathRndNode } from "./rnd.js";
|
||||
import { mathSrandNode } from "./srand.js";
|
||||
import { mathBandNode } from "./band.js";
|
||||
import { mathBorNode } from "./bor.js";
|
||||
import { mathBxorNode } from "./bxor.js";
|
||||
import { mathBnotNode } from "./bnot.js";
|
||||
import { mathShlNode } from "./shl.js";
|
||||
import { mathShrNode } from "./shr.js";
|
||||
import { mathLshrNode } from "./lshr.js";
|
||||
import { mathRotlNode } from "./rotl.js";
|
||||
import { mathRotrNode } from "./rotr.js";
|
||||
import { mathDivNode } from "./div.js";
|
||||
|
||||
/**
|
||||
* All math-related node modules backed by PICO-8 helpers.
|
||||
*/
|
||||
export const mathNodes = [
|
||||
mathMaxNode,
|
||||
mathMinNode,
|
||||
mathMidNode,
|
||||
mathFlrNode,
|
||||
mathCeilNode,
|
||||
mathCosNode,
|
||||
mathSinNode,
|
||||
mathAtan2Node,
|
||||
mathSqrtNode,
|
||||
mathAbsNode,
|
||||
mathRndNode,
|
||||
mathSrandNode,
|
||||
mathBandNode,
|
||||
mathBorNode,
|
||||
mathBxorNode,
|
||||
mathBnotNode,
|
||||
mathShlNode,
|
||||
mathShrNode,
|
||||
mathLshrNode,
|
||||
mathRotlNode,
|
||||
mathRotrNode,
|
||||
mathDivNode,
|
||||
];
|
||||
|
||||
/**
|
||||
* Checklist tracking coverage of documented math helpers.
|
||||
* @type {Array<{ function: string, nodeId: string, implemented: boolean }>}
|
||||
*/
|
||||
export const mathFunctionChecklist = [
|
||||
{ function: "MAX", nodeId: "math_max", implemented: true },
|
||||
{ function: "MIN", nodeId: "math_min", implemented: true },
|
||||
{ function: "MID", nodeId: "math_mid", implemented: true },
|
||||
{ function: "FLR", nodeId: "math_flr", implemented: true },
|
||||
{ function: "CEIL", nodeId: "math_ceil", implemented: true },
|
||||
{ function: "COS", nodeId: "math_cos", implemented: true },
|
||||
{ function: "SIN", nodeId: "math_sin", implemented: true },
|
||||
{ function: "ATAN2", nodeId: "math_atan2", implemented: true },
|
||||
{ function: "SQRT", nodeId: "math_sqrt", implemented: true },
|
||||
{ function: "ABS", nodeId: "math_abs", implemented: true },
|
||||
{ function: "RND", nodeId: "math_rnd", implemented: true },
|
||||
{ function: "SRAND", nodeId: "math_srand", implemented: true },
|
||||
{ function: "BAND", nodeId: "math_band", implemented: true },
|
||||
{ function: "BOR", nodeId: "math_bor", implemented: true },
|
||||
{ function: "BXOR", nodeId: "math_bxor", implemented: true },
|
||||
{ function: "BNOT", nodeId: "math_bnot", implemented: true },
|
||||
{ function: "SHL", nodeId: "math_shl", implemented: true },
|
||||
{ function: "SHR", nodeId: "math_shr", implemented: true },
|
||||
{ function: "LSHR", nodeId: "math_lshr", implemented: true },
|
||||
{ function: "ROTL", nodeId: "math_rotl", implemented: true },
|
||||
{ function: "ROTR", nodeId: "math_rotr", implemented: true },
|
||||
{ function: "\\", nodeId: "math_div", implemented: true },
|
||||
];
|
||||
29
scripts/nodes/library/math/lshr.js
Normal file
29
scripts/nodes/library/math/lshr.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs a logical right bit shift using lshr.
|
||||
*/
|
||||
export const mathLshrNode = createNodeModule(
|
||||
{
|
||||
id: "math_lshr",
|
||||
title: "Logical Shift Right",
|
||||
category: "Math",
|
||||
description: "Shift bits right with zeros entering from the left.",
|
||||
searchTags: ["lshr", "shift", "bitwise", "math"],
|
||||
inputs: [
|
||||
{ id: "value", name: "Value", direction: "input", kind: "number" },
|
||||
{ id: "amount", name: "Amount", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
const amount = resolveValueInput("amount", "0");
|
||||
return `lshr(${value}, ${amount})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/max.js
Normal file
29
scripts/nodes/library/math/max.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Returns the maximum of two values using max.
|
||||
*/
|
||||
export const mathMaxNode = createNodeModule(
|
||||
{
|
||||
id: "math_max",
|
||||
title: "Max",
|
||||
category: "Math",
|
||||
description: "Return the greater of two numeric values.",
|
||||
searchTags: ["max", "maximum", "math", "compare"],
|
||||
inputs: [
|
||||
{ id: "a", name: "A", direction: "input", kind: "number" },
|
||||
{ id: "b", name: "B", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "value", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const a = resolveValueInput("a", "0");
|
||||
const b = resolveValueInput("b", "0");
|
||||
return `max(${a}, ${b})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
31
scripts/nodes/library/math/mid.js
Normal file
31
scripts/nodes/library/math/mid.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Returns the median of three values using mid.
|
||||
*/
|
||||
export const mathMidNode = createNodeModule(
|
||||
{
|
||||
id: "math_mid",
|
||||
title: "Mid",
|
||||
category: "Math",
|
||||
description: "Return the middle value from three numeric inputs.",
|
||||
searchTags: ["mid", "median", "math", "compare"],
|
||||
inputs: [
|
||||
{ id: "a", name: "A", direction: "input", kind: "number" },
|
||||
{ id: "b", name: "B", direction: "input", kind: "number" },
|
||||
{ id: "c", name: "C", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "value", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const a = resolveValueInput("a", "0");
|
||||
const b = resolveValueInput("b", "0");
|
||||
const c = resolveValueInput("c", "0");
|
||||
return `mid(${a}, ${b}, ${c})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/min.js
Normal file
29
scripts/nodes/library/math/min.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Returns the minimum of two values using min.
|
||||
*/
|
||||
export const mathMinNode = createNodeModule(
|
||||
{
|
||||
id: "math_min",
|
||||
title: "Min",
|
||||
category: "Math",
|
||||
description: "Return the lesser of two numeric values.",
|
||||
searchTags: ["min", "minimum", "math", "compare"],
|
||||
inputs: [
|
||||
{ id: "a", name: "A", direction: "input", kind: "number" },
|
||||
{ id: "b", name: "B", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "value", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const a = resolveValueInput("a", "0");
|
||||
const b = resolveValueInput("b", "0");
|
||||
return `min(${a}, ${b})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
25
scripts/nodes/library/math/rnd.js
Normal file
25
scripts/nodes/library/math/rnd.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Generates random numbers using rnd.
|
||||
*/
|
||||
export const mathRndNode = createNodeModule(
|
||||
{
|
||||
id: "math_rnd",
|
||||
title: "Random",
|
||||
category: "Math",
|
||||
description: "Return a random number in the range [0, x).",
|
||||
searchTags: ["rnd", "random", "math"],
|
||||
inputs: [{ id: "value", name: "Range", direction: "input", kind: "number" }],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "1");
|
||||
return `rnd(${value})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/rotl.js
Normal file
29
scripts/nodes/library/math/rotl.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs a left bit rotation using rotl.
|
||||
*/
|
||||
export const mathRotlNode = createNodeModule(
|
||||
{
|
||||
id: "math_rotl",
|
||||
title: "Rotate Left",
|
||||
category: "Math",
|
||||
description: "Rotate bits left by a given amount.",
|
||||
searchTags: ["rotl", "rotate", "bitwise", "math"],
|
||||
inputs: [
|
||||
{ id: "value", name: "Value", direction: "input", kind: "number" },
|
||||
{ id: "amount", name: "Amount", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
const amount = resolveValueInput("amount", "0");
|
||||
return `rotl(${value}, ${amount})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/rotr.js
Normal file
29
scripts/nodes/library/math/rotr.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs a right bit rotation using rotr.
|
||||
*/
|
||||
export const mathRotrNode = createNodeModule(
|
||||
{
|
||||
id: "math_rotr",
|
||||
title: "Rotate Right",
|
||||
category: "Math",
|
||||
description: "Rotate bits right by a given amount.",
|
||||
searchTags: ["rotr", "rotate", "bitwise", "math"],
|
||||
inputs: [
|
||||
{ id: "value", name: "Value", direction: "input", kind: "number" },
|
||||
{ id: "amount", name: "Amount", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
const amount = resolveValueInput("amount", "0");
|
||||
return `rotr(${value}, ${amount})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/shl.js
Normal file
29
scripts/nodes/library/math/shl.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs a left bit shift using shl.
|
||||
*/
|
||||
export const mathShlNode = createNodeModule(
|
||||
{
|
||||
id: "math_shl",
|
||||
title: "Shift Left",
|
||||
category: "Math",
|
||||
description: "Shift bits left with zeros entering from the right.",
|
||||
searchTags: ["shl", "shift", "bitwise", "math"],
|
||||
inputs: [
|
||||
{ id: "value", name: "Value", direction: "input", kind: "number" },
|
||||
{ id: "amount", name: "Amount", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
const amount = resolveValueInput("amount", "0");
|
||||
return `shl(${value}, ${amount})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/shr.js
Normal file
29
scripts/nodes/library/math/shr.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Performs an arithmetic right bit shift using shr.
|
||||
*/
|
||||
export const mathShrNode = createNodeModule(
|
||||
{
|
||||
id: "math_shr",
|
||||
title: "Shift Right",
|
||||
category: "Math",
|
||||
description: "Shift bits right while extending the sign bit.",
|
||||
searchTags: ["shr", "shift", "bitwise", "math"],
|
||||
inputs: [
|
||||
{ id: "value", name: "Value", direction: "input", kind: "number" },
|
||||
{ id: "amount", name: "Amount", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
const amount = resolveValueInput("amount", "0");
|
||||
return `shr(${value}, ${amount})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
26
scripts/nodes/library/math/sin.js
Normal file
26
scripts/nodes/library/math/sin.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Computes the sine of a value using sin.
|
||||
*/
|
||||
export const mathSinNode = createNodeModule(
|
||||
{
|
||||
id: "math_sin",
|
||||
title: "Sin",
|
||||
category: "Math",
|
||||
description:
|
||||
"Return the sine of an angle where 1.0 represents a full turn.",
|
||||
searchTags: ["sin", "sine", "math", "trig"],
|
||||
inputs: [{ id: "value", name: "Value", direction: "input", kind: "number" }],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
return `sin(${value})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
25
scripts/nodes/library/math/sqrt.js
Normal file
25
scripts/nodes/library/math/sqrt.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Computes a square root using sqrt.
|
||||
*/
|
||||
export const mathSqrtNode = createNodeModule(
|
||||
{
|
||||
id: "math_sqrt",
|
||||
title: "Sqrt",
|
||||
category: "Math",
|
||||
description: "Return the square root of a numeric value.",
|
||||
searchTags: ["sqrt", "square root", "math"],
|
||||
inputs: [{ id: "value", name: "Value", direction: "input", kind: "number" }],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
return `sqrt(${value})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/math/srand.js
Normal file
29
scripts/nodes/library/math/srand.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Seeds the random number generator using srand.
|
||||
*/
|
||||
export const mathSrandNode = createNodeModule(
|
||||
{
|
||||
id: "math_srand",
|
||||
title: "Seed Random",
|
||||
category: "Math",
|
||||
description: "Set the random number generator seed.",
|
||||
searchTags: ["srand", "random", "seed", "math"],
|
||||
inputs: [
|
||||
{ id: "exec_in", name: "Exec", direction: "input", kind: "exec" },
|
||||
{ id: "value", name: "Seed", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "exec_out", name: "Exec", direction: "output", kind: "exec" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
emitExec: ({ indent, indentLevel, resolveValueInput, emitNextExec }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
const line = `${indent(indentLevel)}srand(${value})`;
|
||||
return [line, ...emitNextExec("exec_out")];
|
||||
},
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user