Building a tower out of squares in Processing

Hello there!
I need some help.
I want to build a tower made out of squares. The should be made out of 10 squares and they should alternate between red and blue sqares. I have no plan where I even should start.
Already thanks for ur help : )

Start simply.

Can you write code that draws a square?

Once you have that, change it so it draws TWO squares.

Then color the squares. Make one red, and the other blue.

Now draw TEN squares. Are they in the right places?

And then you’re done!


You MUST show the code of your attempt before anyone will help you more. If you have no code, ATTEMPT TO WRITE SOME. Even if you can only write code that draws one square, that is a MILLION times better than the NO-CODE post you have made so far.

hey there,
I´m totally new here but thank u very much for u help. I´m going try writing that code and next time I will have a code !!

Alright! Some handy functions you might need include setup() draw() background() rect() and fill().

1 Like

Hello,

You have to start somewhere…

I encourage you to review the resources available here:

:)

  size(600,800);
  background(255,255,255);
  
  fill(255, 0, 0);
  rect(10,10,50,50);
  fill(0,0,255);
  rect(10,60,50,50);
  fill(255,0,0);
  rect(10,110,50,50);
  fill(0,0,255);
  rect(10,160,50,50);
   fill(255,0,0);
  rect(10,210,50,50);
  fill(0,0,255);
 rect(10,260,50,50);
  fill(255,0,0);
  rect(10,310,50,50);
   fill(0,0,255);
  rect(10,360,50,50);
  fill(255,0,0);
  rect(10,410,50,50);
   fill(0,0,255);
  rect(10,460,50,50);
  }

This is the code I came up so far

Hey,
I really did not know that there is a website like that and I will look into it. Really appreciating ur effort !! Thank u very much

1 Like

That looks like a tower or squares to me! Good job!

1 Like

Hello,

I see a pattern in your data!

Consider using a for() loop:

for(int y = 10; y<= 460; y+= 50)
  {
  println(y);
  // code here that uses y
 }

Reference:
for \ Language (API) \ Processing 3+

:)

1 Like

Hey,
My code is going to look a lot more cleaner and simpler with that. Literally thank u very much

2 Likes