How to resolve the algorithm Draw a cuboid step by step in the XPL0 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Draw a cuboid step by step in the XPL0 programming language

Table of Contents

Problem Statement

Draw a   cuboid   with relative dimensions of   2 × 3 × 4.

The cuboid can be represented graphically, or in   ASCII art,   depending on the language capabilities. To fulfill the criteria of being a cuboid, three faces must be visible. Either static or rotational projection is acceptable for this task.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Draw a cuboid step by step in the XPL0 programming language

Source code in the xpl0 programming language

include c:\cxpl\codes;                  \intrinsic 'code' declarations
real X, Y, Z, Farthest;                 \arrays: 3D coordinates of vertices
int  I, J, K, SI, Segment;
def  Size=50.0, Sz=0.008, Sx=-0.013;    \drawing size and tumbling speeds
[X:= [-2.0, +2.0, +2.0, -2.0,  -2.0, +2.0, +2.0, -2.0];
 Y:= [-1.5, -1.5, +1.5, +1.5,  -1.5, -1.5, +1.5, +1.5];
 Z:= [-1.0, -1.0, -1.0, -1.0,  +1.0, +1.0, +1.0, +1.0];
Segment:= [0,1, 1,2, 2,3, 3,0, 4,5, 5,6, 6,7, 7,4, 0,4, 1,5, 2,6, 3,7];
SetVid($101);                           \set 640x480 graphics with 256 colors
repeat  Farthest:= 0.0;                 \find the farthest vertex
        for I:= 0 to 8-1 do
            if Z(I) > Farthest then [Farthest:= Z(I);  SI:= I];
        Clear;                          \erase screen
        for I:= 0 to 2*12-1 do          \for all the vertices...
            [J:= Segment(I);  I:= I+1;  \get vertex number
            Move(fix(X(J)*Size)+640/2, fix(Y(J)*Size)+480/2);
            K:= Segment(I);
            Line(fix(X(K)*Size)+640/2, fix(Y(K)*Size)+480/2,
                if J=SI ! K=SI then $F009 \dashed blue\ else $C \red\);
            ];
        Sound(0, 1, 1);                 \delay 1/18 second to prevent flicker
        for I:= 0 to 8-1 do
            [X(I):= X(I) + Y(I)*Sz;     \rotate vertices in X-Y plane
             Y(I):= Y(I) - X(I)*Sz;
             Y(I):= Y(I) + Z(I)*Sx;     \rotate vertices in Y-Z plane
             Z(I):= Z(I) - Y(I)*Sx;
            ];
until KeyHit;                           \run until a key is struck
SetVid(3);                              \restore normal text mode (for DOS)
]

  

You may also check:How to resolve the algorithm Subtractive generator step by step in the jq programming language
You may also check:How to resolve the algorithm First-class functions step by step in the Racket programming language
You may also check:How to resolve the algorithm Inconsummate numbers in base 10 step by step in the Wren programming language
You may also check:How to resolve the algorithm Compare a list of strings step by step in the Plain English programming language
You may also check:How to resolve the algorithm Nth root step by step in the Forth programming language