Draw the Warm Welcome Secret Hat

56

6

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.

Specifications

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

Colors:

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

Scoring

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.

Optimizer

Posted 2014-12-15T22:03:18.030

Reputation: 25 836

About the suggested edit: I chose to reject. I see the image displaying correctly as it is. – mbomb007 – 2017-11-19T04:47:15.677

Answers

15

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

Peter Taylor

Posted 2014-12-15T22:03:18.030

Reputation: 41 901

@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. – Peter Taylor – 2014-12-16T09:32:45.563

The "<g>" and "</g>" are not necessary, so you should be able to save a bit more. – Paul LeBeau – 2014-12-16T14:12:06.753

@PaulLeBeau, very true, thanks. – Peter Taylor – 2014-12-16T14:19:08.867

26

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!

Paul LeBeau

Posted 2014-12-15T22:03:18.030

Reputation: 469

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. – Peter Taylor – 2014-12-16T16:09:16.297

Well spotted, thanks. Fixed now. I wasn't using the right arc radius because I forgot to subtract half the stroke width. – Paul LeBeau – 2014-12-17T03:21:12.407

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. – Peter Taylor – 2014-12-17T11:10:55.483

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. – Paul LeBeau – 2014-12-17T13:59:14.380

Radii are specified as 13 I see, so I have updated the SVG. – Paul LeBeau – 2014-12-17T14:59:31.093

I just knew Snippets would be used for something amazing. I was not disappointed. :P – Haney – 2014-12-18T18:02:49.150

Your left-top middle-grey curve is not meeting up with light grey-curve correctly – Optimizer – 2014-12-19T00:27:21.293

Thanks Optimizer. Fixed. No change to size. – Paul LeBeau – 2014-12-19T04:28:28.013

I'll personally award bounty to this answer if it can beat the current minimum score of 350. (of course using the same approach. I want the svg in the answer to be golfed further) – Optimizer – 2014-12-19T10:34:55.073

I think I've pretty much reached the limit now. I definitely don't thing I'm going to find another 35 bytes. :) – Paul LeBeau – 2014-12-19T12:37:07.960

100 rep not enough of a reason to push your limits ? ;) – Optimizer – 2014-12-19T15:36:18.683

I got it to 365 by removing quotes around the colors and getting rid of /></svg> at the end. – NinjaBearMonkey – 2014-12-24T17:09:18.227

Hmm.. which browser did you test on? FF, Chrome and IE all require the quotes for the colour attributes, which is why I didn't remove them. – Paul LeBeau – 2014-12-24T22:05:12.113

Can you use this to reduce 404040 to 444?

– feersum – 2014-12-25T01:33:08.093

It worked on Chrome as long as you add a space before the end of the tag, e.g. stroke="#1f1a1a"/> becomes stroke=#1f1a1a />. – NinjaBearMonkey – 2014-12-25T15:00:36.850

@feersum Three digit colours are treated as a special case. #444 is equivalent to #444444. Although it is very close, I was trying to keep the colours and coords as accurate as posible. – Paul LeBeau – 2014-12-26T01:52:26.480

20

Mathematica 787 612 600 514 506 bytes

Surprising amount of code needed. Will surely be beaten.

Ungolfed form

red=RGBColor[1.,.11,.13]
yellow=RGBColor[1.,.79,.34]
lightGrey=RGBColor[.35,.35,.36]
midGrey=RGBColor[.25,.25,.25]
r=RoundingRadius->8;
pentagonalVertices[offset_]:=Table[{Cos[2π k/5+ offset],Sin[2π k/5+offset]},{k,0,5}];
x=63;x2=72;
y=37;
pts={{e=22,50},{h=72,30},{h,-17},{-h,-15},{-h,30},{-e,50}};
pts2={{-h,-15},{-h,30},{-e,50}}
Graphics[{
{Black,Thickness[.13],JoinForm["Round"],CapForm["Round"], Line[pts]},
midGrey,Rectangle[{-x2,-y},{x2,y},r],
Disk[{0,-55},104,{Pi/3,2Pi/3}],
White,Rectangle[{-40,-60},{40,0},r],
lightGrey,Rectangle[{-x,-y},{x,y},r],
red,Disk[{0,0},25],yellow,Disk[{0,0},19.5],red,
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}]]}]

hat

Golfed

g=GraphicsComplex;c=RGBColor;d=c[1.,.11,.13];o="Round";k=Rectangle;j=Disk;n=Polygon;r=RoundingRadius->8;w@s_:=Table[{Cos[2\[Pi]k/5+s],Sin[2\[Pi]k/5+s]},{k,0,5}];x=63;i=72;y=37;p={{e=22,50},{h=72,30},{h,-17},{-h,-15},{-h,30},{-e,50}};Graphics[{Thickness[.13],JoinForm@o,CapForm@o,Line@p,c[.25,.25,.25],k[{-i,-y},{i,y},r],j[{0,-55},104,{\[Pi]/3,2\[Pi]/3}],White,k[{-40,-60},{40,0},r],c[.35,.35,.36],k[{-x,-y},{x,y},r],d,j[{0,0},25],c[1.,.79,.34],j[{0,0},19.5],d,g[16.7w[\[Pi]/2],n[{1,3,5,2,4}]],g[6.4w[3\[Pi]/2],n[{1,2,3,4,5}]]}]

DavidC

Posted 2014-12-15T22:03:18.030

Reputation: 24 524

Can I ask how you count the bytes? (I'm new here) I get 651 bytes when counting your golfed version with this site: https://mothereff.in/byte-counter

– Jean-Paul – 2014-12-17T14:41:03.853

1

I use an automatic counter app used by Wolfram to evaluate the length of submissions to the one-liner contest (http://blog.wolfram.com/2014/11/10/announcing-the-winners-of-the-2014-one-liner-competition/). 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.

– DavidC – 2014-12-17T14:54:06.190

Makes sense! Too bad I can't do the same for my submission :) Thank you for the answer. – Jean-Paul – 2014-12-17T14:55:23.087

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. – DavidC – 2014-12-18T14:09:14.950

18

HTML + ES6, 533

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

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>

hat!

grc

Posted 2014-12-15T22:03:18.030

Reputation: 18 565

@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. – grc – 2014-12-16T13:01:52.340

@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... – Alexander – 2014-12-16T13:31:38.617

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. – Peter Taylor – 2014-12-16T13:56:06.673

13

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}
<c><d></d><e></e><f></f><a><b><g>★

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

End result looks like:

enter image description here

Optimizer

Posted 2014-12-15T22:03:18.030

Reputation: 25 836

I've never seen golfed HTML tags. Interesting. – Arturo Torres Sánchez – 2014-12-18T04:43:09.680

1

@ArturoTorresSánchez Then you need to see this

– Optimizer – 2014-12-18T05:50:55.783

The star now looks a bit shifted to the left and the top on FF 34.0/Windows – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2014-12-23T04:08:30.550

8

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

lios

Posted 2014-12-15T22:03:18.030

Reputation: 81

1Or: var ww=new WarmWelcome(); stage.addChild(ww); and draw it in Flash with AS3 linkage :) – wchargin – 2014-12-16T16:59:32.487

7

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'
x='FaceColor';z='EdgeColor';v=@rectangle;t=@repmat;s=@set
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])
c=.8:.01:2.2
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

Jean-Paul

Posted 2014-12-15T22:03:18.030

Reputation: 171

6

LaTeX/TikZ (613 bytes)

\RequirePackage{xcolor,tikz}\RequirePackage[active,tightpage]{preview}\PreviewMacro[[!]\tikz\def~#1{\definecolor#1{HTML}}~1{EC2227}~2{F9C960}~3{595A5C}~4{231F20}~5{424143}\def\r{rounded
corners}\def\R{radius}\tikz[x=1pt,y=1pt]{\def~{\fill[}\draw[4,line
width=22.8,line
cap=round,line
join=round](-23.8,41.7)--(-59.9,23.5)--(-59.9,-13.3)--(59.9,-13.3)--(59.9,23.5)--(23.8,41.7);~5,x
\R=53,y
\R=27.4](0,16.4)circle;~5,\r=10.9](-63,-32.65)rectangle(63,32.65);~3,\r=9.5](-55.1,-32.65)rectangle(55.1,32.65);~1,\R=22](0,0)circle;~2,\R=17.8](0,0)circle;~1](90:14.1)\foreach\!in{0,...,4}{--(90+\!*144:14.1)}--cycle;}\stop

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

Result

Ungolfed

\documentclass{minimal}
% Package xcolor provides color model HTML
% in order to take the exact same values, used in the SVG file 
\usepackage{xcolor}
\usepackage{tikz}

% Package preview is used to get a correct bounding
% box for the graphics
\usepackage[active,tightpage]{preview}
\PreviewEnvironment[{[]}]{tikzpicture}

% Color definitions. one digit instead of a name saves many bytes
\definecolor1{HTML}{EC2227}
\definecolor2{HTML}{F9C960}
\definecolor3{HTML}{595A5C}
\definecolor4{HTML}{231F20}
\definecolor5{HTML}{424143}

\begin{document}
  \begin{tikzpicture}[x=1pt,y=1pt]
    % Draws the dark lines in the background
    \draw[4,line width=22.8,line cap=round,line join=round]
    (-23.8,41.7)--(-59.9,23.5)--(-59.9,-13.3)
    --(59.9,-13.3)--(59.9,23.5)--(23.8,41.7);
    % 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
    \fill[1,radius=22](0,0)circle;  
    % Draws the inner yellow circle 
    \fill[2,radius=17.8](0,0)circle;
    % Draw the star
    \fill[1](90:14.1)\foreach\!in{0,...,4}{--(90+\!*144:14.1)}--cycle;
  \end{tikzpicture}%
\end{document}

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.

Animation

Heiko Oberdiek

Posted 2014-12-15T22:03:18.030

Reputation: 3 841

What a beauty :) – Jean-Paul – 2014-12-18T20:52:02.687

2

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;
$c->createPolygon($a=131,$b=163,168,150,$a,$b,$e=269,$b,232,150,$e,$b,$e,$d=225,$a,$d,-outline=>"#1f1a1a",@w);
$c->createPolygon(137,$f=169,263,$f,263,$g=231,137,$g,-outline=>$h="#".40x3,@w);
$c->createOval($a,147,$e,$g,-fill=>$h,-outline=>$h);
$c->createPolygon(143,$f,257,$f,257,$g,143,$g,-fill=>$l="#58585c",-outline=>$l,@w);
$c->createOval(175,175,$d,$d,-width=>5,-fill=>"#ffca57",-outline=>$r="#ff1c22");
$c->createPolygon((map{200+($_%2?17:6)*sin.628*$_,200+($_%2?17:6)*cos.628*$_}0..11),-fill=>$r);
MainLoop

Here's a picture:

enter image description here

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

core1024

Posted 2014-12-15T22:03:18.030

Reputation: 1 811