I don’t know why I cannot add little rectangle to the big rectangle, when I can, it only add one but at the wrong place. Help me solve please.
String storey = “”;
int[] tokens= {}; // split(storey, “,”);
void setup() {
size(1000, 1000);
background (0);
}
void draw() {
textSize(25);
String caret ="";
if (millis() % 1000<500) {
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);
rect(i * 200, 1000-tokens[i]*80, 200, tokens[i]*100);
int n=6;
for(int j=0;j<n;j++){
for(int x=50;x<200;x+=20){
for(int y=0; y <= tokens.length; y+=50){
int a = (int) random(1);
if (a == 1 ){
fill(0,0,255);
}
else {
fill(0);
}
rect(x+10,100*y-50*y,5,15);
}
}
}
}
}
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 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);
}
}
}