QBasic/3D Graphics

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Simple 3D Box[edit | edit source]

3 Dimension or 3D graphics in Qbasic is nothing , but including an additional 'z' axis and to extend the 2 dimensional structure along that axis. This can be achieved by drawing a box, or the structure you want , each time at a new x and y position. It is quite like animation, except, we do not erase the structure after it being drawn , and there is no need of any intermediate pause. You can better understand by looking at the 3d box program given below.

Redo:
cls
screen 1
Input "Enter the X-position?";k  'entering coordinates of the screen from where to start.
Input "Enter the Y-position?";l   ' this also determines the size of the box.
color 1
for i = 1 to 50 step 2   rem box ' step to ensure space between the boxes, make it one to eliminate the space. The 50 number sets the extension of the box along the z axis
    a = k+i:b = l+i          ' this "for-next" loop draws the box over and over again, each with incremented values of k and l.
    line (a,a)-(b,a)
    line (a,b)-(b,b)
    line (a,a)-(a,b)
    line (b,a)-(b,b)
next                            rem diagonals
line (k,k)-(a,a)              ' the four diagonals to the structure , which make it more realistic
line (l,l)-(b,b)
line (l,k)-(b,a)
line (k,l)-(a,b)
Input"Do you want to redo? (Y/N)";ans$
if ucase$(ans$)="Y" then goto Redo
end