Svg 形状处理多重

Svg 形状处理多重,svg,processing,shapes,Svg,Processing,Shapes,我正在尝试制作一个PShape SVG multipy。我希望在每次变量(从CSV文件导入)更改时创建一个新形状。我试着为使用一个,但它不尊重我给它的变量范围,它只是创建了它想要的SVG。基本上,我想做的是,如果变量指示一个X区域之间有21个数据,则在一个和另一个之间的固定距离内绘制SVG的21个副本 Table table; PShape tipi2; PShape tipi3; void setup() { size (1875, 871); table = loadTabl

我正在尝试制作一个PShape SVG multipy。我希望在每次变量(从CSV文件导入)更改时创建一个新形状。我试着为使用一个
,但它不尊重我给它的变量范围,它只是创建了它想要的SVG。基本上,我想做的是,如果变量指示一个X区域之间有21个数据,则在一个和另一个之间的固定距离内绘制SVG的21个副本

Table table;

PShape tipi2;
PShape tipi3;


void setup() {

  size (1875, 871);
  table = loadTable("WHO.csv", "header");
  tipi2 = loadShape("tipi-02.svg");


}


void draw() {

  background(0);


  for (TableRow row : table.rows()) {

    int hale = row.getInt("Healthy life expectancy (HALE) at birth (years) both sexes");


  }
    tipi2.disableStyle();


noStroke();

 for( int i = 0 ;i<=1800;i=i+33){


 pushMatrix();

  translate(0,89.5);

       if(hale > 40 && hale < 60){

shape(tipi2,i,0);

popMatrix();
}

}
表格;
PShape tipi2;
PShape tipi3;
无效设置(){
规模(1875871);
table=loadTable(“WHO.csv”、“header”);
tipi2=loadShape(“tipi-02.svg”);
}
作废提款(){
背景(0);
for(TableRow行:table.rows()){
int hale=row.getInt(“出生时健康预期寿命(hale)(男女年));
}
tipi2.disableStyle();
仰泳();
对于(int i=0;i 40&&hale<60){
形状(tipi2,i,0);
popMatrix();
}
}

在您当前的代码中,有几点可以改进:

  • hale
    变量的可见性(或范围)仅在此循环中:
    for(TableRow:table.rows()){
  • 绘图样式(noStroke()/disableStyle()等)变化不大,因此可以在
    setup()
    中设置一次,而不是在
    draw()中每秒设置多次
  • 您可以在for(TableRow row:table.rows()){
循环中将for循环从0移动到1800,但这可能不是很有效: 我的意思是:

Table table;

PShape tipi2;
PShape tipi3;


void setup() {

  size (1875, 871);
  table = loadTable("WHO.csv", "header");
  tipi2 = loadShape("tipi-02.svg");

  //this styles could be set once in setup, rather than multiple times in draw(); 
  tipi2.disableStyle();
  noStroke();

  background(0);


  for (TableRow row : table.rows()) {

    int hale = row.getInt("Healthy life expectancy (HALE) at birth (years) both sexes");

    for ( int i = 0; i<=1800; i=i+33) {

      pushMatrix();

      translate(0, 89.5);
      //hale is visible within this scope, but not outside the for loop
      if (hale > 40 && hale < 60) {

        shape(tipi2, i, 0);

      }
      //popMatrix(); should be called the same amount of times as pushMatrix
      popMatrix();
    }

  }
}


void draw() {


}
表格;
PShape tipi2;
PShape tipi3;
无效设置(){
规模(1875871);
table=loadTable(“WHO.csv”、“header”);
tipi2=loadShape(“tipi-02.svg”);
//此样式可以在设置中设置一次,而不是在draw()中设置多次;
tipi2.disableStyle();
仰泳();
背景(0);
for(TableRow行:table.rows()){
int hale=row.getInt(“出生时健康预期寿命(hale)(男女年));
对于(int i=0;i 40&&hale<60){
形状(tipi2,i,0);
}
//调用popMatrix()的次数应与调用pushMatrix的次数相同
popMatrix();
}
}
}
作废提款(){
}

您可以清理缩进以提高可读性吗?@LauraFlorez您可以发布.svg(作为代码片段)和.csv(作为链接)文件以便于我们进行测试吗?