【问题标题】:Displaying arrays with processing?显示带有处理的数组?
【发布时间】:2015-05-13 20:54:28
【问题描述】:

所以我写的代码是在屏幕上输出一个数组。我一直基于我的问题的例子是here,其中有一些彼此距离相等的点。如果你懒得点击链接,这是代码:

   float[][] distances;
   float maxDistance;
   int spacer;

   void setup() {
   size(640, 360);
   maxDistance = dist(width/2, height/2, width, height);
   distances = new float[width][height];
   for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      float distance = dist(width/2, height/2, x, y);
       distances[x][y] = distance/maxDistance * 255;
     }
   }
   spacer = 10;
   noLoop();  // Run once and stop
 }

 void draw() {
  background(0);
  // This embedded loop skips over values in the arrays based on
  // the spacer variable, so there are more values in the array
  // than are drawn here. Change the value of the spacer variable
  // to change the density of the points
  for (int y = 0; y < height; y += spacer) {
    for (int x = 0; x < width; x += spacer) {
     stroke(distances[x][y]);
     point(x + spacer/2, y + spacer/2);
   }
 }
}

我编写的代码只返回一个白色窗口。这是代码:

    float []  arrays = {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0};;
    int spacer=50;
    PFont font;
    int row;
    int col;

    void setup(){
      size(640,360);
      font = createFont("Arial",1);
      textFont(font,50);

}

    void draw(){
    background(255,255,255);
    for(int i = 0; i<col; i++){
       for(int j=0;j<row;j++){
          String myArray = nfp(arrays[i*col+j],1,2);
          fill(0,0,0);
          text(myArray, i+spacer/2, j+spacer/2);
       }
     }
}

我对处理和其他东西非常陌生。提前谢谢!

【问题讨论】:

    标签: processing


    【解决方案1】:

    在您的代码中,我没有看到您的 colrow 已初始化。

    你应该在void setup()做这个

    也许这就是你在窗口上看不到任何东西的原因,因为如果这两个变量没有值,你的两个循环就不会执行。在您提供的示例中,使用widthheight,它们是返回窗口大小(示例中为640x360)的“系统变量”

    另外,请注意:

    float []  arrays = {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0};; (two semicolons)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      • 2017-12-14
      • 2018-07-12
      • 2020-01-26
      • 1970-01-01
      相关资源
      最近更新 更多