跳转到内容

QBasic/3D 图形

来自维基教科书,开放的书籍,为开放的世界

简单的 3D 盒子

[编辑 | 编辑源代码]

在 Qbasic 中,三维或 3D 图形不过是添加了额外的 'z' 轴,并沿着该轴扩展二维结构。这可以通过在每次绘制时使用新的 x 和 y 位置来绘制一个盒子或你想要绘制的结构来实现。这非常像动画,不同的是,我们不会在绘制完结构后擦除它,也不需要任何中间暂停。你可以通过查看下面给出的 3d 盒子程序来更好地理解。

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
华夏公益教科书