View difference between Paste ID: 26a1MzhJ and kCT1ybUe
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;
15+
var curX:uint = 0;
16-
var curY:uint;
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-
	curY = i * rowheight;
25+
26
		/* Use curX and curY to place your objects  */
27-
		/* Use curX and curY to place your objects */
27+
                
28-
		curX = j * colwidth;
28+
                /* ... */
29
		curX += colwidth;
30
	}
31
32
        curY += rowheight;
33
}
34
35
/* Some output of using this algorithm. */
36
37
/* First Loop
38
/* Inner Loop
39
 * Loop 1: curX = 0, curY = 0
40
 * Loop 2: curX = 32, curY = 0
41
 * Loop 3: curX = 64, curY = 0
42
 * Loop 4: curX = 96, curY = 0
43
 * Loop 5: curX = 128, curY = 0
44
 * Loop 6: curX = 160, curY = 0
45
 * Loop 7: curX = 192, curY = 0
46
 * Loop 8: curX = 224, curY = 0
47
 * Loop 9: curX = 256, curY = 0
48
 * Loop 10: curX = 288, curY = 0
49
 * Now you can kinda picture what this does to yourself. */