Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将以下内容添加到数组中。处理_Java_Processing - Fatal编程技术网

Java 将以下内容添加到数组中。处理

Java 将以下内容添加到数组中。处理,java,processing,Java,Processing,我想知道如何更改以下代码,以便将构成花瓣的圆存储在一个数组中。所以我可以在另一个函数中使用它 void setup() { size(400, 400); smooth(); noStroke(); // frameRate(15); } void draw() { String[] circles = new String[5]; int c1 = 0; int c2 = -40; int c3 = 50;

我想知道如何更改以下代码,以便将构成花瓣的圆存储在一个数组中。所以我可以在另一个函数中使用它

   void setup() {
     size(400, 400);
     smooth();
     noStroke();
  // frameRate(15);
  }

  void draw() {
    String[] circles = new String[5];
    int c1 = 0;
    int c2 = -40;
    int c3 = 50;
    int c4 = 50;
   // set centre point
    translate(width/2, height/2);
    fill(#c6ff89); // green
    for (int i = 0; i < circles.length; i++) {
      ellipse(c1, c2, c3, c4);
       rotate(radians(72));

    }
   // centre circle
   fill(#fff9bb); // light yellow
   ellipse(0, 0, 50, 50);
  }
void setup(){
尺寸(400400);
光滑的();
仰泳();
//帧率(15);
}
作废提款(){
字符串[]圆圈=新字符串[5];
int c1=0;
int c2=-40;
int c3=50;
int c4=50;
//设置中心点
平移(宽度/2,高度/2);
填充(#c6ff89);//绿色
对于(int i=0;i

还有谁能向我解释一下,如何将其更改为更面向对象的形式?这正在处理中。

假设您的
椭圆
返回
Eclipse
对象,并且您想要创建
5个圆
,则创建一个数组作为类变量,作为
私有Eclipse[]myCircles=new Eclipse[5]
;然后将
for
循环更改如下:

for (int i = 0; i < circles.length; i++) {
   Eclipse cicrle = ellipse(c1, c2, c3, c4);
   rotate(radians(72));
   myCircles[i] = cicrle;
}
for(int i=0;i

请注意:根据您的程序更改对象类名和数组大小。

假设您的
椭圆
正在返回
Eclipse
对象,并且您想要创建
5个圆
,创建一个数组作为类变量,如
私有Eclipse[]myCircles=new Eclipse[5]
;然后将
for
循环更改如下:

for (int i = 0; i < circles.length; i++) {
   Eclipse cicrle = ellipse(c1, c2, c3, c4);
   rotate(radians(72));
   myCircles[i] = cicrle;
}
for(int i=0;i

请注意:根据您的程序更改对象类名和数组大小。

注意:按照代码,字符串[]圆没有任何用处

在这里,我写了一个处理方式的例子。。。希望有帮助:

//an array of your class type
Flower[] flowers = new Flower [3];
// one alone..
Flower atMouse = new Flower(0, 0);

void setup() {
  size(400, 400);

  // initialize objects
  for (int i=0; i < flowers.length;i++)
  {
    int pos = i+1;
    flowers[i] = new Flower (pos*100, pos*100);
  }
  smooth();
  background(255);
}

void draw() {
  background(255);
  for (int i=0; i < flowers.length;i++)
  {
    flowers[i].display();
  }

  atMouse.display(mouseX, mouseY);
}

class Flower {

  //class member variables
  float posX;
  float posY;
  int c1 = 0;
  int c2 = -40;
  int c3 = 50;
  int c4 = 50;

  // a constructor
  Flower(float _posX, float _posY)
  {
    //just pass vars
    posX = _posX;
    posY = _posY;
  }

  void display()
  {
    noStroke();
    pushMatrix();
    translate(posX, posY);
    fill(#c6ff89); // green
    for (int i = 0; i < 5; i++) {
      ellipse(c1, c2, c3, c4);
      rotate(radians(72));
    }
    popMatrix();
    // centre circle
    fill(#fff9bb); // light yellow
    ellipse(posX, posY, 50, 50);
  }

  //an overloaded version to keep pos updating...
  void display(float px, float py)
  {
    noStroke();
    pushMatrix();
    translate(px, py); // here use px instead...
    fill(#c6ff89); // green
    for (int i = 0; i < 5; i++) {
      ellipse(c1, c2, c3, c4);
      rotate(radians(72));
    }
    popMatrix();
    // centre circle
    fill(#fff9bb); // light yellow
    ellipse(px, py, 50, 50);//also here
  }
}//eofcl
//类类型的数组
花[]花=新花[3];
//一个人。。
花在鼠标上=新花(0,0);
无效设置(){
尺寸(400400);
//初始化对象
for(int i=0;i
注意:按照代码,String[]圆圈没有任何用处

在这里,我写了一个处理方式的例子。。。希望有帮助:

//an array of your class type
Flower[] flowers = new Flower [3];
// one alone..
Flower atMouse = new Flower(0, 0);

void setup() {
  size(400, 400);

  // initialize objects
  for (int i=0; i < flowers.length;i++)
  {
    int pos = i+1;
    flowers[i] = new Flower (pos*100, pos*100);
  }
  smooth();
  background(255);
}

void draw() {
  background(255);
  for (int i=0; i < flowers.length;i++)
  {
    flowers[i].display();
  }

  atMouse.display(mouseX, mouseY);
}

class Flower {

  //class member variables
  float posX;
  float posY;
  int c1 = 0;
  int c2 = -40;
  int c3 = 50;
  int c4 = 50;

  // a constructor
  Flower(float _posX, float _posY)
  {
    //just pass vars
    posX = _posX;
    posY = _posY;
  }

  void display()
  {
    noStroke();
    pushMatrix();
    translate(posX, posY);
    fill(#c6ff89); // green
    for (int i = 0; i < 5; i++) {
      ellipse(c1, c2, c3, c4);
      rotate(radians(72));
    }
    popMatrix();
    // centre circle
    fill(#fff9bb); // light yellow
    ellipse(posX, posY, 50, 50);
  }

  //an overloaded version to keep pos updating...
  void display(float px, float py)
  {
    noStroke();
    pushMatrix();
    translate(px, py); // here use px instead...
    fill(#c6ff89); // green
    for (int i = 0; i < 5; i++) {
      ellipse(c1, c2, c3, c4);
      rotate(radians(72));
    }
    popMatrix();
    // centre circle
    fill(#fff9bb); // light yellow
    ellipse(px, py, 50, 50);//also here
  }
}//eofcl
//类类型的数组
花[]花=新花[3];
//一个人。。
花在鼠标上=新花(0,0);
无效设置(){
尺寸(400400);
//初始化对象
for(int i=0;i