강의노트 원호 그리기
강의노트
• 조회수 73
• 댓글 0
• 수정 1주 전
- 도형그리기
- arc
pygame.draw.rect(surface, color, rect, start, end, width=1)
- surface : 도형을 그릴 창
- color : 색
- rect : [ x, y, width, height ] 의 리스트
- start : 시작 각도
- end : 끝 각도
- width : 선의 굵기
import pygame
import numpy as np
pygame.init()
screen = pygame.display.set_mode((500,400))
clock = pygame.time.Clock()
white = (255,255,255)
black = (0,0,0)
pi = np.pi
running = True
rect = [50,50,250,300]
while running:
clock.tick(120)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill(white)
pygame.draw.rect(screen,black,rect,1)
pygame.draw.arc(screen,black,rect, 0, 3*pi/2,3)
pygame.display.update()
pygame.quit()
draw arc
import pygame
from math import pi
pygame.init( )
#색상 정의
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
#화면크기
size = [400, 300]
screen = pygame.display.set_mode(size)
pygame. display.set_caption(”호 그리기”)
#메인루프
running = False
clock = pygame.time.CIock( )
while running:
clock.tick(10)
for event in pygame.event.get( ):
if event.type == pygame.QUIT:
running = False # 루프를 탈출하기 위한 변수값 설정
#배경지우기
screen.fill(WHITE)
#호그리기
#pi : 3. 7 4 7 592653589 793
pygame.draw.arc(screen, BLACK, [75, 75, 150, 150], 0, pi/2, 2)
pygame.draw.arc(screen, GREEN, [75, 75, 150, 150], pi/2, pi, 4)
pygame.draw.arc(screen, BLUE, [75, 75, 150, 150], pi, 3*pi/2, 6)
pygame.draw.arc(screen, RED, [75, 75, 150, 150], 3*pi/2, 2*pi, 8)
pygame.display.flip( )
pygame.quit( )
반원 호 반복 그리기
import pygame
from math import pi
from random import *
pygame.init( )
#색설정
WHITE = (255, 255, 255)
#화면설정
size = [400, 300]
screen = pygame.display.set_mode(size)
pygame.display.set_caption(”호 그리기”)
#메인루프
running = True
clock= pygame.time.Clock()
while running:
clock.tick(2)
for event in pygame.event.get( ):
if event.type== pygame.QUIT:
running = False # 루프 탈출 변수 설정
screen.fill(WHITE)
#타원그리기
#pi= 3.147592653589793, math 모률 Imp。rt!!
for cord_x in range (0, 360, 100):
pygame.draw.arc(screen, (randint(0,255), randint(0,255), randint(0, 255)), [cord_x, 30, 50, 50], 0, pi/2, 4)
pygame.draw.arc(screen, (randint(0,255), randint(0,255), randint(0, 255)), [cord_x, 30, 50, 50], pi/2, pi, 4)
pygame.draw.arc(screen, (randint(0,255), randint(0,255), randint(0, 255)), [cord_x+50, 30, 50, 50], pi,3*pi/2, 4)
pygame.draw.arc(screen, (randint(0,255), randint(0,255), randint(0, 255)), [cord_x+50, 30, 50, 50], 3*pi/2, 2*pi, 4)
pygame.display.flip( )
pygame.quit( )
로그인 하면 댓글을 쓸 수 있습니다.