【发布时间】:2016-11-06 22:13:06
【问题描述】:
void setup() {
size(800, 500);
}
float x=20;
int y=480;
int aptSize=20;
float a, e;
float currentFloor=0;
float s;
float offset;
//float aptNum;
void draw() {
//draw sky
// sky();
float n=0;
// if(keyPressed){
// sky();
//draw a building
for (int f=0; f<3 && x<600; f++, x = x + ((n*20)+20)) {
n = building(x, y, 15);
}
}
//}
void sky() {
float r= 50;
float g= 0;
float b=200;
background(random(r), random(g), random(b));
r=constrain(r, 0, 140);
g=constrain(g, 0, 65);
b=constrain(b, 0, 255);
}
float building(float x, int y, float floorNum) {
for (int i=0; i<floorNum; i++, y=y-aptSize) {
a = random(3, 12);
int b = 7;
currentFloor= y*aptSize;
aptRow(x, y, b);
if (currentFloor<floorNum/3) {
b=b-1;
}
}
return a;
}
void aptRow(float x, int y, float aptNum) {
for (int j=0; j<aptNum; j++, x=x+aptSize) {
if (x<width)
aptUnitA(x, y, aptSize);
}
}
void aptUnitA(float x, int y, int aptSize) {
fill(155);
stroke(0);
rect(x, y, aptSize, aptSize);
noStroke();
fill(242, 235, 53);
ellipse(x+5, y+5, aptSize/5, aptSize/5);
ellipse(x+15, y+5, aptSize/5, aptSize/5);
ellipse(x+10, y+15, aptSize/5, aptSize/2);
}
这个代码是几栋楼。我只是想弄清楚每次按下一个键时如何随机绘制一组新的建筑物,并且在建筑物的顶部有一些不同大小的公寓行?
【问题讨论】:
-
运行这段代码的结果是什么?你有错误吗?发生什么了?您可以编辑您的问题以添加此信息。
标签: processing