diff options
| author | timb <opuscule@gmail.com> | 2015-05-24 17:03:57 -0500 |
|---|---|---|
| committer | timb <opuscule@gmail.com> | 2015-05-24 17:03:57 -0500 |
| commit | a45a3beb47663e9036b926442e205e81abbae986 (patch) | |
| tree | 5015be29d9c1bc3b45d45bde2759a572294cf57c /js/blit.js | |
| parent | 462b2ed2fa649be9cf345a2ead175979de0106a6 (diff) | |
circle brush algo
Diffstat (limited to 'js/blit.js')
| -rw-r--r-- | js/blit.js | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -47,11 +47,26 @@ var blit = (function(){ } }) } + var distance_rect = function(x, y, ratio){ + return Math.sqrt((Math.pow(y * ratio, 2)) + Math.pow(x, 2)) + } + var distance_square = function(x, y, ratio){ + return Math.sqrt((Math.pow(y * ratio, 2)) + Math.pow(x * ratio, 2)) + } blit.circle = function(A, lex){ - var hw = brush.w/2|0, hh = brush.h/2|0 + var hw = brush.w/2, hh = brush.h/2 + var ratio, distance + + if (brush.w === brush.h){ + distance = distance_square + ratio = hw / hh * (brush.w === 3 || brush.w === 5 ? 1.2 : 1.05) + } else { + distance = distance_rect + ratio = hw / hh + } + A.forEach(function(lex,x,y) { - var len = Math.sqrt(Math.pow(x-hw,2)+Math.pow(y-hh,2)) - if (len > Math.abs(hw)) { + if (distance(x - hw + 0.5, y - hh + 0.5, ratio) > hw){ lex.clear() } }) |
