파이썬터틀 3

파이썬 터틀 그래픽 (turtle graphics) 랜덤한 색의 N각형 그리기

질문 내용 파이썬 터틀을 이용하여 원하는 다각형을 그리고, 각각의 다각형 색을 랜덤으로 주어 출력하고 싶습니다. 질문 풀이 import turtle import random t=turtle.Turtle() def draw_polygon(n, length, x): color=["blue", "coral", "green", "purple", "yellow"] for i in range(x): for i in range(n): t.fd(length) t.lt(360/n) #for 문 내에서 각 변의 색 설정 t.color(color[random.randint(0,4)]) t.lt(360/x) n = int(input("원하는 다각형의 종류를 입력하시오")) length = int(input("한변의 길이를 입..

파이썬 터틀 그래픽 (turtle graphics) 펜 및 거북이 색깔 랜덤 변경

문제 내용 1. 터틀이 외부로 나갈 때 마다 터틀 컬러가 빨주노초파남보 순서대로 변하게 하기 2. 펜 컬러 랜덤으로 변하기 문제 풀이 import random import turtle swidth, sheight, pSize, exitCount = 300, 300, 3, 0 r, g, b, angle, dist, curX, curY = [0] * 7 turtle.title('거북이가 맘대로 다니기') turtle.shape('turtle') turtle.pensize(pSize) turtle.setup(width=swidth+30, height=sheight+30) turtle.screensize(swidth, sheight) colors = ['red', 'orange', 'yellow', 'green..

파이썬 터틀 그래픽 (turtle graphics) 포물선 운동 그리기

문제 내용 파이썬으로 각도와 속도를 입력값을 받고, 터틀로 포물선 운동을 표현해야합니다. 풀이 내용 import turtle as t import math t.setup(500,600) t.shape("circle") t.shapesize(0.1,0.1,0) angle = float(input('각도 : ')) v = float(input('속도 : ')) def draw_pos(x,y): #그림을 그리는 draw_pos 함수 t.hideturtle() t.penup() t.setx(x) t.sety(y) t.stamp() hl= -(t.window_height() / 2) tm=0 #시간변수 초기화 while True: X = (v * math.cos(angle*math.pi/180)) * tm Y =..