강의노트 원 그리기

강의노트 • 조회수 105 • 댓글 0 • 수정 3주 전  
  • 도형그리기
  • 원그리기

circle

명령어

pygame.draw.circle(surface, color, pos, radius, width=0)
  • surface : 도형을 그릴 창
  • color : 색
  • pos : 원의 중심점
  • radius : 원의 반지름
  • width : 선의 굵기, 0이면 닫힌 도형안을 채워준다.
import pygame

pygame.init()
screen = pygame.display.set_mode((500,400))
clock = pygame.time.Clock()

white = (255,255,255)
black = (0,0,0)

running = True

while running:
    clock.tick(120)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill(white)
    pygame.draw.circle(screen,black,[50, 50], 50, 5)
    pygame.display.flip()
pygame.quit()

draw random circle

import pygame
from pygame.locals import *
from random import *

pygame.init( )

Width= 640
Height= 480
Radius= 200
WHITE= (255, 255, 255)
running = True

screen = pygame.display.set_mode((Width, Height), 0)
clock= pygame.time.Clock( )
screen.fill(WHITE)

while running:
    clock.tick(2)
    for event in pygame.event.get( ):
        if event.type == QUIT:
            running = False
    random_colar = (randint(0,255), randint(0,255), randint(0,255))
    random_pos = (randint(0, Width -1 ), randint(0, Height -1))
    random_radius = randint(1, Radius)
    pygame.draw.circle(screen, random_color, random_pos, random_radius)
    pygame.display.update( )
pygame.quit( )
이전 글
다음 글
댓글
댓글로 소통하세요.