mirror of
https://github.com/litruv/picoGraph.git
synced 2026-07-24 02:36:04 +10:00
66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
import { createNodeModule } from "../../nodeTypes.js";
|
|
|
|
/**
|
|
* Draws an outlined rectangle.
|
|
*/
|
|
export const rectNode = createNodeModule(
|
|
{
|
|
id: "graphics_rect",
|
|
title: "Draw Rectangle",
|
|
category: "Graphics",
|
|
description: "Render a rectangle outline defined by two corners.",
|
|
searchTags: ["rect", "rectangle", "outline", "shape"],
|
|
inputs: [
|
|
{ id: "exec_in", name: "Exec", direction: "input", kind: "exec" },
|
|
{
|
|
id: "x0",
|
|
name: "X0",
|
|
direction: "input",
|
|
kind: "number",
|
|
defaultValue: 0,
|
|
},
|
|
{
|
|
id: "y0",
|
|
name: "Y0",
|
|
direction: "input",
|
|
kind: "number",
|
|
defaultValue: 0,
|
|
},
|
|
{
|
|
id: "x1",
|
|
name: "X1",
|
|
direction: "input",
|
|
kind: "number",
|
|
defaultValue: 8,
|
|
},
|
|
{
|
|
id: "y1",
|
|
name: "Y1",
|
|
direction: "input",
|
|
kind: "number",
|
|
defaultValue: 8,
|
|
},
|
|
{ id: "color", name: "Color", direction: "input", kind: "color" },
|
|
],
|
|
outputs: [
|
|
{ id: "exec_out", name: "Exec", direction: "output", kind: "exec" },
|
|
],
|
|
properties: [],
|
|
},
|
|
{
|
|
emitExec: ({ indent, indentLevel, resolveValueInput, emitNextExec }) => {
|
|
const x0 = resolveValueInput("x0", "0");
|
|
const y0 = resolveValueInput("y0", "0");
|
|
const x1 = resolveValueInput("x1", "8");
|
|
const y1 = resolveValueInput("y1", "8");
|
|
const color = resolveValueInput("color", "__pg_omit__");
|
|
const args = [x0, y0, x1, y1];
|
|
if (color !== "__pg_omit__") {
|
|
args.push(color);
|
|
}
|
|
const line = `${indent(indentLevel)}rect(${args.join(", ")})`;
|
|
return [line, ...emitNextExec("exec_out")];
|
|
},
|
|
}
|
|
);
|