Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Showing with 144 additions and 37 deletions.
  1. +53 −1 js/app.coffee
  2. +56 −1 js/app.js
  3. +9 −8 js/core.coffee
  4. +1 −1 js/core.js
  5. +13 −14 js/tools.coffee
  6. +12 −12 js/tools.js
View
54 js/app.coffee
@@ -35,6 +35,58 @@ Commands = [
return val
refresh()
},
+ {
+ name: "Invert"
+ func: (doc)->
+ buf = doc.layer.getBuffer()
+ len = buf.length
+ `for(var i=0; i<len; ++i) {
+ buf[i] = -buf[i];
+ }
+ `
+ refresh()
+ },
+ {
+ name: "Flip H"
+ func: (doc)->
+ buf = doc.layer.getBuffer()
+ len = buf.length
+ height = doc.layer.height
+ width = doc.layer.width
+ halfw = Math.floor(doc.layer.width / 2.0)
+ maxx = doc.layer.width - 1;
+ tmp = 0.0
+ `for(var iy=0; iy<height; ++iy) {
+ var offset = iy * width
+ for(var ix=0; ix<halfw; ++ix) {
+ tmp = buf[offset + ix];
+ buf[offset + ix] = buf[offset + maxx - ix];
+ buf[offset + maxx - ix] = tmp;
+ }
+ }
+ `
+ refresh()
+ },
+ {
+ name: "Flip V"
+ func: (doc)->
+ buf = doc.layer.getBuffer()
+ len = buf.length
+ height = doc.layer.height
+ width = doc.layer.width
+ halfh = Math.floor(doc.layer.width / 2.0)
+ maxy = doc.layer.width - 1;
+ tmp = 0.0
+ `for(var iy=0; iy<halfh; ++iy) {
+ for(var ix=0; ix<width; ++ix) {
+ tmp = buf[iy*width + ix];
+ buf[iy*width + ix] = buf[(maxy - iy)*width + ix];
+ buf[(maxy - iy)*width + ix] = tmp;
+ }
+ }
+ `
+ refresh()
+ },
]
class DocumentView
@@ -75,7 +127,7 @@ class DocumentView
local = {}
- $container.mousedown (e)->
+ $backCanvas.mousedown (e)->
e.preventDefault()
if e.which is 1
self.drawing = true
View
57 js/app.js
@@ -51,6 +51,61 @@ Commands = [
});
return refresh();
}
+ }, {
+ name: "Invert",
+ func: function(doc) {
+ var buf, len;
+ buf = doc.layer.getBuffer();
+ len = buf.length;
+ for(var i=0; i<len; ++i) {
+ buf[i] = -buf[i];
+ }
+ ;
+ return refresh();
+ }
+ }, {
+ name: "Flip H",
+ func: function(doc) {
+ var buf, halfw, height, len, maxx, tmp, width;
+ buf = doc.layer.getBuffer();
+ len = buf.length;
+ height = doc.layer.height;
+ width = doc.layer.width;
+ halfw = Math.floor(doc.layer.width / 2.0);
+ maxx = doc.layer.width - 1;
+ tmp = 0.0;
+ for(var iy=0; iy<height; ++iy) {
+ var offset = iy * width
+ for(var ix=0; ix<halfw; ++ix) {
+ tmp = buf[offset + ix];
+ buf[offset + ix] = buf[offset + maxx - ix];
+ buf[offset + maxx - ix] = tmp;
+ }
+ }
+ ;
+ return refresh();
+ }
+ }, {
+ name: "Flip V",
+ func: function(doc) {
+ var buf, halfh, height, len, maxy, tmp, width;
+ buf = doc.layer.getBuffer();
+ len = buf.length;
+ height = doc.layer.height;
+ width = doc.layer.width;
+ halfh = Math.floor(doc.layer.width / 2.0);
+ maxy = doc.layer.width - 1;
+ tmp = 0.0;
+ for(var iy=0; iy<halfh; ++iy) {
+ for(var ix=0; ix<width; ++ix) {
+ tmp = buf[iy*width + ix];
+ buf[iy*width + ix] = buf[(maxy - iy)*width + ix];
+ buf[(maxy - iy)*width + ix] = tmp;
+ }
+ }
+ ;
+ return refresh();
+ }
}
];
@@ -108,7 +163,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;
};

No commit comments for this range

Something went wrong with that request. Please try again.