2
\$\begingroup\$

The goal is to write the smallest program in any language which displays any three dimensional output. It might be graphics, it might be ASCII art, but any reasonable person should immediately and unambiguously recognize it as "something 3d".

Opening external files or other resources is not allowed. All output has to be generated by your program.

The shortest code with a score higher than 1 wins.

\$\endgroup\$
7
  • 8
    \$\begingroup\$ Where are you going to find a reasonable person? This isn't objective enough to be called a spec. \$\endgroup\$ Apr 25, 2013 at 8:39
  • 4
    \$\begingroup\$ @vsz, there are so many trivial answers to this question that you are probably better off making it a pure popularity contest. \$\endgroup\$
    – user7486
    Apr 25, 2013 at 10:03
  • 2
    \$\begingroup\$ @dan1111, or closing it as "not a constructive question". \$\endgroup\$ Apr 25, 2013 at 10:18
  • 3
    \$\begingroup\$ FWIW, there was an attempt in the sandbox (which might still be ongoing) to define a good 3D drawing question \$\endgroup\$ Apr 25, 2013 at 10:20
  • 1
    \$\begingroup\$ from the CowSay question: codegolf.stackexchange.com/a/11252/5011 (not mine, so not taking credit) \$\endgroup\$
    – SeanC
    Apr 25, 2013 at 15:05

11 Answers 11

18
\$\begingroup\$

QBASIC 211 bytes

SCREEN 13
WINDOW(-160,-100)-(159,99)
FOR x=0TO 63
 PALETTE x,x*65793
NEXT
FOR i=16TO-16STEP-.1
 FOR j=16TO-16STEP-.05
  s=SQR(i*i/2+j*j/2)
  PSET(i*10,j*5+17.32*COS(s)),18.2*(COS(s)-SIN(s)*j/s)+31+RND
 NEXT
NEXT

The color for each pixel is chosen by adding the z value on the curve with the partial derivative with respect to y, generating a 'fake' lighting effect. The added random value helps to smooth the borders between regions. Produces something similar to the following:

enter image description here

\$\endgroup\$
1
  • 1
    \$\begingroup\$ That's a blast from the past. \$\endgroup\$
    – recursive
    Sep 23, 2020 at 20:14
14
\$\begingroup\$

HTML, 1 character

This will appear as:

There are several other characters that look three dimensional (at least to me) if you don't like that one:

❒ ❍ ✰ ✞ ➫ ➮ ➪ ♨ ✐ ✏

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

PHP, 23 characters

<?=" __\n/_/|\n|_|/\n";

Outputs:

 __
/_/|
|_|/
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Why not do it in GolfScript? You can use newline for one char rather than two inside ' \$\endgroup\$ Apr 25, 2013 at 8:25
7
\$\begingroup\$

Logo, 31 characters

My Logo is a bit rusty, but this should draw a torus:

repeat 180[rt 2 circle 45 fw 3]

Torus

Run it online: http://logo.twentygototen.org/9NxYy2Pw.

\$\endgroup\$
6
\$\begingroup\$

Lua, 12 characters

print'(.Y.)'
\$\endgroup\$
6
\$\begingroup\$

Mathematica 19

Graphics3D@Cuboid[]

3D

\$\endgroup\$
6
\$\begingroup\$

Python, 11 characters

print'()))'

Prints:

()))

It's a tube an overturned barrel.

\$\endgroup\$
2
  • \$\begingroup\$ +1 for linking to the Wikipedia page for cylinders, because the concept of tube definitely needed more explanation :D \$\endgroup\$
    – user7486
    Apr 25, 2013 at 10:23
  • \$\begingroup\$ Overturned barrel? \$\endgroup\$ Apr 25, 2013 at 13:05
5
\$\begingroup\$

Perl, 7 characters

print A

Prints a road (which has a line painted across it) receding into the distance.

\$\endgroup\$
2
  • 5
    \$\begingroup\$ ...looks more like the letter A to me :P \$\endgroup\$
    – Volatility
    Apr 25, 2013 at 9:34
  • 3
    \$\begingroup\$ @Volatility, then according to my working definition of reasonable, you aren't reasonable :) \$\endgroup\$
    – user7486
    Apr 25, 2013 at 9:38
4
\$\begingroup\$

Python 337 bytes

from pygame import*
from math import*
init();d=display;s=d.set_mode((640,480));a=0
def R(x,y,z,a):c,s=cos(a),sin(a);y,z=y*c-z*s,y*s+z*c;z,x=x*s-z*c-8,z*s+x*c;f=1e3/z;return-f*x+320,f*y+240
while s.fill(time.wait(5)):event.get();t=[R(x,y,z,a)for x in-1,1for y in-1,1for z in-1,1];[draw.line(s,-1,i,j)for i in t for j in t];a+=.01;d.flip()

A basic cube spinner.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Put R on one line, replace the nested for loop with [draw.line(s,-1,i,j)for i in t for j in t] and then put the whole while loop on a single line. That'll save you quite a few bytes. \$\endgroup\$
    – Volatility
    Apr 25, 2013 at 10:18
3
\$\begingroup\$

R - 73 characters

Way longer than the previous answer but i like it:

t=seq(0,2*pi,.01);r=1e3:1;plot(r%o%cos(t),r%o%sin(t),col=grey(1:1e3/1e3))

enter image description here

Basically draw a thousand circles of decreasing radius and shade of grey. Because of the default aspect ratio the result is more an ellipsoid than a sphere however.

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

Python, 0 characters

Output:

>>>

Which can only reasonably be interpreted as some sort of angled surface :). I prefer to think of it as a jagged, concave cliff face.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ To me seems like the first step of a paper folding diagram… \$\endgroup\$
    – manatwork
    Apr 25, 2013 at 10:11
  • \$\begingroup\$ LOL !!! 0 Charachters solution !! :D \$\endgroup\$ May 2, 2013 at 11:03

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