日期:2018/7/23
由於我們之前做的動畫,都是在按在 F5 後自動開始執行,如果我們想要在動畫中新增按鈕,讓使用者可以自己控制動畫,應該要怎麼做呢?我們希望按鈕的功能有:
- Run:按下時開始執行動畫
- Reset:按下時還原成起始狀態
- Stop:按下時停止執行程式
我們使用最簡單的動畫〈等速度直線運動〉的程式碼來改寫,成果如下:
有按鈕的等速度直線運動畫面截圖
按下 Run 按鈕後
用滑桿改變速度,使木塊向左移動
按下 Reset 按鈕後
VPython 教學文件目錄 安裝及測試 基本語法 等速度直線運動 自由落下 終端速度 水平抛射 使用For迴圈計算水平抛射資料 斜向抛射 圓周運動 簡諧運動 單擺 木塊彈簧系統分離 重力及簡諧 行星運動 相疊木塊 雙重簡諧運動 一維彈性碰撞 ...
《天龍》中的人物個性與武功本領,有很多誇張或事實上不可能的地方,如「六脈神劍」、「火焰刀」、「北冥神功」、無崖子傳功、童姥返老還童等等。讀讀者們想像一下現代派繪畫中超現實主義、像徵主義的畫風,例如一幅畫中一個女人有朝左朝右兩個頭之類,在藝術上,脫離現實的表現方式是容許的。
"""
Python筆記: 2D曲線圖
日期: 2018/6/13
作者: 王一哲
"""
import numpy as np # 引入科學計算函式庫
import matplotlib.pyplot as plt # 引入繪圖函式庫
xmin, xmax, num = -4*np.pi, 4*np.pi, 1000 # 設定繪圖範圍、取點數
x = np.linspace(xmin, xmax, num) # 產生x
y = np.sin(x) # 產生y
plt.figure(figsize = (8, 6), dpi = 100) # 設定圖片尺寸
plt.xlabel('x(rad)', fontsize = 16) # 設定坐標軸標籤
plt.ylabel('sin(x)', fontsize = 16)
plt.xticks(fontsize = 12) # 設定坐標軸數字格式
plt.yticks(fontsize = 12)
plt.grid(color = 'red', linestyle = '--', linewidth = 1) # 設定格線顏色、種類、寬度
plt.plot(x, y, color = 'blue', linewidth = 3) # 繪圖並設定線條顏色、寬度
plt.savefig('plot_2D.svg') # 儲存圖片
plt.savefig('plot_2D.png')
plt.show() # 顯示圖片
file = open("data.txt", "w", encoding = "UTF-8")
file.write("h(m), t(s), R(m)\n")
for h in range(5, 51, 1):
......
file.write(str(h) + "," + str(t) + "," + str(ball.pos.x + L/2) + "\n")
file.close()
with open("data.txt", "w", encoding = "UTF-8") as file:
file.write("h(m), t(s), R(m)\n")
for h in range(5, 51, 1):
......
with open("data.txt", "a", encoding = "UTF-8") as file:
file.write(str(h) + "," + str(t) + "," + str(ball.pos.x + L/2) + "\n")


