Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update colors.txt
  • Loading branch information
sfan5 committed Jun 6, 2017
1 parent 4f7d2a5 commit 25d1d43
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 50 deletions.
80 changes: 38 additions & 42 deletions autogenerating-colors.txt
@@ -1,11 +1,14 @@
==FILE== mods/dumpnodes/init.lua
local function nd_get_tiles(nd)
if nd.tiles then
return nd.tiles
elseif nd.tile_images then
return nd.tile_images
return nd.tiles or nd.tile_images
end

local function nd_get_tile(nd, n)
local tile = nd_get_tiles(nd)[n]
if type(tile) == 'table' then
tile = tile.name
end
return nil
return tile
end

local function pairs_s(dict)
Expand All @@ -20,40 +23,37 @@ end
minetest.register_chatcommand("dumpnodes", {
params = "",
description = "",
func = function(plname, param)
func = function(player, param)
local n = 0
local ntbl = {}
for _, nn in pairs_s(minetest.registered_nodes) do
local nd = minetest.registered_nodes[nn]
local prefix, name = nn:match('(.*):(.*)')
if prefix == nil or name == nil or prefix == '' or name == '' then
if prefix == nil or name == nil then
print("ignored(1): " .. nn)
else
if ntbl[prefix] == nil then
ntbl[prefix] = {}
end
ntbl[prefix][name] = nd
ntbl[prefix][name] = true
end
end
local out, err = io.open('nodes.txt', 'wb')
if not out then
return true, "io.open(): " .. err
end
for _, prefix in pairs_s(ntbl) do
local nodes = ntbl[prefix]
out:write('# ' .. prefix .. '\n')
for _, name in pairs_s(nodes) do
local nd = nodes[name]
if nd.drawtype ~= 'airlike' and nd_get_tiles(nd) ~= nil then
local tl = nd_get_tiles(nd)[1]
if type(tl) == 'table' then
tl = tl.name
end
tl = (tl .. '^'):match('(.-)^')
out:write(prefix .. ':' .. name .. ' ' .. tl .. '\n')
n = n + 1
for _, name in pairs_s(ntbl[prefix]) do
local nn = prefix .. ":" .. name
local nd = minetest.registered_nodes[nn]
if nd.drawtype == 'airlike' or nd_get_tiles(nd) == nil then
print("ignored(2): " .. nn)
else
print("ignored(2): " .. prefix .. ':' .. name)
local tl = nd_get_tile(nd, 1)
tl = (tl .. '^'):match('(.-)^') -- strip modifiers
out:write(nn .. ' ' .. tl .. '\n')
n = n + 1
end
end
out:write('\n')
Expand All @@ -67,56 +67,52 @@ minetest.register_chatcommand("dumpnodes", {
import sys
from PIL import Image

def tsum(a, b):
def tadd(a, b):
return tuple(sum(e) for e in zip(a, b))

if len(sys.argv) < 2:
print("Prints average color (RGB) of input image")
print("Usage: %s <input>" % sys.argv[0])
exit(1)

inp = Image.open(sys.argv[1])
inp = inp.convert('RGBA')
inp = Image.open(sys.argv[1]).convert('RGBA')
ind = inp.load()

cl = (0, 0, 0)
counted = 0
for x in range(inp.size[0]):
for y in range(inp.size[1]):
px = ind[x, y]
if px[3] < 128:
continue
cl = tsum(cl, px[:3])
counted = counted + 1
if px[3] < 128: continue # alpha
cl = tadd(cl, px[:3])
counted += 1

if counted == 0:
sys.stderr.write("didn't find avg. color for %s\n" % sys.argv[1])
sys.stderr.write("did not find avg color for %s\n" % sys.argv[1])
print("0 0 0")
exit(0)

cl = tuple(int(n / counted) for n in cl)
print("%d %d %d" % cl)
else:
cl = tuple(int(n / counted) for n in cl)
print("%d %d %d" % cl)
==SCRIPT==
#!/bin/bash -e

AVGCOLOR_PATH=/path/to/avgcolor.py
MTGAME_PATH=/path/to/minetest_game
GAME_PATH=/path/to/minetest_game
MODS_PATH= # path to "mods" folder, only set if you have loaded mods
NODESTXT_PATH=./nodes.txt
COLORSTXT_PATH=./colors.txt

while read -r line; do
set -- junk $line
shift
set -- junk $line; shift
if [[ -z "$1" || $1 == "#" ]]; then
echo $line
continue
echo "$line"; continue
fi
tex=$(find $MTGAME_PATH -type f -name "$2")
tex=$(find $GAME_PATH -type f -name "$2")
[[ -z "$tex" && -n "$MODS_PATH" ]] && tex=$(find $MODS_PATH -type f -name "$2")
if [ -z "$tex" ]; then
echo "skip $1: texture not found" >&2
continue
fi
echo $1 $(python $AVGCOLOR_PATH "$tex")
echo "$1" $(python $AVGCOLOR_PATH "$tex")
echo "ok $1" >&2
done < $NODESTXT_PATH > $COLORSTXT_PATH
# Use nicer colors for water and lava:
Expand All @@ -128,8 +124,8 @@ sed -re 's/^doors:(.*glass[^ ]*) ([0-9 ]+)$/doors:\1 \2 64 16/g' $COLORSTXT_PATH
# Fix xpanes color:
sed -re 's/^xpanes:((pane|bar)(_flat)?) [0-9 ]+$/xpanes:\1 194 194 227 64 16/g' $COLORSTXT_PATH -i
==INSTRUCTIONS==
1) Make sure avgcolors.py outputs the usage instructions
1) Make sure avgcolors.py works (outputs the usage instructions when run)
2) Add the dumpnodes mod to Minetest
3) Create a world and load dumpnodes & all mods you want to generate colors for
4) Execute /dumpnodes ingame
5) Run the script to generate colors.txt (make sure to replace /path/to/... with the actual paths)
5) Run the script to generate colors.txt (make sure to adjust the PATH variables at the top)
42 changes: 34 additions & 8 deletions colors.txt
Expand Up @@ -14,24 +14,28 @@ carts:rail 143 123 90

# default
default:acacia_bush_leaves 90 124 55
default:acacia_bush_sapling 85 118 58
default:acacia_bush_stem 84 76 69
default:acacia_leaves 108 147 67
default:acacia_sapling 87 116 61
default:acacia_tree 188 109 90
default:acacia_wood 146 60 37
default:apple 145 20 9
default:aspen_leaves 66 89 38
default:aspen_leaves 70 104 27
default:aspen_sapling 82 110 43
default:aspen_tree 218 197 166
default:aspen_wood 209 198 169
default:bookshelf 128 99 55
default:brick 117 71 69
default:bronzeblock 185 110 15
default:bush_leaves 34 52 29
default:bush_sapling 65 60 40
default:bush_stem 45 33 23
default:cactus 52 116 15
default:chest 140 108 65
default:chest_locked 140 108 65
default:chest_locked_open 140 108 65
default:chest_open 140 108 65
default:clay 182 182 182
default:cloud 255 255 255
default:coalblock 57 57 57
Expand All @@ -42,6 +46,9 @@ default:coral_orange 191 62 12
default:coral_skeleton 235 230 214
default:desert_cobble 146 95 76
default:desert_sand 206 165 98
default:desert_sandstone 195 152 92
default:desert_sandstone_block 192 151 94
default:desert_sandstone_brick 191 151 94
default:desert_stone 129 79 60
default:desert_stone_block 130 79 60
default:desert_stonebrick 129 79 60
Expand All @@ -50,7 +57,8 @@ default:dirt 95 64 39
default:dirt_with_dry_grass 187 148 77
default:dirt_with_grass 66 112 31
default:dirt_with_grass_footsteps 66 112 31
default:dirt_with_snow 223 224 236
default:dirt_with_rainforest_litter 74 38 8
default:dirt_with_snow 224 225 238
default:dry_grass_1 208 172 87
default:dry_grass_2 210 174 87
default:dry_grass_3 210 174 87
Expand Down Expand Up @@ -84,6 +92,7 @@ default:lava_flowing 255 100 0
default:lava_source 255 100 0
default:leaves 34 52 29
default:mese 220 220 0
default:mese_post_light 131 102 57
default:meselamp 211 213 139
default:mossycobble 86 90 68
default:obsidian 19 21 24
Expand All @@ -105,8 +114,11 @@ default:sapling 65 59 40
default:sign_wall_steel 144 144 144
default:sign_wall_wood 145 101 64
default:silver_sand 193 191 179
default:snow 223 224 236
default:snowblock 223 224 236
default:silver_sandstone 195 192 181
default:silver_sandstone_block 192 190 179
default:silver_sandstone_brick 190 188 178
default:snow 224 225 238
default:snowblock 224 225 238
default:steelblock 194 194 194
default:stone 97 94 93
default:stone_block 99 96 95
Expand All @@ -116,7 +128,9 @@ default:stone_with_diamond 97 94 93
default:stone_with_gold 97 94 93
default:stone_with_iron 97 94 93
default:stone_with_mese 97 94 93
default:stone_with_tin 97 94 93
default:stonebrick 99 96 95
default:tinblock 149 149 149
default:torch 120 98 67
default:torch_ceiling 120 98 67
default:torch_wall 120 98 67
Expand Down Expand Up @@ -190,10 +204,6 @@ flowers:tulip 130 99 36
flowers:viola 106 60 159
flowers:waterlily 102 158 61

# nyancat
nyancat:nyancat 198 111 167
nyancat:nyancat_rainbow 123 100 94

# stairs
stairs:slab_acacia_wood 146 60 37
stairs:slab_aspen_wood 209 198 169
Expand All @@ -202,10 +212,14 @@ stairs:slab_bronzeblock 185 110 15
stairs:slab_cobble 88 84 82
stairs:slab_copperblock 192 126 63
stairs:slab_desert_cobble 146 95 76
stairs:slab_desert_sandstone 195 152 92
stairs:slab_desert_sandstone_block 192 151 94
stairs:slab_desert_sandstone_brick 191 151 94
stairs:slab_desert_stone 129 79 60
stairs:slab_desert_stone_block 130 79 60
stairs:slab_desert_stonebrick 129 79 60
stairs:slab_goldblock 230 201 29
stairs:slab_ice 167 206 247
stairs:slab_junglewood 54 37 11
stairs:slab_mossycobble 86 90 68
stairs:slab_obsidian 19 21 24
Expand All @@ -215,6 +229,10 @@ stairs:slab_pine_wood 221 184 128
stairs:slab_sandstone 197 193 143
stairs:slab_sandstone_block 195 190 141
stairs:slab_sandstonebrick 193 189 140
stairs:slab_silver_sandstone 195 192 181
stairs:slab_silver_sandstone_block 192 190 179
stairs:slab_silver_sandstone_brick 190 188 178
stairs:slab_snowblock 224 225 238
stairs:slab_steelblock 194 194 194
stairs:slab_stone 97 94 93
stairs:slab_stone_block 99 96 95
Expand All @@ -228,10 +246,14 @@ stairs:stair_bronzeblock 185 110 15
stairs:stair_cobble 88 84 82
stairs:stair_copperblock 192 126 63
stairs:stair_desert_cobble 146 95 76
stairs:stair_desert_sandstone 195 152 92
stairs:stair_desert_sandstone_block 192 151 94
stairs:stair_desert_sandstone_brick 191 151 94
stairs:stair_desert_stone 129 79 60
stairs:stair_desert_stone_block 130 79 60
stairs:stair_desert_stonebrick 129 79 60
stairs:stair_goldblock 230 201 29
stairs:stair_ice 167 206 247
stairs:stair_junglewood 54 37 11
stairs:stair_mossycobble 86 90 68
stairs:stair_obsidian 19 21 24
Expand All @@ -241,6 +263,10 @@ stairs:stair_pine_wood 221 184 128
stairs:stair_sandstone 197 193 143
stairs:stair_sandstone_block 195 190 141
stairs:stair_sandstonebrick 193 189 140
stairs:stair_silver_sandstone 195 192 181
stairs:stair_silver_sandstone_block 192 190 179
stairs:stair_silver_sandstone_brick 190 188 178
stairs:stair_snowblock 224 225 238
stairs:stair_steelblock 194 194 194
stairs:stair_stone 97 94 93
stairs:stair_stone_block 99 96 95
Expand Down

0 comments on commit 25d1d43

Please sign in to comment.