1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Restructure buildings

This commit is contained in:
tobspr
2020-09-24 12:53:40 +02:00
parent 0202387739
commit c54ec9fd2a
99 changed files with 2374 additions and 2449 deletions

View File

@@ -104,7 +104,7 @@
</struct>
</struct>
<key>shapePadding</key>
<uint>0</uint>
<uint>2</uint>
<key>jpgQuality</key>
<uint>80</uint>
<key>pngOptimizationLevel</key>
@@ -118,7 +118,7 @@
<key>textureFormat</key>
<enum type="SettingsBase::TextureFormat">png</enum>
<key>borderPadding</key>
<uint>1</uint>
<uint>3</uint>
<key>maxTextureSize</key>
<QSize>
<key>width</key>
@@ -197,7 +197,7 @@
<key>scaleMode</key>
<enum type="ScaleMode">Smooth</enum>
<key>extrude</key>
<uint>3</uint>
<uint>2</uint>
<key>trimThreshold</key>
<uint>2</uint>
<key>trimMargin</key>
@@ -260,35 +260,6 @@
<key type="filename">sprites/blueprints/balancer-merger-inverse.png</key>
<key type="filename">sprites/blueprints/balancer-merger.png</key>
<key type="filename">sprites/blueprints/balancer-splitter-inverse.png</key>
<key type="filename">sprites/blueprints/balancer-splitter.png</key>
<key type="filename">sprites/blueprints/constant_signal.png</key>
<key type="filename">sprites/blueprints/display.png</key>
<key type="filename">sprites/blueprints/lever.png</key>
<key type="filename">sprites/blueprints/logic_gate-not.png</key>
<key type="filename">sprites/blueprints/logic_gate-or.png</key>
<key type="filename">sprites/blueprints/logic_gate-transistor.png</key>
<key type="filename">sprites/blueprints/logic_gate-xor.png</key>
<key type="filename">sprites/blueprints/logic_gate.png</key>
<key type="filename">sprites/blueprints/miner-chainable.png</key>
<key type="filename">sprites/blueprints/miner.png</key>
<key type="filename">sprites/blueprints/reader.png</key>
<key type="filename">sprites/blueprints/rotater-ccw.png</key>
<key type="filename">sprites/blueprints/rotater-rotate180.png</key>
<key type="filename">sprites/blueprints/rotater.png</key>
<key type="filename">sprites/blueprints/trash.png</key>
<key type="filename">sprites/blueprints/underground_belt_entry-tier2.png</key>
<key type="filename">sprites/blueprints/underground_belt_entry.png</key>
<key type="filename">sprites/blueprints/underground_belt_exit-tier2.png</key>
<key type="filename">sprites/blueprints/underground_belt_exit.png</key>
<key type="filename">sprites/blueprints/virtual_processor-analyzer.png</key>
<key type="filename">sprites/blueprints/virtual_processor-painter.png</key>
<key type="filename">sprites/blueprints/virtual_processor-rotater.png</key>
<key type="filename">sprites/blueprints/virtual_processor-shapecompare.png</key>
<key type="filename">sprites/blueprints/virtual_processor-stacker.png</key>
<key type="filename">sprites/blueprints/virtual_processor-unstacker.png</key>
<key type="filename">sprites/blueprints/virtual_processor.png</key>
<key type="filename">sprites/blueprints/wire_tunnel-coating.png</key>
<key type="filename">sprites/blueprints/wire_tunnel.png</key>
<key type="filename">sprites/buildings/balancer-merger-inverse.png</key>
<key type="filename">sprites/buildings/balancer-merger.png</key>
<key type="filename">sprites/buildings/balancer-splitter-inverse.png</key>
@@ -298,13 +269,14 @@
<key type="filename">sprites/buildings/lever.png</key>
<key type="filename">sprites/buildings/logic_gate-not.png</key>
<key type="filename">sprites/buildings/logic_gate-or.png</key>
<key type="filename">sprites/buildings/logic_gate-transistor.png</key>
<key type="filename">sprites/buildings/logic_gate-xor.png</key>
<key type="filename">sprites/buildings/logic_gate.png</key>
<key type="filename">sprites/buildings/miner-chainable.png</key>
<key type="filename">sprites/buildings/reader.png</key>
<key type="filename">sprites/buildings/rotater-ccw.png</key>
<key type="filename">sprites/buildings/rotater-rotate180.png</key>
<key type="filename">sprites/buildings/transistor-mirrored.png</key>
<key type="filename">sprites/buildings/transistor.png</key>
<key type="filename">sprites/buildings/underground_belt_entry-tier2.png</key>
<key type="filename">sprites/buildings/underground_belt_entry.png</key>
<key type="filename">sprites/buildings/underground_belt_exit-tier2.png</key>
@@ -316,26 +288,25 @@
<key type="filename">sprites/buildings/virtual_processor-stacker.png</key>
<key type="filename">sprites/buildings/virtual_processor-unstacker.png</key>
<key type="filename">sprites/buildings/virtual_processor.png</key>
<key type="filename">sprites/buildings/wire_tunnel-coating.png</key>
<key type="filename">sprites/buildings/wire_tunnel.png</key>
<key type="filename">sprites/misc/reader_overlay.png</key>
<key type="filename">sprites/wires/lever_on.png</key>
<key type="filename">sprites/wires/sets/color_cross.png</key>
<key type="filename">sprites/wires/sets/color_forward.png</key>
<key type="filename">sprites/wires/sets/color_split.png</key>
<key type="filename">sprites/wires/sets/color_turn.png</key>
<key type="filename">sprites/wires/sets/conflict_cross.png</key>
<key type="filename">sprites/wires/sets/conflict_forward.png</key>
<key type="filename">sprites/wires/sets/conflict_split.png</key>
<key type="filename">sprites/wires/sets/conflict_turn.png</key>
<key type="filename">sprites/wires/sets/regular_cross.png</key>
<key type="filename">sprites/wires/sets/regular_forward.png</key>
<key type="filename">sprites/wires/sets/regular_split.png</key>
<key type="filename">sprites/wires/sets/regular_turn.png</key>
<key type="filename">sprites/wires/sets/shape_cross.png</key>
<key type="filename">sprites/wires/sets/shape_forward.png</key>
<key type="filename">sprites/wires/sets/shape_split.png</key>
<key type="filename">sprites/wires/sets/shape_turn.png</key>
<key type="filename">sprites/wires/sets/first_cross.png</key>
<key type="filename">sprites/wires/sets/first_forward.png</key>
<key type="filename">sprites/wires/sets/first_split.png</key>
<key type="filename">sprites/wires/sets/first_turn.png</key>
<key type="filename">sprites/wires/sets/second_cross.png</key>
<key type="filename">sprites/wires/sets/second_forward.png</key>
<key type="filename">sprites/wires/sets/second_split.png</key>
<key type="filename">sprites/wires/sets/second_turn.png</key>
<key type="filename">sprites/wires/sets/third_cross.png</key>
<key type="filename">sprites/wires/sets/third_forward.png</key>
<key type="filename">sprites/wires/sets/third_split.png</key>
<key type="filename">sprites/wires/sets/third_turn.png</key>
<struct type="IndividualSpriteSettings">
<key>pivotPoint</key>
<point_f>0.5,0.5</point_f>
@@ -350,13 +321,6 @@
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">sprites/blueprints/balancer.png</key>
<key type="filename">sprites/blueprints/cutter.png</key>
<key type="filename">sprites/blueprints/filter.png</key>
<key type="filename">sprites/blueprints/mixer.png</key>
<key type="filename">sprites/blueprints/painter-mirrored.png</key>
<key type="filename">sprites/blueprints/painter.png</key>
<key type="filename">sprites/blueprints/stacker.png</key>
<key type="filename">sprites/buildings/balancer.png</key>
<key type="filename">sprites/buildings/filter.png</key>
<key type="filename">sprites/buildings/painter-mirrored.png</key>
@@ -374,20 +338,9 @@
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">sprites/blueprints/belt_left.png</key>
<key type="filename">sprites/blueprints/belt_right.png</key>
<key type="filename">sprites/blueprints/belt_top.png</key>
<key type="filename">sprites/blueprints/wire-cross.png</key>
<key type="filename">sprites/blueprints/wire-split.png</key>
<key type="filename">sprites/blueprints/wire-turn.png</key>
<key type="filename">sprites/blueprints/wire.png</key>
<key type="filename">sprites/buildings/belt_left.png</key>
<key type="filename">sprites/buildings/belt_right.png</key>
<key type="filename">sprites/buildings/belt_top.png</key>
<key type="filename">sprites/buildings/wire-cross.png</key>
<key type="filename">sprites/buildings/wire-split.png</key>
<key type="filename">sprites/buildings/wire-turn.png</key>
<key type="filename">sprites/buildings/wire.png</key>
<struct type="IndividualSpriteSettings">
<key>pivotPoint</key>
<point_f>0.5,0.5</point_f>
@@ -402,8 +355,6 @@
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">sprites/blueprints/cutter-quad.png</key>
<key type="filename">sprites/blueprints/painter-quad.png</key>
<key type="filename">sprites/buildings/cutter-quad.png</key>
<key type="filename">sprites/buildings/painter-quad.png</key>
<struct type="IndividualSpriteSettings">
@@ -420,24 +371,6 @@
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">sprites/blueprints/painter-double.png</key>
<key type="filename">sprites/blueprints/storage.png</key>
<key type="filename">sprites/buildings/painter-double.png</key>
<key type="filename">sprites/buildings/storage.png</key>
<struct type="IndividualSpriteSettings">
<key>pivotPoint</key>
<point_f>0.5,0.5</point_f>
<key>spriteScale</key>
<double>1</double>
<key>scale9Enabled</key>
<false/>
<key>scale9Borders</key>
<rect>96,96,192,192</rect>
<key>scale9Paddings</key>
<rect>96,96,192,192</rect>
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">sprites/buildings/cutter.png</key>
<key type="filename">sprites/buildings/mixer.png</key>
<key type="filename">sprites/buildings/painter.png</key>
@@ -493,6 +426,22 @@
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">sprites/buildings/painter-double.png</key>
<key type="filename">sprites/buildings/storage.png</key>
<struct type="IndividualSpriteSettings">
<key>pivotPoint</key>
<point_f>0.5,0.5</point_f>
<key>spriteScale</key>
<double>1</double>
<key>scale9Enabled</key>
<false/>
<key>scale9Borders</key>
<rect>96,96,192,192</rect>
<key>scale9Paddings</key>
<rect>96,96,192,192</rect>
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">sprites/colors/blue.png</key>
<key type="filename">sprites/colors/cyan.png</key>
<key type="filename">sprites/colors/green.png</key>

View File

@@ -1,226 +1,213 @@
/**
*
* Run `yarn global add canvas` first
*/
const { createCanvas } = require("canvas");
const fs = require("fs");
const path = require("path");
const outputFolder = path.join(__dirname, "..", "wires", "sets");
const dimensions = 192;
const lineSize = 12;
const lowerLineSize = 20;
function hexToRGB(h) {
let r = 0,
g = 0,
b = 0;
// 3 digits
if (h.length == 4) {
r = "0x" + h[1] + h[1];
g = "0x" + h[2] + h[2];
b = "0x" + h[3] + h[3];
// 6 digits
} else if (h.length == 7) {
r = "0x" + h[1] + h[2];
g = "0x" + h[3] + h[4];
b = "0x" + h[5] + h[6];
}
return [+r, +g, +b];
}
function RGBToHSL(r, g, b) {
// Make r, g, and b fractions of 1
r /= 255;
g /= 255;
b /= 255;
// Find greatest and smallest channel values
let cmin = Math.min(r, g, b),
cmax = Math.max(r, g, b),
delta = cmax - cmin,
h = 0,
s = 0,
l = 0;
// Calculate hue
// No difference
if (delta == 0) h = 0;
// Red is max
else if (cmax == r) h = ((g - b) / delta) % 6;
// Green is max
else if (cmax == g) h = (b - r) / delta + 2;
// Blue is max
else h = (r - g) / delta + 4;
h = Math.round(h * 60);
// Make negative hues positive behind 360°
if (h < 0) h += 360;
// Calculate lightness
l = (cmax + cmin) / 2;
// Calculate saturation
s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
// Multiply l and s by 100
s = +(s * 100).toFixed(1);
l = +(l * 100).toFixed(1);
return [h, s, l];
}
function HSLToRGB(h, s, l) {
// Must be fractions of 1
s /= 100;
l /= 100;
let c = (1 - Math.abs(2 * l - 1)) * s,
x = c * (1 - Math.abs(((h / 60) % 2) - 1)),
m = l - c / 2,
r = 0,
g = 0,
b = 0;
if (0 <= h && h < 60) {
r = c;
g = x;
b = 0;
} else if (60 <= h && h < 120) {
r = x;
g = c;
b = 0;
} else if (120 <= h && h < 180) {
r = 0;
g = c;
b = x;
} else if (180 <= h && h < 240) {
r = 0;
g = x;
b = c;
} else if (240 <= h && h < 300) {
r = x;
g = 0;
b = c;
} else if (300 <= h && h < 360) {
r = c;
g = 0;
b = x;
}
r = Math.round((r + m) * 255);
g = Math.round((g + m) * 255);
b = Math.round((b + m) * 255);
return [r, g, b];
}
async function run() {
console.log("Running");
const variants = {
regular: "#25fff2",
color: "#eba458",
shape: "#8858eb",
conflict: "#ff3e3e",
};
const promises = [];
for (const variantId in variants) {
const variantColor = variants[variantId];
const variantHSL = RGBToHSL(...hexToRGB(variantColor));
const darkenedColor = HSLToRGB(variantHSL[0], variantHSL[1] - 15, variantHSL[2] - 20);
const hexDarkenedColor = "rgb(" + darkenedColor.join(",") + ")";
console.log(variantColor, "->", hexToRGB(variantColor), variantHSL, "->", darkenedColor);
const parts = {
forward: [[0.5, 0, 0.5, 1]],
turn: [
[0.5, 0.5, 0.5, 1],
[0.5, 0.5, 1, 0.5],
],
split: [
[0.5, 0.5, 0.5, 1],
[0, 0.5, 1, 0.5],
],
cross: [
[0, 0.5, 1, 0.5],
[0.5, 0, 0.5, 1],
],
};
for (const partId in parts) {
const partLines = parts[partId];
const canvas = createCanvas(dimensions, dimensions);
const context = canvas.getContext("2d");
context.quality = "best";
context.clearRect(0, 0, dimensions, dimensions);
context.strokeStyle = hexDarkenedColor;
context.lineWidth = lowerLineSize;
context.lineCap = "square";
context.imageSmoothingEnabled = false;
// Draw lower lines
partLines.forEach(([x1, y1, x2, y2]) => {
context.beginPath();
context.moveTo(x1 * dimensions, y1 * dimensions);
context.lineTo(x2 * dimensions, y2 * dimensions);
context.stroke();
});
context.strokeStyle = variantColor;
context.lineWidth = lineSize;
// Draw upper lines
partLines.forEach(([x1, y1, x2, y2]) => {
context.beginPath();
context.moveTo(x1 * dimensions, y1 * dimensions);
context.lineTo(x2 * dimensions, y2 * dimensions);
context.stroke();
});
const out = fs.createWriteStream(path.join(outputFolder, variantId + "_" + partId + ".png"));
const stream = canvas.createPNGStream();
stream.pipe(out);
promises.push(new Promise(resolve => stream.on("end", resolve)));
}
}
console.log("Waiting for completion");
await Promise.all(promises);
// Also wait a bit more
await new Promise(resolve => setTimeout(resolve, 1000));
console.log("Copying files to all locations");
// // Copy other files
fs.copyFileSync(
path.join(outputFolder, "regular_forward.png"),
path.join(__dirname, "..", "buildings", "wire.png")
);
fs.copyFileSync(
path.join(outputFolder, "regular_turn.png"),
path.join(__dirname, "..", "buildings", "wire-turn.png")
);
fs.copyFileSync(
path.join(outputFolder, "regular_split.png"),
path.join(__dirname, "..", "buildings", "wire-split.png")
);
fs.copyFileSync(
path.join(outputFolder, "regular_cross.png"),
path.join(__dirname, "..", "buildings", "wire-cross.png")
);
console.log("Done!");
}
run();
/**
*
* Run `yarn global add canvas` first
*/
const { createCanvas } = require("canvas");
const fs = require("fs");
const path = require("path");
const outputFolder = path.join(__dirname, "..", "wires", "sets");
const dimensions = 192;
const lineSize = 14;
const lowerLineSize = 32;
const variants = {
first: "#61ef6f",
second: "#f0bd65",
third: "#5fb2f1",
conflict: "#f74c4c",
};
function hexToRGB(h) {
let r = 0,
g = 0,
b = 0;
// 3 digits
if (h.length == 4) {
r = "0x" + h[1] + h[1];
g = "0x" + h[2] + h[2];
b = "0x" + h[3] + h[3];
// 6 digits
} else if (h.length == 7) {
r = "0x" + h[1] + h[2];
g = "0x" + h[3] + h[4];
b = "0x" + h[5] + h[6];
}
return [+r, +g, +b];
}
function RGBToHSL(r, g, b) {
// Make r, g, and b fractions of 1
r /= 255;
g /= 255;
b /= 255;
// Find greatest and smallest channel values
let cmin = Math.min(r, g, b),
cmax = Math.max(r, g, b),
delta = cmax - cmin,
h = 0,
s = 0,
l = 0;
// Calculate hue
// No difference
if (delta == 0) h = 0;
// Red is max
else if (cmax == r) h = ((g - b) / delta) % 6;
// Green is max
else if (cmax == g) h = (b - r) / delta + 2;
// Blue is max
else h = (r - g) / delta + 4;
h = Math.round(h * 60);
// Make negative hues positive behind 360°
if (h < 0) h += 360;
// Calculate lightness
l = (cmax + cmin) / 2;
// Calculate saturation
s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
// Multiply l and s by 100
s = +(s * 100).toFixed(1);
l = +(l * 100).toFixed(1);
return [h, s, l];
}
function HSLToRGB(h, s, l) {
// Must be fractions of 1
s /= 100;
l /= 100;
let c = (1 - Math.abs(2 * l - 1)) * s,
x = c * (1 - Math.abs(((h / 60) % 2) - 1)),
m = l - c / 2,
r = 0,
g = 0,
b = 0;
if (0 <= h && h < 60) {
r = c;
g = x;
b = 0;
} else if (60 <= h && h < 120) {
r = x;
g = c;
b = 0;
} else if (120 <= h && h < 180) {
r = 0;
g = c;
b = x;
} else if (180 <= h && h < 240) {
r = 0;
g = x;
b = c;
} else if (240 <= h && h < 300) {
r = x;
g = 0;
b = c;
} else if (300 <= h && h < 360) {
r = c;
g = 0;
b = x;
}
r = Math.round((r + m) * 255);
g = Math.round((g + m) * 255);
b = Math.round((b + m) * 255);
return [r, g, b];
}
async function run() {
console.log("Running");
const promises = [];
for (const variantId in variants) {
const variantColor = variants[variantId];
const variantHSL = RGBToHSL(...hexToRGB(variantColor));
const darkenedColor = HSLToRGB(variantHSL[0], variantHSL[1] - 15, variantHSL[2] - 20);
const hexDarkenedColor = "rgb(" + darkenedColor.join(",") + ")";
console.log(variantColor, "->", hexToRGB(variantColor), variantHSL, "->", darkenedColor);
const parts = {
forward: [[0.5, 0, 0.5, 1]],
turn: [
[0.5, 0.5, 0.5, 1],
[0.5, 0.5, 1, 0.5],
],
split: [
[0.5, 0.5, 0.5, 1],
[0, 0.5, 1, 0.5],
],
cross: [
[0, 0.5, 1, 0.5],
[0.5, 0, 0.5, 1],
],
};
for (const partId in parts) {
const partLines = parts[partId];
const canvas = createCanvas(dimensions, dimensions);
const context = canvas.getContext("2d");
context.quality = "best";
context.clearRect(0, 0, dimensions, dimensions);
const lineCanvas = createCanvas(dimensions, dimensions);
const lineContext = lineCanvas.getContext("2d");
lineContext.quality = "best";
lineContext.clearRect(0, 0, dimensions, dimensions);
lineContext.strokeStyle = hexDarkenedColor;
lineContext.lineWidth = lowerLineSize;
lineContext.lineCap = "square";
lineContext.imageSmoothingEnabled = false;
// Draw lower lines
partLines.forEach(([x1, y1, x2, y2]) => {
lineContext.beginPath();
lineContext.moveTo(x1 * dimensions, y1 * dimensions);
lineContext.lineTo(x2 * dimensions, y2 * dimensions);
lineContext.stroke();
});
context.globalAlpha = 0.4;
context.drawImage(lineCanvas, 0, 0, dimensions, dimensions);
context.globalAlpha = 1;
context.imageSmoothingEnabled = false;
context.lineCap = "square";
context.strokeStyle = variantColor;
context.lineWidth = lineSize;
// Draw upper lines
partLines.forEach(([x1, y1, x2, y2]) => {
context.beginPath();
context.moveTo(x1 * dimensions, y1 * dimensions);
context.lineTo(x2 * dimensions, y2 * dimensions);
context.stroke();
});
const out = fs.createWriteStream(path.join(outputFolder, variantId + "_" + partId + ".png"));
const stream = canvas.createPNGStream();
stream.pipe(out);
promises.push(new Promise(resolve => stream.on("end", resolve)));
}
}
console.log("Waiting for completion");
await Promise.all(promises);
console.log("Done!");
}
run();

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 957 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

View File

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 503 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 498 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -1,110 +1,92 @@
# Requirements: numpy, scipy, Pillow,
from __future__ import print_function
import sys
import numpy as np
from scipy import ndimage
from PIL import Image, ImageFilter, ImageChops
import math
from os import listdir
from os.path import isdir, isfile
roberts_cross_v = np.array([[0, 0, 0],
[0, 1, 0],
[0, 0, -1]])
roberts_cross_h = np.array([[0, 0, 0],
[0, 0, 1],
[0, -1, 0]])
def rgb2gray(rgb):
return np.dot(rgb[..., :3], [0.2989, 0.5870, 0.1140])
def save_image(data, outfilename, src_image):
img = Image.fromarray(np.asarray(
np.clip(data, 0, 255), dtype="uint8"), "L")
dest = Image.new("RGBA", (img.width, img.height))
src = img.load()
dst = dest.load()
realSrc = src_image.load()
mask = src_image.filter(ImageFilter.GaussianBlur(10)).load()
orig = src_image.load()
isWire = "wire" in outfilename
targetR = 104
targetG = 200
targetB = 255
if isWire:
targetR = 255
targetG = 104
targetB = 232
for x in range(img.width):
for y in range(img.height):
realpixl = realSrc[x, y]
greyval = float(src[x, y])
greyval = min(255.0, greyval)
greyval = math.pow(
min(1, float(greyval / 255.0 * 1)), 1.5) * 255.0 * 1
greyval = max(0, greyval)
alpha = mask[x, y][3] / 255.0 * 1
edgeFactor = src[x, y] / 255.0
noEdge = 1 - edgeFactor
shadow = min(1, 1 - realpixl[3] / 255.0 - edgeFactor)
noShadow = 1 - shadow
dst[x, y] = (
min(255, int((realpixl[0] / 255.0 * 0.4 + 0.6) * targetR * 1.1)),
min(255, int((realpixl[1] / 255.0 * 0.4 + 0.6) * targetG * 1.1)),
min(255, int((realpixl[2] / 255.0 * 0.4 + 0.6) * targetB * 1.1)),
min(255, int(float(realpixl[3]) * (0.6 + 5 * edgeFactor))))
dest.save(outfilename)
def roberts_cross(infilename, outfilename):
print("Processing", infilename)
img = Image.open(infilename)
img.load()
img = img.filter(ImageFilter.GaussianBlur(0.5))
image = rgb2gray(np.asarray(img, dtype="int32"))
vertical = ndimage.convolve(image, roberts_cross_v)
horizontal = ndimage.convolve(image, roberts_cross_h)
output_image = np.sqrt(np.square(horizontal) + np.square(vertical))
save_image(output_image, outfilename, img)
def generateUiPreview(srcPath, buildingId):
print(srcPath, buildingId)
img = Image.open(srcPath)
img.load()
img.thumbnail((110, 110), Image.ANTIALIAS)
img.save("../res/ui/hud/building_previews/" + buildingId + ".png")
img = img.convert("LA")
data = img.load()
for x in range(img.width):
for y in range(img.height):
data[x, y] = (data[x, y][0], int(data[x, y][1] * 0.5))
img.save("../res/ui/hud/building_previews/" + buildingId + "_disabled.png")
buildings = listdir("buildings")
for buildingId in buildings:
if "hub" in buildingId:
continue
roberts_cross("buildings/" + buildingId + "", "blueprints/" + buildingId + "")
# Requirements: numpy, scipy, Pillow,
from __future__ import print_function
import sys
import numpy as np
from scipy import ndimage
from PIL import Image, ImageFilter, ImageChops
import math
from os import listdir
from os.path import isdir, isfile
generate_blueprint_sprite_v = np.array([[0, 0, 0],
[0, 1, 0],
[0, 0, -1]])
generate_blueprint_sprite_h = np.array([[0, 0, 0],
[0, 0, 1],
[0, -1, 0]])
def rgb2gray(rgb):
return np.dot(rgb[..., :3], [0.2989, 0.5870, 0.1140])
def process_image(data, outfilename, src_image):
img = Image.fromarray(np.asarray(
np.clip(data, 0, 255), dtype="uint8"), "L")
dest = Image.new("RGBA", (img.width, img.height))
src = img.load()
dst = dest.load()
realSrc = src_image.load()
mask = src_image.filter(ImageFilter.GaussianBlur(10)).load()
orig = src_image.load()
# isWire = "wire" in outfilename
isWire = False
targetR = 104
targetG = 200
targetB = 255
if isWire:
targetR = 255
targetG = 104
targetB = 232
for x in range(img.width):
for y in range(img.height):
realpixl = realSrc[x, y]
greyval = float(src[x, y])
greyval = min(255.0, greyval)
greyval = math.pow(
min(1, float(greyval / 255.0 * 1)), 1.5) * 255.0 * 1
greyval = max(0, greyval)
alpha = mask[x, y][3] / 255.0 * 1
edgeFactor = src[x, y] / 255.0
noEdge = 1 - edgeFactor
shadow = min(1, 1 - realpixl[3] / 255.0 - edgeFactor)
noShadow = 1 - shadow
dst[x, y] = (
min(255, int((realpixl[0] / 255.0 * 0.4 + 0.6) * targetR * 1.1)),
min(255, int((realpixl[1] / 255.0 * 0.4 + 0.6) * targetG * 1.1)),
min(255, int((realpixl[2] / 255.0 * 0.4 + 0.6) * targetB * 1.1)),
min(255, int(float(realpixl[3]) * (0.6 + 5 * edgeFactor))))
dest.save(outfilename)
def generate_blueprint_sprite(infilename, outfilename):
print("Processing", infilename)
img = Image.open(infilename)
img.load()
img = img.filter(ImageFilter.GaussianBlur(0.5))
image = rgb2gray(np.asarray(img, dtype="int32"))
vertical = ndimage.convolve(image, generate_blueprint_sprite_v)
horizontal = ndimage.convolve(image, generate_blueprint_sprite_h)
output_image = np.sqrt(np.square(horizontal) + np.square(vertical))
process_image(output_image, outfilename, img)
buildings = listdir("buildings")
for buildingId in buildings:
if "hub" in buildingId:
continue
if "wire-" in buildingId:
continue
generate_blueprint_sprite("buildings/" + buildingId + "", "blueprints/" + buildingId + "")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 701 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 649 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 502 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 501 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 690 B

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 642 B

After

Width:  |  Height:  |  Size: 647 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 501 B

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 496 B

After

Width:  |  Height:  |  Size: 513 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 503 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 498 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 705 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 648 B

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 501 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 500 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 515 B