Computes value and assigns the result to name while executing commands.
When commands finishes, name becomes undefined (or reverts to whatever it was before).
(If you're familiar with these terms, PixelNote is a language with immutable lexically-scoped variable bindings. You can bind a name within a scope, and if desired rebind it within a nested scope, but not update it.)
The first version sets variable to start, executes commands, increments or decrements variable by 1 in the direction of end, and repeats until variable passes end. (If you loop from 1 to 5 or from 5 to 1, it runs 5 times; if you loop from 1 to 1, it runs once.)
The second version sets variable to start and then repeats commands forever, incrementing variable by 1 each time.
The third version repeats commands exactly count times, but doesn't use a variable to do the counting.
The fourth version repeats commands forever.
Note that these loops do not pause between loops and therefore do not create an animation. To create an animation by looping, either use the anim command, or combine a loop with an explicit pause using pause.
anim: Animated looping
Animates. This sets up a loop which runs commands, pauses, then runs it again. The pause defaults to 1/10 of a second (which is normal for an animated GIF), but you can control this by putting a pause command at the end of commands.
The first version just loops forever. The second version also loops forever, but assigns variable (which may be any alphabetic name you choose) to the loop counter, starting at 1. The third version starts variable to start, then adds or subtracts 1 each loop, stopping after it reaches end.
eachp: Loop over pixels
Executes commands for every pixel on the screen, or for every pixel in the given shape (where shape is a box, disk, exdisk, or line command; see Graphics Commands for details).
xname and yname may be any alphabetic variable names you choose. For each pixel, xname and yname are set to the X and Y coordinate, and the commands are executed.
case: Select commands based on conditions
Checks each of test1, test2, etc., in order; the first one which succeeds causes its corresponding commands to execute. If none of the tests succeed, but a commands is given at the end of the list with no test, then it is run as an alternative.
Each test must compare two numeric values and may be any of the following:
for less-than, less-than-or-equal, equal, greater-than-or-equal, greater-than, or not-equal, respectively.
if: Select subsequent commands based on just one condition
Evaluates test, which is one of the tests defined by case above, and only runs commands if it's true.
You can put this in parentheses if you need to group it:
pause: Pause for a bit
Pauses. This simply stops and waits. If you have drawn on the screen, the screen is updated now, and if you are capturing an animation, the current screen is treated as a frame. The first version pauses for one second; the second version pauses for ms milliseconds, approximately.
touch: Take touch input
Pauses and waits for a touch on the screen. The first version waits until the given timeout (in milliseconds, just like the pause command), and, after you touch the screen, stores the coordinates of the touch in xvar and yvar. If the command times out while waiting, these variables are both set to the value -999.
The second and third versions wait forever for a touch. The third version just stores the touch coordinates in the default drawing location, so for example,
will wait for a touch and then paint a pixel there. This means that the simplest possible “drawing program” in PixelNote is just: