Shortest program that displays a red 3D cube

2

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.
  • Your program cannot load any textures.
  • More than 1 side must be visible.
  • The result does not need to be rotatable.

icedvariables

Posted 2014-03-03T21:30:58.567

Reputation: 453

Question was closed 2017-05-02T17:58:49.747

I think this needs to be tagged [tag:graphical-output] or this question should be closed as unclear. – mbomb007 – 2017-05-02T17:31:39.467

In respect to the close vote going on at the moment: I don't think this is specified enough. For example, does an orthographic projection count as 3D? What about an isometric projection? The question asks for a projection to be hardcoded ("does not need to be rotatable"); is it sufficient to instead hardcode the projected locations of the points? Is any lighting required, or can all the sides be the exact same shade of red? If so, is it legal to just draw a solid rectangle/hexagon, or must it be drawn as two rectangles/parallelograms/trapezia? – None – 2017-05-02T17:32:15.407

Someone answer in Minecraft – mbomb007 – 2017-05-02T17:34:19.287

8i think u need to add a condition that more than 1 side is visible. – user13107 – 2014-03-04T03:19:50.780

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 – 2014-03-04T10:27:48.453

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 – 2014-03-04T19:02:16.610

@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 – 2014-03-04T19:30:50.370

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 – 2014-03-05T15:58:36.400

Generally, you should not change the contest rules after answers have been given. If you do so, it should be only to add clarification of what was meant by the rules already given. – Jonathan Van Matre – 2014-03-05T16:17:18.287

Answers

28

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:

srs errr

Jonathan Van Matre

Posted 2014-03-03T21:30:58.567

Reputation: 2 307

Nice rule bending! – Ismael Miguel – 2014-03-03T23:09:07.987

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 – 2014-03-04T19:22:57.070

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 – 2014-03-04T19:46:49.920

If lazy answers like this are upvoted, what incentive is there to work on real solutions? – Stephen Melvin – 2014-03-05T16:13:57.620

7I 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 – 2014-03-05T16:27:00.337

13

Mathematica 25

Graphics3D@{Red,Cuboid[]}

Mathematica graphics

Instructions for testing this answer without Mathematica installed:

  1. Download http://pastebin.com/3dnGNHCP and save it as *.CDF
  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!

Dr. belisarius

Posted 2014-03-03T21:30:58.567

Reputation: 5 345

Kudos for including CDF instructions! – Jonathan Van Matre – 2014-03-03T22:15:51.370

@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 – 2014-03-03T22:20:49.313

Does mathematica use OpenGL? – TheDoctor – 2014-03-03T22:30:54.997

@TheDoctor Short answer:"yes".Long answer: "You can configure it" (http://support.wolfram.com/kb/3303)

– Dr. belisarius – 2014-03-03T22:54:19.337

10

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:
cube.txt

Tobia

Posted 2014-03-03T21:30:58.567

Reputation: 5 455

3

This is a really clever answer, but txt doesn't technically meet the criteria for a programming language

– James – 2016-05-15T05:14:48.617

3But you could use /// or PHP as a workaround. – jimmy23013 – 2016-05-15T11:03:55.797

I´d use some *nix shell for that. – Titus – 2017-01-06T00:06:15.187

7

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

example

TheDoctor

Posted 2014-03-03T21:30:58.567

Reputation: 7 793

So far the only actual OpenGL answer.. – TheDoctor – 2014-03-03T22:31:50.080

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 – 2014-03-03T23:07:38.860

1You 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. – user12205 – 2014-03-03T23:13:04.967

1Too bad there's no award for most improved, because it would surely be yours. – Jonathan Van Matre – 2014-03-05T18:07:33.240

6

Sage, 17

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

cube(color='red')

Output:

enter image description here

I can finally beat Mathematica!

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

user12205

Posted 2014-03-03T21:30:58.567

Reputation: 8 752

Does this use OpeGL? – TheDoctor – 2014-03-03T22:31:13.437

Nice:). How many chars does it cost to remove the numbers? – Dr. belisarius – 2014-03-03T22:31:44.620

@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. – user12205 – 2014-03-03T23:05:48.423

@TheDoctor Sorry, no. Added a note in the answer to state that. – user12205 – 2014-03-03T23:06:14.017

Looks like OpenGL/Direct has been dropped from the requirements. – Stephen Melvin – 2014-03-05T16:13:17.180

@belisarius I just found out, to remove the numbers I can do cube(color='red',frame=0) which costs an extra of 8 chars. – user12205 – 2014-03-05T23:30:39.367

@ace Good! Now you know more Sage! :) – Dr. belisarius – 2014-03-05T23:54:52.227

3

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.

enter image description here

Level River St

Posted 2014-03-03T21:30:58.567

Reputation: 22 049

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 – 2014-03-05T11:27:31.337

3

Mathematica 9, 21

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

enter image description here


Mathematica 10, 17

Image3D@{{{Red}}}

alephalpha

Posted 2014-03-03T21:30:58.567

Reputation: 23 988

2

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.

Gavriel Feria

Posted 2014-03-03T21:30:58.567

Reputation: 51

Haha, chutzpah! – Jonathan Van Matre – 2014-03-04T15:20:10.930

1

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/

rafaelcastrocouto

Posted 2014-03-03T21:30:58.567

Reputation: 315

1

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
showpage/ang ang 3 add def}loop

Ungolfed and commented.

%!
/olddiv/div load def
/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
    /ang ang 3 add def
} loop

luser droog

Posted 2014-03-03T21:30:58.567

Reputation: 4 535

0

RBX.Lua, 83 bytes

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

Result:

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.

devRicher

Posted 2014-03-03T21:30:58.567

Reputation: 1 609