<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] # **pygame.draw** Pygame 中繪制圖形的模塊。 ## **函數** * pygame.draw.rect() — 繪制矩形 * pygame.draw.polygon() — 繪制多邊形 * pygame.draw.circle() — 根據圓心和半徑繪制圓形 * pygame.draw.ellipse() — 根據限定矩形繪制一個橢圓形 * pygame.draw.arc() — 繪制弧線 * pygame.draw.line() — 繪制線段 * pygame.draw.lines() — 繪制多條連續的線段 * pygame.draw.aaline() — 繪制抗鋸齒的線段 * pygame.draw.aalines() — 繪制多條連續的線段(抗鋸齒) 該模塊用于在 Surface 對象上繪制一些簡單的形狀。這些函數將渲染到任何格式的 Surface 對象上。硬件渲染會比普通的軟件渲染更耗時。 大部分函數用 width 參數指定圖形邊框的大小,如果 width = 0 則表示填充整個圖形。 所有的繪圖函數僅能在 Surface 對象的剪切區域生效。這些函數返回一個 Rect,表示包含實際繪制圖形的矩形區域。 大部分函數都有一個 color 參數,傳入一個表示 RGB 顏色值的三元組,當然也支持 RGBA 四元組。其中的 A 是 Alpha 的意思,用于控制透明度。不過該模塊的函數并不會繪制透明度,而是直接傳入到對應 Surface 對象的 pixel alphas 中。color 參數也可以是已經映射到 Surface 對象的像素格式中的整型像素值。 當這些函數在繪制時,必須暫時鎖定 Surface 對象。許多連續繪制的函數可以通過一次性鎖定直到畫完再解鎖來提高效率。 ## **函數詳解** ### **pygame.draw.rect()** 繪制矩形。 rect(Surface, color, Rect, width=0) -> Rect 在 Surface 對象上繪制一個矩形。Rect 參數指定矩形的位置和尺寸。width 參數指定邊框的寬度,如果設置為 0 則表示填充該矩形。 ### **pygame.draw.polygon()** 繪制多邊形。 ### **polygon(Surface, color, pointlist, width=0) -> Rect** 在 Surface 對象上繪制一個多邊形。pointlist 參數指定多邊形的各個頂點。width 參數指定邊框的寬度,如果設置為 0 則表示填充該矩形。 繪制一個抗鋸齒的多邊形,只需要將 aalines() 的 closed 參數設置為 True 即可。 ### **pygame.draw.circle()** 根據圓心和半徑繪制圓形。 circle(Surface, color, pos, radius, width=0) -> Rect 在 Surface 對象上繪制一個圓形。pos 參數指定圓心的位置,radius 參數指定圓的半徑。width 參數指定邊框的寬度,如果設置為 0 則表示填充該矩形。 ### **pygame.draw.ellipse()** 根據限定矩形繪制一個橢圓形。 ellipse(Surface, color, Rect, width=0) -> Rect 在 Surface 對象上繪制一個橢圓形。Rect 參數指定橢圓外圍的限定矩形。width 參數指定邊框的寬度,如果設置為 0 則表示填充該矩形。 ### **pygame.draw.arc()** 繪制弧線。 arc(Surface, color, Rect, start\_angle, stop\_angle, width=1) -> Rect 在 Surface 對象上繪制一條弧線。Rect 參數指定弧線所在的橢圓外圍的限定矩形。兩個 angle 參數指定弧線的開始和結束位置。width 參數指定邊框的寬度。 ### **pygame.draw.line()** 繪制線段。 line(Surface, color, start\_pos, end\_pos, width=1) -> Rect 在 Surface 對象上繪制一條線段。兩端以方形結束。 ### **pygame.draw.lines()** 繪制多條連續的線段。 lines(Surface, color, closed, pointlist, width=1) -> Rect 在 Surface 對象上繪制一系列連續的線段。pointlist 參數是一系列短點。如果 closed 參數設置為 True,則繪制首尾相連。 ### **pygame.draw.aaline()** 繪制抗鋸齒的線段。 aaline(Surface, color, startpos, endpos, blend=1) -> Rect 在 Surface 對象上繪制一條抗鋸齒的線段。blend 參數指定是否通過繪制混合背景的陰影來實現抗鋸齒功能。該函數的結束位置允許使用浮點數。 ### **pygame.draw.aalines()** 繪制多條連續的線段(抗鋸齒)。 aalines(Surface, color, closed, pointlist, blend=1) -> Rect 在 Surface 對象上繪制一系列連續的線段(抗鋸齒)。如果 closed 參數為 True,則首尾相連。blend 參數指定是否通過繪制混合背景的陰影來實現抗鋸齒功能。該函數的結束位置允許使用浮點數。 下邊是部分例子,僅供參考: ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNTU2MzE4_size_16_color_FFFFFF_t_70](https://image.dandelioncloud.cn/images/20220328/0cb5ffef48714b768088ef64c48a7cff.png) 代碼如下: ``` import pygame import sys import math from pygame.locals import * pygame.init() WHITE = (255, 255, 255) BLACK = (0, 0, 0) GREEN = (0, 255, 0) RED = (255, 0, 0) BLUE = (0, 0, 255) points = [(200, 175), (300, 125), (400, 175), (450, 125), (450, 225), (400, 175), (300, 225)] size = width, height = 640, 1000 screen = pygame.display.set_mode(size) pygame.display.set_caption("Python Demo") clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == QUIT: sys.exit() screen.fill(WHITE) pygame.draw.rect(screen, BLACK, (50, 30, 150, 50), 0) pygame.draw.rect(screen, BLACK, (250, 30, 150, 50), 1) pygame.draw.rect(screen, BLACK, (450, 30, 150, 50), 10) pygame.draw.polygon(screen, GREEN, points, 0) pygame.draw.circle(screen, RED, (320, 400), 25, 1) pygame.draw.circle(screen, GREEN, (320, 400), 75, 1) pygame.draw.circle(screen, BLUE, (320, 400), 125, 1) pygame.draw.ellipse(screen, BLACK, (100, 600, 440, 100), 1) pygame.draw.ellipse(screen, BLACK, (220, 550, 200, 200), 1) pygame.draw.arc(screen, BLACK, (100, 800, 440, 100), 0, math.pi, 1) pygame.draw.arc(screen, BLACK, (220, 750, 200, 200), math.pi, math.pi * 2, 1) pygame.display.flip() clock.tick(10) ```
                  <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>

                              哎呀哎呀视频在线观看