Skip to content

Instantly share code, notes, and snippets.

@jafish
Last active March 5, 2019 13:37
Show Gist options
  • Save jafish/68bc9181af1a3f91d6d3849300baeed3 to your computer and use it in GitHub Desktop.
Save jafish/68bc9181af1a3f91d6d3849300baeed3 to your computer and use it in GitHub Desktop.
An example showing how you can use a variable to accomplish what the interior for loop is doing without repeating the two drawing commands.
// Column 2. Draws 64 rectangles in descending order of transparency in a second column.
var y = 0;
for (i = 65; i < 128; i += 1) {
//for (y = 0; y <= 640; y += 10) {
fill(0, 255, 0, i += 1);
rect(50, y, 40, 5);
y += 10;
}
}
// Column 3. Draws 64 rectangles in descending order of transparency in a third column.
for (i = 128; i < 191; i += 1) {
for (y = 0; y <= 640; y += 10) {
fill(0, 255, 0, i += 1);
rect(100, y, 40, 5);
}
}
// Column 4. Draws 64 rectangles in descending order of transparency in a fourth column.
for (i = 191; i < 255; i += 1) {
for (y = 0; y <= 640; y += 10) {
fill(0, 255, 0, i += 1);
rect(150, y, 40, 5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment