Loading...
Logo
Processing Forum

Need help with Lab

in General Discussion  •  Other  •  1 year ago  
I have a Lab due later today which implements Looping and Conditionals. 

The directions are: You are writing a program that will fill up the screen with 2 alternating shapes. Each row must start with a different shape. The shape cannot be truncated at the edge of the screen; rather it must fit. When the screen is filled, display the total count of the number of shapes. 

I don't really have any clue on where to begin.. I have a triangle and rect that I want to use for the 2 shapes, but I am stuck, at the very beginning of this lab. 

Any help possible would be greatly appreciated at this point. 

Replies(7)

Does it have to cover the whole screen without overlap? If not then just make shapes of random sizes and at random locations (that do not go off the screen). Keep a boolean array of length width*height. Every time you put a new shape down, set all of the elements in the array that correspond to the array to true. If all of the elements are true then you are done.
I just realized what I wrote might not be clear regarding the array. Here is an example:
Copy code
  1. rect(x, y, 50, 50);
  2. for (int i = x; i < x+50; i++) {
  3.       for (int j = y; j < y+50; j++) {
  4.             gotCoveredUp[i+j*width] = true;
  5.       }
  6. }
the shapes have to start from the top left of the screen and go across in rows; once the row reaches the end of the screen, it will continue in a row beneath the previous one, and so forth. The shapes can't be cut off at the edges of the screen. 
Then just use shapes that you know the height and width of. If your width is 400, and you are using shapes that are 40 units wide then you know to move down a row after 10 shapes. If your height is 600 and your shapes are also 30 units tall then you know that after 20 rows you have covered the screen.
I know I need to declare what x and y are, but don't know what to declare them. hehe. Here is my code so far. The triangle's dimensions will change once I know what is going on in my code. 


void setup ()  {
  size (500,500);
}


void draw ()  {
background (255);

//Display triangle
stroke (0);
fill (0,255,100);
triangle (100,100,120,140,80,140);

//Display rectangle
stroke (0);
fill (200,0,100);
rect(x, y, 50, 50);
for (int i = x; i < x+50; i++) {
      for (int j = y; j < y+50; j++) {
            gotCoveredUp[i+j*width] = true;
      }
}
}



Ignore the first code I put, I didn't know it needed to go from left to right and then down when I put that. Here's something to start with. I only put rects() on purpose, you get to figure out how to toggle between another shape, this is homework after all :)
Copy code
  1. int x = 0;
  2. int y = 0;

  3. void setup() {
  4.   size(500, 500);
  5.   background(255);
  6. }

  7. void draw() {
  8.   if (x <= width) {
  9.     rect(x, y, 50, 50);
  10.     x += 50;
  11.   }
  12.   else {
  13.     x = 0;
  14.     y += 50;
  15.   }
  16.   if (y >= height) {
  17.     println("DONE!");
  18.   }
  19. }
Alright, thank you for the help.