SHOW:
|
|
- or go back to the newest paste.
| 1 | /* Submitted by Ryan Clark (W3Geek) */ | |
| 2 | /* Link to post: http://redd.it/1aw8am */ | |
| 3 | ||
| 4 | /* These variables are used to calculate | |
| 5 | * how many times the for loops execute, | |
| 6 | * height and width of each object on | |
| 7 | * every loop. */ | |
| 8 | var numrows:uint = 10; | |
| 9 | var numcols:uint = 10; | |
| 10 | var rowheight:uint = 32; | |
| 11 | var colwidth:uint = 32; | |
| 12 | ||
| 13 | /* No sense declaring the variables over | |
| 14 | * and over inside the nested for loop. */ | |
| 15 | var curX:uint; | |
| 16 | var curY:uint; | |
| 17 | ||
| 18 | /* The meat of the code. The outer for | |
| 19 | * loop executes causing the inner for | |
| 20 | * loop to execute 'numcol' times. Once | |
| 21 | * the inner for loop finishes, the outer | |
| 22 | * loop checks to see if it needs to be | |
| 23 | * executed again... */ | |
| 24 | for (i = 0; i < numrows; i++) {
| |
| 25 | curY = i * rowheight; | |
| 26 | for (j = 0; j < numcols; j++) {
| |
| 27 | /* Use curX and curY to place your objects */ | |
| 28 | - | curY = i * rowheight; |
| 28 | + | |
| 29 | } | |
| 30 | } | |
| 31 | ||
| 32 | /* Some output of using this algorithm. */ | |
| 33 | ||
| 34 | /* First Loop | |
| 35 | /* Inner Loop | |
| 36 | * Loop 1: curX = 0, curY = 0 | |
| 37 | * Loop 2: curX = 32, curY = 0 | |
| 38 | * Loop 3: curX = 64, curY = 0 | |
| 39 | * Loop 4: curX = 96, curY = 0 | |
| 40 | * Loop 5: curX = 128, curY = 0 | |
| 41 | * Loop 6: curX = 160, curY = 0 | |
| 42 | * Loop 7: curX = 192, curY = 0 | |
| 43 | * Loop 8: curX = 224, curY = 0 | |
| 44 | * Loop 9: curX = 256, curY = 0 | |
| 45 | * Loop 10: curX = 288, curY = 0 | |
| 46 | * Now you can kinda picture what this does to yourself. */ |