Tree 取消绘制对象的问题-处理
查看文档,它看起来像noFill();和仰泳();这些都是我应该调用的“undraw”对象。现在,单击,我将显示树的子节点,但再次单击父节点,我希望这些子节点折叠并“取消绘制”。有人能告诉我这里可能出了什么问题吗?非常感谢。在javascript中运行 主要草图:Tree 取消绘制对象的问题-处理,tree,processing,processing.js,Tree,Processing,Processing.js,查看文档,它看起来像noFill();和仰泳();这些都是我应该调用的“undraw”对象。现在,单击,我将显示树的子节点,但再次单击父节点,我希望这些子节点折叠并“取消绘制”。有人能告诉我这里可能出了什么问题吗?非常感谢。在javascript中运行 主要草图: //SFD Tree Visualization //Austin Slominski 2014 Node root; Node current; XML data; void setup(){ root = new No
//SFD Tree Visualization
//Austin Slominski 2014
Node root;
Node current;
XML data;
void setup(){
root = new Node();
data = loadXML("nodes.xml");
size(750,750);
smooth(true);
background(255);
loadChild(root, data, null);
current = root;
}
void loadChild(Node node, XML data, Node parent) {
XML title = data.getChild("title");
String xmlTitle = title.getContent();
node.title = xmlTitle;
XML[] XMLchildren = data.getChildren("child");
node.children = new Node[XMLchildren.length];
for(int i=0;i<XMLchildren.length;i++){
node.children[i] = new Node();
}
//DEBUG
println("Current Node: " + node.title);
if(parent!=null){
println("Parent: " + parent.title);
node.parent = parent;
}
if(node.children!=null){
println("Number of Children:" + XMLchildren.length);
}
println("");
for (int i = 0; i < XMLchildren.length; i++) {
loadChild(node.children[i], XMLchildren[i], node);
}
}
void draw(){
current.display();//starts inactive, null collapsed
if(current.collapsed == false) {
for (int i = 0; i < current.children.length; i++) {
current.children[i].display();
}
}
}
void mousePressed(){
current.clickedActive();
for (int i = 0; i < current.children.length; i++) {
current.children[i].clickedActive();
}
}
//SFD树可视化
//奥斯汀·斯洛明斯基2014
节根;
节点电流;
XML数据;
无效设置(){
根=新节点();
data=loadXML(“nodes.xml”);
规模(750750);
平滑(真实);
背景(255);
loadChild(根,数据,空);
电流=根;
}
void loadChild(节点、XML数据、节点父节点){
XML title=data.getChild(“title”);
字符串xmlttitle=title.getContent();
node.title=xmlTitle;
XML[]XMLchildren=data.getChildren(“child”);
node.children=新节点[XMLchildren.length];
对于(int i=0;i x&&mouseXy-tHeight&&mouseY
NODES.XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<type></type>
<title>ROOT</title>
<description></description>
<image></image>
<child>
<type></type>
<title>Test Child 1</title>
<description></description>
<image></image>
<child>
<type></type>
<title>Test Child 1b</title>
<description></description>
<image></image>
</child>
</child>
<child>
<type></type>
<title>Test Child 2</title>
<description></description>
<image></image>
<child>
<type></type>
<title>Test Child 2b</title>
<description></description>
<image></image>
</child>
</child>
</root>
根
测试儿童1
测试儿童1b
测试儿童2
测试儿童2b
在绘制任何内容之前,您需要添加背景()
(或大小等于窗口尺寸的矩形()
或图像()
),以便将过去的帧“隐藏”在新帧的后面
像这样:
void draw() {
background(0); // will set the background to black
current.display(); //starts inactive, null collapsed
if (current.collapsed == false) {
for (int i = 0; i < current.children.length; i++) {
current.children[i].display();
}
}
}
void draw(){
背景(0);//将背景设置为黑色
current.display();//启动不活动,空
如果(current.collapsed==false){
for(int i=0;i
处理是一种画蛇添足的语言。你不能“拆开”东西,你只需要在你已经拥有的东西上画更多的东西(或者你清理整个画布,用一张新的纸开始)。这个问题已经在一个横杆上得到了回答。
void draw() {
background(0); // will set the background to black
current.display(); //starts inactive, null collapsed
if (current.collapsed == false) {
for (int i = 0; i < current.children.length; i++) {
current.children[i].display();
}
}
}