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.

  • 9
    \$\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\$ Jun 11 '15 at 12:21
  • \$\begingroup\$ Similar: codegolf.stackexchange.com/questions/39915/… \$\endgroup\$ 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\$ Jun 11 '15 at 18:37
  • \$\begingroup\$ @Calvin'sHobbies Is input allowed? \$\endgroup\$
    – user41805
    Oct 6 '15 at 17:46

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!!!!




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).

  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"')

  • \$\begingroup\$ Could this be shortened by using base64 encoding instead of hex? \$\endgroup\$
    – lirtosiast
    Jun 11 '15 at 3:34
  • 7
    \$\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\$ 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\$ 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

CJam, 119 bytes


Try it online!

I've chosen the shovel.

This program prints a PPM file to STDOUT.

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}
  • \$\begingroup\$ This is 129 bytes, not 119. \$\endgroup\$
    – Makonede
    May 27 at 20:12
  • \$\begingroup\$ @Makonede I don't think so? \$\endgroup\$ May 28 at 10:10
  • \$\begingroup\$ Well, TIO also claims Pyth uses an SBCS when in reality it does not. If CJam really does use an SBCS, could you link to it? \$\endgroup\$
    – Makonede
    May 28 at 16:00
  • \$\begingroup\$ CJam doesn't so much use an SBCS as allow any byte value in the program @Makonede. These are often shown in older CJam answers, such as this, using extended ASCII characters to avoid using unprintable characters. \$\endgroup\$ May 28 at 17:15

05AB1E, 113 97 bytes

-16 by using RLE (run-length encoding) for the color palette indices.

„P3žvD₅•P{¡æjž²+JGÀ‰íÔñ•Ƶ‡в3ô•N…ý~îc|\мﶄÄ^€¿^•5⦕RθŪ`<≠cλS²bÖ"₁Þ@„ÉI¬5øëY4ÀΘØ¥P@û h•29вÅΓ蘻»

Try it online! Beats all other answers. Outputs a plain PPM of a diamond hoe.

Note: The first » can be a ) (or a , ð, or õ) to output the image data separated by spaces: Try it online! However, in the official PPM Format Specification, under Plain PPM, it states:

  • No line should be longer than 70 characters.

It still renders properly, but is not recommended.

The first » can also be a ` with no change in functionality: Try it online!

Pure GIF compression, 109 107 bytes


Try it online! Outputs as a list of hexadecimal codepoints.

•...•h2ô  # trimmed program
•...•     # 121686424391392225557581524495943776461362082974476220323034665137613008241067075561955081975776948192923502794622971144661356950543760600319115998403445050769039958830830234731371315671091547736084642764295720991029129326629299863698388004372539...
     h    # in hexadecimal...
       ô  # split into pieces of length...
      2   # literal
          # implicit output

Node.JS using jimp, 393 377 376 bytes

377, 376 thanks to Makonede


I'm not sure if this one is allowed as it uses a separate library for processing the image.

Uses hex colors in decimal, sets i.s to i.setPixelColor to save bytes, sets color variables as it's first used

  • \$\begingroup\$ as long as the question does not disallow libraries, and the library is explicitly stated, it is fine. \$\endgroup\$
    – Razetime
    Mar 28 at 14:12
  • \$\begingroup\$ However, it is a good idea to tell us which tool you've made. \$\endgroup\$
    – Razetime
    Mar 28 at 14:12
  • \$\begingroup\$ -49 by removing some semicolons, using an empty file name, using s instead of i.s, and only assigning variables when first needed: new(require('jimp'))(16,16,1263684095,(e,i)=>{(s=i.setPixelColor)(x=673057791,2,12);s(x,4,14);s(d=871091199,13,3);for(j=0;j<8;j++){s(w=2305239039,3+j,13-j);s(x,2+j,13-j);s(x,3+j,14-j)}for(j=0;j<3;j++){s(e=239023871,11+j,2);s(e,14,3+j);s(e,8+j,5-j);s(d,9+j,5-j);s(d,10+j,5-j);s(d,10+j,6-j);s(d,11+j,6-j);s(d,11+j,7-j);s(e,11+j,8-j)}i.write('')}). \$\endgroup\$
    – Makonede
    Mar 29 at 22:15
  • \$\begingroup\$ @Makonede that's actually really clever assigning variables like that. however i tried using s instead of i.s and jimp threw an error for this being undefined. \$\endgroup\$
    – mekb
    Mar 30 at 6:27
  • \$\begingroup\$ actually it seems it's if it's s not i.s or if it's using the assignment in the use or both \$\endgroup\$
    – mekb
    Mar 30 at 6:54

Python 3, 483 bytes

I chose to make the sword

from PIL import Image as IG, ImageColor as IC
s.putdata([IC.getrgb(t[i:i+7]) for i in range(0,len(t),7)])

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.

  • \$\begingroup\$ You can save 5 bytes by replacing 's.png' with ''. It assumes that the system the program is being run on allows empty file names. This does not apply to any popular OS (AFAIK) but it's OK to make assumptions here. \$\endgroup\$
    – Makonede
    Mar 25 at 21:11
  • \$\begingroup\$ Actually, you can save 7 bytes by using s.save('.png'). The format argument isn't necessary if a corresponding extension is given, and s.save('.png') is 2 bytes shorter than s.save('','PNG'). \$\endgroup\$
    – Makonede
    Mar 26 at 17:07
  • \$\begingroup\$ You can save another 9 on top of that by changing Image as IG, ImageColor as IC to Image,ImageColor as c, changing IG to Image, changing IC to c, removing the space between (t[i:i+7]) and for, and replacing len(t) with 1792 (the guaranteed length of t). \$\endgroup\$
    – Makonede
    Mar 26 at 17:15
  • \$\begingroup\$ And yet another 18 saved by 1. fixing some inefficiencies in the definition of t (for example, b+b*9 -> b*10), 2. making t a tuple instead of a string, 3. not using a variable (this method uses t only once) and 4. using all that to allow for a much shorter putdata method: s.putdata(map(c.getrgb,[*[b]*13,a,a,a,*[b]*12,a,d,d,a,*[b]*11,a,d,d,d,a,*[*[b]*10,a,d,d,d,a]*2,*[b]*5,a,a,b,b,b,a,d,d,d,a,*[b]*6,a,d,a,b,a,d,d,d,a,*[b]*8,a,d,a,d,d,d,a,*[b]*9,a,d,a,d,d,a,*[b]*11,a,d,a,a,*[b]*11,n,w,a,d,d,a,*[b]*9,n,w,n,b,a,a,d,a,*[b]*6,a,a,w,n,*[b]*4,a,a,*[b]*6,a,d,a,*[b]*13,a,a,a,*[b]*13])). \$\endgroup\$
    – Makonede
    Mar 26 at 17:30
  • \$\begingroup\$ (continued from previous comment because of length limitations) A total of 34 bytes saved! \$\endgroup\$
    – Makonede
    Mar 26 at 17:30

GIF, 102 bytes


00000000: 4749 4638 3961 1000 1000 7000 002c 0000  GIF89a....p..,..
00000010: 0000 1000 1000 824b 5249 0e3f 3633 ebcb  .......KRI.?63..
00000020: 281e 0b89 6727 0000 0000 0000 0000 0003  (...g'..........
00000030: 3308 babc f12d 8220 4490 8cd6 8b67 b59d  3....-. D....g..
00000040: b785 1a98 71a2 9981 25da 506d 078f a4e5  ....q...%.Pm....
00000050: 4a03 a1dd 4c3e 4cb0 c883 f073 f082 21c5  J...L>L....s..!.
00000060: 8327 4900 003b                           .'I..;

Renders as:

Diamond Sword


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.

  • 3
    \$\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
  • 5
    \$\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\$ Sep 22 '15 at 22:06
  • 3
    \$\begingroup\$ I'm not sure if this is valid because if I change the texture back for my game and run this command from a command block. it will not display the correct image. Also -2 bytes by getting rid of the 0s in ~0; ~ behaves identically to ~0. \$\endgroup\$
    – hyper-neutrino
    Mar 19 '18 at 12:10

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.