Skip to content

Commit

Permalink
Clock CodingTrain#5 - Fixed spaces between rectangels
Browse files Browse the repository at this point in the history
I am checking if there is a rectangle to the right or bottom and increasing the width or height by 1 to 'connect' them. It is a somewhat ugly solution since it is now always drawing every rectangle twice (to prevent an extra 1 by 1 rectangle when both height and width are increased on the same rectangle). Maybe it would be better to draw an extra 1 by 'size' rectangle at the bottom and/or right?
  • Loading branch information
Merijn-DH authored Oct 1, 2017
1 parent 626017d commit d225d86
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion clocks/clock-05.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ var clock05 = function(sketch) {
for (let row = 0; row < dots.length; row++) {
for (let col = 0; col < dots[row].length; col++) {
if (dots[row][col] === 1) {
sketch.rect(size * col - size*2.5, size * row - size*3.5, size, size);
sketch.rect(size * col - size*2.5, size * row - size*3.5, size + joined(row, col + 1), size);
sketch.rect(size * col - size*2.5, size * row - size*3.5, size, size + joined(row + 1, col));
}
}
}
sketch.pop();

function joined(row, col) {
if (row < 0 || row >= dots.length || col < 0 || col >= dots[row].length) {
return false;
}
return dots[row][col] === 1;
}
}
}

0 comments on commit d225d86

Please sign in to comment.