处理随机建筑绘图窗口问题 [英] Processing Randomized Building Drawing Window Issue

查看:53
本文介绍了处理随机建筑绘图窗口问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重新发布此内容,因为我第一次发布此代码时代码不正确.我把这一切都归结到这一部分.看起来像这样.

I'm reposting this as the code was not correct the first time I posted this. I got it all down up to this part. It looks like this.

但它应该是这样的.

任何使窗户与建筑物对齐的帮助都会很棒,因为我对此很陌生.谢谢

Any Help with making it so the windows align to the buildings would be great as I am quite new to this. Thanks

int[] buildingHeights = new int[12];
int[] starXValues = new int[200];
int[] starYValues = new int[200];

void setup(){
 size(600,450);
 background(0);
}
void draw(){}
void drawAll(){
  fill(255);
  stroke(255);
  drawSky();
  drawBuildings();
}
void drawSky(){
  stroke(255);
  strokeWeight(1);
  ellipse(500,-20,150,150);
  for(int i = 0; i<starXValues.length; i++)
  point(starXValues[i],starYValues[i]);
}
void drawBuildings(){
  stroke(0);
  for(int i = 0; i<buildingHeights.length;i++){
    drawBuilding(i*50,height-buildingHeights[i]*50);
  }
}
void drawBuilding(int x, int y){
  fill(100);
  rect(x,height,50,-y);
  for(int i = 1; i < 7; i++){
    for(int j = 1; j < height/y; j++){
       int lights = (int)random(2);
       if(lights==1)
       fill(#ECFF27);
       else
       fill(255);
       rect(x*i,y*i,5,10);
    }
  }
}
void randomize(){
  for (int n = 0; n < starXValues.length; n++ ) 
    starXValues[n] = (int)random(width);  
  for (int n = 0; n < starYValues.length; n++ ) 
    starYValues[n] = (int)random(width);   
  for (int n = 0; n < buildingHeights.length; n++ ) 
    buildingHeights[n] = (int)random(8); 
    
}
void mousePressed(){
  background(0);
  randomize();
  drawAll();
}

推荐答案

您在根据您的建筑物调整窗口 x/y 位置时遇到问题,我尝试修复它以使其看起来尽可能接近您展示的示例图片

You had a problem adjusting the windows x/y positions according to your building, I tried to fix it to look as close as possible to the example picture you showed

void drawBuilding(int x, int y){
  fill(100);
  rect(x,height,50,-y);
  for(int i = 1; i < 6; i++){
    for(int j = 1; j <= y/25; j++){
       int lights = (int)random(2);
       if(lights==1)
       fill(#ECFF27);
       else
       fill(0);
       
       rect(x+i*10-8,height-j*25+12,5,10);
    }
  }
}

这篇关于处理随机建筑绘图窗口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆