有没有一种方法可以从for循环中将顶点添加到多边形中

时间:2020-02-14 10:08:36

标签: processing

enter image description here

我希望对这些被水平线划分的部分进行不同的着色,但是不知道将这些顶点转换为形状,是否可以进行处理?我唯一想过的想法是,在每次检查是否将年份除以10的除数是1到9的每次迭代过程中,将每年的顶点和总体(这里用椭圆表示)添加到形状中。

我什至不知道代码的哪一部分放在这里,所以我将整个过程发布。

Table populationData;
int rowCount;
float mx = 79;


void setup() {
  size(1000, 600);
  populationData = new Table("population_by_year.tsv");
  rowCount = populationData.getRowCount();  //69

}

void draw() {
  background(153);
  textFont(titleFont);
  stroke(230);
  fill(230);
  textAlign(CENTER);
  text("Population of Nepal by year", width/2, 30);

  textFont(labelFont);
  textAlign(LEFT);

  //read Data for population of each year:
  for(int row = 0; row < rowCount; row++) {
    int years = populationData.getInt(row, 0);
    float populations = populationData.getFloat(row, 1);
    //println(rowCount);
    println(years);
    //println(populations);
    float x = map(populations, 8570449, 29709449, 80, width-80);
    println(x);
    float y = map(years, 2019, 1951, 80, height-180);
    println(y);
    float x2 = map(row, 0, 69, 80, width-80);

    float roundedPopulations = populations/1000000;
    //println(roundedPopulations);


    //X-axis label lines
    line(x2, height-80, x2, height-85);

    //X-axis text in difference of 10
    if((row % 10 == 0) || (row == 69)) {
      textFont(miniFont);
      println("rowCount:" +rowCount);
      stroke(255);
      fill(255);
      text(roundedPopulations, x2-20, height-60);
      println("roundedPopulations:" +roundedPopulations);
      println("x2:" + x2);
    }

    if((years == 1951) || (years == 2019)) {
      textFont(labelFont);
      text(years, x2-40, y);
      line(x2, y, x2, height-85);
    }

    if(years % 10 == 1){
       line(x, y, width-90, y);

    }

    //Information Line - with Interaction   
    if((mx > 80) && (mx < width-80)) {

      if(abs(mx - x) < 5) {
        line(mx, y, mx, height-80);
        textFont(labelFont);
        fill(palette[3]);
        text(years, mx+10, y-65);
        text(roundedPopulations, mx + 6, y-45);
      }
    }  

     //Ellipse dot 
     fill(palette[1]);
     int d = 7;
     fill(230);
     ellipse(x, y, d, d);
    }
     //noLoop();
  }


void mouseMoved() {
  mx = mouseX;
}

0 个答案:

没有答案
相关问题