Homework help with loops

Question: Draw a character that would fit within a 40×40 pixel box. Once you have this working, use for loops to “tile” the image 100 times on a 400×400 pixel canvas. Hint: can you do this using only 2 for loops?

problem: every time I attempt this program it always fails and I cant make it only with 2 loops, can anyone help me start off the code? It wont let me write my code.

1 Like

Hi

Post your attempt

Here is some references

Its working now, I can type my code here it is.

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  
  for (var x= 0; x <= width; x += 40) {
    for (var y= 0; y <= height; y += 40) { 
    fill(255,0,255);
    ellipse(x, y, 25, 25)
    }
  }
}

I put the for loops together as I cant figure out how to make it so that I only have two loops but have the same out come.

How do I make it so that it tiles it 100 times.

Hi
Change this values x += 40
Y+= 40… let’s say make it 10
See what happens

Then change this values

ellipse(x, y, 25, 25) and see what happens

Edit

for (var x= 0; x <= width; x += 40) {
for (var y= 0; y <= height; y += 40)

For var x =0; and var y=0; change zero with other values see what happens

Hi

Watch this video

Thank so much! I changed your solution a bit so I could fit the question but I got it :slight_smile:

1 Like

Hi

Screenshot_2023-05-03-22-10-37-865