mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Draw lines of pixels instead of single pixels
This commit is contained in:
parent
1402394d07
commit
0642e17aa8
@ -178,7 +178,6 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
ns.AnimatedPreviewController.prototype.setRenderFlag_ = function (bool) {
|
ns.AnimatedPreviewController.prototype.setRenderFlag_ = function (bool) {
|
||||||
console.log('setRenderFlag_', bool);
|
|
||||||
this.renderFlag = bool;
|
this.renderFlag = bool;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,9 +19,18 @@
|
|||||||
ns.CanvasRenderer.prototype.render = function () {
|
ns.CanvasRenderer.prototype.render = function () {
|
||||||
var canvas = this.createCanvas_();
|
var canvas = this.createCanvas_();
|
||||||
var context = canvas.getContext('2d');
|
var context = canvas.getContext('2d');
|
||||||
this.frame.forEachPixel(function (color, x, y) {
|
|
||||||
this.renderPixel_(color, x, y, context);
|
for(var x = 0, width = this.frame.getWidth(); x < width; x++) {
|
||||||
}.bind(this));
|
for(var y = 0, height = this.frame.getHeight(); y < height; y++) {
|
||||||
|
var color = this.frame.getPixel(x, y);
|
||||||
|
var w = 1;
|
||||||
|
while (color === this.frame.getPixel(x, y+w)) {
|
||||||
|
w++;
|
||||||
|
}
|
||||||
|
this.renderLine_(color, x, y, w, context);
|
||||||
|
y = y + w - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var scaledCanvas = this.createCanvas_(this.zoom);
|
var scaledCanvas = this.createCanvas_(this.zoom);
|
||||||
var scaledContext = scaledCanvas.getContext('2d');
|
var scaledContext = scaledCanvas.getContext('2d');
|
||||||
@ -40,6 +49,13 @@
|
|||||||
context.fillRect(x, y, 1, 1);
|
context.fillRect(x, y, 1, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.CanvasRenderer.prototype.renderLine_ = function (color, x, y, width, context) {
|
||||||
|
if(color != Constants.TRANSPARENT_COLOR) {
|
||||||
|
context.fillStyle = color;
|
||||||
|
context.fillRect(x, y, 1, width);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ns.CanvasRenderer.prototype.createCanvas_ = function (zoom) {
|
ns.CanvasRenderer.prototype.createCanvas_ = function (zoom) {
|
||||||
zoom = zoom || 1;
|
zoom = zoom || 1;
|
||||||
var width = this.frame.getWidth() * zoom;
|
var width = this.frame.getWidth() * zoom;
|
||||||
|
@ -223,7 +223,12 @@
|
|||||||
for(var x = 0, width = frame.getWidth(); x < width; x++) {
|
for(var x = 0, width = frame.getWidth(); x < width; x++) {
|
||||||
for(var y = 0, height = frame.getHeight(); y < height; y++) {
|
for(var y = 0, height = frame.getHeight(); y < height; y++) {
|
||||||
var color = frame.getPixel(x, y);
|
var color = frame.getPixel(x, y);
|
||||||
this.renderPixel_(color, x, y, context);
|
var w = 1;
|
||||||
|
while (color === frame.getPixel(x, y+w)) {
|
||||||
|
w++;
|
||||||
|
}
|
||||||
|
this.renderLine_(color, x, y, w, context);
|
||||||
|
y = y + w - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,4 +269,11 @@
|
|||||||
context.fillRect(x, y, 1, 1);
|
context.fillRect(x, y, 1, 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.FrameRenderer.prototype.renderLine_ = function (color, x, y, width, context) {
|
||||||
|
if(color != Constants.TRANSPARENT_COLOR) {
|
||||||
|
context.fillStyle = color;
|
||||||
|
context.fillRect(x, y, 1, width);
|
||||||
|
}
|
||||||
|
};
|
||||||
})();
|
})();
|
Loading…
x
Reference in New Issue
Block a user