Processing 如何为正在处理的饼图创建单独的类选项卡?

Processing 如何为正在处理的饼图创建单独的类选项卡?,processing,Processing,我想在我的项目中添加一个饼图,但我希望能够有一个类选项卡,只用于饼图的编码,而在setup()draw()选项卡中,只需要有代码来输出饼图。我希望能够使setup()draw()编码窗口看起来更干净,因为它是在我的项目中评估的。 下面我将提供我的原始代码,然后尝试为饼图的代码创建一个单独的类选项卡 我得到的错误是setup()draw()选项卡第8行中的“构造函数”PieChart(int,int,int,int[],int[])“不存在”,以及PieChart选项卡第7行中的“方法的返回类型丢

我想在我的项目中添加一个饼图,但我希望能够有一个类选项卡,只用于饼图的编码,而在setup()draw()选项卡中,只需要有代码来输出饼图。我希望能够使setup()draw()编码窗口看起来更干净,因为它是在我的项目中评估的。 下面我将提供我的原始代码,然后尝试为饼图的代码创建一个单独的类选项卡

我得到的错误是setup()draw()选项卡第8行中的“构造函数”PieChart(int,int,int,int[],int[])“不存在”,以及PieChart选项卡第7行中的“方法的返回类型丢失”

原始代码:

int[] values = {32, 11, 7};
int[] colors = {#E4000F, #655CBE, #107C10};

void setup() {
  size(300, 300);
  pixelDensity(2); 
  smooth();
}

void draw() {
  background(25);
  pieChart(width/2, height/2, 200, values, colors);
}

// pX, pY : position
// pRad : diameter
// pVal: Array of Values
// pCols: Array of colors

void pieChart(float pX, float pY, float pDia, int[] pVal, int[]pCols) {
  stroke(225);
  float total = 0;
  float lastAngle= -PI;
  float mouseAngle = atan2(mouseY-pY, mouseX-pX);

  // get sum of values
  for (int i =0; i<pVal.length; i++) {
    total += pVal[i];
  }

  for (int i =0; i<pVal.length; i++) {
    fill(pCols[i]);
    float angle = map(pVal[i], 0, total, 0, 2*PI);
    arc(pX, pY, pDia, pDia, lastAngle, lastAngle+angle, PIE);

    if ( mouseAngle >= lastAngle && mouseAngle < lastAngle+angle ) {
      text(values[i] + "/50", pX-pDia/2, pY-pDia/2);
    }

    lastAngle += angle;
  }
}
尝试创建单独的类代码(图表选项卡):

类图表{
//pX,pY:位置
//普拉德:直径
//pVal:值数组
//pCols:颜色数组
pieChart(浮点pX、浮点pY、浮点pDia、int[]pVal、int[]pCols){
仰泳();
浮动总数=0;
浮动角度=-PI;
float mouseAngle=atan2(mouseY-pY,mouseX-pX);
//获取值的和

对于(int i=0;i,以下在我的系统上以Java运行:

int[] values = {32, 11, 7};
int[] colors = {#E4000F, #655CBE, #107C10};

class PieChart {

void pieChart(float pX, float pY, float pDia, int[] pVal, int[]pCols) {
    noStroke();
    float total = 0;
    float lastAngle= -PI;
    float mouseAngle = atan2(mouseY-pY, mouseX-pX);

    // get sum of values
    for (int i =0; i<pVal.length; i++) {
      total += pVal[i];
    }

    for (int i =0; i<pVal.length; i++) {
      fill(pCols[i]);
      float angle = map(pVal[i], 0, total, 0, 2*PI);
      arc(pX, pY, pDia, pDia, lastAngle, lastAngle+angle, PIE);

      if ( mouseAngle >= lastAngle && mouseAngle < lastAngle+angle ) {
        text(values[i] + "/50)", pX-pDia/2, pY-pDia/2);
      }
      lastAngle += angle;
    }
  }
}

PieChart pieChart;

void setup() {
  size(300, 300);
  pixelDensity(2); 
  smooth();
  pieChart = new PieChart();
}

void draw() {
  background(25);
  pieChart.pieChart(width/2.0, height/2.0, 200.0, values, colors);
}

int[]值={32,11,7};
int[]颜色={E4000F,{655CBE,{107C10};
班级图表{
无效图表(浮动pX、浮动pY、浮动pDia、int[]pVal、int[]pCols){
仰泳();
浮动总数=0;
浮动角度=-PI;
float mouseAngle=atan2(mouseY-pY,mouseX-pX);
//获取值的和

对于(int i=0;i)构造函数的名称和大小写不应该与类相同吗?我的意思是:
pieChart(float pX,float pY,float pDia,int[]pVal,int[]pCols){…}
不应该是
pieChart(float pX,float pY,float pDia,int[]pVal,int[]pCols){…}
和P?
class PieChart {
  //pX, pY : position
  // pRad : diameter
  // pVal: Array of Values
  // pCols: Array of colors

  pieChart(float pX, float pY, float pDia, int[] pVal, int[]pCols) {
    noStroke();
    float total = 0;
    float lastAngle= -PI;
    float mouseAngle = atan2(mouseY-pY, mouseX-pX);


    // get sum of values
    for (int i =0; i<pVal.length; i++) {
      total += pVal[i];
    }

    for (int i =0; i<pVal.length; i++) {
      fill(pCols[i]);
      float angle = map(pVal[i], 0, total, 0, 2*PI);
      arc(pX, pY, pDia, pDia, lastAngle, lastAngle+angle, PIE);

      if ( mouseAngle >= lastAngle && mouseAngle < lastAngle+angle ) {
        text(values[i] + "/50)", pX-pDia/2, pY-pDia/2);
      }
      lastAngle += angle;
    }
  }
}
int[] values = {32, 11, 7};
int[] colors = {#E4000F, #655CBE, #107C10};

class PieChart {

void pieChart(float pX, float pY, float pDia, int[] pVal, int[]pCols) {
    noStroke();
    float total = 0;
    float lastAngle= -PI;
    float mouseAngle = atan2(mouseY-pY, mouseX-pX);

    // get sum of values
    for (int i =0; i<pVal.length; i++) {
      total += pVal[i];
    }

    for (int i =0; i<pVal.length; i++) {
      fill(pCols[i]);
      float angle = map(pVal[i], 0, total, 0, 2*PI);
      arc(pX, pY, pDia, pDia, lastAngle, lastAngle+angle, PIE);

      if ( mouseAngle >= lastAngle && mouseAngle < lastAngle+angle ) {
        text(values[i] + "/50)", pX-pDia/2, pY-pDia/2);
      }
      lastAngle += angle;
    }
  }
}

PieChart pieChart;

void setup() {
  size(300, 300);
  pixelDensity(2); 
  smooth();
  pieChart = new PieChart();
}

void draw() {
  background(25);
  pieChart.pieChart(width/2.0, height/2.0, 200.0, values, colors);
}