Improved draw.js.

This commit is contained in:
sk89q 2011-01-30 22:04:36 -08:00
parent c6537a783d
commit ee9b50264e

View File

@ -74,13 +74,16 @@ function findClosestWoolColor(col) {
return closestId; return closestId;
} }
var sess = context.remember();
context.checkArgs(1, 2, "<image> <orientation>"); context.checkArgs(1, 2, "<image> <orientation>");
var f = context.getSafeFile("drawings", argv[1]); var f = context.getSafeFile("drawings", argv[1]);
var sess = context.remember();
var upright = argv[2] == "v";
if (f != null) { if (!f.exists()) {
player.error("Specified file doesn't exist.");
} else {
var img = ImageIO.read(f); var img = ImageIO.read(f);
var width = img.getWidth(); var width = img.getWidth();
@ -92,12 +95,12 @@ if (f != null) {
for (var y = 0; y < height; y++) { for (var y = 0; y < height; y++) {
var c = new Color(img.getRGB(x, y)); var c = new Color(img.getRGB(x, y));
var data = findClosestWoolColor(c); var data = findClosestWoolColor(c);
//added this to enable the user to create images stood up rather than flat on the ground // Added this to enable the user to create images upright
if(argv[2]=="h"){ // rather than flat on the ground
sess.setBlock(origin.add(x, 0, y), new BaseBlock(35, data)); if (!upright) {
} sess.setBlock(origin.add(x, 0, y), new BaseBlock(35, data));
if(argv[2]=="v"){ } else {
sess.setBlock(origin.add(x, height-y, 0), new BaseBlock(35, data)); sess.setBlock(origin.add(x, height - y, 0), new BaseBlock(35, data));
} }
} }
} }