summaryrefslogtreecommitdiff
path: root/js/blit.js
diff options
context:
space:
mode:
authortimb <opuscule@gmail.com>2015-05-24 17:03:57 -0500
committertimb <opuscule@gmail.com>2015-05-24 17:03:57 -0500
commita45a3beb47663e9036b926442e205e81abbae986 (patch)
tree5015be29d9c1bc3b45d45bde2759a572294cf57c /js/blit.js
parent462b2ed2fa649be9cf345a2ead175979de0106a6 (diff)
circle brush algo
Diffstat (limited to 'js/blit.js')
-rw-r--r--js/blit.js21
1 files changed, 18 insertions, 3 deletions
diff --git a/js/blit.js b/js/blit.js
index 367d67b..16c62a5 100644
--- a/js/blit.js
+++ b/js/blit.js
@@ -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()
}
})