簡體   English   中英

不確定為什么這個簡短的處理任務不起作用

[英]Not sure why this short processing assignment isn't working

這是一項家庭作業。 工作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;}
}

第二個文件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();
    }
}

您的代碼運行,因此它正在執行您要求它執行的操作,僅此而已。

我讓我的貓檢查出來然而她就是這樣,“那個人在循環的每次傳遞中重新初始化他的變量,他永遠不會得到那樣的blob網格。告訴他從移動float y = 1; float x = 1;開始float y = 1; float x = 1;在兩個for循環的邊界之外的populate()中,從那里開始調試。“

然后她轉過身來,她拍了拍她。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM