강의노트 타원 그리기

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

draw ellipse

  • ellipse

    pygame.draw.ellipse(surface, color, rect, width=0)
    
  • surface : 도형을 그릴 창

  • color : 색

  • rect : [ x, y, width, height ] 의 사각형 안에 타원을 그려준다.

  • 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
rect = [50,50,200,100]
while running:
    clock.tick(120)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill(white)
    pygame.draw.ellipse(screen,black, rect, 0)
    pygame.display.update()
pygame.quit()
import pygame
from pygame.locals import *
from random import *

pygame.init( )

LEFT = 1 #왼쪽버튼
WIDTH = 640
HEIGHT = 480
running = True
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)

while running:
    for event in pygame.event.get( ):
        if event.type == QUIT:
            running = False
    if event.type == MOUSEBUTTONDOWN and event.button == LEFT:
        ellipse_width, ellipse_height = pygame.mouse.get_pos( )
        screen.fill((255,255,255))
        random_color = (randint(0, 255), randint(0, 255), randint(0, 255))
        pygame.draw.ellipse(screen, random_color, (0, 0, ellipse_width, ellipse_height))
        pygame.display.update( )
pygame.quit( )
이전 글
다음 글
댓글
댓글로 소통하세요.