跳轉到內容

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
華夏公益教科書