Use integer out of a for loop
in
Programming Questions
•
9 months ago
Hello I have written this button, and I was wondering if there is some way to use the "i" at the place of "buttonX" in the rect.
And I would like your input on the code if there is some way I can better it.
Thanks in advance.
- void setup () {
- size (500, 350);
- }
- void button (int nr, String text) {
- int buttonX = 0;
- int buttonY = 100;
- int buttonW = 70;
- int buttonH = 20;
- for (int i = 10; i <= 80*nr; i += buttonW+10) {
- buttonX = i;
- }
- rect (buttonX, buttonY, buttonW, buttonH);
- text (text, buttonX, buttonY);
- }
- void draw () {
- button(1, "Button1");
- button(2, "Button2");
- button(3, "Button3");
- button(4, "Button4");
- button(5, "Button5");
- button(6, "Button6");
- }
1