# Need help to solve (skyscraper)

I have not try yet, as I am out right now. Thanks for helping.

1 Like

The little rectangles are the windows of the houses, correct?

my version

``````

String storey = "";
int[] tokens= {};

void setup() {
size(1000, 1000);
background (0);
}

void draw() {

textSize(25);

// Input rectangle
fill(255);
rect (0, 0, 1000, 40);
fill(0);
text( storey + caret(), 0, 30);

// help text
textSize(15);
fill(255);
text("Please enter your number from 1 to 10. Maximum input is 5.",
250, 60);
} //func

void showSkyscaper() {

//for (int i = 0; i<tokens.length; i++)
int i = tokens.length-1;
if (i<tokens.length&&tokens.length>0)
{
fill(211, 211, 211);
rect(i * 200, height-tokens[i]*80,
200, tokens[i]*80);

// windows:
for (int x1=0; x1 < 20-1; x1++) {
for (int y1=0; y1 < tokens[i]*80; y1+=20) {
// int a = (int) random(1);
if (random(1) < 0.5 ) {
fill(0, 0, 255);//blue
} else {
fill(255);
}
rect((i * 200)+(x1*10)+9, height -y1,
5, 15);
}
} //for
} //for
}

void keyTyped() {
if (key == BACKSPACE) {
// delete last letter
if (storey.length()>0) {
storey = storey.substring(0, storey.length()-1);
}
} else if (key == ENTER) {
// We submit when the user presses enter
tokens = (int[]) append (tokens, int(storey));
// reset
storey="";
showSkyscaper();
} else if (key>='0' && key <= '9') {
storey += key;
} else if (key=='n') { //night time
background(0);
} else if (key=='d') { //day time
background(135, 206, 235);
} else if (key=='m') { //moon
fill(230, 230, 250);
ellipse(200, 200, 100, 100);
} else if (key=='S') { //sun
fill(255, 255, 224);
noStroke();
ellipse(800, 200, 150, 150);
} else if (key=='s') { //star
background(25, 25, 112);
for (int k=0; k<50; k++) {
fill(0, 10);
rect(0, 0, width, height);
fill(255);
noStroke();
ellipse(random(width), random(height), 3, 3);
}
}
}

String caret() {
String caret ="";

if (millis() % 1000<500) {
caret="|";
}//if

return caret;
}//func
//

``````

Would u mind explaining what is void showSkyscaper() ?
I have edited to this.

String storey = ββ;
int[] tokens= {}; // split(storey, β,β);

void setup() {
size(1000, 1000);
background (0);
}

void draw() {
textSize(25);
String caret ="";
if (millis() % 1000<200) {
caret="|";
}
fill(255);
rect (0, 0, 1000, 40);
fill(0);
text( storey + caret, 0, 30);

textSize(15);
fill(255);
text(βPlease enter your number from 1 to 10. Maximum input is 5.β, 250, 60);

for (int i = 0; i<tokens.length; i++) {
fill(211, 211, 211);
noStroke();
rect(i * 200, 1000-tokens[i]*80, 200, tokens[i]*80);

``````for (int y=0; y < 20-1; y++) {
for (int z=0; z < tokens[i]*80; z+=30) {
// int a = (int) random(1);
if (random(2) < 0.5 ) {
fill(0, 0, 255);//blue
}
else {
fill(255);
}
rect((i * 200)+(y*10)+9, height -z,
5, 10);
}
}
``````

}
}

void keyTyped() {
if (key == BACKSPACE) {
if (storey.length()>0) {
storey = storey.substring(0, storey.length()-1);
}
} else if (key == ENTER) {
// We submit when the user presses enter
tokens = (int[]) append (tokens, int(storey));
// reset
storey="";
} else if (key>=β0β && key <= β9β) {
storey += key;
}
else if (key==βnβ){ //night mode
background(0);
}
else if (key==βdβ){ // day mode
background(135,206,235);
}
else if (key==βmβ){ // moon
fill(230,230,250);
ellipse(200, 200, 100, 100);
}
else if (key==βSβ){ // Sun
fill(255,255,224);
noStroke();
ellipse(800, 200, 150, 150);
}
else if (key==βsβ){ // star
background(25,25,112);
for(int k=0;k<70;k++){
fill(0,10);
rect(0,0,width,height);
fill(255);
noStroke();
ellipse(random(width),random(height), 3, 3);
}
}
}

you really should learn how to post code.

showSkyscaper() is a new function that I defined. I call it when a new skyscraper is made (with Enter in keypressed). It shows the windows in one (the new) skyscraper.

Chrisir

What do you mean?

And I would be very happy if you teach me how.

Joseph explained it above

2 Likes