diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-03-31 13:12:41 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-03-31 13:12:41 +0200 |
| commit | d9f1628cbc3e96c584279b8d58e2e2c2a0d75b56 (patch) | |
| tree | 4341725d1a741536eee81562f89a0e8802321083 /js/draw.js | |
| parent | 6048890a8ee3750d8d0c252b7f77a1ed0bf42259 (diff) | |
mirror x/y
Diffstat (limited to 'js/draw.js')
| -rw-r--r-- | js/draw.js | 44 |
1 files changed, 40 insertions, 4 deletions
@@ -4,13 +4,32 @@ var draw = (function(){ var last_point = [0,0] function down (e, lex, point) { + var w = canvas.w, h = canvas.h erasing = (e.which == "3" || e.ctrlKey) changed = true if (e.shiftKey) { line (lex, last_point, point, erasing) + if (mirror_x) { + line(lex, [w-last_point[0], last_point[1]], [w-point[0], point[1]], erasing) + } + if (mirror_y) { + line(lex, [last_point[0], h-last_point[1]], [point[0], h-point[1]], erasing) + } + if (mirror_x && mirror_y) { + line(lex, [w-last_point[0], h-last_point[1]], [w-point[0], h-point[1]], erasing) + } } else { stamp (canvas, brush, point[0], point[1], erasing) + if (mirror_x) { + stamp (canvas, brush, w-point[0], point[1], erasing) + } + if (mirror_y) { + stamp (canvas, brush, point[0], h-point[1], erasing) + } + if (mirror_x && mirror_y) { + stamp (canvas, brush, w-point[0], h-point[1], erasing) + } } last_point[0] = point[0] last_point[1] = point[1] @@ -22,7 +41,18 @@ var draw = (function(){ } function move (e, lex, point) { + var w = canvas.w, h = canvas.h line(lex, last_point, point, erasing) + if (mirror_x) { + line(lex, [w-last_point[0], last_point[1]], [w-point[0], point[1]], erasing) + } + if (mirror_y) { + line(lex, [last_point[0], h-last_point[1]], [point[0], h-point[1]], erasing) + } + if (mirror_x && mirror_y) { + line(lex, [w-last_point[0], h-last_point[1]], [w-point[0], h-point[1]], erasing) + } + last_point[0] = point[0] last_point[1] = point[1] } @@ -82,11 +112,17 @@ var draw = (function(){ } 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 ) + var x_a = mod( last_point[0], w ) + var y_a = mod( last_point[1], h ) + var x_b = mod( point[0], w ) + var y_b = mod( point[1], h ) line(lex, last_point_mod, point_mod, erasing) + if (mirror_x) { + line(lex, [w-last_point_mod[0], last_point_mod[1]], [w-point_mod[0], point_mod[1]], erasing) + } + if (mirror_y) { + line(lex, [last_point_mod[0], h-last_point_mod[1]], [point_mod[0], h-point_mod[1]], erasing) + } } last_point[0] = point[0] last_point[1] = point[1] |
