<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] ### 課前準確: * 在`Windows`系統里安裝`python`,參考 [安裝python](http://www.hmoore.net/k12edu/k_12/785427#Windowspython_4) ***** ### 本節課參考資料 * `Teach Your Kids to Code.pdf` 第八章:計數器和動漫 ***** ### 一個簡單的靜態動漫 ``` #chapter8_1.py import pygame #導入動漫工具pygame pygame.init() #初始化,相當于打開電視 screen = pygame.display.set_mode([800,600]) #建立一個動漫基地 keep_going = True GREEN = (0,255,0) # RGB color triplet for GREEN #給一個球涂上綠色 radius = 50 #定義球的大小 while keep_going: #檢查是不是要繼續動漫 for event in pygame.event.get(): if event.type == pygame.QUIT: #從動漫基地尋找是不是要退出的信號 keep_going = False # 如果有退出的信號,告訴keep_going pygame.draw.circle(screen, GREEN, (100,100), radius) # 畫球 pygame.display.update() pygame.quit() #關閉動漫 ``` ![](https://box.kancloud.cn/c806a601d2b64a6cbc26b17256d26aa8_527x384.png) ***** ### 復雜一點的靜態笑臉動漫 ``` #chapter8_2 import pygame pygame.init() screen = pygame.display.set_mode([800,600]) keep_going = True pic = pygame.image.load("CrazySmile.bmp") #和上面那個例子的區別是,我們不再畫圖,而是直接導入一張笑臉 while keep_going: for event in pygame.event.get(): if event.type == pygame.QUIT: keep_going = False screen.blit(pic, (100,100)) pygame.display.update() pygame.quit() # Exit ``` ![](https://box.kancloud.cn/914254cda5c9c9d567214dfd23377364_434x365.png) ***** ### 一個會動的笑臉動漫 ``` #chapter8_3.py import pygame # Setup pygame.init() screen = pygame.display.set_mode([600,600]) keep_going = True pic = pygame.image.load("CrazySmile.bmp") colorkey = pic.get_at((0,0)) pic.set_colorkey(colorkey) picx = 0 picy = 0 BLACK = (0,0,0) timer = pygame.time.Clock() # Timer for animation while keep_going: # Game loop for event in pygame.event.get(): if event.type == pygame.QUIT: keep_going = False picx += 1 # 移動笑臉 picy += 1 # 移動笑臉 screen.fill(BLACK) # 用黑板擦把笑臉移動的痕跡抹掉 screen.blit(pic, (picx,picy)) pygame.display.update() timer.tick(60) # 每秒鐘顯示60幅畫面 pygame.quit() ``` ![](https://box.kancloud.cn/f1bc6ce7b757a3f70c573e025bf0d62d_456x447.png) ***** ### 一個加速了、可以回彈的笑臉動漫 ``` #chapter8_4.py import pygame # Setup pygame.init() screen = pygame.display.set_mode([600,600]) keep_going = True pic = pygame.image.load("CrazySmile.bmp") colorkey = pic.get_at((0,0)) pic.set_colorkey(colorkey) picx = 0 picy = 0 BLACK = (0,0,0) timer = pygame.time.Clock() speed = 5 #給動漫加速 while keep_going: # Game loop for event in pygame.event.get(): if event.type == pygame.QUIT: keep_going = False picx += speed picy += speed if picx <= 0 or picx + pic.get_width() >= 600: speed = -speed # 回彈 screen.fill(BLACK) screen.blit(pic, (picx,picy)) pygame.display.update() timer.tick(60) pygame.quit() ``` ![](https://box.kancloud.cn/01b8dc1f00d1e04bde1f697cdad78eab_446x448.png) ***** ### 一個更加活躍的笑臉動漫 ``` #chapter8_5 import pygame # Setup pygame.init() screen = pygame.display.set_mode([800,600]) keep_going = True pic = pygame.image.load("CrazySmile.bmp") colorkey = pic.get_at((0,0)) pic.set_colorkey(colorkey) picx = 0 picy = 0 BLACK = (0,0,0) timer = pygame.time.Clock() speedx = 5 speedy = 5 while keep_going: # Game loop for event in pygame.event.get(): if event.type == pygame.QUIT: keep_going = False picx += speedx picy += speedy if picx <= 0 or picx + pic.get_width() >= 800: speedx = -speedx if picy <= 0 or picy + pic.get_height() >= 600: speedy = -speedy screen.fill(BLACK) screen.blit(pic, (picx, picy)) pygame.display.update() timer.tick(60) pygame.quit() # Exit ``` ![](https://box.kancloud.cn/9e58c60c8bee8e255212d993087b0279_593x444.png) ***** ### 課程小結 `pygame` 是動漫開發工具,使用這個工具我們可以知道動漫是怎么實現的。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看