# Drawing an faulty advent calendar

**URL:** <https://discourse.processing.org/t/drawing-an-faulty-advent-calendar/34171>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 17, 2021, 2:06pm UTC](https://discourse.processing.org/t/drawing-an-faulty-advent-calendar/34171 "2021-12-17T14:06:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thorbensson](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@thorbensson](https://discourse.processing.org/u/thorbensson)\
**Post date:** [December 17, 2021, 2:06pm UTC](https://discourse.processing.org/t/drawing-an-faulty-advent-calendar/34171/1 "2021-12-17T14:06:37Z")

</div>

Hey guys, I hope you are having a nice pre-christmas time…

For my university homework I’ll have to draw an advent calendar which (in the first step) has to be drawn by a loop and a _draw\_advent\_calendar\_door(float x, float y, int number)_ function.

It draws the windows quiet nicely, but sadly I am stuck displaying the right number. Everything, including the constrain function, I’ve tried before does not work for me so far.

I would like to ask for some Ideas, how I can better try to solve this. Please do not provide a definite solutions as this is my homework and I’ll have to solve it myself.

Thank you in advance!

PS: I forgot to mention that we have doors from day 1 to day 24.

```auto
int doorNr = 1;

void setup() {
  size(777, 500);
  background(0, 150, 0);
}

void draw() {
  rectMode(CENTER);

  for (float i = 111; i <= 666; i += 111) {
    for (float a = 100; a <= 400; a += 100) {
      //for (int e = 1; e <= 24; e++) {

      draw_advent_calendar_door(i, a, doorNr);

      // }
    }
  }
  doorNr++;
  constrain(doorNr, 1, 24);
}

void draw_advent_calendar_door(float x, float y, int number) {
  fill(255);
  rect(x, y, 75, 75);
  fill(200, 0, 0);
  textAlign(CENTER, CENTER);
  textSize(60);
  text(number, x, y-10);
}

```

---

<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:** [December 17, 2021, 3:00pm UTC](https://discourse.processing.org/t/drawing-an-faulty-advent-calendar/34171/2 "2021-12-17T15:00:01Z")

</div>

> [@thorbensson](#):
>
> It draws the windows quiet nicely, but sadly I am stuck displaying the right number. Everything, including the constrain function, I’ve tried before does not work for me so far.

there are several solutions.

Place

```auto
 doorNr++;

```

right after

```auto
      draw_advent_calendar_door(i, a, doorNr);

```

So that the number increases every step/door.

Disadvantage is that you have a fixed order which is a bit boring.

**Solution**

You can also use an array (defined before `setup()`) with the numbers 1…24 and shuffle it.

`int[] listOfNumbers = { 13, 7, 1, 24, ... };`

and then use doorNr as an index (it gets bigger by 1 every step, like mentioned above) for that array:

`listOfNumbers [doorNr];`

---

<div class="post-metadata">

**Author:** ![thorbensson](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@thorbensson](https://discourse.processing.org/u/thorbensson)\
**Post date:** [December 17, 2021, 3:28pm UTC](https://discourse.processing.org/t/drawing-an-faulty-advent-calendar/34171/3 "2021-12-17T15:28:35Z")

</div>

Thank you for your reply @Chrisir ! I’ve tried to write doorNr++ right after the function inside the loop. But then the numbers keep counting up and are no stopping, even with the constrain function.

Please only give me a hint how to fix this. I’ll have to do everything myself for the university 🙂 .

The array to receive random numbers seems to be way better. But we have not learned about this yet, so I guess I must not use it…

---

<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:** [December 17, 2021, 9:02pm UTC](https://discourse.processing.org/t/drawing-an-faulty-advent-calendar/34171/4 "2021-12-17T21:02:05Z")

</div>

> [@thorbensson](#):
>
> numbers keep counting up and are no stopping

Right

Reset the variable before the for loops please

---

<div class="post-metadata">

**Author:** ![thorbensson](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@thorbensson](https://discourse.processing.org/u/thorbensson)\
**Post date:** [December 18, 2021, 12:16am UTC](https://discourse.processing.org/t/drawing-an-faulty-advent-calendar/34171/5 "2021-12-18T00:16:23Z")

</div>

Thank you very much!
