We are about to switch to a new forum software. Until then we have removed the registration on this forum.
A program to generate and display the first 5 lines of a Floyd triangle. (use n=5 and n=11 rows)?
I got this right now:
void setup() {
size(800, 600);
background(0);
for(int i = 1; i <= 1; i ++) {
text(i, i * 10 + 100, 100);
}
}
What I want the sketch to look like:
Answers
make a for loop around your current for loop
the outer for loop tells you in which line number you are.
in the 1st line number, the inner for loop wants to go to 1,
in the 2nd line number, the inner for loop wants to go to 2,
etc.
so the inner for loop takes the current number from the outer for loop as upper bound / max
have a separate counter for the numbers you are printing
it's called a nested for loop
after the inner for loop, make a line break, e.g. by saying y+=19;
when you use y in your text statement
So put:
How's this:
not bad!
But that's not good.... :
this is sending the sketch in an endless loop between line 7 and 12 as soon as k>15 (and it's starting for loops again and again without ever ending them)
instead design the for loops so that they just stop and have the right lower and upper bounds (where they start and end at)
this is your starting point:
the outer for loop tells you in which line number you are. So the outer for loop is just from line zero to how many lines you want!
start from here:
for usage of text():
How about this short way:
Nice!
Congratulations!!