์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- js
- ๊ฒ์
- https://m.blog.naver.com/tt2t2am1118/221010125300
- JS #ํ๋ก์ ํธ
- sql
- webpack
- json
- db
- ๋๊ธฐ
- slow and steady
- Porject
- setTimeout()
- execCommand
- Import
- prj
- ajax
- async
- eport
- mysql
- addEventListener
- callback
- ์ฐธ๊ณ ๋ธ๋ก๊ทธ
- promise
- await
- ํผํ
- database
- https://youtube.com/playlist?list=PLuHgQVnccGMA5836CvWfieEQy0T0ov6Jh&si=FTaYv8m21EhO-A2K
- object
- ๋น๋๊ธฐ
- Project
- Today
- Total
C-log
๐ฉ๐ซclass : 4week ๋ณธ๋ฌธ
#๊ณผ์ ์ ์ถ ํ ๋ ๊ผญ ์ฃผ์ ์ฒ๋ฆฌํ๊ธฐ.
ํฐํ ๊ทธ๋ํฝ ํ์ฉ
ํฐํ ๊ทธ๋ํฝ์ ํตํด์ ๋ค์ํ ๋ํ๋ค์ ๋ง๋ค์ด ๋ณด์.
import turle
import turtle
t =turtle.Turtle()
t.shape("turtle")
์ฐ๋ฆฌ๊ฐ ํฐํ ๊ทธ๋ํฝ์ ์ฌ์ฉํ๋ ค๋ฉด ์์ ์ฝ๋๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ฉํด์ผํ๋ค. shape()์๋ ๋ค์ํ ๋ชจ์์ด ์กด์ฌํ๋ค. ์๋ ํ๋ฅผ ์ดํด๋ณด์.
t.forward(), right(), left()
import turtle
t =turtle.Turtle()
t.shape("turtle")
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
forward()๋ ์์ผ๋ก ๊ฐ๋ ์์ง์ด๋ ๋ช ๋ น์ด์ด๋ค. right()/left()๊ฐ์ ๊ฒฝ์ฐ ๋ฐฉํฅ์ ์ ํ๋ ๋ช ๋ น์ด์ด๋ค. ์์ ์ฝ๋์ ๊ฒฐ๊ณผ๋ฌผ์ ์๋ ์ด๋ฏธ์ง์ ๊ฐ๋ค.
์์ ๊ฒฐ๊ณผ๋ฌผ์ t.stamp()๋ฅผ ํตํด์ ๊ฐ ์ ๋ง๋ค turtle์ด ์๋ ๋ฐฉ๋ฒ์ ๊ตฌํํด๋ณด์. ์ฝ๋๋ ์๋์ ๊ฐ๋ค.
t.stamp(), t.write(t.position())
t.stamp()
t.write(t.position())
t.forward(100)
t.stamp()
t.write(t.position())
t.right(90)
t.forward(100)
t.stamp()
t.write(t.position())
t.right(90)
t.forward(100)
t.write(t.position())
t.stamp()
t.right(90)
t.forward(100)
t.write(t.position())
t.stamp()๋ช ๋ น์ด๊ฐ ์๋ ์ค์์๋ turtle๋ชจ์์ด ์ฐํ๋ค. ์ด์ ๋์์ t.write(t.position())์ด๋ผ๋ ๋ช ๋ น์ด๋ก ๊ฐํด๋น ์๋ฆฌ์ turtle์ position ๊ฐ์ด ํ๊ธฐ ๋๋ค. ์๋์ ๊ฒฐ๊ณผ๋ฌผ์ ๋ณด์.
color(), circle()
์ด๋ฒ์๋ colorํจ์๋ฅผ ์ฌ์ฉํด์ turtle์์ด์ฝ์ ๋นจ๊ฐ์์ผ๋ก ๋ณ๊ฒฝํด๋ณด์. ์๋ ์ฝ๋๋ฅผ ์ดํด๋ณด์
import turtle
t = turtle.Turtle()
t.shape("turtle")
t.width(3)
t.color("red")
t.circle(50)
์ฌ๊ธฐ์ t.color("red")๋ฅผ ์ฌ์ฉํด์ circle()ํจ์๋ฅผ ํตํด ๋นจ๊ฐ์ ์ํ์ ๋ง๋ ๋ค. ๋ํด์ ๋นจ๊ฐ์ turtle์์ด์ฝ์ด ์์ฑ๋๋ค. ์ด๋ฒ์๋ ๋นจ๊ฐ์ ์ ๋ ธ๋์์ผ๋ก ์ฑ์ ๋ฃ์ด๋ณด์. ์๋ ์ฝ๋๋ฅผ ์ดํด๋ณด์.
up(),down(),fillcolor()
t.up()
t.forward(80)
t.down()
t.fillcolor("yellow")
t.begin_fill()
t.circle(70)
t.end_fill()
์์ ์ฝ๋๋ฅผ ๋ณด๋ฉด up()์ ํตํด์ ์ ์ ์์น๋ฅผ ๋ณ๊ฒฝํด์ค๋ค. ๊ทธ๋ฆฌ๊ณ ์ํ๋ ํด๋น ์์น๋ก forward()๋ก ์ด๋ํ๊ณ down()์ ํตํด์ ๋ค์ ์ ์ ๊ทธ๋ฆด ์ค๋น๋ฅผ ํ๋ค. ์ฌ๊ธฐ์ fillcolor()ํจ์๋ฅผ ํตํด์ ํด๋น ๋ํ์ ์ฑ์ธ ์์ ๊ฐ์ ๋ฏธ๋ฆฌ ์ค์ ํ๊ณ begin_fill()์ด๋ผ๋ ํจ์๋ก ์ฑ์์ค ์ค๋น๋ฅผ ํ๋ค. ์ดํ ํด๋น ๋ํ์ ๊ทธ๋ฆฌ๊ณ ํด๋น ๋ํ์ ๋ค ์ฑ์ฐ๊ณ ๋๋ฉด end_fill()ํจ์๋ฅผ ์ฌ์ฉํ๋ค.
์์ ์๋ ์ฝ๋๋ฅผ ๋ชจ๋ ์ฐ๊ฒฐํด์ ๋ณด๋ฉด ์๋์ ๊ฐ์ ๊ฒฐ๊ณผ๊ฐ ๋์จ๋ค.
turtle.colormode(),pensize()
์ฐ๋ฆฌ๋ colorํจ์๋ก ์์์ ์ ํ๋ค. ์ด๋ฒ์๋ colormode๋ผ๋ ํจ์๋ฅผ ์ด์ฉํด์ ์๋ก์ด ์ํ์ ๋ง๋ค์ด๋ณด์. ์ฐ์ colormode()๋ RGB์นผ๋ฌ๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ๋ชจ๋๋ฅผ ์ค์ ํด์ฃผ๋ ํจ์์ด๋ค. ๋ฐ๋ผ์ 0์์ ๋ถํฐ 255์ธ 256๊ฐ์ง์ ์์์ ์ ํํ ์ ์๋ค. ์๋ ์ฝ๋๋ฅผ ์ดํด๋ณด์.
import turtle
t =turtle.Turtle()
t.shape("turtle")
turtle.colormode(255)
t.pensize(3)
t.color(0,0,255)
t.fillcolor(255,255,0)
t.begin_fill()
t.circle(50)
t.end_fill()
์ฐ๋ฆฌ๋ colormode๋ฅผ 255์ธ RGB์นผ๋ผ๋ฅผ ์ ํํ๊ณ colorํจ์๋ ์ด์ ๋ถํฐ RGB ์์ํ๋ฅผ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ ์ฌ๊ธฐ์ ์ ํํ ์์์ ํ๋์์ ์ ํํ๋ค. pensizeํจ์๋ก ํฌ์ ๊ตต๊ธฐ๋ฅผ ์กฐ์ ํ๊ณ fillcolorํจ์ ๋ํ RGB ์์ํ๋ฅผ ์ฌ์ฉํด์ ๋ ธ๋์์ ์ ํํ๋ค. ์๋ ์ฝ๋๋ ์์์ ์ฐ๋ฆฌ๊ฐ ์ดํด๋ณธ ์ฝ๋์ด๋ฉฐ ์ง์ ์ค์ต์ ํตํด ํ์ธํด ๋ณด์. ์๋ ์ด๋ฏธ์ง๋ ํด๋น ์ฝ๋์ ๊ฒฐ๊ณผ์ด๋ค.
goto(), hideturtle()
๋ง์ง๋ง์ผ๋ก goto๋ผ๋ ํจ์๋ฅผ ์ฌ์ฉํด๋ณผ ๊ฒ์ด๋ค. forward์๋ ๋ฌ๋ฆฌ x,y์ขํ๋ฅผ ์ฌ์ฉํด์ ์์ง์ผ ์ ์๋ค. ๋ฌผ๋ก goto์ x๊ฐ์ ์ขํ๋ง์ ์ด์ฉํด์ ํฌ์ ์ด๋์ํฌ ์ ์๋ ์์ผ๋ y์ ๊ฐ์ ๋ฐ๋ก right๋ left๋ก ์ง์ ์ ํด์ผํ๋ ๋ฒ๊ฑฐ๋ก์์ด ์๋ค. ์๋ฅผ ๋ค์ด ์๋ ์ฝ๋๋ฅผ ์ดํด๋ณด์.
#forward_test
import turtle
t =turtle.Turtle()
t.shape("turtle")
t.up()
t.forward(-200)
t.right(90)
t.forward(100)
t.down()
t.write("forward" + str(t.position()))
t.circle(50)
t.hideturtle()
์ฐ์ forward๋ฅผ ์ฌ์ฉํด์ ํฌ์ ์์น๋ฅผ ์ด๋ ์ํค๋ ์ฝ๋๋ ์์ ๊ฐ๋ค. ์๊ณ ๋ก์์ด ์ฌ๋ฌ๋ฒ ํ์ํ์ง๋ง goto๋ฅผ ์ฌ์ฉํ์ ๋๋ ์ข ๋ ๊ฐ๋ตํ๊ฒ ์ฝ๋๊ฐ ์์ฑ๋๋ค. ์๋ ์ฝ๋๋ฅผ ์ดํด๋ณด์.
#goto_test
import turtle
t =turtle.Turtle()
t.shape("turtle")
t.up()
t.goto(-200,-100)
t.down()
t.write("goto" + str(t.position()))
t.circle(50)
t.hideturtle()
๋์ด ๊ฐ์ ์์น์์ ์์ํ์ง๋ง ์ฝ๋์ ๊ธธ์ด๋ง ๋ณด์๋ ๊ฐ๋ตํ๊ณ ๋ ๋ณด๊ธฐ ํธํ๋ค๋ ๊ฒ์ ์ ์ ์๋ค. ๊ทธ๋ ๋ค๋ฉด ์ ๋์ ์ฝ๋์ ๊ฒฐ๊ณผ๋ฅผ ํ๋ฒ ์ดํด๋ณด์.
๋๋ค ๊ฐ์ ์์น์ ์กด์ฌํ๋ ์ํ์ด์ง๋ง ์ด๋ค ํจ์๋ฅผ ์ด์ฉํ๋๋์ ๋ฐ๋ผ ๊ฐ๋ฐ์๊ฐ ์ฝ๋๋ฅผ ์ฝ์ ๋ ๋๋ ์ฌ์ฉํ ๋ ํธ๋ฆฌํจ์ ์ฐจ์ด๊ฐ ์๋ค๋ ๊ฒ์ ์ ์ ์๋ค. ์ด๋ ๊ฒ ์ค๋์ ์์ ๋ณต์ต์ ๋ง์น๋๋ก ํ๊ฒ ๋ค.
๊ฐ๋จํ ๊ณผ์
์์ ์ฝ๋๋ค์ ์กฐํฉํด์ ์๋์ ๊ณผ์ ๋ฅผ ์ํ ํ์๋ค.
#์ค๋ฅ๊ธฐ ๊ทธ๋ฆฌ๊ธฐ
#150์ด๋
t.pensize(5)
t.speed(5)
turtle.colormode(255)
#t.color(0,0,255)
#1st
t.color(0,0,255)
t.up()
t.goto(-150,50)
t.down()
t.circle(70)
#2nd
t.color(0,0,0)
t.up()
t.goto(0,50)
t.down()
t.circle(70)
#3rd
t.color(255,0,0)
t.up()
t.goto(150,50)
t.down()
t.circle(70)
#4th
t.color(0,255,0)
t.up()
t.goto(75,-50)
t.down()
t.circle(70)
#5th
t.color(255,255,0)
t.up()
t.goto(-75,-50)
t.down()
t.circle(70)
'๐Python > ๐ฉโ๐ซclass' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉโ๐ซclass : 7week (0) | 2023.10.16 |
---|---|
๐ฉโ๐ซclass : 5week (0) | 2023.09.26 |
๐ฉโ๐ซclass : 3week (0) | 2023.09.12 |
๐ฉโ๐ซclass : 2week (0) | 2023.09.05 |
๐ฉโ๐ซclass : 1week (0) | 2023.09.05 |