pygame 이동 사각형 을 그립 니 다. 경계 에 닿 았 을 때 색 을 바 꿉 니 다.
1739 단어 Python
import pygame,sys;
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((700,600))
pygame.display.set_caption("Drawing Rectangles")
pos_x = 300
pos_y = 250
vel_x = 6
vel_y = 3
a = int(10)
b = int(20)
c = int(10)
while True:
for event in pygame.event.get():
if event.type in (QUIT,KEYDOWN):
sys.exit()
screen.fill((0,0,200))
pos_x+=vel_x
pos_y+=vel_y
if pos_x > 600 or pos_x < 0:
vel_x = -vel_x
if a <= 205 and a >= 50:
a = a + 50
elif a > 205:
a = a - 5
elif a < 5:
a = a + 50
if b <= 205 and b >= 50:
b = b + 50
elif b > 205:
b = b - 50
elif b < 50:
b = b + 50
if c <= 205 and c >= 50:
c = c + 5
elif c > 205:
c = c - 50
elif c < 50:
c = c + 20
print(a)
print(b)
print(c)
if pos_y > 500 or pos_y < 0:
vel_y = -vel_y
if a <= 205 and a >= 50:
a = a + 22
elif a > 205:
a = a - 32
elif a < 50:
a = a + 21
if b <= 205 and b >= 50:
b = b + 23
elif b > 205:
b = b - 21
elif b < 50:
b = b + 21
if c <= 205 and c >= 50:
c = c + 23
elif c > 205:
c = c - 32
elif c < 50:
c = c + 43
print(a)
print(b)
print(c)
color = a,b,c
width = 0
pos = pos_x,pos_y,100,100
pygame.draw.rect(screen,color,pos,width)
pygame.display.update()
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Python의 None과 NULL의 차이점 상세 정보그래서 대상 = 속성 + 방법 (사실 방법도 하나의 속성, 데이터 속성과 구별되는 호출 가능한 속성 같은 속성과 방법을 가진 대상을 클래스, 즉 Classl로 분류할 수 있다.클래스는 하나의 청사진과 같아서 하나의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.