Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
package com.marginallyclever.makelangelo.donatelloimpl.nodes;
import com.marginallyclever.donatello.ports.InputColor;
import com.marginallyclever.donatello.ports.InputInt;
import com.marginallyclever.donatello.ports.OutputInt;
import com.marginallyclever.nodegraphcore.Node;
import com.marginallyclever.nodegraphcore.PrintWithGraphics;
import java.awt.*;
/**
* A node that creates a canvas with a given size and color.
*/
public class Canvas extends Node implements PrintWithGraphics {
private final InputInt width = new InputInt("width", 1);
private final InputInt height = new InputInt("height", 1);
private final InputColor color = new InputColor("color", Color.WHITE);
private final OutputInt outx = new OutputInt("x",0);
private final OutputInt outy = new OutputInt("y",0);
private final OutputInt outw = new OutputInt("width",width.getValue());
private final OutputInt outh = new OutputInt("height",height.getValue());
public Canvas() {
super("Canvas");
addVariable(width);
addVariable(height);
addVariable(color);
addVariable(outx);
addVariable(outy);
addVariable(outw);
addVariable(outh);
}
@Override
public void update() {
var w = Math.max(1,width.getValue());
var h = Math.max(1,height.getValue());
outx.send(0);
outy.send(0);
outw.send(w);
outh.send(h);
}
@Override
public void print(Graphics g) {
var w = Math.max(1,width.getValue());
var h = Math.max(1,height.getValue());
g.setColor(color.getValue());
g.fillRect(0,0,w,h);
}
}
9e679da90This file is pinned to the selected release. Download the original to open it in your design tool.