20
\$\begingroup\$

In Minecraft, the default item textures are all reasonably simple 16×16 pixel images, which makes them seem ideal for golfing.

Below are simplified textures of the five "core" diamond tools in Minecraft: pickaxe, shovel, axe, sword, and hoe.

The images shown are enlarged to show their detail. Click on an image to view its correctly sized 16×16 pixel version.

pickaxe shovel axe sword hoe

To make golfing easier, I've modified each of them from the originals to only use the five same 24-bit RGB colors:

  • R=75 G=82 B=73 for the background.
  • R=51 G=235 B=203 for the diamond tool heads.
  • R=14 G=63 B=54 for the diamond outlines.
  • R=137 G=103 B=39 for the wooden handle core.
  • R=40 G=30 B=11 for the wooden handle outlines.

Choose your favorite tool out of the five and write a program that outputs its simplified 16×16 pixel texture in any common lossless truecolor image format (such as bpm, png, ppm, etc.).

So, for example, if you chose the axe, you would write a program that outputs this image: axe example

No input should be taken and a web connection should not be required. The image can be output as a file with the name of your choice, or the raw image file data can be output to stdout, or you can simply display the image.

You only need to choose one of the five images. The program that outputs any one of the five images in the fewest number of bytes is the winner.

You may write programs for more than one of the images, but only the one with the minimum number of bytes counts towards your score. If there's a tie, the highest voted post wins.


If you enjoy PPCG and play Minecraft, I invite you to come join our trial Minecraft server. Just ask in the dedicated chatroom.

\$\endgroup\$
  • 5
    \$\begingroup\$ "Enlarged to show detail." I can only think of cereal boxes. \$\endgroup\$ – Alex A. Jun 11 '15 at 4:17
  • \$\begingroup\$ I think there may be some compression issues or you have some typos in the colours. Mathematica claims, these five colours are used (at least for the shovel): [[76 82 73] [26 63 54] [106 234 204] [39 30 13] [133 102 45]] \$\endgroup\$ – Martin Ender Jun 11 '15 at 12:21
  • \$\begingroup\$ Similar: codegolf.stackexchange.com/questions/39915/… \$\endgroup\$ – NinjaBearMonkey Jun 11 '15 at 16:48
  • \$\begingroup\$ @MartinBüttner Are you sure? I re-downloaded the shovel image and made sure that the 5 colors are correct. I also made sure there were exactly 5 colors. imgur may be compressing the enlarged images but those are not the ones you should be using. \$\endgroup\$ – Calvin's Hobbies Jun 11 '15 at 18:37
  • \$\begingroup\$ @Calvin'sHobbies Is input allowed? \$\endgroup\$ – Kritixi Lithos Oct 6 '15 at 17:46
6
\$\begingroup\$

CJam, 119 bytes

I've chosen the shovel.

'P3NGSGN255N]o67T"vîþáy$<OW¥ÓNZ"256b9b~99T]2/e~W%"LRI?6jêÌ'
f-":i3/f=F,_W%:)+{)/(\:~}%{G/({)S*S+oNo}%1>\:~+}G*

Test it here.

This program prints a PPM file to STDOUT.

I used this script to help with encoding the image. (This is mostly for myself if I need to reuse it later.)

The basic idea is to unroll the image along antidiagonals and then use run-length encoding. With this technique, the shovel contains the fewest runs. For reference the number of runs per image (in the order given in the challenge) is:

{60, 26, 38, 43, 37}

I'll add more explanation when I'm done golfing this.

\$\endgroup\$
7
\$\begingroup\$

JavaScript ES6, 353 bytes

document.write(`<p style="width:1px;height:1px;box-shadow:${'931a31b31841940a40b40c41951a51b50c50d51e53f52b61c60d60e62f63c73d70e70f71b83c82d83e81a93b92c939a3aa2ba38b39b2ab37c38c29c36d37d28d35e36e27e34f35f26f34g35g3'.replace(/.../g,e=>(p=parseInt)(e[0],17)+`px ${p(e[1],17)}px 0 #${['33EBCB','0E3F36','896727','281E0B'][e[2]]},`)}9px 9px 0 8px #4B5249"`)

This heavily abuses CSS3 box-shadows to create a pixelized version of the image, in this case the Minecraft hoe. The Stack Snippet below uses ES5 for easy testing and is somewhat ungolfed (You'll have to zoom in to see it well).

s='931a31b31841940a40b40c41951a51b50c50d51e53f52b61c60d60e62f63c73d70e70f71b83c82d83e81a93b92c939a3aa2ba38b39b2ab37c38c29c36d37d28d35e36e27e34f35f26f34g35g3'.replace(/.../g,function(e){
  return parseInt(e[0],17)+'px '+parseInt(e[1],17)+'px 0 #'+['33EBCB','0E3F36','896727','281E0B'][e[2]]+','
})
document.write('<p style="width:1px;height:1px;box-shadow:'+s+'9px 9px 0 8px #4B5249"')

\$\endgroup\$
  • \$\begingroup\$ Could this be shortened by using base64 encoding instead of hex? \$\endgroup\$ – lirtosiast Jun 11 '15 at 3:34
  • 6
    \$\begingroup\$ The largest source image is 297 bytes. Kinda sad to be over that :) \$\endgroup\$ – J B Jun 11 '15 at 7:40
  • \$\begingroup\$ @JB It's [kolmogorov-complexity] for a reason ;) \$\endgroup\$ – NinjaBearMonkey Jun 11 '15 at 16:45
  • \$\begingroup\$ @ThomasKwa Doesn't base64 actually make it longer? (It's actually base-17 because there's gs near the end.) \$\endgroup\$ – NinjaBearMonkey Jun 11 '15 at 16:46
  • \$\begingroup\$ I don't know how expensive interpreting base64 encoding is in Javascript, but the string literal itself should be 2/3rds the size in base64 as in hex. \$\endgroup\$ – lirtosiast Jun 11 '15 at 16:51
2
\$\begingroup\$

Since this is a minecraft problem, I will do a command block solution: 50 characters

summon ItemFrame ~1 ~0 ~0 {Item:{id:diamond_axe}}

creates an item frame showing an axe.

\$\endgroup\$
  • 2
    \$\begingroup\$ You need to output an image. \$\endgroup\$ – Deusovi Sep 8 '15 at 1:23
  • 1
    \$\begingroup\$ The image is outputted on screen as part of the game. \$\endgroup\$ – Lucas Sep 12 '15 at 4:24
  • 1
    \$\begingroup\$ Because of perspective, it will never be a perfect image - it's supposed to be pixelart too, only 16x16. \$\endgroup\$ – Deusovi Sep 12 '15 at 5:11
  • 3
    \$\begingroup\$ I think this qualifies as a standard loophole - same as getting the image from an external source. I think it would have been alright to summon blocks to act as the pixels, with the colors as close as possible. \$\endgroup\$ – Calvin's Hobbies Sep 22 '15 at 22:06
  • 1
    \$\begingroup\$ I count this as a language feature. \$\endgroup\$ – Lucas Sep 25 '15 at 20:40
1
\$\begingroup\$

Python 3, 483 bytes

I chose to make the sword

from PIL import Image as IG, ImageColor as IC
s=IG.new('RGB',(16,16))
w='#6b6727'
b='#4b5249'
d='#33ebcb'
a='#0e3f36'
n='#281e0b'
t=b*13+a*3+b*12+a+d*2+a+b*11+a+d*3+a+b*10+a+d*3+a+b+b*9+a+d*3+a+b*2+b*8+a+d*3+a+b*3+b*2+a*2+b*3+a+d*3+a+b*4+b*2+a+d+a+b+a+d*3+a+b*5+b*3+a+d+a+d*3+a+b*6+b*3+a+d+a+d*2+a+b*7+b*4+a+d+a*2+b*8+b*3+n+w+a+d*2+a+b*7+b*2+n+w+n+b+a*2+d+a+b*6+a*2+w+n+b*4+a*2+b*6+a+d+a+b*13+a*3+b*13
s.putdata([IC.getrgb(t[i:i+7]) for i in range(0,len(t),7)])
s.save('s.png','PNG')

here is the output: enter image description here

I created a string for each color, and combined them to get a string of hexadecimal numbers. Then I used the python image library to convert that string into an image.

\$\endgroup\$
1
\$\begingroup\$

Minecraft 18w11a (.mcfunction), 757 bytes

fill ~ ~ ~ ~15 ~ ~15 ice
fill ~13 ~ ~13 ~7 ~ ~11 cyan_wool
fill ~12 ~ ~14 ~10 ~ ~8 cyan_wool
fill ~12 ~ ~13 ~10 ~ ~11 diamond_block
fill ~11 ~ ~12 ~9 ~ ~10 diamond_block
fill ~10 ~ ~11 ~8 ~ ~9 diamond_block
fill ~3 ~ ~4 ~1 ~ ~2 dirt
setblock ~3 ~ ~4 oak_planks
setblock ~2 ~ ~3 oak_planks
clone ~3 ~ ~4 ~1 ~ ~2 ~4 ~ ~5
setblock ~4 ~ ~5 oak_planks
setblock ~4 ~ ~7 ice
setblock ~6 ~ ~5 ice
clone ~6 ~ ~5 ~4 ~ ~7 ~7 ~ ~8
setblock ~9 ~ ~10 diamond_block
setblock ~4 ~ ~4 dirt
setblock ~3 ~ ~5 dirt
setblock ~7 ~ ~7 dirt
setblock ~6 ~ ~8 dirt
setblock ~1 ~ ~2 ice
fill ~12 ~ ~9 ~12 ~ ~8 ice
setblock ~11 ~ ~8 ice
fill ~8 ~ ~13 ~7 ~ ~13 ice
setblock ~7 ~ ~12 ice
fill ~ ~ ~ ~15 ~ ~15 light_gray_concrete replace ice
fill ~ ~ ~ ~9 ~ ~10 dark_oak_bark replace dirt

Of course someone had to answer the question with Minecraft. Place answer inside of a datapack, and run with /function <packname>:<filename>. The shovel is drawn relative to you in the +X and +Z direction. Colors are wrong but I'll count that as a language limitation ;)

But the shovel is actually made out of wood and diamonds!!!!

Output

Shoveled

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.