gpt4 book ai didi

java - 不知道为什么这个简短的处理任务不起作用

转载 作者:行者123 更新时间:2023-12-02 07:47:32 26 4
gpt4 key购买 nike

这是一项家庭作业。作业 19 5/16 是作业 http://sites.stuycs.org/home/courses/ml2x/dyrland-weaver/work

我在程序处理中运行它,不需要 main 方法。

Blob 已交给我们。我们必须自己制作 BlobRunner。任何关于为什么我的代码没有做它应该做的事情的建议将不胜感激。第一个文件 BlobRunner

int popSize = 4;
int wobble = 2;
int numSides = 4;
float rad = 100;
int radInt = (int) rad;
float a = sqrt(popSize);
int rootPop = (int) a;
Blob[][] blobs = new Blob[popSize/rootPop][rootPop];
/*=====================================
The trickiest part of setup is to make
the screen an appropriate size for the
grid of blobs. The grid should be just
big enough to contain all of the blobs.
====================================*/
void setup() {
size ((popSize/rootPop)*(2*(radInt+3)), rootPop*(2*(radInt+3)));
populate();
}

/*=====================================
The main purpose of draw is to go through
the array of blobs and display each.
====================================*/
void draw() {
int createdSoFar = 0;
for (int i = 0; i<rootPop; i++){
for (int j = 0; j<popSize/rootPop; j++){
if (createdSoFar < popSize){
blobs[j][i].display();
}
createdSoFar++;
}
}
}

/*=====================================
Populate the array of blobs.
You can use any values for radius, number of sides
and wobble factor that you'd like, but you must
use x and y coordinates that ensure the blobs
are drawn in a grid without overlaping each other.

Your code should work for any reasonable value
of population (i.e. something that would fit on a
normal monitor).
====================================*/
void populate() {
for (int i = 0; i < rootPop; i++){
float y = 1;
for (int j = 0; j < (popSize/rootPop); j++){
float x = 1;
blobs[j][i] = new Blob (x*(rad+3), y*(rad+3), numSides, radInt, wobble, wobble);
x=x+2;}
y=y+2;}
}

第二个文件 block

/*=====================================
A Blob object is a regular polygon variant that
can have various features.
Instance Variables:
numSides: number of sides
rad: distance from the center of the polygon
to any vertext
x: x coordinate of the center
y: y coordinate of the center
xFactor: "wobble" foctor in the x direction
yFactor: "wobble" factor in the y direction
====================================*/

class Blob {

int numSides;
int rad;
float x;
float y;
int xFactor;
int yFactor;

Blob(float cx, float cy, int sides, int r, int xf, int yf ) {

x = cx;
y = cy;
numSides = sides;
rad = r;
xFactor = xf;
yFactor = yf;
}

void display() {

float nx;
float ny;
int rx, ry;

float sy;

strokeWeight(1);
beginShape();
for( float t = 0; t <= 1; t+=( 1.0/numSides ) ) {

/*
"wobble" effect is created by adding a random number to each
x and y coordinate. The larger the x and y factors, the higher
the possible wobble value could be
*/
rx = (int)random(xFactor);
ry = (int)random(yFactor);

nx = rad * cos( 2 * PI * t ) + x + rx;
ny = rad * sin( 2 * PI * t ) + y + ry;

vertex(nx, ny);
}
endShape();
}
}

最佳答案

您的代码运行,因此它正在执行您要求它执行的操作,仅此而已。

我让我的猫检查一下,她说:“这家伙在循环的每次传递中都重新初始化了他的变量,这样他永远不会得到 Blob 网格。告诉他从将 populate() 中的 float y = 1; float x = 1; 移动到两个 for 循环的边界之外,并从那里开始调试”。

然后她翻身侧身,我拍了拍她。

关于java - 不知道为什么这个简短的处理任务不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10628563/

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