Okay, I'm sorry but I had to change the whole script because I'm working on something with a slider:
Short explanation:
every time when you move the slider a bit up one block will be added to the pyramid. So it starts really small and gets bigger and bigger. What is important though is that the pyramid will be created from the middle. So first the top, then three beneath, starting with the block in the middle of three, then 5 beneath, starting with the one in the middle, then left, then right, then the most left one and then the most right one, and on and on.
I came this far but can't stop the loop. I was trying to stop the loop when it got a certain amount but it won't work unfortunately :(. Can someone help me out? I can't seem to find the solution..
- int xPos = 400;
- int yPos = 400;
- int rectSize= 10;
- int count = 1;
- int countY = 1;
- int countP = 1;
- void setup() {
- background(100);
- size(800, 800);
- noStroke();
- fill(200, 50);
- }
- void draw() {
- int xPos = 400;
- int yPos = 400;
- int rectSize= 10;
- int count = 1;
- int countY = 1;
- int countP = 1;
- int j= 0;
- //rows van de piramide
- for (int r =0; r < 5; r++) {
- rect(xPos, yPos, rectSize, rectSize);
- j++;
- count = 1;
- countY = 1;
- for (int i = 1; i < countP; i++) {
- xPos = xPos - rectSize*count;
- rect(xPos, yPos, rectSize, rectSize);
- j++;
- count++;
- xPos = xPos + rectSize*count;
- rect(xPos, yPos, rectSize, rectSize);
- j++;
- count++;
- countY++;
- }
- countP++;
- yPos = yPos + 10;
- xPos = xPos - rectSize*countY + 10;
- }
- }
Thanks in advance!