Browse Source

Rewrote CTRLPainter LineToSurface() function. Lines should be MUCH better now.

dev-bank
Bryan Miller 6 years ago
parent
commit
e5916272ae
1 changed files with 28 additions and 19 deletions
  1. +28
    -19
      app/js/ctrls/CTRLPainter.js

+ 28
- 19
app/js/ctrls/CTRLPainter.js View File



var LineToSurface = (function(x0, y0, x1, y1, ci, pi){ var LineToSurface = (function(x0, y0, x1, y1, ci, pi){
var dx = x1 - x0; var dx = x1 - x0;
var ix = Math.sign(dx);
dx = 2 * Math.abs(dx);

var dy = y1 - y0; var dy = y1 - y0;
var iy = Math.sign(dy);
dy = 2 * Math.abs(dy);


if (dx == 0){ if (dx > dy){
// Verticle line var err = dy - (dx/2);
var x = x0; var y = y0;
var s = Math.min(y0, y1); Utils.range(x0, x1, 1).forEach((x) => {
var e = Math.max(y0, y1);
for (var y = s; y <= e; y++){
this.__surface.setColorIndex(x, y, ci, pi); this.__surface.setColorIndex(x, y, ci, pi);
} if (err > 0 || (err == 0 && ix > 0)){
err -= dx;
y += iy;
}
err += dy;
});
} else { } else {
var slope = Math.abs(dy/dx); var err = dx - (dy/2);
var err = 0.0; var x = x0;
var y = y0; Utils.range(y0, y1, 1).forEach((y) => {
var surf = this.__surface; this.__surface.setColorIndex(x, y, ci, pi);
Utils.range(x0, x1, 1).forEach(function(x){ if (err > 0 || (err == 0 && iy > 0)){
surf.setColorIndex(Math.floor(x), Math.floor(y), ci, pi); err -= dy;
err += slope; x += ix;
if (err > 0.5){
y += Math.sign(dy);
err -= 1.0;
} }
err += dx;
}); });
} }
}).bind(this); }).bind(this);


var handle_draw = (function(e){ var handle_draw = (function(e){
if (e.isCombo || e.button == 0){ if (e.isCombo || e.button == 0){
if (this.__surface !== null){ if (this.__surface !== null){
//console.log(this.__brushPos);
//console.log(this.__brushLastPos);
var x = Math.floor((this.__brushPos[0] - this.__offset[0]) * (1.0 / this.__scale)); var x = Math.floor((this.__brushPos[0] - this.__offset[0]) * (1.0 / this.__scale));
var y = Math.floor((this.__brushPos[1] - this.__offset[1]) * (1.0 / this.__scale)); var y = Math.floor((this.__brushPos[1] - this.__offset[1]) * (1.0 / this.__scale));
var sx = (e.isCombo) ? Math.floor((this.__brushLastPos[0] - this.__offset[0]) * (1.0 / this.__scale)) : x; var sx = (e.isCombo) ? Math.floor((this.__brushLastPos[0] - this.__offset[0]) * (1.0 / this.__scale)) : x;
var sy = (e.isCombo) ? Math.floor((this.__brushLastPos[1] - this.__offset[1]) * (1.0 / this.__scale)) : y; var sy = (e.isCombo) ? Math.floor((this.__brushLastPos[1] - this.__offset[1]) * (1.0 / this.__scale)) : y;
if (x >= 0 && x < this.__surface.width && y >= 0 && y < this.__surface.height){ if (x >= 0 && x < this.__surface.width && y >= 0 && y < this.__surface.height){
LineToSurface(sx, sy, x, y, this.__brushColor, this.__brushPalette); LineToSurface(sx, sy, x, y, this.__brushColor, this.__brushPalette);
//this.__surface.setColorIndex(x, y, this.__brushColor, this.__brushPalette);
RenderD(); RenderD();
} }
} }

Loading…
Cancel
Save