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 = 0; | |
16 | var curY:uint = 0; | |
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 | for (j = 0; j < numcols; j++) { | |
26 | /* Use curX and curY to place your objects */ | |
27 | ||
28 | - | /* ... */ |
28 | + | // ... |
29 | ||
30 | curX += colwidth; | |
31 | } | |
32 | ||
33 | curY += rowheight; | |
34 | curX = 0; // reset the X location (since we're going to the next row) | |
35 | } | |
36 | ||
37 | /* Some output of using this algorithm. */ | |
38 | ||
39 | /* First Loop | |
40 | /* Inner Loop | |
41 | * Loop 1: curX = 0, curY = 0 | |
42 | * Loop 2: curX = 32, curY = 0 | |
43 | * Loop 3: curX = 64, curY = 0 | |
44 | * Loop 4: curX = 96, curY = 0 | |
45 | * Loop 5: curX = 128, curY = 0 | |
46 | * Loop 6: curX = 160, curY = 0 | |
47 | * Loop 7: curX = 192, curY = 0 | |
48 | * Loop 8: curX = 224, curY = 0 | |
49 | * Loop 9: curX = 256, curY = 0 | |
50 | * Loop 10: curX = 288, curY = 0 | |
51 | * Now you can kinda picture what this does to yourself. */ |