diff options
Diffstat (limited to 'js/draw.js')
| -rw-r--r-- | js/draw.js | 67 |
1 files changed, 67 insertions, 0 deletions
@@ -27,6 +27,72 @@ var draw = (function(){ last_point[1] = point[1] } + function move_toroidal (e, lex, point) { + var w = canvas.w, h = canvas.h + var src_x_quantile = quantile( last_point[0], w ) + var src_y_quantile = quantile( last_point[1], h ) + var dst_x_quantile = quantile( point[0], w ) + var dst_y_quantile = quantile( point[1], h ) + var src_x_mod = mod( last_point[0], w ) + var src_y_mod = mod( last_point[1], h ) + var dst_x_mod = mod( point[0], w ) + var dst_y_mod = mod( point[1], h ) + // if we've moved across the edge of the board, draw two lines + if (src_x_quantile != dst_x_quantile || src_y_quantile != dst_y_quantile) { + var xa, ya + if (src_x_quantile < dst_x_quantile) { + xa = [ + [src_x_mod, dst_x_mod + w], + [src_x_mod-w, dst_x_mod], + ] + } + else if (src_x_quantile == dst_x_quantile) { + xa = [ + [src_x_mod, dst_x_mod], + [src_x_mod, dst_x_mod], + ] + } + else { + xa = [ + [src_x_mod, dst_x_mod-w], + [src_x_mod+w, dst_x_mod], + ] + } + + if (src_y_quantile < dst_y_quantile) { + ya = [ + [src_y_mod, dst_y_mod + h], + [src_y_mod-h, dst_y_mod], + ] + } + else if (src_y_quantile == dst_y_quantile) { + ya = [ + [src_y_mod, dst_y_mod], + [src_y_mod, dst_y_mod], + ] + } + else { + ya = [ + [src_y_mod, dst_y_mod-h], + [src_y_mod+h, dst_y_mod], + ] + } + line(lex, [ xa[0][0], ya[0][0] ], [ xa[0][1], ya[0][1] ], erasing) + line(lex, [ xa[1][0], ya[1][0] ], [ xa[1][1], ya[1][1] ], erasing) + } + else { + var last_point_mod = [], point_mod = [] + last_point_mod[0] = mod( last_point[0], w ) + last_point_mod[1] = mod( last_point[1], h ) + point_mod[0] = mod( point[0], w ) + point_mod[1] = mod( point[1], h ) + line(lex, last_point_mod, point_mod, erasing) + } + last_point[0] = point[0] + last_point[1] = point[1] + // y = point.y + } + function point (lex, x, y, erasing) { stamp (canvas, brush, x, y, erasing) } @@ -109,6 +175,7 @@ var draw = (function(){ draw.down = down draw.set_last_point = set_last_point draw.move = move + draw.move_toroidal = move_toroidal draw.stamp = stamp draw.line = line draw.point = point |
