# Shortest program that displays a red 3D cube [closed]

Write the shortest program you can that displays a red 3D cube.

Rules:

• The cube must be red, have 6 rendered sides, and be displayed in 3D.
• More than 1 side must be visible.
• The result does not need to be rotatable.

## closed as unclear what you're asking by Sriotchilism O'Zaic, user62131, mbomb007, Toto, SteadyboxMay 2 '17 at 17:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• i think u need to add a condition that more than 1 side is visible. – user13107 Mar 4 '14 at 3:19
• Only few languages would do the job for "must use either Direct3D or OpenGL" and like have been said, include a sample and How many sides? Is there a degree? – Dadan Mar 4 '14 at 10:27
• What does "red, have 6 sides and be 3D" mean? Did you mean that there needs to be shading? That we have to actually draw 6 sides, but only 2 or 3 have to be visible? Did you mean that the displayed result has to rotatable? – Justin Mar 4 '14 at 19:02
• @Quincunx sorry if what I said was unclear. The cube has to be a solid red colour and 6 sides must be rendered but only 2 or 3 sides must be visible. The result doesn't have to be rotatable. – icedvariables Mar 4 '14 at 19:30
• What do you mean by 'cannot load any textures'? Do you mean that you can't simply load an image of a red cube or that you can't use textures to make the cube red? – Stephen Melvin Mar 5 '14 at 15:58

## T-SQL, 168 chars (but no OpenGL)

Decidedly not using OpenGL or Direct3D because there is absolutely no way to do that in SQL. I think I have a pretty nice little cube, anyway.

RAISERROR('
@@@
@@@@@@@@@
@@@@@@@@@@@@@@@
x@@@@@@@@@@@@&&
xxx@@@@@@@@&&&&
xxxxx@@@&&&&&&&
xxxxxx&&&&&&&&&
xxxxx&&&&&&&
xxx&&&&
x&&
',15,1)


Exploiting the fact that errors of high severity are raised in red:

• Nice rule bending! – Ismael Miguel Mar 3 '14 at 23:09
• There are some trailing spaces in cube's 2nd line. Without them is just 156 characters long. If you specify the code block's language as “lang-sql”, the cube will be red even in the source code. – manatwork Mar 4 '14 at 19:22
• Yeah, I deliberately didn't super-golf this one because it is technically against the rules since it uses no OpenGL/Direct3D. People can vote me up if they like but I shouldn't win here. – Jonathan Van Matre Mar 4 '14 at 19:46
• If lazy answers like this are upvoted, what incentive is there to work on real solutions? – Stephen Melvin Mar 5 '14 at 16:13
• I don't consider it a lazy answer - I drew my cube by hand! How is that more lazy than using a built-in Cuboid/cube function in Mathematica/Sage? Toward your question of incentive, I offer my own incentive for this answer: self-amusement. I fully expected a healthy heap of downvotes, but I made (and honestly advertised) this non-compliant answer for my own delight. If your work isn't for your own pleasure, what is it good for? – Jonathan Van Matre Mar 5 '14 at 16:27

## Mathematica 25

Graphics3D@{Red,Cuboid[]}


Instructions for testing this answer without Mathematica installed:

2. Dowload the free CDF environment from Wolfram Research at https://www.wolfram.com/cdf-player/ (not a small file)
3. The cube can be "dragged" to rotate it!
• Kudos for including CDF instructions! – Jonathan Van Matre Mar 3 '14 at 22:15
• @JonathanVanMatre Thanks! One of the major problems for using Mathematica solutions in this site is the need for a non-free environment to test them. That can be overcome (to a certain extent) by sharing CDF documents. – Dr. belisarius Mar 3 '14 at 22:20
• Does mathematica use OpenGL? – TheDoctor Mar 3 '14 at 22:30
• @TheDoctor Short answer:"yes".Long answer: "You can configure it" (support.wolfram.com/kb/3303) – Dr. belisarius Mar 3 '14 at 22:54

# TXT, 12 bytes

This is a TXT file with ANSI escape codes and UTF-8 characters. I can show its contents as a C string:

"\033[31m\xe2\xac\xa2\033[m\n"


or as a hexdump:

0000000: 1b5b 3331 6de2 aca2 1b5b 6d0a            .[31m....[m.


This is the result when it is "executed" with cat on a terminal.

You can see the small cube, solid red, with 3 visible faces and no texture loaded:

• This is a really clever answer, but txt doesn't technically meet the criteria for a programming language – DJMcMayhem May 15 '16 at 5:14
• But you could use /// or PHP as a workaround. – jimmy23013 May 15 '16 at 11:03
• I´d use some *nix shell for that. – Titus Jan 6 '17 at 0:06

May i be the first to...

# Processing, 513 110

void setup(){size(640,360,P3D);}void draw(){fill(255,0,0);translate(width/2,height/2,0);rotateX(0.7);box(99);}


• So far the only actual OpenGL answer.. – TheDoctor Mar 3 '14 at 22:31
• Mathematica uses OGL and D3D under the hood, although the problem becomes "How do you prove it was used when this particular graphic was rendered?" There is probably a way to do that in MM; I just don't know what it is. I upvoted you because I like your choice of perspective. – Jonathan Van Matre Mar 3 '14 at 23:07
• You can reduce some characters by using a smaller size i.e. size(99,99,P3D); and then use 50 instead of width/2 and height/2 in your translate(). Also, you can remove the 0 in the 0.7, i.e. make it rotateX(.7);. Also remember to scale down the box. Finally, you can move everything into setup() and delete the void draw() altogether. – ace Mar 3 '14 at 23:13
• Too bad there's no award for most improved, because it would surely be yours. – Jonathan Van Matre Mar 5 '14 at 18:07

# Sage, 17

Note: after some research I realised that this does not use OpenGL.

cube(color='red')


Output:

I can finally beat Mathematica!

It uses Jmol (which comes with the Sage installation) to show the cube, which allows rotation by dragging.

• Does this use OpeGL? – TheDoctor Mar 3 '14 at 22:31
• Nice:). How many chars does it cost to remove the numbers? – Dr. belisarius Mar 3 '14 at 22:31
• @belisarius I'm quite new to this Sage thing, and after going through the documentation I can't seem to find a way to remove the axes. Sorry. – ace Mar 3 '14 at 23:05
• @TheDoctor Sorry, no. Added a note in the answer to state that. – ace Mar 3 '14 at 23:06
• Looks like OpenGL/Direct has been dropped from the requirements. – Stephen Melvin Mar 5 '14 at 16:13

# Processing, 68 Chars

Ultra-golf version of @TheDoctor 's answer, using tips from @Ace, plus one of my own (rotation.)

void setup(){size(99,99,P3D);fill(#FF0000);translate(9,9,0);box(9);}


Produces a pathetically small cube of just 9 units per side (image at left.) Changing the 9's to 25's we get a larger cube (image at right.)

By keeping the cube far from the centre of the window, we can see the bottom and right hand side without needing to rotate (if it was in the centre of the window, they would be hidden.

• Colour in Processing is a 4-byte value: alpha(opaqueness),R,G,B. The # notation implies an opaqueness of FF. I just found I can save 1 character by specifiying the colour as -65536, which gets coerced into 0xFFFF0000 unsigned. -9766=-38*(256+1) gives a pale pink cube. – Level River St Mar 5 '14 at 11:27

# Mathematica 9, 21

Image3D@{{{{3,0,0}}}}


# Mathematica 10, 17

Image3D@{{{Red}}}


# Windows Batch, 51 chars

@echo off
color 0c
echo   _
echo /!_!
echo |/_/


I know this is cheating, but at least I get bronze (at the time this was posted). Partially inspired by Jonathan van Matre's answer.

• Haha, chutzpah! – Jonathan Van Matre Mar 4 '14 at 15:20

# Postscript 920

Requires mat.ps.

/olddiv/div load def/div{dup 0 eq{pop pop
100000}{olddiv}ifelse}def(mat.ps)run/disp<</cam[0
0 10]/theta[0 0 0]/eye[0 0 20]/Rot 3 ident>>def/makerot{theta
0 get roty theta 1 get rotx matmul theta 2 get rotz matmul}def/proj{DICT
begin cam{sub}vop Rot matmul 0 get aload pop eye aload pop 4 3 roll div
exch neg 4 3 roll add 1 index mul 4 1 roll 3 1 roll sub mul exch end}dup
0 disp put def/v[[1 1 -1][-1 1 -1][-1 -1 -1][1 -1 -1][1 1 1][-1 1 1][-1 -1 1][1 -1 1]]def
/fv[[0 1 2 3][0 4 5 1][1 5 6 2][2 6 7 3][3 7 4 0][4 7 6 5]]def/R 20 def/H -3 def/ang 0 def
{300 700 translate 1 70 dup dup scale div setlinewidth
disp begin/cam[ang sin R mul H ang cos R mul]def/theta[ang H R atan 0]def/Rot makerot def end
fv{{v exch get proj}forall moveto lineto lineto lineto closepath 1 0 0 setrgbcolor fill}forall
fv{{v exch get proj} forall moveto lineto lineto lineto closepath 0 setgray stroke}forall


Ungolfed and commented.

%!
/div{dup 0 eq{pop pop 100000}{olddiv}ifelse}def
(mat.ps)run

/disp <<
/cam [ 0 0 10 ] % Camera position
/theta [ 0 0 0 ] % Rotation sequence
/eye [ 0 0 20 ] % Eye relative to image surface
/Rot 3 ident
>> def

/makerot {
theta 0 get roty
theta 1 get rotx matmul
theta 2 get rotz matmul
} def

% Ax Ay Az
/proj { DICT begin
%3 array astore
%dup == flush
cam {sub}vop %Camera translation
%pstack()=
Rot matmul %Camera rotation
0 get aload pop % Dx Dy Dz
eye aload pop % Dx Dy Dz Ex Ey Ez
%pstack()=
4 3 roll div % Dx Dy Ex Ey Ez/Dz
exch neg % Dx Dy Ex Ez/Dz -Ey
4 3 roll add % Dx Ex Ez/Dz Dy-Ey
1 index mul % Dx Ex Ez/Dz Ez(Dy-Ey)/Dz
4 1 roll 3 1 roll % Ez(Dy-Ey)/Dz Ez/Dz Dx Ex
sub mul exch % Ez(Dx-Ex)/Dz Ez(Dy-Ey)/Dz
%pstack ()=
end } dup 0 disp put def

/v [[  1  1  -1 ] %cube vertices
[ -1  1  -1 ]
[ -1 -1  -1 ]
[  1 -1  -1 ]
[  1  1   1 ]
[ -1  1   1 ]
[ -1 -1   1 ]
[  1 -1   1 ]] def
/fv [[ 0 1 2 3 ] %cube faces out of vertices
[ 0 4 5 1 ]
[ 1 5 6 2 ]
[ 2 6 7 3 ]
[ 3 7 4 0 ]
[ 4 7 6 5 ]
] def

/R 20 def
/H -3 def
/ang 0 def

{
300 700 translate
1 70 dup dup scale div setlinewidth

disp begin
/cam [ ang sin R mul  H  ang cos R mul ] def
/theta [ ang  H R atan  0 ] def
/Rot makerot def
end

fv {
{ v exch get proj } forall
moveto lineto lineto lineto closepath
1 0 0 setrgbcolor fill
} forall

fv {
{ v exch get proj } forall
moveto lineto lineto lineto closepath
0 setgray stroke
} forall

showpage
} loop


## JAVASCRIPT - TQUERY (108 chars)

w=tQuery.createWorld().boilerplate().start();tQuery.createCube().addTo(w).setBasicMaterial().color(0xff0000)
<script src="https://jeromeetienne.github.io/tquery/build/tquery-bundle.js"></script>

http://jsfiddle.net/Gy4w7/335/

## RBX.Lua, 83 bytes

s=Instance.new("Part",workspace)s.BrickColor=BrickColor.new(21)s.Size=Vector3.new()


Result:

Explanation:

s=Instance.new("Part",workspace)  Instances a new Brick in the world.
s.BrickColor=BrickColor.new(21)   Makes it red. 21 is the color code for "Bright red".
s.Size=                           We have to set the size, because a brick isn't cubic.
Vector3.new()                     Initiates a [0, 0, 0] size. The brick rounds this up
to the minimum size.