Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix: brush antialiasing and minor stuff

  • Loading branch information...
commit 38ebb85e8695eb745843e7ee7f3ed4594ea45330 1 parent ee3dfef
@trethaller authored
View
2  js/app.coffee
@@ -75,7 +75,7 @@ class DocumentView
local = {}
- $container.mousedown (e)->
+ $backCanvas.mousedown (e)->
e.preventDefault()
if e.which is 1
self.drawing = true
View
2  js/app.js
@@ -108,7 +108,7 @@ DocumentView = (function() {
return self.screenToCanvas(v);
};
local = {};
- $container.mousedown(function(e) {
+ $backCanvas.mousedown(function(e) {
var coords;
e.preventDefault();
if (e.which === 1) {
View
17 js/core.coffee
@@ -320,27 +320,28 @@ genBrushFunc = (args, brushExp, blendExp)->
str = "
(function (rect, dstFb, #{args}) {
- var minx = rect.x;
- var miny = rect.y;
- var sw = rect.width;
- var sh = rect.height;
+ var sw = Math.round(rect.width);
+ var sh = Math.round(rect.height);
var invw = 2.0 / (rect.width - 1);
var invh = 2.0 / (rect.height - 1);
+ var offx = -(rect.x % 1.0) * invw - 1.0;
+ var offy = -(rect.y % 1.0) * invh - 1.0;
var fbw = dstFb.width;
var fbh = dstFb.height;
+ var minx = Math.floor(rect.x) + fbw;
+ var miny = Math.floor(rect.y) + fbh;
var dstData = dstFb.getBuffer();
for(var sy=0; sy<sh; ++sy) {
- var y = sy * invh - 1.0;
+ var y = sy * invh + offy;
for(var sx=0; sx<sw; ++sx) {
- var x = sx * invw - 1.0;
- var dsti = (((sy + miny) + fbh) % fbh) * fbw + (((sx + minx) + fbw) % fbw);
+ var x = sx * invw + offx;
+ var dsti = ((sy + miny) % fbh) * fbw + ((sx + minx) % fbw);
var _tmp = 0.0;
#{brushExp};
#{blendExp};
}
}
})"
- #console.log("Generating brush function", str)
return eval(str)
View
2  js/core.js
@@ -371,7 +371,7 @@ genBrushFunc = function(args, brushExp, blendExp) {
var str;
blendExp = blendExp.replace(/{dst}/g, "dstData[dsti]").replace(/{src}/g, "_tmp");
brushExp = brushExp.replace(/{out}/g, "_tmp");
- str = " (function (rect, dstFb, " + args + ") { var minx = rect.x; var miny = rect.y; var sw = rect.width; var sh = rect.height; var invw = 2.0 / (rect.width - 1); var invh = 2.0 / (rect.height - 1); var fbw = dstFb.width; var fbh = dstFb.height; var dstData = dstFb.getBuffer(); for(var sy=0; sy<sh; ++sy) { var y = sy * invh - 1.0; for(var sx=0; sx<sw; ++sx) { var x = sx * invw - 1.0; var dsti = (((sy + miny) + fbh) % fbh) * fbw + (((sx + minx) + fbw) % fbw); var _tmp = 0.0; " + brushExp + "; " + blendExp + "; } } })";
+ str = " (function (rect, dstFb, " + args + ") { var sw = Math.round(rect.width); var sh = Math.round(rect.height); var invw = 2.0 / (rect.width - 1); var invh = 2.0 / (rect.height - 1); var offx = -(rect.x % 1.0) * invw - 1.0; var offy = -(rect.y % 1.0) * invh - 1.0; var fbw = dstFb.width; var fbh = dstFb.height; var minx = Math.floor(rect.x) + fbw; var miny = Math.floor(rect.y) + fbh; var dstData = dstFb.getBuffer(); for(var sy=0; sy<sh; ++sy) { var y = sy * invh + offy; for(var sx=0; sx<sw; ++sx) { var x = sx * invw + offx; var dsti = ((sy + miny) % fbh) * fbw + ((sx + minx) % fbw); var _tmp = 0.0; " + brushExp + "; " + blendExp + "; } } })";
return eval(str);
};
View
27 js/tools.coffee
@@ -14,7 +14,7 @@ class StepBrush
move: (pos, pressure) ->;
draw: (layer, pos, pressure) ->
rect = new Rect(pos.x, pos.y, 1, 1)
- intensity = pressure * @stepSize / 10.0
+ intensity = pressure
if @lastpos?
delt = pos.sub(@lastpos)
length = delt.length()
@@ -86,15 +86,15 @@ RoundBrush = (()->
{
id: 'stepSize'
name: "Step size"
- defaultValue: 3
- range: [1, 20]
+ defaultValue: 2
+ range: [1, 10]
type: 'int'
},
{
id: 'hardness'
name: "Hardness"
- defaultValue: 0.5
- range: [0.0, 10.0]
+ defaultValue: 0.2
+ range: [0.0, 1.0]
},
{
id: 'size'
@@ -112,8 +112,8 @@ RoundBrush = (()->
{
id:'intensity'
name: "Intensity"
- defaultValue: 0.5
- range: [0.0, 3.0]
+ defaultValue: 1.0
+ range: [0.0, 1.0]
}
]
@@ -122,9 +122,9 @@ RoundBrush = (()->
createTool = (env)->
sb = new StepBrush()
sb.stepSize = self.get('stepSize')
- rad = self.get('size')
+ size = self.get('size')
- hardness = self.get('hardness')
+ hardness = Math.pow(self.get('hardness'), 2.0) * 8.0;
hardnessPlus1 = hardness + 1.0
func = genBrushFunc("intensity, target, h, hp1",
"var d = Math.min(1.0, Math.max(0.0, (Math.sqrt(x*x + y*y) * hp1 - h)));
@@ -133,13 +133,12 @@ RoundBrush = (()->
sb.drawStep = (layer, pos, intensity, rect)->
r = new Rect(
- pos.x - rad * 0.5,
- pos.y - rad * 0.5,
- rad,
- rad).round()
+ pos.x - size * 0.5,
+ pos.y - size * 0.5,
+ size, size)
func(r, layer, intensity * self.get('intensity'), env.get('targetValue'), hardness, hardnessPlus1)
- rect.extend(r)
+ rect.extend(r.round())
return sb
self.properties = properties
View
24 js/tools.js
@@ -26,7 +26,7 @@ StepBrush = (function() {
StepBrush.prototype.draw = function(layer, pos, pressure) {
var delt, dir, intensity, length, pt, rect;
rect = new Rect(pos.x, pos.y, 1, 1);
- intensity = pressure * this.stepSize / 10.0;
+ intensity = pressure;
if (this.lastpos != null) {
delt = pos.sub(this.lastpos);
length = delt.length();
@@ -117,14 +117,14 @@ RoundBrush = (function() {
{
id: 'stepSize',
name: "Step size",
- defaultValue: 3,
- range: [1, 20],
+ defaultValue: 2,
+ range: [1, 10],
type: 'int'
}, {
id: 'hardness',
name: "Hardness",
- defaultValue: 0.5,
- range: [0.0, 10.0]
+ defaultValue: 0.2,
+ range: [0.0, 1.0]
}, {
id: 'size',
name: "Size",
@@ -139,24 +139,24 @@ RoundBrush = (function() {
}, {
id: 'intensity',
name: "Intensity",
- defaultValue: 0.5,
- range: [0.0, 3.0]
+ defaultValue: 1.0,
+ range: [0.0, 1.0]
}
];
self = new Backbone.Model;
createTool = function(env) {
- var func, hardness, hardnessPlus1, rad, sb;
+ var func, hardness, hardnessPlus1, sb, size;
sb = new StepBrush();
sb.stepSize = self.get('stepSize');
- rad = self.get('size');
- hardness = self.get('hardness');
+ size = self.get('size');
+ hardness = Math.pow(self.get('hardness'), 2.0) * 8.0;
hardnessPlus1 = hardness + 1.0;
func = genBrushFunc("intensity, target, h, hp1", "var d = Math.min(1.0, Math.max(0.0, (Math.sqrt(x*x + y*y) * hp1 - h))); {out} = Math.cos(d * Math.PI) * 0.5 + 0.5;", BlendModes[self.get('blendMode')]);
sb.drawStep = function(layer, pos, intensity, rect) {
var r;
- r = new Rect(pos.x - rad * 0.5, pos.y - rad * 0.5, rad, rad).round();
+ r = new Rect(pos.x - size * 0.5, pos.y - size * 0.5, size, size);
func(r, layer, intensity * self.get('intensity'), env.get('targetValue'), hardness, hardnessPlus1);
- return rect.extend(r);
+ return rect.extend(r.round());
};
return sb;
};
Please sign in to comment.
Something went wrong with that request. Please try again.