【问题标题】:trying to make overlapping rectangles on canvas grid试图在画布网格上制作重叠的矩形
【发布时间】:2022-01-19 10:48:18
【问题描述】:

我正在尝试制作一个带有在黑白之间变化的重叠正方形的网格。到目前为止,我可以对画布做出响应的网格,也可以分配随机颜色,但重叠部分并没有完全解决。我尝试在黑色方块上添加黑色笔触,但不知何故出现了非常小的方块。有任何想法吗?这是我的代码:

void setup() {  
  size(900, 900);
}



void draw() {
  fill(255);
  noStroke();
  int divW=width/6;
  int horS=divW/5*2;
  int divH=height/6;
  int verS=divH/5*2;
  
  
  for (int p = 0; p < width; p = p+divH-verS) {
    for (int q = 0; q < height; q = q+divW-verS) {
      push();
      
      int col = int(random(100));
      if (col <= 65) {
        fill(0);
      }
       
      rect(q, p, divW, divH);
      pop();
      
  
}
  }

if (frameCount == 10) {
    exit();
    }
   
    saveFrame("output/2grid65_o###.png");

}

IMG of what I was getting without the stroke

IMG of what I´m getting with the stroke

IMG of what I want (see the overlap between squares?)

【问题讨论】:

    标签: random grid processing overlap


    【解决方案1】:

    看起来白色方块与黑色方块上的笔划重叠,这让你看到那些从后面伸出来的小点。

    由于您的背景是白色的,一个简单的解决方案是不绘制白色方块(让背景显示出来)。然后你应该能够使用你的 stroke 方法让它们重叠。

    int col = int(random(100));
    if (col <= 65) {
        // only draw the square if it's black
        fill(0);
        rect(q, p, divW, divH);
    }
    

    【讨论】:

    • 嗨!感谢那。问题是我没有填充白色矩形。只有黑色。一开始,唯一的白色是背景。我也需要中风,因为这就是我实现黑色方块重叠的方式
    • 您正在填充白色方块。 fill(255); 在你的绘图函数开始时将填充设置为白色。您在 if 语句中将其更改为黑色,然后在 if 语句之外绘制一个矩形。因此,如果未选择黑色方块,则绘制一个白色方块。如果将 rect 调用移到 if 语句中,则只会绘制黑色的。
    猜你喜欢
    • 2015-10-25
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    相关资源
    最近更新 更多