不确定为什么这个简短的处理任务不起作用

时间:2012-05-17 00:44:21

标签: java processing

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

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

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;}
}

SECOND FILE Blob

/*=====================================
  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();
    }
}

1 个答案:

答案 0 :(得分:2)

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

我让我的猫检查出来但她就是全部,“那个人正在重新初始化他在循环的每个传递中的变量,他将永远不会得到一个blob网格。告诉他从开始在float y = 1; float x = 1;中将populate()移动到两个for循环的边界之外,然后从那里开始调试。“

然后她转过身来,她拍了拍她。