Winter Bash 2014 is on its prime and don't we all love the hats? Especially the secret hats!

So why not draw one of secret hats?

The challenge

Your task is to draw the Warm Welcome Hat in proportion, in a language of your choice and having an exact construction as appearing on this page.

As always, you can render the hat to a file or screen using vector or raster graphics. If your output is rasterised, your image must have dimensions of 400x400 pixels or more.

Moreover, the actual contents of the hat (the area of the bounding rectangle of the colored parts of the image) should cover more than 40% of your output image.


The image below lists out various dimensions of the hat. All dimensions are in the unit, for example, pixels. All border radius in the image are to be drawn with a radius of 13 units.

enter image description here


  • Red in the star and circular ring - rgb(255, 28, 34)
  • Yellow in the circle - rgb(255, 202, 87)
  • Lightest grey - rgb(88, 88, 92)
  • Darkest grey - rgb(31, 26, 26)
  • Middle grey - rgb(64, 64, 64)


This is code golf, so the shortest answer (in bytes) wins.

As a word of warning, using existing compression (like embedding a compressed GIF) falls into several standard loopholes.

  • \$\begingroup\$ About the suggested edit: I chose to reject. I see the image displaying correctly as it is. \$\endgroup\$
    – mbomb007
    Nov 19 '17 at 4:47

GolfScript (376 373 364 350 or 645 610 607 bytes)

Following the original specification, which called for the exact construction of the SVG, a golfed SVG is generated in 607 bytes.

Code contains lots of non-printing characters, so here's the xxd output:

0000000: 221a c837 cde6 0c0c 4658 5786 cead ca66  "..7....FXW....f
0000010: 3507 d130 1577 4657 4067 df6b 97e7 510f  5..0.wFW@g.k..Q.
0000020: cbb0 e3e5 77c6 a91d d830 fa92 eea0 d447  ....w....0.....G
0000030: 7721 cc59 3f4c 230b e0bb fd3e ecf3 d4f7  w!.Y?L#....>....
0000040: 2c6b abd5 b1e5 939d 68b4 e89e 39ca a259  ,k......h...9..Y
0000050: b934 ef6f 203a 7abf 1a2c b468 3351 4c53  .4.o :z..,.h3QLS
0000060: c056 9a59 f38c a97e cf82 8840 ee7c 43e4  .V.Y...~...@.|C.
0000070: 123f df1a 00d4 542d a29c 0195 3ad5 4af4  .?....T-....:.J.
0000080: c644 57c7 0b6b 4d4f 908b 8cf7 c8e2 536d  .DW..kMO......Sm
0000090: 9d36 1139 1406 5c5c dcbc 3a11 1993 63a6  .6.9..\\..:...c.
00000a0: 4f8b 7b62 de77 5158 a485 dec1 87b4 1d11  O.{b.wQX........
00000b0: 01b1 e49d 8adb 0b29 ad44 93e4 7bbd 027e  .......).D..{..~
00000c0: 7a6f 60ca 99f4 6ab3 7bc0 63c3 ba70 1220  zo`...j.{.c..p. 
00000d0: 1aea 9206 da5a 95ce 6f70 67f8 856e 8807  .....Z..opg..n..
00000e0: adec e533 0c1e 3dc6 96e5 54d4 2837 4497  ...3..=...T.(7D.
00000f0: f5ea 2135 d261 9c02 fa61 c12a 7180 085a  ..!5.a...a.*q..Z
0000100: a5b8 e3d6 68cb 0659 f4ad d01d 5fc4 9e5b  ....h..Y...._..[
0000110: d030 46d5 96c4 439f da99 2cb1 52b9 5d53  .0F...C...,.R.]S
0000120: 098e 7598 2785 a962 a40d edbd 18cb e46c  ..u.'..b.......l
0000130: 6edb ba9f 17be 36ab ef23 0caf 3ce8 352d  n.....6..#..<.5-
0000140: fad5 762b a388 ca17 413f 7dac 6dd1 116e  ..v+....A?}.m..n
0000150: b2e8 9cd1 d00a dda1 716d a148 acc7 8749  ........qm.H...I
0000160: f2c3 a7a9 8128 02e9 d83c f350 7a02 74ec  .....(...<.Pz.t.
0000170: 6270 6089 a16d 7bfa b6dd e56a 366a d85b  bp`..m{....j6j.[
0000180: 33e5 b777 05c1 6f4e f06b ca95 3ffc 49f7  3..w..oN.k..?.I.
0000190: 1a08 6bc5 abb0 c745 e439 b87e b81c 52c8  ..k....E.9.~..R.
00001a0: a445 935e 5c5c 00d3 34de c002 721c b69d  .E.^\\..4...r...
00001b0: 16ee aab0 9562 4d44 44ed 0193 13a7 eed2  .....bMDD.......
00001c0: 99e4 6350 a756 c21a 980b 6bca 57f9 8443  ..cP.V....k.W..C
00001d0: eecc 9fd1 05ce 78c4 f95f dc90 8926 6eb4  ......x.._...&n.
00001e0: 88b8 7b90 44be 33c3 cc2a b032 d809 17d0  ..{.D.3..*.2....
00001f0: 7e32 c4c9 e37f ceb3 b1e0 b634 a690 8163  ~2.........4...c
0000200: cd34 e3d9 9768 3e13 ac10 5003 1cb7 af6b  .4...h>...P....k
0000210: 863f cba0 9896 e50a d029 8e2b 584c d86f  .?.......).+XL.o
0000220: 67a7 120e 318a cb22 3235 3662 6173 6520  g...1.."256base 
0000230: 3132 3462 6173 655b 305d 2f28 3332 2c7b  124base[0]/(32,{
0000240: 5c5b 3124 295d 2f5c 3224 3d2a 7d2f 5c2c  \[1$)]/\2$=*}/\,
0000250: 297b 2d2e 3634 3e33 322a 2b7d 2b25 2b    ){-.64>32*+}+%+

It's a variant on the constructive grammar engine which followers of will be familiar with:

'MAGIC STRING'256base 124base[0]/(40,{\[1$)]/\2$=*}/\,){-.64>32*+}+%+

It turned out to be slightly better to upper-case the golfed SVG, compress that, and then lower-case after decompression.

When run it produces an 840-byte SVG:

<svg width="192" height="192"><g transform="translate(-19.356 39.823) scale(.11435537421402706)"><path d="m873 126c-28-56-97-79-153-50l-361 182c-40 20-63 60-62 102v369c0 63 51 114 114 114h1198c63 0 114-51 114-114v-369c1-62-22-82-62-102l-361-182c-56-29-125-6-153 50c-28 56-6 124 49 152h-372c55-28 77-96 49-152z" fill="#231f20"/><path d="m1642 812c0 60-49 109-109 109h-1047c-60 0-109-49-109-109v-435c0-60 49-109 109-109h96.557636322653a530 274 0 0 1 854.884727354693 0h96.557636322653c60 0 109 49 109 109v435z" fill="#424143"/><path d="m1561 826c0 52-42 95-95 95h-912c-52 0-95-42-95-95v-463c0-52 42-95 95-95h912c52 0 95 42 95 95v463z" fill="#595a5c"/><circle cy="594" cx="1010" r="199" fill="#f9c960" stroke="#ec2227" stroke-width="42"/><path d="m1063 615l85-62-105 0-33-100-33 100-105 0 85 62-32 100 85-62 85 62z" fill="#ec2227"/></g></svg>

I've tweaked the position by a few millipixels and corrected one small asymmetry in the darkest grey part.

But the changes to the question and discussion in chat indicate that it's actually permissible to create a good approximation to the SVG, which can be done in 364 bytes. The decompression chain is similar, so the xxd output of the GolfScript file is:

0000000: 2710 9f1d b7bb 6ca9 ad60 1325 b869 45a6  '.....l..`.%.iE.
0000010: 9371 2eee 1271 1dac 0244 9ca3 2820 e6be  .q...q...D..( ..
0000020: b038 68e4 4e53 bbe9 7809 a67a 5f02 2f14  .8h.NS..x..z_./.
0000030: 66a1 0cb3 648c 76d4 0450 028d fd32 b81f  f...d.v..P...2..
0000040: 351a d449 bba8 e685 4de8 1fc0 abfd 8b9f  5..I....M.......
0000050: d9d9 33cd 16e9 5c27 b7a0 dc0f 4138 a2ca  ..3...\'....A8..
0000060: 2b45 a2c2 571e 7e1e 1030 dcfd b48e 377b  +E..W.~..0....7{
0000070: 112e 7762 d14c 1fed 0bcb 15b4 c383 f828  ..wb.L.........(
0000080: b317 8c9f 890b ce84 7782 4c10 fc8e 7602  ........w.L...v.
0000090: 9fef 9563 fe30 45b0 7144 30b3 f3c5 fa22  ...c.0E.qD0...."
00000a0: ccae 8a08 c506 466b 6b84 317e 62dd a558  ......Fkk.1~b..X
00000b0: 8423 d8ef 9d67 e807 0d23 847d 4dab 68ff  .#...g...#.}M.h.
00000c0: 952b ca20 14d3 0881 2880 6611 eb53 10c6  .+. ....(.f..S..
00000d0: 0058 573f 3c87 957c 8512 59ff 94f3 ae38  .XW?<..|..Y....8
00000e0: 4145 bf8d 4123 6e84 aa62 904d a878 0bca  AE..A#n..b.M.x..
00000f0: 854b deaa 32ae 70fc b31a 9578 676a df8a  .K..2.p....xgj..
0000100: 7310 ecfc 47d2 5dde 1a8c 3898 943b ede3  s...G.]...8..;..
0000110: d0a2 55a4 eb00 b623 0302 d79c a712 b616  ..U....#........
0000120: 5037 dc2d 0dad 2732 3536 6261 7365 2031  P7.-..'256base 1
0000130: 3133 6261 7365 5b30 5d2f 2832 312c 7b5c  13base[0]/(21,{\
0000140: 5b31 2429 5d2f 5c32 243d 2a7d 2f5c 2c29  [1$)]/\2$=*}/\,)
0000150: 7b2d 2e36 343e 3332 2a2b 7d2b 252b       {-.64>32*+}+%+

and generates a 547-byte SVG file:

<svg width="1426" height="858"><path d="m475 114-361.5 182v370h1199v-370l-361.5-182" stroke="#231f20" stroke-linecap="round" stroke-linejoin="round" stroke-width="227"/><ellipse cx="713" cy="367" rx="530" ry="274" fill="#424143"/><rect x="80" y="205" width="1266" height="653" rx="109" ry="109" fill="#424143"/><rect x="161" y="205" width="1103" height="653" rx="95" ry="95" fill="#595a5c"/><circle cx="713" cy="531" r="199" fill="#f9c960" stroke="#ec2227" stroke-width="42"/><path d="m713 390 85 262-223-162 276 0-223 162z" fill="#ec2227"/></svg>

Thanks to Paul LeBeau for pointing out a 7-byte saving in the SVG which translated to 9 bytes in the GolfScript, and for his answer which demonstrated that the star can be drawn with just the 5 points. (Using his answer I could get down to 329 bytes, or 323 with some tweaking to his answer, but I'm not comfortable with that).

Exported at 50% with Inkscape:

Hat image rendered as PNG

To see the structure, here's the SVG rendered with fill="none" on everything and some fill colours changed to stroke colours: Outline image

  • \$\begingroup\$ @Optimizer, but unlike the JS one it is almost pixel-perfect. Other than golfing it, the only difference to the original SVG is that it fixes an asymmetry. If I relax it in the style of Martin's marked-up image, I can probably save a lot. \$\endgroup\$ Dec 16 '14 at 9:32
  • \$\begingroup\$ The "<g>" and "</g>" are not necessary, so you should be able to save a bit more. \$\endgroup\$ Dec 16 '14 at 14:12
  • \$\begingroup\$ @PaulLeBeau, very true, thanks. \$\endgroup\$ Dec 16 '14 at 14:19

SVG (462 460 454 429 384 365 bytes)

I know it isn't a programming language, but I thought this will at least be useful to anyone generating SVG output...

This is based on Peter Taylor's SVG.

By using the original coords, and optimizing the paths a little, I managed to shrink the SVG down. I also fixed the colours.

<svg><g stroke-linecap=round stroke-linejoin=round stroke-width=26><path d=M54,13,13,36V75H151V36L110,13 stroke=#1f1a1a /><path d=M21,84V36H37A91,91,0,0,1,127,36h16V84z stroke=#404040 /><path d=M30,36v48h104V36z stroke=#58585c fill=#58585c /></g><circle cx=82 cy=60 r=23 fill=#ffca57 stroke=#ff1c22 stroke-width=5 /><path d=M82,43,92,74,66,55H98L72,74z fill=#ff1c22

Update: Fixed flaw pointed out by Peter Taylor and position of rects and saved 2 more bytes.

Update 2: Incorporated another fix and suggestions from Peter (-6 bytes)

Update 3: Just noticed the instructions now specify all radii are 13, so taking advantage of that, and optimizing the paths a bit more, I saved another 25 bytes. More readable fiddle here.

Update 4: Since I am already assuming the SVG is embedded in HTML (standalone SVGs need the namespace declaration), I can actually squeeze this more. (a) I don't need the width and height attributes because the size of the SVG is smaller than the default size browsers give to objects whose size is indeteminate (300x150), and (b) the HTML parser is forgiving about attributes which don't have quotes, so some of them can be removed (idea from Squeamish Ossifrage). Saves another 45 bytes.

Update 5: Using hsl's tricks for de-quoting the colours and dropping the trailing end tags. We saved another 19 bytes. The latter seemed a bit cheaty to me at first, but since it works in all browsers, I changed my mind. :) Thanks hsl!

  • \$\begingroup\$ Some nice ideas, but there's one pretty bad flaw. The mid-grey doesn't come high enough to cover the fill of the dark grey. I'm not sure whether this is best fixed by adding fill="none" to the group or by adjusting the curve. \$\endgroup\$ Dec 16 '14 at 16:09
  • \$\begingroup\$ Well spotted, thanks. Fixed now. I wasn't using the right arc radius because I forgot to subtract half the stroke width. \$\endgroup\$ Dec 17 '14 at 3:21
  • \$\begingroup\$ The <rect> should have height 74 rather than 78. And I make it a 5-char saving to replace it with a <path> with both fill and stroke, stroke-width="18", then moved inside the <g> and the common stroke-width="18" moved from two paths to the <g>. Having another <path> rather than a <rect> should also help the compressibility a tiny bit. \$\endgroup\$ Dec 17 '14 at 11:10
  • \$\begingroup\$ Thanks. There seems to be a difference between the radii (8 vs 9), which is why I had them different. But it's not absolutely clear, so having both as 9 is barely noticeable anyway. \$\endgroup\$ Dec 17 '14 at 13:59
  • \$\begingroup\$ Radii are specified as 13 I see, so I have updated the SVG. \$\endgroup\$ Dec 17 '14 at 14:59

Mathematica 787 612 600 514 506 bytes

Surprising amount of code needed. Will surely be beaten.

Ungolfed form

pentagonalVertices[offset_]:=Table[{Cos[2π k/5+ offset],Sin[2π k/5+offset]},{k,0,5}];
{Black,Thickness[.13],JoinForm["Round"],CapForm["Round"], Line[pts]},
GraphicsComplex[16.7 pentagonalVertices[Pi/2],Polygon[{1,3,5,2,4}]],
GraphicsComplex[6.4 pentagonalVertices[3 Pi/2],Polygon[{1,2,3,4,5}]]}]



  • \$\begingroup\$ Can I ask how you count the bytes? (I'm new here) I get 651 bytes when counting your golfed version with this site: mothereff.in/byte-counter \$\endgroup\$
    – Jean-Paul
    Dec 17 '14 at 14:41
  • 1
    \$\begingroup\$ I use an automatic counter app used by Wolfram to evaluate the length of submissions to the one-liner contest (blog.wolfram.com/2014/11/10/…). It does not count optional spaces included for readability. It actually reads the no, of characters, not bytes, but I assume one char=one byte. \$\endgroup\$
    – DavidC
    Dec 17 '14 at 14:54
  • \$\begingroup\$ Makes sense! Too bad I can't do the same for my submission :) Thank you for the answer. \$\endgroup\$
    – Jean-Paul
    Dec 17 '14 at 14:55
  • \$\begingroup\$ I suppose you could see it that way. But that leaves a very difficult-to-read display on a single line. I prefer to keep it legible. \$\endgroup\$
    – DavidC
    Dec 18 '14 at 14:09

HTML + ES6, 533

<canvas id=D width=600 height=400><script>c=D.getContext('2d')
L=s=>B()||eval('for(i in s)i%2||c.lineTo('+G+G+'0)')&&B()
c.font='105px serif'

Snippet (modified):

<canvas style="margin:-40px 0 0 100px;height:250px;" id=D width=600 height=400><script>stages=[function(){c=D.getContext('2d');S=function(x){return c.strokeStyle=F(x)};F=function(x){return c.fillStyle=x};W=function(x){return c.lineWidth=x};B=function(x){return c.stroke()||c.fill()||c.beginPath()};G='s.charCodeAt(i++)*9-300,';L=function(s){return B()||eval('for(i in s)i%2||c.lineTo('+G+G+'0)')&&B()}},function(){c.lineCap=c.lineJoin='round';W(60);S('#1F1A1A');L(';,+3+BXBX3H,')},function(){S('#404040');L('.3.EUEU3.3')},function(){c.arc(291,390,270,4,5.2,0);B()},function(){S('#58585C');L('131ERER313')},function(){S(R='#FF1C22');F('#FFCA57');W(30);c.arc(291,240,69,0,7,0);B()},function(){c.font='105px serif';S(R);c.fillText('\u2605',239,276)}];next=function(i){stages[i]();if(i<6)setTimeout(next,1000,i+1)};next(0)</script>


  • \$\begingroup\$ @Optimizer I've added an image, since it looks fine for me in both FF and Chrome. The font must be different on Windows or something. \$\endgroup\$
    – grc
    Dec 16 '14 at 13:01
  • \$\begingroup\$ @grc I think you can't rely on certain fonts being readily available on all systems; especially not if you use serif, which isn't even a specific font... \$\endgroup\$
    – Alexander
    Dec 16 '14 at 13:31
  • \$\begingroup\$ In Arial Unicode MS (the Windows Arial font which actually has the codepoint) that codepoint doesn't even have the right shape. The points have a narrower base. \$\endgroup\$ Dec 16 '14 at 13:56

HTML + CSS, 676 636 625 bytes

This can be golfed a lot, by getting rid of those left:XXXpx and using some sort of centering Now using transforms to center everything instead of left:XXXpx.

*{left:50%;transform:translate(-50%);position:absolute;border-radius:13px;height:75px}a,b,f{width:145px;background:#404040}b{width:126px;background:#58585C}c{width:163px;height:61px;top:50px}d,e{width:68px;height:40px;top:-15px}c,d,e{background:#1F1A1A}d{left:0;transform:skew(0deg,-26deg);border-radius:9px 24px}e{left:96px;transform:skew(0deg,26deg);border-radius:24px 9px}f{height:40px;width:99px;top:-13px;border-radius:150px/60px}g{height:34px;width:34px;background:#FFCA57;border:5px solid #FF1C22;border-radius:40px;top:13px;color:#FF1C22;font-size:1cm;line-height:31px;padding:3px}

Note: This works best/as expected in Firefox on Windows

End result looks like:

enter image description here


ActionScript 3.0, 491 bytes

Golfed form:

var h=new Shape(),g=h.graphics,l=g.lineTo,m=g.moveTo,s=g.lineStyle,b=g.beginFill,e=g.endFill,r=g.drawRoundRect;s(23,0x231F20);m(77,18);l(41,36);l(41,73);m(125,18);l(161,36);l(161,73);s();b(0x424143);g.drawEllipse(48,16,106,55);e();b(0x424143);r(38,27,126,65,23,23);e();b(0x595A5C);r(46,27,110,65,17,17);e();s(4.2,0xEC2227);b(0xF9C960);g.drawCircle(101,59,20);e();s();b(0xEC2227);m(106,61);l(115,55);l(104,55);l(101,45);l(98,55);l(87,55);l(96,61);l(93,71);l(101,65);l(110,71);e();addChild(h);

Output: http://megaswf.com/file/2708781.swf

  • 1
    \$\begingroup\$ Or: var ww=new WarmWelcome(); stage.addChild(ww); and draw it in Flash with AS3 linkage :) \$\endgroup\$
    – wchargin
    Dec 16 '14 at 16:59

MATLAB R2013a, 551 541

This is my first Code Golf. So if anything is not according to the rules, please teach/tell me :)

Golfed form:

hold on
r=[1 .11 .13];h=[];b=2.4;q=-37;o='Curvature';p='Position'
for i=1:19;h=[h v(p,[-82+b*i -32+i 22 73]) v(p,[60-b*i -32+i 22 73])];end
s(h,o,1,x,[.12 .1 .1])
h=[h fill(104*cos(c),104*sin(c)-52,t(.25,1,3))]
h=[h v(p,[-72 q 144 74],o,.1,x,t(.25,1,3))]
a=v(p,[-63 q 126 74])
a=[a v(p,[-63 q 126 74])]
s(a,o,.1,x,[t(.35,1,2) .36])
v(p,[-20 -20 40 40],o,1,x,[1 .79 .34],z,r,'LineWidth',10)
plot(0,0,'rp',['Marker' x],r,'MarkerSize',58.5)
s([a h],z,'none')
axis equal off

Output (rasterized):

enter image description here


LaTeX/TikZ (613 bytes)


The result of pdflatex is a PDF file with the hat as vector graphics and a tight bounding box.



% Package xcolor provides color model HTML
% in order to take the exact same values, used in the SVG file 

% Package preview is used to get a correct bounding
% box for the graphics

% Color definitions. one digit instead of a name saves many bytes

    % Draws the dark lines in the background
    \draw[4,line width=22.8,line cap=round,line join=round]
    % Draws the ellipsis
    \fill[5,x radius=53,y radius=27.4](0,16.4)circle;
    % Draw the rear rectangle 
    \fill[5,rounded corners=10.9](-63,-32.65)rectangle(63,32.65);   
    % Draws the rectangle in the foreground
    \fill[3,rounded corners=9.5](-55.1,-32.65)rectangle(55.1,32.65);
    % Draws the red full circle
    % Draws the inner yellow circle 
    % Draw the star

The values are taken from the SVG file, they were more accurate (but it also contains rounding errors). The trickiest part was the dark slanted lines in the background. They are drawn as very thick line with rounded line caps and joins.


  • \$\begingroup\$ What a beauty :) \$\endgroup\$
    – Jean-Paul
    Dec 18 '14 at 20:52

Perl + TK: 555

The new lines are only for readability, although I got lost of so many variables.

use Tk;@w=(-width=>13);$c=tkinit->Canvas->pack;

Here's a picture:

enter image description here

I don't think it's near pixel perfect, but it's close enough :)


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.