JavaScript (V8), 7773 bytes
Expects (w)(h). Prints the coordinates.
w=>h=>{for(i=j=0;j<=i||i=j=0;~j||(j=0,++i<w+hj=++i);j++<w+h;j--)i-(x=i&1?j:i-j:j)<h&x<w&&print(x,i-x)}
How?
We walk through the upper-left diagonals of a square of width \$w+h\$, going alternately from top-right to bottom-left and the other way around. We print only the coordinates that are within the target rectangle.
Below is an example for \$w=3\$ and \$h=2\$:
NB: Processing the longest diagonal never brings any new cell. It's just golfier to include it.
JavaScript (V8), 77 bytes
Expects (w)(h). Prints the coordinates.
w=>h=>{for(i=j=0;j<=i||(j=0,++i<w+h);j++)i-(x=i&1?j:i-j)<h&x<w&&print(x,i-x)}
How?
We walk through the upper-left diagonals of a square of width \$w+h\$, going alternately from top-right to bottom-left and the other way around. We print only the coordinates that are within the target rectangle.
Below is an example for \$w=3\$ and \$h=2\$:
NB: Processing the longest diagonal never brings any new cell. It's just golfier to include it.
JavaScript (V8), 73 bytes
Expects (w)(h). Prints the coordinates.
w=>h=>{for(i=j=0;~j||(j=++i)<w+h;j--)i-(x=i&1?i-j:j)<h&x<w&&print(x,i-x)}
How?
We walk through the upper-left diagonals of a square of width \$w+h\$, going alternately from top-right to bottom-left and the other way around. We print only the coordinates that are within the target rectangle.
Below is an example for \$w=3\$ and \$h=2\$:
NB: Processing the longest diagonal never brings any new cell. It's just golfier to include it.
JavaScript (V8), 7977 bytes
Expects (w)(h). Prints the coordinates.
w=>h=>{for(i=j=0;j<=i||(j=0,++i<w+h);j++)i-(x=i&1?j:i-j,y=i-x)<h&x<w&&print(x,yi-x)}
How?
We walk through the upper-left diagonals of a square of width \$w+h\$, going alternately from top-right to bottom-left and the other way around. We print only the coordinates that are within the target rectangle.
Below is an example for \$w=3\$ and \$h=2\$:
NB: Processing the longest diagonal never brings any new cell. It's just golfier to include it.
JavaScript (V8), 79 bytes
Expects (w)(h). Prints the coordinates.
w=>h=>{for(i=j=0;j<=i||(j=0,++i<w+h);j++)(x=i&1?j:i-j,y=i-x)<h&x<w&&print(x,y)}
How?
We walk through the upper-left diagonals of a square of width \$w+h\$, going alternately from top-right to bottom-left and the other way around. We print only the coordinates that are within the target rectangle.
Below is an example for \$w=3\$ and \$h=2\$:
JavaScript (V8), 77 bytes
Expects (w)(h). Prints the coordinates.
w=>h=>{for(i=j=0;j<=i||(j=0,++i<w+h);j++)i-(x=i&1?j:i-j)<h&x<w&&print(x,i-x)}
How?
We walk through the upper-left diagonals of a square of width \$w+h\$, going alternately from top-right to bottom-left and the other way around. We print only the coordinates that are within the target rectangle.
Below is an example for \$w=3\$ and \$h=2\$:
NB: Processing the longest diagonal never brings any new cell. It's just golfier to include it.
JavaScript (V8), 79 bytes
Expects (w)(h). Prints allthe coordinates.
w=>h=>{for(i=j=0;j<=i||(j=0,++i<w+h);j++)(x=i&1?j:i-j,y=i-x)<h&x<w&&print(x,y)}
How?
We walk through allthe upper-left diagonals of length \1ドル\$ toa square of width \$w+h\$, going alternately from top-right to bottom-left and the other way around, printing. We print only the coordinates that are within the target rectangle.
Below is an example for \$w=3\$ and \$h=2\$:
JavaScript (V8), 79 bytes
Expects (w)(h). Prints all coordinates.
w=>h=>{for(i=j=0;j<=i||(j=0,++i<w+h);j++)(x=i&1?j:i-j,y=i-x)<h&x<w&&print(x,y)}
How?
We walk through all diagonals of length \1ドル\$ to \$w+h\$, going alternately from top-right to bottom-left and the other way around, printing only coordinates that are within the target rectangle.
Below is an example for \$w=3\$ and \$h=2\$:
JavaScript (V8), 79 bytes
Expects (w)(h). Prints the coordinates.
w=>h=>{for(i=j=0;j<=i||(j=0,++i<w+h);j++)(x=i&1?j:i-j,y=i-x)<h&x<w&&print(x,y)}
How?
We walk through the upper-left diagonals of a square of width \$w+h\$, going alternately from top-right to bottom-left and the other way around. We print only the coordinates that are within the target rectangle.
Below is an example for \$w=3\$ and \$h=2\$: