48
\$\begingroup\$

Requirements

For the sake of the challenge let's define a unit:

A unit is defined as any point that compose the grid in which the face is drawn (pixels for screen, characters for ASCII art, etc..).

The minimal requirements for the face are:

A smiley face is composed of a shape that resemble a circle (not necessarily perfect) of any radius. There must be at least 1 unit for each of the two eyes and at least 2 units for the mouth. Both eyes and mouth should be within the face shape. The mouth can be oriented however you want (happy, sad, indifferent, etc..).

Here's an example of the output:

 0 0 0    . . .
0 . . 0  . o o .
0 --- 0  . \_/ .
 0 0 0    . . .

Goals

Of course the main goal is to come up with the shortest code possible, but art is also important.

Winner

The winner is chosen based on the amount of votes from the users, in, at least, the next 5 days.

\$\endgroup\$
6
  • \$\begingroup\$ Similar: codegolf.stackexchange.com/questions/8932/smile-just-smile/… \$\endgroup\$
    – DavidC
    Commented Dec 29, 2013 at 2:16
  • 5
    \$\begingroup\$ Wow, 8 questions on the hot question list. Our site should be getting more traffic. \$\endgroup\$
    – Justin
    Commented Dec 29, 2013 at 6:27
  • \$\begingroup\$ Isn't indifferent face strictly easier than happy, and sad sometimes more difficult? \$\endgroup\$
    – o0'.
    Commented Dec 29, 2013 at 13:50
  • 2
    \$\begingroup\$ Not going to make this an answer since it doesn't fit the minimum requirements, but I wanted to chime in... alt + 1 and alt + 2 will produce ☺ and ☻ respectively. For the sake of argument I'll consider the alt key press a character and call that 2 characters. \$\endgroup\$ Commented Dec 30, 2013 at 17:30
  • 1
    \$\begingroup\$ Will this thread ever end? :) \$\endgroup\$
    – avall
    Commented Jan 13, 2014 at 10:43

34 Answers 34

114
\$\begingroup\$

Javascript, 340

var i=0,b=document.body,d=20,n=b.clientWidth,m=b.clientHeight,f="width=10,height=10,"
var o=new Function("f","i","t",'open("","",f+"left="+i+",top="+t)')
for(j=0;j<m/d;++j,i=j*d){
   u=Math.sqrt(i*(m-i))
   t=m/2+u*(j%2-0.5)*2
   o(f,i,t)
   i>m/5&&i<0.8*m&&j%2&&o(f,i,t-m/4);
   ((i<m/3&&i>m/4)||(i<3*m/4&&i>2*m/3))&&o(f,i,m/3)
}

Javascript, 283

optimized version (with some improvements & without unnecessary white spaces)

var i=0,b=document.body,d=20,n=b.clientWidth,m=b.clientHeight,f="width=10,height=10,"
function o(i,t){open("","",f+"left="+i+",top="+t)}for(j=0;j<m/d;i=++j*d){u=Math.sqrt(i*(m-i));t=m/2+j%2*2*u-u;o(i,t);i>m/5&&i<0.8*m&&j%2&&o(i,t-m/4);((i<m/3&&i>m/4)||(i<3*m/4&&i>2*m/3))&&o(i,m/3)}

Well.. maybe it isn't as short as you would want to but it's unconventional for sure. It looks better when your browser is maximized. I really enjoyed your question! If you want to increase the details just reduce d variable slightly.

edit: Unfortunately I can't run it on jsfiddle but you can paste it to Javascript console in aby browser. Oh, and enable popups on the page :).

edit2: You can run it making a new html file and paste the code into it:

<body>
<script>
var i=0,b=document.body,d=20,n=b.clientWidth,m=b.clientHeight,f="width=10,height=10,"
var o=new Function("f","i","t",'open("","",f+"left="+i+",top="+t)')
for(j=0;j<m/d;++j,i=j*d){
   u=Math.sqrt(i*(m-i))
   t=m/2+u*(j%2-0.5)*2
   o(f,i,t)
   i>m/5&&i<0.8*m&&j%2&&o(f,i,t-m/4);
   ((i<m/3&&i>m/4)||(i<3*m/4&&i>2*m/3))&&o(f,i,m/3)
}
</script>
</body>

Then when you run it and nothing happens, just enable the popup windows and reload the page. In addition I paste screenshot

\$\endgroup\$
17
  • 23
    \$\begingroup\$ In the name of Bwian of Judea, what is this... \$\endgroup\$
    – nitro2k01
    Commented Dec 29, 2013 at 12:08
  • 2
    \$\begingroup\$ Now it's working. Took me about 2m to close all popups \$\endgroup\$
    – s3lph
    Commented Dec 29, 2013 at 20:27
  • 7
    \$\begingroup\$ After spending so much time trying to disable annoying popups, enabling them is hard. I disabled adBLock and allowed all popups in my browser...after half the face appears, it decides to turn the blocker back on! \$\endgroup\$ Commented Dec 30, 2013 at 1:54
  • 4
    \$\begingroup\$ Amazing out-of-the-box thought! I would never think to do something like this. \$\endgroup\$
    – Gari BN
    Commented Jan 16, 2014 at 10:01
  • 4
    \$\begingroup\$ That's outstandingly original! \$\endgroup\$
    – Oberon
    Commented Jan 16, 2014 at 14:16
68
\$\begingroup\$

HTML, 200 141 characters

Thanks to avail, I've cut this down to 141 characters:

<fieldset><legend>\\\\\\\\\\\\ ////</legend><center><input size=1 value=o> <input size=1 value=o /><br><input type=radio><br><button>........

Here's the original HTML:

<fieldset>
<legend>\\\\\\\\\\\\ ////</legend>
<center><input type=text size=1 value=o />
<input type=text size=1 value=o /><br/>
<input type=radio /><br/>
<button>........</button></center></fieldset>

Works best on small screens:

:-|

\$\endgroup\$
7
  • 4
    \$\begingroup\$ This is art :P \$\endgroup\$
    – Shoe
    Commented Dec 29, 2013 at 22:53
  • 3
    \$\begingroup\$ You don't have to close most of your tags (most browsers will handle it), you don't need to define the type of input (text is default) and don't close <br> (html5). Here's the optimised code with only 150 chars :): jsfiddle.net/avall/TdPkF \$\endgroup\$
    – avall
    Commented Dec 30, 2013 at 0:38
  • \$\begingroup\$ 158 chars and now centers the hair so it looks good on any size screen. jsfiddle.net/TdPkF/5 \$\endgroup\$ Commented Dec 30, 2013 at 8:27
  • \$\begingroup\$ @AverageMarcus It can be align=center instead of style=text-align:center in <legend> tag so 11 characters less :) \$\endgroup\$
    – avall
    Commented Dec 30, 2013 at 14:56
  • 1
    \$\begingroup\$ @squeamishossifrage You should remove all but 3 of the hairs, and then it would be Homer Simpson! \$\endgroup\$
    – mbomb007
    Commented Jan 16, 2015 at 17:48
55
\$\begingroup\$

Brainfuck: 583 characters (without counting whitespace)

 >>------>->->+++++>->->---->>>>------>>>>
 >>>>---->->------->>->->->---->>-------->
 ->->------>>>>>>>>>>-->---->>-->---->>->
  -->>>------>>>>>>>>->---->---->>->->->-
  >>->---->---->>++++[-<++++>]<[-<++++
  ++<++++++++<+++<++<++++++<++++++<++++++
 <++++++<++<++++++<++++++++<+++<++<++<++<++
<++<++<++<+<++<++++<++++++++<+++<++<+++<+++
<++<++++++   <++++++++<++++<    ++<++<++<++
<++<++<++<++<+<+++<++++++<+++<++<++++++<+++
+++<++++++<+++<++<++  +<++++++<++++++<++<++
 <++<++<++<++<++<+<++<++<++<++++++<++++++
  <++++++<+++++<++++++<+++<+>>>>>>>>>>>>
    >>>>>>                       >>>>>
     >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
          >>>>>>>>>>>>>>>]<[.<]

Output:

\|/ ____ \|/       
 @~/ ,. \~@        
/_( \__/ )_\       
   \__U_/
\$\endgroup\$
4
  • 12
    \$\begingroup\$ The original code looks a bit like a face (if you try really hard...), I wonder how hard it would be to make the code and output both be faces... \$\endgroup\$ Commented Dec 29, 2013 at 18:25
  • 1
    \$\begingroup\$ @handuel Both are faces, but different. Did you mean the code and the output to be the same like a quine? I'm sure it can be done. \$\endgroup\$
    – Sylwester
    Commented Dec 29, 2013 at 18:30
  • \$\begingroup\$ I just meant for the code to look more like a face, I didn't realize it was intentional. \$\endgroup\$ Commented Dec 29, 2013 at 18:31
  • 1
    \$\begingroup\$ In Brainfuck, everything that is not a control character is a comment. That is why the source code can be made to look like a smiley. \$\endgroup\$ Commented Jan 1, 2014 at 22:35
39
\$\begingroup\$

SVG

<svg xmlns="http://www.w3.org/2000/svg">
    <defs>
        <radialGradient id="f" fx="25%" fy="25%" r="60%">
            <stop offset="0" stop-color="#fff"/>
            <stop offset="0.6" stop-color="#ff0"/>
            <stop offset="1" stop-color="#f80"/>
        </radialGradient>
    </defs>
    <circle fill="url(#f)" stroke="#000" stroke-width="2" cx="100" cy="100" r="90"/>
    <ellipse cx="70" cy="70" rx="10" ry="20"/>
    <ellipse cx="130" cy="70" rx="10" ry="20"/>
    <path fill="none" stroke="#000" stroke-width="5" d="M 40 120 S 100 200 160 120"/>
</svg>

Renders like this:

Smiley

\$\endgroup\$
4
  • \$\begingroup\$ Infinite units? \$\endgroup\$
    – user80551
    Commented Dec 31, 2013 at 15:02
  • 6
    \$\begingroup\$ The right tool for the right job. \$\endgroup\$
    – Alpha
    Commented Jan 3, 2014 at 2:02
  • \$\begingroup\$ I wouldn't say SVG is really a programming language \$\endgroup\$
    – Oliver Ni
    Commented Jan 2, 2015 at 4:43
  • \$\begingroup\$ @Oliver It's as much a programming language as HTML is... (which it isn't). \$\endgroup\$
    – mbomb007
    Commented Jan 16, 2015 at 17:49
37
\$\begingroup\$

Ruby, 224

Douglas Adams would be horrified. :-P

w=?$;"^XA[_AXeMFGIAHJLjKNAEFEJJNHQHNKLAEMINJOJOHLAGKHOJOJ[AG[HQHRFJAH}IH
IGGwIIAHHGwKHAHGHrEUAGQFiGVAGQGfIPAFHKHHbJHAQII]MGASHNSOHATIdIAUJJRLIAWLIQGK
ZOFUA]ZAeSAiPAjOAkL".codepoints{|r|r-=68;$><<(r<0??\n:(w=w==?$?' ':?$)*r)}

Output:

                          $$$$$$$$$$$$$$$$$$$$
                       $$$$$$$$$$$$$$$$$$$$$$$$$$$
                    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$         $$   $$$$$
    $$$$$$        $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$       $$$$$$$$$$
 $$ $$$$$$      $$$$$$$$$$    $$$$$$$$$$$$$    $$$$$$$$$$       $$$$$$$$
 $$$$$$$$$     $$$$$$$$$$      $$$$$$$$$$$      $$$$$$$$$$$    $$$$$$$$
   $$$$$$$    $$$$$$$$$$$      $$$$$$$$$$$      $$$$$$$$$$$$$$$$$$$$$$$
   $$$$$$$$$$$$$$$$$$$$$$$    $$$$$$$$$$$$$    $$$$$$$$$$$$$$  $$$$$$
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     $$$$
     $$$   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     $$$$$
    $$$$   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$       $$$$
    $$$    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$
   $$$$$$$$$$$$$  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   $$$$$$$$$$$$$$$$$$
   $$$$$$$$$$$$$   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     $$$$$$$$$$$$
  $$$$       $$$$    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$      $$$$
             $$$$$     $$$$$$$$$$$$$$$$$$$$$$$$$         $$$
               $$$$          $$$$$$$$$$$$$$$           $$$$
                $$$$$                                $$$$$
                 $$$$$$      $$$$$$$$$$$$$$        $$$$$
                   $$$$$$$$     $$$$$$$$$$$$$   $$$$$$$
                      $$$$$$$$$$$  $$$$$$$$$$$$$$$$$
                         $$$$$$$$$$$$$$$$$$$$$$
                                 $$$$$$$$$$$$$$$
                                     $$$$$$$$$$$$
                                      $$$$$$$$$$$
                                       $$$$$$$$

Ruby, 110

Same technique. Less code. Less artful. Looks like someone melted a plastic smiley. :-}

w=?$;"TXANdAKQGZAHSI[AGaGRAFaIRAFPGeAGQJ_AHURQAJkANc
TX".codepoints{|r|r-=68;$><<(r<0??\n:(w=w==?$?' ':?$)*r)}

Output:

                $$$$$$$$$$$$$$$$$$$$
          $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
       $$$$$$$$$$$$$   $$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$     $$$$$$$$$$$$$$$$$$$$$$$
   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$   $$$$$$$$$$$$$$
  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$     $$$$$$$$$$$$$$
  $$$$$$$$$$$$   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
   $$$$$$$$$$$$$      $$$$$$$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$              $$$$$$$$$$$$$
      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
          $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
                $$$$$$$$$$$$$$$$$$$$
\$\endgroup\$
2
  • \$\begingroup\$ Does the second example count? There's no circle around the face. \$\endgroup\$
    – Kevin
    Commented Dec 29, 2013 at 19:01
  • 1
    \$\begingroup\$ @Kevin, good point. Amended. \$\endgroup\$ Commented Dec 29, 2013 at 19:42
23
\$\begingroup\$

QBasic ASCII, 134 (unoptimized)

SCREEN 1
PRINT CHR$(1)
FOR i = 0 TO 64
  x = i \ 8
  y = i MOD 8
  LOCATE y + 2, x + 1
  IF POINT(x, y) THEN PRINT "X"
NEXT

This answer totally cheats by using ASCII character 1 for its smiley. However, unlike the BF and "plain text" answers, it actually obeys the rules by making ASCII art based on the pixels of the smiley character, rather than just plainly printing the character as its full solution. The unoptimized version represents how QBasic's IDE saves the files. The IDE is "helpfully" fixing up the syntax for us and adding a lot of whitespace where "needed".

Output: QBasic ASCII smiley unoptimized

QBasic ASCII, 80 (optimized)

SCREEN 1
?"☺"
FOR i=0TO 64
x=i\8
y=i MOD 8
LOCATE y+2,x+1
?CHR$(POINT(x,y))
NEXT

This is an optimized version of the first code sample, which still loads in QBasic. Things that were done:

  • Removed all unnecessary whitespace. (D'uh!)
  • Changed the CRLF line breaks to LF only.
  • Replaced CHR$(1) with a string containing the actual character. (Here illustrated with a matching Unicode character. If you actually want to try the code, please replace it with a real ASCII character 1 using a hex editor.)
  • Replaced PRINT with ?, as the BASIC tradition allows for.
  • Replaced the IF line with a line that prints characters based on the source pixel value. This will be be either 0 or 3. 0 is the color black. Character 0 prints a null character which is treated like a space. 3 is the color white in CGA's 4-color palette. ASCII character 3 is a heart.

Output: QBasic ASCII smile optimized

QBasic graphical, 83 (whitespace optimized)

SCREEN 1
CIRCLE(50,50),50
CIRCLE(50,50),30,,4,5.4
CIRCLE(30,40),10
CIRCLE(70,40),10

But wait, I here you ask, can't you just use QBasic's built-in graphics commands? Sure, but that won't actually save you any bytes, because of the verbosity of the language. But it does have a built-in function to only draw a circle arc between two given angles, which is nice. The angles are given in radians, and 4 and 5.4 approximate a circle arc symmetrically centered around π*3/2, or if you've joined the good side, τ*3/4.

Output: QBasic graphical smiley optimized

Note: The sizes in this answer denote how big the file is in, in bytes.

\$\endgroup\$
1
  • \$\begingroup\$ I feel that I may be the youngest person here who can still read QBASIC... :) Nice one \$\endgroup\$
    – apnorton
    Commented Dec 30, 2013 at 16:45
11
\$\begingroup\$

APL, 97 chars/bytes*

(63⍴1 0)\' /%'[1+(12≥⊃+/¨2*⍨m+¨⊂6 ¯6)+((⍉18<(⍴n)⍴⍳32)∧28≥|100-n)+256≥n←⊃+/¨2*⍨m←x∘.,|x←¯16.5+⍳32]

It works by computing a few circle equations. Tested on GNU APL.

Output smiley output ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
*: APL can be written in its own (legacy) single-byte charset that maps APL symbols to the upper 128 byte values. Therefore, for the purpose of scoring, a program of N chars that only uses ASCII characters and APL symbols can be considered to be N bytes long.

\$\endgroup\$
10
\$\begingroup\$

Bash, 63 chars

echo $'$the_cow=""'>.cow;cowsay -f ./.cow $'O O\n\n\_/';rm .cow

Output:

 _____
/ O O \
|     |
\ \_/ /
 -----

Artistry:

Cows.

\$\endgroup\$
10
\$\begingroup\$

Bash, 22 chars

wget x.co/3WG0m -q -O-

Sample output: enter image description here

Edit: this could be golfed further as suggested by several people. The shortest self-contained version found so far is:

curl -L x.co/3WG0m

(thanks nitro2k01)

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Could be optimized to curl -L x.co/3WG0m. Could be further optimized if we have a local, one-character hostname which also return the data directly (eliminating the -L switch needed to follow redirects.) \$\endgroup\$
    – nitro2k01
    Commented Dec 29, 2013 at 22:10
  • 4
    \$\begingroup\$ Where's the challange in posting a smiley in pastebin and downloading it using wget? \$\endgroup\$
    – s3lph
    Commented Dec 30, 2013 at 11:34
  • \$\begingroup\$ @the_Seppi: that's exactly the joke. It's intended as a thinking-outside-the-box solution. \$\endgroup\$
    – Riot
    Commented Dec 30, 2013 at 15:29
  • 1
    \$\begingroup\$ We need to find someone with access to the root nameservers and convince him to add a domain called Z that points to a server hosting the file. \$\endgroup\$
    – marinus
    Commented Dec 31, 2013 at 5:46
  • 1
    \$\begingroup\$ beautiful, this is my favorite :) \$\endgroup\$
    – jcora
    Commented Dec 31, 2013 at 15:45
8
\$\begingroup\$

Python 247 230 227 Characters - and a cuter version

from matplotlib.pyplot import*
from numpy import*
y=x=arange(-8,11,.1)
x,y=meshgrid(x,y)
contour(x,y,(x*x*(x**2+2*y*y-y-40)+y*y*(y*y-y-40)+25*y+393)*((x+3)**2+(y-5)**2-2)*((x-3)**2+(y-5)**2-2)*(x*x+(y-2)**2-64),[0])
show()

enter image description here

Python 243 Characters - Using colors

from pylab import*
from numpy import*
y=x=arange(-9,11,.1)
x,y=meshgrid(x,y)
contourf(x,y,(x*x*(x**2+2*y*y-y-40)+y*y*(y*y-y-40)+25*y+393)*((x+3)**2+(y-5)**2-2)*((x-3)**2+(y-5)**2-2)*(x*x+(y-2)**2-64),1,colors=("#F0E68C",'#20B2AA'))
show()

enter image description here

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

C++ - 122 characters without unnecessary spaces

This is the most realistic I could come up with:

#include <iostream>

int main() {
  std::cout << "  |||||\n 0 . . 0\n0   ^   0\n0  \\_/  0\n 0     0\n  00000\n   888\n    8\n\n";
}

For those of you who are missing out, it creates this:

ASCII art image

\$\endgroup\$
2
  • 2
    \$\begingroup\$ return 0; is not required in ISO C++ :) \$\endgroup\$
    – Shoe
    Commented Dec 29, 2013 at 12:03
  • \$\begingroup\$ Thanks. That will help cut characters in future puzzles. \$\endgroup\$
    – user10766
    Commented Dec 29, 2013 at 14:52
5
\$\begingroup\$

PHP, many other languages... - 1601 characters

                          oooo$$$$$$$$$$$$oooo
                      oo$$$$$$$$$$$$$$$$$$$$$$$$o
                   oo$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$o         o$   $$ o$
   o $ oo        o$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$o       $$ $$ $$o$
oo $ $ "$      o$$$$$$$$$    $$$$$$$$$$$$$    $$$$$$$$$o       $$$o$$o$
"$$$$$$o$     o$$$$$$$$$      $$$$$$$$$$$      $$$$$$$$$$o    $$$$$$$$
  $$$$$$$    $$$$$$$$$$$      $$$$$$$$$$$      $$$$$$$$$$$$$$$$$$$$$$$
  $$$$$$$$$$$$$$$$$$$$$$$    $$$$$$$$$$$$$    $$$$$$$$$$$$$$  """$$$
   "$$$""""$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     "$$$
    $$$   o$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     "$$$o
   o$$"   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$       $$$o
   $$$    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" "$$$$$$ooooo$$$$o
  o$$$oooo$$$$$  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   o$$$$$$$$$$$$$$$$$
  $$$$$$$$"$$$$   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     $$$$""""""""
 """"       $$$$    "$$$$$$$$$$$$$$$$$$$$$$$$$$$$"      o$$$
            "$$$o     """$$$$$$$$$$$$$$$$$$"$$"         $$$
              $$$o          "$$""$$$$$$""""           o$$$
               $$$$o                                o$$$"
                "$$$$o      o$$$$$$o"$$$$o        o$$$$
                  "$$$$$oo     ""$$$$o$$$$$o   o$$$$""
                     ""$$$$$oooo  "$$$o$$$$$$$$$"""
                        ""$$$$$$$oo $$$$$$$$$$
                                """"$$$$$$$$$$$
                                    $$$$$$$$$$$$
                                     $$$$$$$$$$"
                                      "$$$""  

Smiley source: Asciiworld.com : Smiley

\$\endgroup\$
5
\$\begingroup\$
cowsay -f calvin Hey, What´s up?
 _________________
< Hey, What´s up? >
 -----------------
 \                   .,
   \         .      .TR   d'
     \      k,l    .R.b  .t .Je
       \   .P q.   a|.b .f .Z%      
           .b .h  .E` # J: 2`     .
      .,.a .E  ,L.M'  ?:b `| ..J9!`.,
       q,.h.M`   `..,   ..,""` ..2"`
       .M, J8`   `:       `   3;
   .    Jk              ...,   `^7"90c.
    j,  ,!     .7"'`j,.|   .n.   ...
   j, 7'     .r`     4:      L   `...
  ..,m.      J`    ..,|..    J`  7TWi
  ..JJ,.:    %    oo      ,. ....,
    .,E      3     7`g.M:    P  41
   JT7"'      O.   .J,;     ``  V"7N.
   G.           ""Q+  .Zu.,!`      Z`
   .9.. .         J&..J!       .  ,:
      7"9a                    JM"!
         .5J.     ..        ..F`
            78a..   `    ..2'
                J9Ksaw0"'
               .EJ?A...a.
               q...g...gi
              .m...qa..,y:
              .HQFNB&...mm
               ,Z|,m.a.,dp
            .,?f` ,E?:"^7b
            `A| . .F^^7'^4,
             .MMMMMMMMMMMQzna,
         ...f"A.JdT     J:    Jp,
          `JNa..........A....af`
               `^^^^^'`
\$\endgroup\$
4
\$\begingroup\$

html, css

I know it's neither short nor real coding, but I still wanted to post this

<head>
<style>

#a{
width:100px;
height:100px;
border-radius:50px;
border: 1px solid black; 
}
#b{
position: absolute;
top:30px;
left:30px;
width:20px;
height:20px;
border-radius:10px;
border: 1px solid black;
}
#c{
position: absolute;
top:0px;
left:40px;
width:20px;
height:20px;
border-radius:10px;
border: 1px solid black;
}#d{
position: absolute;
top:30px;
left:-30px;
width:40px;
height:20px;
border-radius:10px;
border: 1px solid black;
}
</style>
</head>
<body>
<div id="a">
<div id="b"/>
<div id="c"/>
<div id="d"/>
</div>
</body>

jsFiddle

\$\endgroup\$
1
  • \$\begingroup\$ Maybe would look better with #d{border-radius:20px/10px;}. Or with #d{border-radius:0 0 20px 20px/0 0 10px 10px;}. Or with #d{height:10px;border-radius:0 0 20px 20px/0 0 10px 10px;margin-top:10px;}. \$\endgroup\$
    – manatwork
    Commented Dec 30, 2013 at 12:40
4
\$\begingroup\$

JavaScript 262 251

Edit: added better eyes.

Prints a smiley face into the console.

Could lose quite a few characters to make my bitmask simpler and print a less pretty face, or use a circle equation instead of an ellipse to account for character spacing - but that's not the spirit.

You can change the r variable to change the size and get a more or less detailed face; any number >=7 && <=99 will give a good result and stay within the character limit.

function c(e,t,n){return t/2*Math.sqrt(1-e*e/(n*n))+.5|0}r=42;p=r/2;q=p/5;s="";for(y=-p;++y<p;){for(x=-r;++x<r;){d=c(y,r*2,p);e=c(y+q,r/5,q);f=e-p;g=e+p;h=c(y,r*1.3,r/3);s+=x>=d||x<=-d||x>=-g&&x<f||x<=g&&x>-f||y>q&&x>-h&&x<h?" ":0}s+="\n"}console.log(s)

Human readable:

function c(y,w,h){return w/2*Math.sqrt(1-y*y/(h*h))+0.5|0}
r = 42
p = r/2
q = p/5
s = ''
for (y = -p; ++y < p;) {
  for (x = -r; ++x < r;) {
    d = c(y,r*2,p)
    e = c(y+q,r/5,q)
    f = e - p
    g = e + p
    h = c(y,r*1.3,r/3)
    s+=(x>=d||x<=-d||(x>-g&&x<f)||(x<g&&x>-f)||(y>q&&(x>-h&&x<h)))?' ':0
  }
  s += '\n'
}
console.log(s)

Output:

smiley in console

My first game of golf so likely to be some improvements.

\$\endgroup\$
4
\$\begingroup\$

Bash + ImageMagick: 137 characters

c=circle
convert -size 99x99 xc: -draw "fill #ff0 $c 49,49,49" -fill 0 -draw "$c 30,35,30,30 $c 70,35,70,30 ellipse 50,60,25,20,0,180" x:

Sample output:

graphical smiley

But as this is an challenge…

Bash + ImageMagick: 172 characters

d=-draw
p=-pointsize
convert -size 99x99 xc: -font times.ttf $p 140 -stroke 0 -fill \#ff0 $d 'text 0,96 O' $p 40 $d 'text 25,50 "o 0"' $p 50 $d 'rotate 95 text 50,-40 D' x:

Sample output:

ASCII smiley

\$\endgroup\$
3
\$\begingroup\$

Rebmu, 24 chars

Oh, the m-i-n-i-m-a-l humanity. :-) Least impressive Rebmu program yet, so purposefully embedding pHp as a tribute to the blue pill in the programming world:

H{ -- }pHp{|..|^/|\/|}pH

Execution:

>> rebmu [H{ -- }pHp{|..|^/|\/|}pH]
 -- 
|..|
|\/|
 -- 

Explanation

Rebmu is just a dialect of Rebol. It inherits the parse constraints, uses abbreviated terms without spaces separated by runs of capitalization. It has a special treatment when the first run is capitalized vs uncapitalized.

(So rather than separating terms like AbcDefGhi it can use the difference between ABCdefGHI and abcDEFghi to squeeze out a bit of information. Sequences whose runs start in all capitalized are separated so the first term represents a "set-word!", often contextually interpreted as a desire for an assignment. see video)

If you want to translate this to native Rebol, you have to accept things like that it starts with a capital H to mean that's actually an h: and not an h. The source is thus analogous to:

h: { -- }
print h
print {|..|^/|\/|}
print h

Assigns the string -- to h (using asymmetric string delimiters because print {"Isn't it nice," said {Dr. Rebmu}, "when you have asymmetric multi-line string delimiters with no need for escaping matched nested pairs, and that accept apostrophes and quotes too?"}

Prints h once, prints another string where ^/ is the escape sequence for newline (carets being less used in software than backslashes which appear often in paths), prints h again.

\$\endgroup\$
3
\$\begingroup\$

Perl, 106 chars

It is a Perl oneliner, just have to C&P it on command prompt, provided the Perl Acme::EyeDrops module is already installed on the machine.

touch temp && perl -MAcme::EyeDrops='sightly' -e 'print sightly({Shape=>"smiley", SourceFile => "temp" } );'

enter image description here

Another way , a smiley with Pulling a face

     touch temp && perl -MAcme::EyeDrops='sightly' -e 'print sightly({Shape=>"smiley2",SourceFile=>"temp"});'

enter image description here

Yet another way,a smiley with Pulling a face upside down,

 touch temp && perl -MAcme::EyeDrops='sightly' -e 'print sightly({Shape=>"smiley2",SourceFile=>"temp",RotateFlip=>'true',Rotate=>'180'});'

enter image description here

\$\endgroup\$
0
2
\$\begingroup\$

Brainf*** - 2

+.

Prints or ascii value 1. (might not work with some platforms)

\$\endgroup\$
3
  • \$\begingroup\$ Nitpick: ASCII 1 is SOH, a non-printable character. That smiley is U+263A, or 1 in CP437, what you are probably using. Unfortunately, your output fails the condition of using enough “units” for the eyes and mouth. \$\endgroup\$ Commented Dec 29, 2013 at 9:42
  • 2
    \$\begingroup\$ @ChristopherCreutzig It does not fail that condition. Each eye is 1 or so pixels, the mouth is more than twice as large. \$\endgroup\$
    – Justin
    Commented Dec 29, 2013 at 15:57
  • \$\begingroup\$ The exp. "ASCII ART" consists of two parts. I see neither of them here \$\endgroup\$
    – s3lph
    Commented Dec 30, 2013 at 11:37
2
\$\begingroup\$

GolfScript, 27

This outputs the 2nd example exactly as given.

' .'3*.'
. o o .
. \_/ .
'\

First one can be done the same way, but I think the 2nd one looks nicer :)

\$\endgroup\$
2
\$\begingroup\$

Bash - one liner: 442 characters

c(){ e "define a(i){scale=scale(i);return(sqrt(i*i));};""$@"|bc -l;};e(){ echo "$@";};s(){ h=$1;c=$2;if [ -z $c ];then c=" ";fi;while (($((h=h-1))>0));do e -n "$c"; done; };m(){ t=`c 2*$1`;while (($((t=t-1))));do l=`c a\($1-$t\)+1`;s $l;q=`c 2*\($1-$l\)`;w=`s $q`;if (($l>$t&&$l<($t+3)&&$q>2)); then w=" "`s $((q-2)) 0`" ";elif (($t>($1+1)&&$q>3));then g=`s $(((q-1)/2)) 0`;w=" $g $g ";fi;e -n +;if [ ! -z "$w" ];then e -n "$w+";fi;e;done;};

Example output: (called by m 8)

       +
      + +
     +   +
    + 0 0 +
   + 00 00 +
  + 000 000 +
 +           +
+             +
 +           +
  +         +
   +       +
    + 000 +
     +   +
      + +
       +

Kind of crazy, but I chose to use a diamond instead of a circle. The eyes are covered by safety goggles.

BASH - 252 characters (thanks @manatwork)

s(){ (($1>1))&&echo -n "${2:- }"&&s $[$1-1] $2;};m(){ ((t=2*$1));while ((t=t-1));do v=$[$1-t];l=$[${v#-}+1];s $l;q=$[2*($1-l)];w=`s $q`;((l>t&&l<t+3&&q>2))&&w=" `s $[q-2] 0` ";((t>$1+1&&q>3))&&{ g=`s $[(q-1)/2] 0`;w=" $g $g ";};echo "+${w:+$w+}";done;}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Cool. With that shape it could replace my gravatar image. :) It can be reduced to 252 characters: s(){ (($1>1))&&echo -n "${2:- }"&&s $[$1-1] $2;};m(){ ((t=2*$1));while ((t=t-1));do v=$[$1-t];l=$[${v#-}+1];s $l;q=$[2*($1-l)];w=`s $q`;((l>t&&l<t+3&&q>2))&&w=" `s $[q-2] 0` ";((t>$1+1&&q>3))&&{ g=`s $[(q-1)/2] 0`;w=" $g $g ";};echo "+${w:+$w+}";done;}. Or 245 if you give up the function m and put the code in a script file. Probably can be reduced even more by tweaking the calculations, but I have no time for that now. \$\endgroup\$
    – manatwork
    Commented Dec 30, 2013 at 11:53
2
\$\begingroup\$

HTML + CSS, 83

<div><a>o<a>o</a><hr><hr><style>a,div{width:2em;border:2px solid;border-radius:8px

screenshot(using firefox): enter image description here

too bad that I'm too late with my answer (got +10 rep also quite late ...)

\$\endgroup\$
12
  • \$\begingroup\$ I like it more with border-radius:50% and a single <hr>: dabblet.com/gist/8472397 \$\endgroup\$
    – manatwork
    Commented Jan 17, 2014 at 12:08
  • \$\begingroup\$ @manatwork or like this: jsfiddle.net/T9BdL/1 \$\endgroup\$ Commented Jan 17, 2014 at 12:11
  • 1
    \$\begingroup\$ @TimSeguine, using a literal non-breaking space character is shorter than &nbsp;: jsfiddle.net/T9BdL/2 \$\endgroup\$
    – manatwork
    Commented Jan 17, 2014 at 12:23
  • 1
    \$\begingroup\$ Eyes overlapping the face is against the rules, I think. That's why I did it like it is currently. Also it kinda reminds me of the canadians face in south park. \$\endgroup\$
    – Leo Pflug
    Commented Jan 17, 2014 at 12:39
  • 2
    \$\begingroup\$ Not really golfed, but as requested, a css only version: jsfiddle.net/T9BdL/9 \$\endgroup\$ Commented Jan 17, 2014 at 13:54
1
\$\begingroup\$

GolfScript, 18

This program uses some binary-encoded values which appear as weird/invalid characters in a text editor.

Here's the hex dump:

00000000  27 c1 94 80 a2 9c c1 27  7b 32 62 61 73 65 20 70  |'......'{2base p|
00000010  7d 25                                             |}%|

Note: it doesn't work in a UTF-8 locale, but works fine with ISO-8859-1 for example.

The expanded version with escaped characters:

"\xc1\x94\x80\xa2\x9c\xc1"{2base p}%

Output:

[1 1 0 0 0 0 0 1]
[1 0 0 1 0 1 0 0]
[1 0 0 0 0 0 0 0]
[1 0 1 0 0 0 1 0]
[1 0 0 1 1 1 0 0]
[1 1 0 0 0 0 0 1]

For nicer output, you can replace the block with {2base{38+}%n} which brings the binary version to 23 bytes. Expanded version:

"\xc1\x94\x80\xa2\x9c\xc1"{2base{38+}%n}%

Output:

''&&&&&'
'&&'&'&&
'&&&&&&&
'&'&&&'&
'&&'''&&
''&&&&&'
\$\endgroup\$
1
\$\begingroup\$

JavaScript

This code must be run in f12 on this page:

console.log(document.getElementsByTagName("code")[0].innerHTML)

Output:

 0 0 0    . . .
0 . . 0  . o o .
0 --- 0  . \_/ .
 0 0 0    . . .
\$\endgroup\$
1
\$\begingroup\$

CJam, 18

I decided to go for short code... Try it here.

" ##O#- #"2/{_(N}%

Explanation

" ##O#- #"      "Push a string onto the stack";
2/              "Split it into an array of two-character groups";
{_(N}%          "For each item in the array, execute _(N : duplicate the element,
                 remove the first character and place it onto the stack after what's left,
                 and push a new line.";

This exploits the symmetry of the smiley face I designed.

Output

 ## 
#OO#
#--#
 ## 
\$\endgroup\$
3
  • 1
    \$\begingroup\$ This face it not smiling ;). \$\endgroup\$
    – Optimizer
    Commented Dec 26, 2014 at 21:49
  • \$\begingroup\$ @Optimizer It's closer to a smile than this... Because of how I've used symmetry, you can't have a smile here. \$\endgroup\$
    – user16402
    Commented Dec 26, 2014 at 21:53
  • \$\begingroup\$ Using uu for the smile is an option, if you're going for that "cat" kind of smile... \$\endgroup\$
    – mbomb007
    Commented Jan 16, 2015 at 17:42
1
\$\begingroup\$

Python

smileyFace = '''
       000000000000000
      00000000000000000
     000000   00   00000
    0000000 . 00 . 000000
   00000000   00   0000000
  0000000000000000000000000
 000000 . 00000000 . 0000000
  000000 . 000000 . 0000000
   0000000 ....... 0000000
    000000000000000000000
     0000000000000000000
      00000000000000000'''
print(smileyFace)

print('  _________\n /         \\\n |  /\\ /\\  |\n |    -    |\n |  \\___/  |\n \\_________/');

Output:

  _________
 /         \
 |  /\ /\  |
 |    -    |
 |  \___/  |
 \_________/
\$\endgroup\$
2
  • \$\begingroup\$ second example is missing the circle \$\endgroup\$
    – Jasen
    Commented Dec 26, 2014 at 22:50
  • \$\begingroup\$ @Jasen I fixed it. \$\endgroup\$
    – Oliver Ni
    Commented Dec 27, 2014 at 2:10
1
\$\begingroup\$

Javascript console

a frog:

prompt("◉◉ ", ' '.repeat(25)+"⊂(‿)つ")  

table flip

prompt("┻━┻", ' '.repeat(24)+"ʕノ•ᴥ•ʔノ") 

and i am not sure what this one is

prompt('◕  '.repeat(24),prompt("◕              ◕", '  ▇  '.repeat(24))) 
\$\endgroup\$
0
\$\begingroup\$

Python, 42

print ' 0 0 0 \n0 . . 0\n0 --- 0\n 0 0 0 '
\$\endgroup\$
0
\$\begingroup\$

HTML 5 : 321 Characters

<canvas id=a><script>_=document.getElementById("a"),c=_.getContext("2d"),p=Math.PI,P=2*p;C();c.arc(95,85,40,0,P);B();c.lineWidth=2;c.stroke();c.fillStyle="red";C();c.arc(75,75,5,0,P);B();C();c.arc(114,75,5,0,P);B();C();c.arc(95,90,26,p,P,true);B();function C(){c.beginPath()};function B(){c.closePath();c.fill()}</script>

Fiddle : http://jsfiddle.net/wfNGx/

enter image description here

Source : http://www.codecademy.com/courses/web-beginner-en-SWM11/0/1

\$\endgroup\$
0
\$\begingroup\$

Shell command or builtin

$ echo -e ' ,---.\n/ o o \\\n\ \\_/ /\n `---´'
 ,---.
/ o o \
\ \_/ /
 `---´
$ printf ' ,---.\n/ o o \\\n\ \\_/ /\n `---´\n'
 ,---.
/ o o \
\ \_/ /
 `---´

Depending on the flavour of your shell or command set, echo may or may not interprete control characters with or witout -e... (...and I demand that I may or may not be Vroomfondel!) just try... and if all else fails, using printf should be a safe bet...

\$\endgroup\$

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