gpt4 book ai didi

java - 为什么会出现这个错误? - 加工

转载 作者:行者123 更新时间:2023-12-01 18:57:21 26 4
gpt4 key购买 nike

有人可以告诉我为什么我会收到此错误吗?基本上这是一个我想模拟基本植物生长的程序。我想以这样的方式做到这一点:花瓣都存储在一个圆圈数组中。

Stem myStem;
Circle circles;

float scaleFactor=0.5;

void setup() {
size(floor(400*scaleFactor), floor(800*scaleFactor));
myStem = new Stem(200,800);

}

void draw() {

background(150);
smooth();
Circle circles[];
circles = new Circle[5];
circles[0] = new Circle(0, -40, 50, 50);
circles[1] = new Circle(0, -40, 50, 50);
circles[2] = new Circle(0, -40, 50, 50);
circles[3] = new Circle(0, -40, 50, 50);
circles[4] = new Circle(0, -40, 50, 50);

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

myStem.drawStem();

}

class Stem {
int initalloX=200;
int initalloY=800;

Stem(int tempInitalloX, int tempInitalloY) {
initalloX = tempInitalloX;
initalloY = tempInitalloY;

}

void drawStem() {
background(#0DBADB);
scale(scaleFactor, scaleFactor);
stroke (12, 149, 11);
fill (12, 149, 11);
strokeWeight(10);
line(initalloX, initalloY, initalloX, ((frameCount>250)?initalloY-500:initalloY-(2*frameCount)));
//stem1
if (frameCount>101) {
noStroke();
translate(initalloX, initalloY-200);
scale(min((float)(frameCount-100)/100, 1), min((float)(frameCount-100)/100, 1));
beginShape();
vertex(0, 0);
bezierVertex(-40, -5, -30, -40, -80, -20);
bezierVertex(-47, -16, -52, 8, 0, 0);
endShape(CLOSE);
scale(1/min((float)(frameCount-100)/100, 1), 1/min((float)(frameCount-100)/100, 1));
translate(-initalloX, -(initalloY-200));
}
//stem2
if (frameCount>151) {
noStroke();
translate(initalloX, initalloY-300);
scale(-min((float)(frameCount-150)/150, 1), min((float)(frameCount-150)/150, 1));
beginShape();
vertex(0, 0);
bezierVertex(-40, -5, -30, -40, -80, -20);
bezierVertex(-47, -16, -52, 8, 0, 0);
endShape(CLOSE);
scale(-1/min((float)(frameCount-150)/150, 1), 1/min((float)(frameCount-150)/150, 1));
translate(-initalloX, -(initalloY-300));
}
}
}

class Circle {

int c1 = 0;
int c2 = -40;
int c3 = 50;
int c4 = 50;

Circle(int tc1, int tc2, int tc3, int tc4) {
c1 = tc1;
c2 = tc2;
c3 = tc3;
c4 = tc4;
}
}

提前致谢...非常感谢所有帮助。

最佳答案

除了已经指出的所有内容之外,请注意 ellipse() 是一个 void 方法,因此它不会返回任何内容。因此像这样的线圆 = 椭圆(x,y,z,z)没有任何意义。您可能想要使用存储在 ciclcle[i] 中的值来绘制椭圆,所以只需调用椭圆(圆[i].c1,圆[i].c2,圆[i].c3,圆[i].c4);不需要分配它。我也不明白为什么要创建 5 个相等的圆圈。如果您的圆形对象只是存储数据,为什么要存储相同的数据五次?调用:

for (int i = 0; i < circles.length; i++) {
ellipse(0, -40, 50, 50);
rotate(radians(72));
}

具有相同的效果。

此外,在绘制结束时调用background()(通过myStem.drawStem())将隐藏之前绘制的所有内容。然而,无需重新创建数组并每秒重新分配值 60 次,您可以将其移至设置。

我对您的代码进行了这些更改。现在就可以编译了。仍然是在原点绘制“花瓣”,并且需要处理它们的填充/描边,但至少它正在运行:)您可能想在您的圆圈类中创建一个显示方法...更多就像我在您发表的另一篇文章中指出的那样。干杯!

Stem myStem;

//Circle circles; // double declaration
Circle circles[]; // keeping the array one only

float scaleFactor=0.5;

void setup() {
size(floor(400*scaleFactor), floor(800*scaleFactor));
myStem = new Stem(200,800);

//mpoved this to setup, no need to recreate each frame
circles = new Circle[5];
circles[0] = new Circle(0, -40, 50, 50);
circles[1] = new Circle(0, -40, 50, 50);
circles[2] = new Circle(0, -40, 50, 50);
circles[3] = new Circle(0, -40, 50, 50);
circles[4] = new Circle(0, -40, 50, 50);
// also smooth only needs to be called once
// unless ther is a noSmooth() somewhere
smooth();

}

void draw() {

// moved this here
background(#0DBADB);

for (int i = 0; i < circles.length; i++) {
ellipse(circles[i].c1, circles[i].c2, circles[i].c3, circles[i].c4);
// note you may use this instead
//ellipse(0, -40, 50, 50);
rotate(radians(72));
}

myStem.drawStem();


}



class Stem {
int initalloX=200;
int initalloY=800;

Stem(int tempInitalloX, int tempInitalloY) {
initalloX = tempInitalloX;
initalloY = tempInitalloY;

}

void drawStem() {
//background(#0DBADB); // this was hiding all other draws
scale(scaleFactor, scaleFactor);
stroke (12, 149, 11);
fill (12, 149, 11);
strokeWeight(10);
line(initalloX, initalloY, initalloX, ((frameCount>250)?initalloY-500:initalloY-(2*frameCount)));
//stem1
if (frameCount>101) {
noStroke();
translate(initalloX, initalloY-200);
scale(min((float)(frameCount-100)/100, 1), min((float)(frameCount-100)/100, 1));
beginShape();
vertex(0, 0);
bezierVertex(-40, -5, -30, -40, -80, -20);
bezierVertex(-47, -16, -52, 8, 0, 0);
endShape(CLOSE);
scale(1/min((float)(frameCount-100)/100, 1), 1/min((float)(frameCount-100)/100, 1));
translate(-initalloX, -(initalloY-200));
}
//stem2
if (frameCount>151) {
noStroke();
translate(initalloX, initalloY-300);
scale(-min((float)(frameCount-150)/150, 1), min((float)(frameCount-150)/150, 1));
beginShape();
vertex(0, 0);
bezierVertex(-40, -5, -30, -40, -80, -20);
bezierVertex(-47, -16, -52, 8, 0, 0);
endShape(CLOSE);
scale(-1/min((float)(frameCount-150)/150, 1), 1/min((float)(frameCount-150)/150, 1));
translate(-initalloX, -(initalloY-300));
}
}
}

class Circle {

int c1 = 0;
int c2 = -40;
int c3 = 50;
int c4 = 50;

Circle(int tc1, int tc2, int tc3, int tc4) {
c1 = tc1;
c2 = tc2;
c3 = tc3;
c4 = tc4;
}
}

关于java - 为什么会出现这个错误? - 加工,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13468104/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com