家長登入
報名專線
教育理念
教育理念
學習地圖
文章分享
課程列表
樂高動力機械SPM
6+
樂高創意程式BOOST
7+
樂高科技機器人EV3
9+
Scratch遊戲程式設計
8+
Python程式設計
11+
C++程式設計
12+
最新課表
2023夏令營
班
學生作品
聯絡我們
大拇指粉絲團
X
訂閱課程訊息
Email:
聯絡我們
請您向大拇指按讚!
我們會用大拇指多鼓勵孩子
地址:台北市忠孝東路五段246號5樓
教室連絡資訊
訂閱電子報
Python程式設計 Python物件導向的練習 | Webber
執行
# 課程 www.thumb.com.tw/course/python # 標題:Python物件導向的練習 # 作者:Webber import simplegui import random class Ball(): def __init__(self): self.px = 100 self.py = 250 self.vx = random.randint(2,7) self.vy = random.randint(2,7) def move(self): self.px = self.px + self.vx self.py = self.py + self.vy if self.px > 450 or self.px < 50: self.vx = self.vx * -1 #sound.play() if self.py > 450 or self.py < 50: self.vy = self.vy * -1 sound = simplegui.load_sound('http://commondatastorage.googleapis.com/codeskulptor-assets/Epoq-Lepidoptera.ogg') sound.set_volume(0.7) def draw_handler(canvas): global balls for b in balls: b.move() canvas.draw_image(image, (256 / 2, 256 / 2), (256, 256), (b.px,b.py), (100, 100)) image = simplegui.load_image('http://developer.asustor.com/uploadIcons/0020_14587_1410046873_minecraft_icon.png') sound = simplegui.load_sound('http://static.thumb.com.tw/paste/IB2C8B7.wav') sound.set_volume(0.7) balls = [] for i in range(250): b = Ball() balls.append(b) frame = simplegui.create_frame('Testing', 500, 500) frame.set_draw_handler(draw_handler) frame.start()
輸出:
執行