Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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.

share|improve this question
    
5  
Wow, 8 questions on the hot question list. Our site should be getting more traffic. –  Quincunx Dec 29 '13 at 6:27
    
Isn't indifferent face strictly easier than happy, and sad sometimes more difficult? –  Lohoris Dec 29 '13 at 13:50
2  
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. –  Dryden Long Dec 30 '13 at 17:30
1  
Will this thread ever end? :) –  avall Jan 13 at 10:43

31 Answers 31

up vote 83 down vote accepted

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

share|improve this answer
18  
In the name of Bwian of Judea, what is this... –  nitro2k01 Dec 29 '13 at 12:08
1  
Now it's working. Took me about 2m to close all popups –  the_Seppi Dec 29 '13 at 20:27
5  
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! –  CharityAbbott Dec 30 '13 at 1:54
1  
Amazing out-of-the-box thought! I would never think to do something like this. –  Gari BN Jan 16 at 10:01
1  
That's outstandingly original! –  Oberon Jan 16 at 14:16

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:

:-|

share|improve this answer
2  
+1 really cool :D –  Songo Dec 29 '13 at 22:24
3  
This is art :P –  Jefffrey Dec 29 '13 at 22:53
3  
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 –  avall Dec 30 '13 at 0:38
    
@avall Excellent, thanks :-) –  squeamish ossifrage Dec 30 '13 at 0:55
    
158 chars and now centers the hair so it looks good on any size screen. jsfiddle.net/TdPkF/5 –  AverageMarcus Dec 30 '13 at 8:27

Brainfuck: 583 characters (without counting whitespace)

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

Output:

\|/ ____ \|/       
 @~/ ,. \~@        
/_( \__/ )_\       
   \__U_/
share|improve this answer
10  
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... –  handuel Dec 29 '13 at 18:25
1  
@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. –  Sylwester Dec 29 '13 at 18:30
    
I just meant for the code to look more like a face, I didn't realize it was intentional. –  handuel Dec 29 '13 at 18:31
9  
+1 I thought the code was the face :))))) –  Songo Dec 29 '13 at 22:25
1  
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. –  Emil Vikström Jan 1 at 22:35

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

share|improve this answer
    
Infinite units? –  user80551 Dec 31 '13 at 15:02
3  
The right tool for the right job. –  Alpha Jan 3 at 2:02

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:

                $$$$$$$$$$$$$$$$$$$$
          $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
       $$$$$$$$$$$$$   $$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$     $$$$$$$$$$$$$$$$$$$$$$$
   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$   $$$$$$$$$$$$$$
  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$     $$$$$$$$$$$$$$
  $$$$$$$$$$$$   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
   $$$$$$$$$$$$$      $$$$$$$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$              $$$$$$$$$$$$$
      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
          $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
                $$$$$$$$$$$$$$$$$$$$
share|improve this answer
    
Does the second example count? There's no circle around the face. –  Kevin Dec 29 '13 at 19:01
1  
@Kevin, good point. Amended. –  Darren Stone Dec 29 '13 at 19:42

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.

share|improve this answer
    
I feel that I may be the youngest person here who can still read QBASIC... :) Nice one –  anorton Dec 30 '13 at 16:45

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)

share|improve this answer
2  
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.) –  nitro2k01 Dec 29 '13 at 22:10
4  
Where's the challange in posting a smiley in pastebin and downloading it using wget? –  the_Seppi Dec 30 '13 at 11:34
    
@the_Seppi: that's exactly the joke. It's intended as a thinking-outside-the-box solution. –  Riot Dec 30 '13 at 15:29
    
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. –  marinus Dec 31 '13 at 5:46
1  
beautiful, this is my favorite :) –  jco Dec 31 '13 at 15:45

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.

share|improve this answer

Bash, 63 chars

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

Output:

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

Artistry:

Cows.

share|improve this answer

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

share|improve this answer

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";
}

It surprisingly compiles and runs without return 0.

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

ASCII art image

share|improve this answer
2  
return 0; is not required in ISO C++ :) –  Jefffrey Dec 29 '13 at 12:03
    
Thanks. That will help cut characters in future puzzles. –  hosch250 Dec 29 '13 at 14:52

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

share|improve this answer

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

share|improve this answer
    
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;}. –  manatwork Dec 30 '13 at 12:40

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.

share|improve this answer
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`
               `^^^^^'`
share|improve this answer

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.

share|improve this answer

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

share|improve this answer

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

share|improve this answer

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;}
share|improve this answer
1  
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. –  manatwork Dec 30 '13 at 11:53

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

share|improve this answer

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

share|improve this answer
    
I like it more with border-radius:50% and a single <hr>: dabblet.com/gist/8472397 –  manatwork Jan 17 at 12:08
    
@manatwork or like this: jsfiddle.net/T9BdL/1 –  Tim Seguine Jan 17 at 12:11
1  
@TimSeguine, using a literal non-breaking space character is shorter than &nbsp;: jsfiddle.net/T9BdL/2 –  manatwork Jan 17 at 12:23
1  
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. –  Leo Pflug Jan 17 at 12:39
2  
Not really golfed, but as requested, a css only version: jsfiddle.net/T9BdL/9 –  Tim Seguine Jan 17 at 13:54

Brainf*** - 2

+.

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

share|improve this answer
    
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. –  Christopher Creutzig Dec 29 '13 at 9:42
2  
@ChristopherCreutzig It does not fail that condition. Each eye is 1 or so pixels, the mouth is more than twice as large. –  Quincunx Dec 29 '13 at 15:57
    
The exp. "ASCII ART" consists of two parts. I see neither of them here –  the_Seppi Dec 30 '13 at 11:37

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:

''&&&&&'
'&&'&'&&
'&&&&&&&
'&'&&&'&
'&&'''&&
''&&&&&'
share|improve this answer

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)
share|improve this answer

Python, 42

print ' 0 0 0 \n0 . . 0\n0 --- 0\n 0 0 0 '
share|improve this answer

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

share|improve this answer

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    . . .
share|improve this answer

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

share|improve this answer

JavaScript 25

document.write("&#9786;")

Providing you have Arial Unicode MS installed (and most modern day machines do...) you should get the Unicode smiley face! Granted, it's a little cheaty, but it satisfies all the requirements:

A smiley face is composed of a shape that resemble a circle (not necessarily perfect) of any radius. (Check! The shape resembles a circle)

There must be at least 1 unit for each of the two eyes and at least 2 units for the mouth. (Check! Given the rule for a unit also allowing for pixels, this rule is also satisfied!)

Both eyes and mouth should be within the face shape. (Check, eyes and mouth are wholly within the face shape!)

The mouth can be oriented however you want (happy, sad, indifferent, etc..). (Check! Already smiling!)

share|improve this answer

Plain text, 1​​​​​

It looks good and is scalable, too.

share|improve this answer
6  
Looks like the squared face guy sitting in front of me (a.k.a a box). –  FrenzY DT. Dec 29 '13 at 4:25
2  
Doesn’t seem to me to use enough “units.” –  Christopher Creutzig Dec 29 '13 at 9:44
5  
The whole idea in defining a "unit" was to prevent this kind of answers, that have, already, been posted here. –  Jefffrey Dec 29 '13 at 12:05
1  
@Jefffrey: I wasn’t going to add this one, but then I read that in your definition of “units” you also said “pixels”. I’ll delete it if you’d like to clarify that, though. –  U2744 SNOWFLAKE Dec 29 '13 at 19:16
1  
I just see a box (Google Chrome Version 31.0.1650.63 m). Where are the eyes and mouth? –  user13267 Dec 31 '13 at 8:40

protected by Community Dec 31 '13 at 6:40

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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