# Need help to solve (skyscraper)

**URL:** <https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685>\
**Category:** Coding Questions\
**Created:** [February 9, 2021, 5:24am UTC](https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685 "2021-02-09T05:24:50Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Sett](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Sett](https://discourse.processing.org/u/Sett)\
**Post date:** [February 12, 2021, 1:05pm UTC](https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685/21 "2021-02-12T13:05:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 12, 2021, 1:51pm UTC](https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685/22 "2021-02-12T13:51:22Z")

</div>

> [@Sett](#):
>
> These are the little rectangle code.  
> And yes they appear in the input bos on top of the screen.

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 12, 2021, 8:15pm UTC](https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685/23 "2021-02-12T20:15:54Z")

</div>

my version

```auto

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() {
  // blink 
  String caret ="";

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

  return caret;
}//func 
//

```

---

<div class="post-metadata">

**Author:** ![Sett](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Sett](https://discourse.processing.org/u/Sett)\
**Post date:** [February 13, 2021, 3:46am UTC](https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685/24 "2021-02-13T03:46:22Z")

</div>

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);  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 13, 2021, 7:11am UTC](https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685/25 "2021-02-13T07:11:08Z")

</div>

you really should learn how to post code.

> [@Sett](#):
>
> Would u mind explaining what is void showSkyscaper() ?

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

---

<div class="post-metadata">

**Author:** ![Sett](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Sett](https://discourse.processing.org/u/Sett)\
**Post date:** [February 13, 2021, 7:13am UTC](https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685/26 "2021-02-13T07:13:47Z")

</div>

> [@Chrisir](#):
>
> you really should learn how to post code.

What do you mean?

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 13, 2021, 8:00am UTC](https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685/27 "2021-02-13T08:00:05Z")

</div>

Joseph explained it above

[Previous page](https://discourse.processing.org/t/need-help-to-solve-skyscraper/27685.md?page=1)
