Damn, I broke Chromatic
This commit is contained in:
parent
efc8ac170f
commit
b6a61cd0d5
@ -33,11 +33,11 @@
|
|||||||
<script type="text/javascript" src="scripts/filters/stencil.js"></script>
|
<script type="text/javascript" src="scripts/filters/stencil.js"></script>
|
||||||
<script type="text/javascript" src="scripts/filters/rotate.js"></script>
|
<script type="text/javascript" src="scripts/filters/rotate.js"></script>
|
||||||
<script type="text/javascript" src="scripts/filters/invert.js"></script>
|
<script type="text/javascript" src="scripts/filters/invert.js"></script>
|
||||||
|
<script type="text/javascript" src="scripts/filters/chromatic.js"></script>
|
||||||
|
|
||||||
<!-- Need to migrate
|
<!-- Need to migrate
|
||||||
<script type="text/javascript" src="scripts/filters/saturation.js"></script>
|
<script type="text/javascript" src="scripts/filters/saturation.js"></script>
|
||||||
<script type="text/javascript" src="scripts/filters/chromatic.js"></script>
|
|
||||||
<script type="text/javascript" src="scripts/filters/offset.js"></script>
|
<script type="text/javascript" src="scripts/filters/offset.js"></script>
|
||||||
<script type="text/javascript" src="scripts/filters/eval.js"></script>
|
|
||||||
<script type="text/javascript" src="scripts/filters/balance.js"></script>
|
<script type="text/javascript" src="scripts/filters/balance.js"></script>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
Filter.prototype.filter_chromatic = function(pixels = this.pixels(),p = null)
|
|
||||||
{
|
|
||||||
var s;
|
|
||||||
if(p.length === 0)
|
|
||||||
s = {r:2,g:2,b:2};
|
|
||||||
else if(p.length < 3)
|
|
||||||
s = {r:parseFloat(p[0]), g:parseFloat(p[0])*.5, b:0};
|
|
||||||
else
|
|
||||||
s = {r:parseFloat(p[0]), g:parseFloat(p[1]), b:parseFloat(p[2])};
|
|
||||||
var hw = pixels.width*.5;
|
|
||||||
var hh = pixels.height*.5;
|
|
||||||
var maxLength = Math.sqrt(hw*hw+hh*hh);
|
|
||||||
var output = new ImageData(pixels.width, pixels.height);
|
|
||||||
for (var i=0; i<pixels.width; i++) {
|
|
||||||
for(var j=0; j<pixels.height; j++){
|
|
||||||
var x = i-hw;
|
|
||||||
var y = j-hh;
|
|
||||||
var a = Math.atan2(y,x);
|
|
||||||
var d = Math.sqrt(x*x+y*y);
|
|
||||||
var f = (d-s.r*d/maxLength);
|
|
||||||
x = Math.cos(a)*f+hw;
|
|
||||||
y = Math.sin(a)*f+hh;
|
|
||||||
var r = this.get_color_bilinear(pixels, x, y);
|
|
||||||
f = (d-s.g*d/maxLength);
|
|
||||||
x = Math.cos(a)*f+hw;
|
|
||||||
y = Math.sin(a)*f+hh;
|
|
||||||
var g = this.get_color_bilinear(pixels, x, y);
|
|
||||||
f = (d-s.b*d/maxLength);
|
|
||||||
x = Math.cos(a)*f+hw;
|
|
||||||
y = Math.sin(a)*f+hh;
|
|
||||||
var b = this.get_color_bilinear(pixels, x, y);
|
|
||||||
var c = {r:r.r, g:g.g, b:b.b,a:Math.max(r.a, Math.max(g.a,b.a))};
|
|
||||||
this.set_color(output, c, i,j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ronin.canvas.clear();
|
|
||||||
ronin.surface.context().putImageData(output, 0, 0, 0, 0, pixels.width, pixels.height);
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
Filter.prototype.filter_eval = function(pixels = this.pixels(),p = null)
|
|
||||||
{
|
|
||||||
console.log("working");
|
|
||||||
|
|
||||||
// : eval {x} % 100 == 0
|
|
||||||
|
|
||||||
var data = pixels.data;
|
|
||||||
|
|
||||||
for (var i = 0; i < data.length; i += 4) {
|
|
||||||
|
|
||||||
var x = (i/4) % pixels.width;
|
|
||||||
var y = Math.floor((i/4)/pixels.width);
|
|
||||||
|
|
||||||
var q = (x % parseInt(p[0]) === 0 && y % parseInt(p[1]) === 0);
|
|
||||||
|
|
||||||
if(x % 20 == 0 && y % 20 == 0){
|
|
||||||
data[i] = 50; // red
|
|
||||||
data[i + 1] = 50; // green
|
|
||||||
data[i + 2] = 50; // blue
|
|
||||||
data[i + 3] = 255; // alpha?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ronin.canvas.clear();
|
|
||||||
ronin.surface.context().putImageData(pixels, 0, 0, 0, 0, pixels.width, pixels.height);
|
|
||||||
console.log("done.");
|
|
||||||
}
|
|
43
scripts/filters/chromatic.js
Normal file
43
scripts/filters/chromatic.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
function Filter_Chromatic()
|
||||||
|
{
|
||||||
|
Filter.call(this);
|
||||||
|
|
||||||
|
this.parameters = [];
|
||||||
|
|
||||||
|
// var pixels = this.pixels();
|
||||||
|
// var s;
|
||||||
|
// if(p.length === 0)
|
||||||
|
// s = {r:2,g:2,b:2};
|
||||||
|
// else if(p.length < 3)
|
||||||
|
// s = {r:parseFloat(p[0]), g:parseFloat(p[0])*.5, b:0};
|
||||||
|
// else
|
||||||
|
// s = {r:parseFloat(p[0]), g:parseFloat(p[1]), b:parseFloat(p[2])};
|
||||||
|
// var hw = pixels.width*.5;
|
||||||
|
// var hh = pixels.height*.5;
|
||||||
|
// var maxLength = Math.sqrt(hw*hw+hh*hh);
|
||||||
|
// var output = new ImageData(pixels.width, pixels.height);
|
||||||
|
// for (var i=0; i<pixels.width; i++) {
|
||||||
|
// for(var j=0; j<pixels.height; j++){
|
||||||
|
// var x = i-hw;
|
||||||
|
// var y = j-hh;
|
||||||
|
// var a = Math.atan2(y,x);
|
||||||
|
// var d = Math.sqrt(x*x+y*y);
|
||||||
|
// var f = (d-s.r*d/maxLength);
|
||||||
|
// x = Math.cos(a)*f+hw;
|
||||||
|
// y = Math.sin(a)*f+hh;
|
||||||
|
// var r = this.get_color_bilinear(pixels, x, y);
|
||||||
|
// f = (d-s.g*d/maxLength);
|
||||||
|
// x = Math.cos(a)*f+hw;
|
||||||
|
// y = Math.sin(a)*f+hh;
|
||||||
|
// var g = this.get_color_bilinear(pixels, x, y);
|
||||||
|
// f = (d-s.b*d/maxLength);
|
||||||
|
// x = Math.cos(a)*f+hw;
|
||||||
|
// y = Math.sin(a)*f+hh;
|
||||||
|
// var b = this.get_color_bilinear(pixels, x, y);
|
||||||
|
// var c = {r:r.r, g:g.g, b:b.b,a:Math.max(r.a, Math.max(g.a,b.a))};
|
||||||
|
// this.set_color(output, c, i,j);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// ronin.canvas.clear();
|
||||||
|
// ronin.surface.context().putImageData(output, 0, 0, 0, 0, pixels.width, pixels.height);
|
||||||
|
}
|
@ -22,5 +22,4 @@ function Filter_Invert()
|
|||||||
ronin.surface.active_layer.clear();
|
ronin.surface.active_layer.clear();
|
||||||
context.putImageData(imageData, 0, 0);
|
context.putImageData(imageData, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ function Render(rune)
|
|||||||
this.collection["stencil"] = new Filter_Stencil();
|
this.collection["stencil"] = new Filter_Stencil();
|
||||||
this.collection["rotate"] = new Filter_Rotate();
|
this.collection["rotate"] = new Filter_Rotate();
|
||||||
this.collection["invert"] = new Filter_Invert();
|
this.collection["invert"] = new Filter_Invert();
|
||||||
|
this.collection["chromatic"] = new Filter_Chromatic();
|
||||||
|
|
||||||
this.active = function(cmd)
|
this.active = function(cmd)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user