-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathCanvas.java
More file actions
61 lines (53 loc) · 1.84 KB
/
Canvas.java
File metadata and controls
61 lines (53 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 InputInt layer = new InputInt("layer",5);
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");
addPort(width);
addPort(height);
addPort(color);
addPort(outx);
addPort(outy);
addPort(outw);
addPort(outh);
addPort(layer);
}
@Override
public void update() {
var w = Math.max(1,width.getValue());
var h = Math.max(1,height.getValue());
outx.setValue(-w/2);
outy.setValue(-h/2);
outw.setValue(w);
outh.setValue(h);
}
@Override
public void print(Graphics g) {
var x = outx.getValue();
var y = outy.getValue();
var w = Math.max(1,width.getValue());
var h = Math.max(1,height.getValue());
g.setColor(color.getValue());
g.fillRect(x,y,w,h);
}
@Override
public int getLayer() {
return layer.getValue();
}
}