---
# System prepended metadata

title: 建立物件
tags: [選修]

---

## 學習目標
學習如何建立物件，並賦予物件不同的屬性，如：物件的顏色與位置、球體半徑、立方體的長寬高等等。

## 課堂練習
畫出一xy平面，並以此平面為基準畫出x軸、y軸、z軸，在三軸的交點(0,0,0)畫一顆球，且在不為(0,0,0)之處再畫一顆球與一個立方體（兩物件之位置不可重疊）。

### 成果
![image](https://hackmd.io/_uploads/B1X8QCSYyg.png)

### 程式碼
```python=
Web VPython 3.2
cuboid2 = box(pos = vector (-2,0,0) , length = 10, width = 10, height = 0, color = color.white) #畫出xy平面
#畫出座標軸
pointer_ax = arrow(pos = vector(0,0,0) , axis = vector(5,0,0) , shaftwidth = 0.1 , color = color.orange)
pointer_ay = arrow(pos = vector(0,0,0) , axis = vector(0,5,0) , shaftwidth = 0.1 , color = color.red)
pointer_az = arrow(pos = vector(0,0,0) , axis = vector(0,0,5) , shaftwidth = 0.1 , color = color.green)
ball1 = sphere(pos = vector(0,0,0) , radius = 0.5 , color = color.green) #畫出位於(0,0,0)的球
ball2 = sphere(pos = vector(1,2,1) , radius = 0.3 , color = color.red) #畫出一顆不位於(0,0,0)的球
cuboid1 = box(pos = vector (-2,0,0) , length = 0.3, width = 0.2, height = 1, color = color.white) #畫出一個不位於(0,0,0)立方體
```
