여러가지/Python

Day 18 - Turtle, colorgram, tuples(터플), PyCharm

15June 2024. 4. 27. 14:21

Tip 1. 변수 이름 변경하기

 

Tip 2. 모듈 다운로드 받기 

turtle은 기본 클래스이다.

> pip install heroes

 

import turtle as t
tim = t.Turtle

# as : Turtle을 t로 별명 짓기

 

● 학습 내용

1) 터플(Tuples)

: tuples 값은 불변성

 

 

2) colorgram 모듈을 활용해 색상 추출하기

Step 1. 초기

colors = colorgram.extract('color.jpeg', 20)
print(colors)

 

Step 2. 리스트 변환

colors = colorgram.extract('color.jpeg', 20)

rgb_colors = []
for color in colors:
    rgb_colors.append(color.rgb)

print(rgb_colors)

 

 

Step 3. 터플 변환

colors = colorgram.extract('color.jpeg', 20)

rgb_colors = []
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)

 

 

● GIT URL : https://github.com/yooyijun15/Python/blob/main/Day18/main.py

 

Python/Day18/main.py at main · yooyijun15/Python

Contribute to yooyijun15/Python development by creating an account on GitHub.

github.com