[udemy] python 부트캠프_secion 18_Turtle & GUI

Dreamer ·2022년 9월 11일
0
post-thumbnail

01. 튜플

  • 튜플은 리스트와 비슷하지만, 가장 큰 차이점이 있다.
  • 튜플은 돌에 새기는 것과 비슷한 것으로, 값을 변경하거나 삭제할 수 없다.
  • 튜플을 사용하는 이유는 색상 구성표와 같이 값을 일정하게 유지하고자 하는 리스트를 생성하고, 누가 실수로 변경하는 것을 방지하기 위해서이다.
  • 튜플 값을 변경하려면 list로 변환 후 값을 변경한다.
my_tuple = (1,3,8)
my_tuple[0] # 1 출력
list(my_tuple) # 값 변경 가능 
import random
import turtle as t
tim = t.Turtle()
t.colormode(255)

def random_color():
    r = random.randint(0,255)
    g = random.randint(0,255)
    b = random.randint(0,255)
    random_color = (r, g, b)
    return random_color

directions = [0,90,180,270]
tim.pensize(15)
tim.speed("fastest")

for _ in range(200):
    tim.color(random_color())
    tim.forward(30)
    tim.setheading(random.choice(directions))

02. 이미지에서 rgb 값 추출하기

  • python의 colorgram 라이브러리 사용하여 추출하기
import colorgram

rgb_colors = []
colors = colorgram.extract('hirst_painting.jpeg',30)

for color in colors:
    r = color.rgb.r
    g = color.rgb.g
    b = color.rgb.b
    new_color = (r,g,b)
    rgb_colors.append(new_color)

print(rgb_colors)
profile
To be a changer who can overturn world

0개의 댓글