728x90
반응형
색 채우기
1) 리스트에서 순서대로 색 선택
import turtle
t=turtle.Turtle()
color_list=['red', 'blue', 'gold', 'silver', 'pink', 'skyblue']
for count in range(6):
t.begin_fill() # 채우기 시작
t.fillcolor(color_list[count]) # 색 리스트에서 인덱스로 순서대로 선택
t.circle(100) # 원 그리기
t.end_fill() # 채우기 끝
t.left(360/6)
turtle.done()
2) 색 리스트에서 임의의 색 선택
import turtle
import random
t=turtle.Turtle()
color_list=['red', 'blue', 'gold', 'silver', 'pink', 'skyblue']
for count in range(6):
t.begin_fill()
t.fillcolor(color_list[random.randint(0,5)]) # 색 리스트에서 임의의 인덱스 번호로 선택
t.circle(100)
t.end_fill()
t.left(360/6)
turtle.done()
3) RGB 색으로 임의의 색 지정
import turtle
import random
t=turtle.Turtle()
color_list=['red', 'blue', 'gold', 'silver', 'pink', 'skyblue']
for count in range(6):
t.begin_fill()
r = random.random() # R 색의 번호를 임의로 선택
g = random.random()
b = random.random()
t.fillcolor((r, g, b)) # RGB 컬러를 임의로 지정
t.circle(100)
t.end_fill()
t.left(360/6)
turtle.done()
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 문제 : 입력한 문자열에 동일한 두 문자가 연속되는지 검사 (0) | 2022.12.14 |
---|---|
[파이썬] 문제 : 2차원 리스트의 정렬 및 합계,평균 구하고 결과 파일에 쓰기 (0) | 2022.12.14 |
[파이썬] 화폐 환전코드 해석 (0) | 2022.12.13 |
[파이썬] 문제 : 커피 자판기 (0) | 2022.12.12 |
[파이썬] 문제 : 문자열 중간 반복문자의 조작 (0) | 2022.12.11 |
댓글