Permalink
Browse files

Fixing the pixel wrapping algorithm.

  • Loading branch information...
1 parent 29c4ede commit 7b916c68178aacaeb5470e2c7e990f95ac9fe4d7 @reu committed Mar 24, 2013
Showing with 4 additions and 10 deletions.
  1. +4 −10 src/screen.js
View
@@ -28,17 +28,11 @@
*/
this.setPixel = function(x, y) {
// Wrap around pixels that overflow the screen
- if (x > this.columns) {
- x -= this.columns;
- } else if (x < 0) {
- x += this.columns;
- }
+ if (x > this.columns - 1) while (x > this.columns - 1) x -= this.columns;
+ if (x < 0) while (x < 0) x += this.columns;
- if (y > this.rows) {
- y -= this.rows;
- } else if (y < 0) {
- y += this.rows;
- }
+ if (y > this.rows - 1) while (y > this.rows - 1) y -= this.rows;
+ if (y < 0) while (y < 0) y += this.rows;
var location = x + (y * this.columns);
this.bitMap[location] = this.bitMap[location] ^ 1;

0 comments on commit 7b916c6

Please sign in to comment.