def szach(n): ustNaStart() numPowX = 1 numPowY = 1 bok = floor(450 / n) while(numPowY <= n / 2): while(numPowX <= n / 2): parzDwaKwadraty(bok) numPowX = numPowX + 1 korDuza(n) turtle.pu() turtle.lt(90) turtle.fd(bok) turtle.rt(90) turtle.pd() numPowX = 1 while(numPowX <= n / 2): nieParzDwaKwadraty(bok) numPowX = numPowX + 1 korDuza(n) turtle.pu() turtle.lt(90) turtle.fd(bok) turtle.rt(90) turtle.pd() numPowX = 1 numPowY = numPowY + 1
def rogi(bok): gamma = 90 + 18 beta = 360 / 5 alpha = 180 - beta romb(bok) naGoreRombu(bok) turtle.lt(gamma) romb(bok) naGoreRombu(bok) turtle.rt(gamma) romb(bok) turtle.pu() turtle.rt(gamma) turtle.fd(bok) turtle.lt(beta) turtle.fd(60) turtle.rt(beta) turtle.pd() romb(bok) naGoreRombu(bok) turtle.lt(alpha) romb(bok) turtle.lt(beta) naGoreRombu(bok) turtle.lt(beta*1.5) naGoreRombu(bok) turtle.rt(180)
def ustNaStart(r): turtle.lt(90) turtle.pu() turtle.rt(90) turtle.fd(r) turtle.lt(90) turtle.pd()
def makeshape(): B = 25 # base unit size turtle.begin_poly() turtle.fd(B) # roof turtle.rt(45) turtle.fd(B * 3/4) # windshield turtle.lt(45) turtle.fd(B) # hood turtle.rt(90) turtle.fd(B * 3/4) # front turtle.rt(90) turtle.fd(B * 1/7) turtle.lt(90) turtle.circle(-B/2, 180) # front tire turtle.lt(90) turtle.fd(B) turtle.lt(90) turtle.circle(-B/2, 180) # back tire turtle.lt(90) turtle.fd(B * 1/7) turtle.rt(90) turtle.fd(B * 5/6) # back turtle.end_poly() poly = turtle.get_poly() turtle.register_shape('car', poly)
def ustNaStart(a): turtle.pu() turtle.bk(a) turtle.lt(90) turtle.fd(a / 2) turtle.rt(90) turtle.pd()
def circle (r, cl, lt, p, t): t.goto(0, 0) t.color(cl) t.pensize(1) for i in range (0, 360): t.fd(2.0*math.sin(math.pi/360)*r) turtle.lt(1)
def wiatrak(wysokosc): turtle.lt(90) turtle.fd(wysokosc*26) trapez(pomaranczowy) turtle.pu() turtle.fd(26) turtle.rt(90) turtle.fd(26) turtle.rt(180) turtle.pd() trapez(zielony) turtle.pu() turtle.fd(26) turtle.rt(90) turtle.fd(26) turtle.rt(180) turtle.pd() trapez(pomaranczowy) turtle.pu() turtle.fd(26) turtle.rt(90) turtle.fd(26) turtle.lt(180) turtle.pd() trapez(zielony) turtle.pu() turtle.fd(26) turtle.rt(90) turtle.fd(26*(wysokosc+1)) turtle.pd()
def ustNaStartKwiatki(rozmKanwy, segment): turtle.pu() turtle.bk(225) turtle.lt(90) turtle.bk(225) turtle.rt(90) turtle.pd()
def kwadrat(bok): numPow = 1 while(numPow <= 4): turtle.fd(bok) turtle.lt(90) numPow = numPow + 1 korMala(bok)
def ustDoElki(dlBokKw, bokKr): turtle.pu() turtle.fd(bokKr - dlBokKw) turtle.lt(90) turtle.fd(dlBokKw) turtle.lt(90) turtle.pd()
def naGoreWiezy(bokProst1, bokTroj): turtle.pu() turtle.fd(bokProst1) turtle.rt(30) turtle.fd(bokTroj) turtle.lt(30) turtle.pd()
def kwiatek(): p = 0 while (p <= 7): platek() turtle.bk(50) turtle.lt(360/8) p = p + 1
def okoP(a): turtle.begin_fill() wielokat(6, a *4, 4) turtle.end_fill() turtle.rt(180) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.fd(a * 4) turtle.colormode(255) turtle.fillcolor(255, 255, 255) turtle.rt(180) turtle.fd(a) turtle.rt(120) turtle.begin_fill() wielokat(6, 2 * a, 4) turtle.end_fill() turtle.rt(60) turtle.fd(a / 2) turtle.rt(120) turtle.fillcolor(0, 0, 0) turtle.begin_fill() wielokat(6, a, 4) turtle.end_fill()
def plansza(bok): bokMalKw = bok/7 rDuzKol = bokMalKw rMalKol = bokMalKw/2 numPowPlus = 1 numPowKola = 1 ustNaStart(bok) turtle.pu() ##W figurach nie ma krawędzi duzyKwadrat(bok) ustDoPlusa(bokMalKw) while numPowPlus <= 4: plus(bokMalKw, rMalKol) turtle.rt(90) turtle.fd(bokMalKw) numPowPlus = numPowPlus + 1 ustDoKol(bokMalKw) turtle.fillcolor(250, 250, 0) while numPowKola <= 4: turtle.rt(90) turtle.fd(bokMalKw) turtle.lt(180) turtle.begin_fill() turtle.circle(rDuzKol) turtle.end_fill() turtle.lt(180) turtle.fd(bokMalKw * 6) numPowKola = numPowKola + 1 turtle.pd()
def turtleXYZ(): turtle.goto(0, 0) turtle.pd() turtle.goto(0, 300) turtle.goto(6, 290) turtle.pu() turtle.goto(-6, 290) turtle.pd() turtle.goto(0, 300) turtle.goto(0, 0) turtle.goto(300, 0) turtle.goto(290, 6) turtle.pu() turtle.goto(290, -6) turtle.pd() turtle.goto(300, 0) turtle.goto(0, 0) turtle.rt(135) turtle.fd(212.1) turtle.lt(135) turtle.fd(5) turtle.bk(10) turtle.lt(90) turtle.fd(10) turtle.pu() turtle.goto(0, 0)
def draw_l(word): turtle.up() turtle.clear() turtle.setposition(0, 0) turtle.setheading(0) turtle.bk(INITIAL_POS[0]) turtle.down() turtle.st() stack = [] for char in word: if char == '0': turtle.fd(SIZE[0]) if char == '1': turtle.fd(SIZE[0]) if char == '[': stack.append((turtle.position(), turtle.heading())) turtle.lt(45) if char == ']': position, heading = stack.pop() turtle.up() turtle.setposition(position) turtle.setheading(heading) turtle.rt(45) turtle.down() turtle.ht()
def ustNaStart(dlBokKw, ile): turtle.pu() turtle.bk(dlBokKw * ile / 2 +5) turtle.lt(90) turtle.fd(dlBokKw * (ile - 2) / 2 - 5) turtle.rt(90) turtle.pd()
def ustDoNastKraw(ile, bokKw=10): turtle.pu() turtle.lt(90) turtle.fd(bokKw) turtle.rt(90) turtle.rt(180) turtle.pd()
def ustDoNastElem(dlBokMalKw): turtle.pu() turtle.rt(90) turtle.fd(dlBokMalKw * 5) turtle.lt(90) turtle.fd(dlBokMalKw) turtle.pd()
def ustDoNastTetki(orient=1, bokKw=10): turtle.pu() turtle.rt(90*orient) turtle.fd(bokKw*2) turtle.lt(90*orient) turtle.fd(bokKw*3) turtle.pd()
def ustDoKwadratu(dlBokKw): turtle.pu() turtle.fd(dlBokKw * 2) turtle.lt(90) turtle.fd(dlBokKw * 2) turtle.lt(90) turtle.pd()
def ustNaStart(): turtle.pu() turtle.bk(250) turtle.lt(90) turtle.bk(250) turtle.rt(90) turtle.pd()
def korDuza(popr,ile): turtle.pu() turtle.bk(popr * ile) turtle.lt(90) turtle.bk(popr) turtle.rt(90) turtle.pd()
def powrNaSrodekSowy(r, bokKw): rMalegoKola = bokKw/4 turtle.pu() turtle.lt(90) turtle.fd(rMalegoKola) turtle.lt(90) turtle.fd(rMalegoKola) turtle.pd()
def korDuza(a): dlBokKw = a / 5 turtle.pu() turtle.bk(a) turtle.rt(90) turtle.fd(dlBokKw) turtle.lt(90) turtle.pd()
def main(i): t.speed('fastest'); t.tracer(1,0); t.colormode(255) t.lt(90) while (i >= 1): drawLineOfSqrs(i) i -= 1 raw_input()
def polygon(n): degrees = 180 * (n - 2) / n print(degrees) for d in range(n): turtle.fd(100) turtle turtle.lt(180 - degrees)
def koch(n): assert n >= 0 tm = thue_morse(n) for i in tm: if i: turtle.lt(60) else: turtle.fd(1)
def prostokat(bokDl, bokKr): numPow = 1 while numPow <= 2: turtle.fd(bokKr) turtle.lt(90) turtle.fd(bokDl) turtle.lt(90) numPow = numPow + 1
def y(n): if n==0: return turtle.fd(l) x(n-1) turtle.lt(90) y(n-1) turtle.fd(l) x(n)
def portrait(line_color, fill_color): turtle.pu() turtle.goto(0, 0) turtle.pd() turtle.speed(0) turtle.width(2.5) turtle.color(line_color, fill_color) turtle.begin_fill() for i in range(2): for i in range(2): turtle.fd(220) turtle.lt(90) turtle.fd(295) turtle.lt(90) turtle.goto(0, 50) for i in range(2): turtle.fd(200) turtle.lt(90) turtle.fd(200) turtle.lt(90) turtle.goto(0, 70) for i in range(2): turtle.fd(220) turtle.lt(90) turtle.fd(295) turtle.lt(90) turtle.goto(0, 50) for i in range(2): turtle.fd(200) turtle.lt(90) turtle.fd(200) turtle.lt(90) turtle.end_fill() turtle.pu() d=random.randint(1, 100) turtle.color("brown") turtle.write(d, font=("Arial", 60, 'bold'))
import turtle as t t.pensize(4) t.hideturtle() t.circle(50, steps=3) t.circle(50) t.pu() t.goto(25 * (3**0.5), 25) t.pd() for i in range(0, 3): t.lt(120) t.fd(50 * (3**0.5)) t.pu() t.goto(0, 49) t.pd() t.pensize(4) t.circle(1) t.pu() t.goto(50 * (3**0.5), 0) t.pd() for a in range(0, 3): t.lt(120) t.fd(100 * (3**0.5)) t.done()
turtle.rt(40) turtle.end_fill() turtle.pen(pencolor="#C8520A", pensize="1") #ECE19F circ("#C8520A", 172) turtle.pen(pencolor="#770E13", pensize="1") circ("#770E13", 162) turtle.pen(pencolor="#E67B47", pensize="1") circ("#E67B47", 152) turtle.pen(pencolor="orange", pensize="1") circ("orange", 142) turtle.begin_fill() turtle.fillcolor("#383629") turtle.pen(pencolor="#383629", pensize="1") flower(turtle, 9, 140.0, 60.0) turtle.end_fill() turtle.lt(30) turtle.begin_fill() turtle.fillcolor("#EFE19A") turtle.pen(pencolor="#EFE19A", pensize="1") flower(turtle, 9, 140.0, 60.0) turtle.end_fill() turtle.lt(30) turtle.begin_fill() turtle.fillcolor("#C8520A") turtle.pen(pencolor="#C8520A", pensize="1") flower(turtle, 9, 140.0, 60.0) turtle.end_fill() turtle.lt(30) turtle.pen(pencolor="orange", pensize="1") for k in range(6): turtle.begin_fill()
t.pu() t.seth(0) t.fd(10) y = t.pos() t.lt(90) t.fd(25) t.pd() t.dot(12, "blue") t.pu() t.goto(y) t.seth(0) t.fd(10) t.seth(0) t.pd() t.pu() t.lt(90) t.fd(100) t.rt(90) t.fd(60) t.pd() for k in range(namelistlen): print draw(drawnum[k]) t.pu() t.fd(10) t.pd() t.exitonclick()
import turtle as tr tr.fd(250) tr.lt(90) tr.fd(250) tr.lt(90) tr.fd(250) tr.lt(90) tr.fd(250) tr.lt(90) tr.done()
def radian_left(ang, dis, step, n): for i in range(n): dis += step # dis增大step t.lt(ang) # 向左转ang度 t.fd(dis) # 向前走dis的步长
print turtle.pos() print '---------------------------' turtle.home() turtle.dot(20, 'blue') # 画一个点,点半径20,颜色为blue turtle.color('blue') # 线条颜色为blue print turtle.stamp() for i in range(8): turtle.stamp() turtle.fd(30) turtle.clearstamps(2) for i in range(5): turtle.fd(50) turtle.lt(72) for i in range(10): turtle.undo() # 回退,返回到之前的操作 turtle.speed(6) turtle.circle(40) print '--------------------------------------' print '--------------------------------------' # 2、Tell Turtle's state turtle.home() print turtle.position() turtle.goto(10, 10) # 直接去某一点 print turtle.position() print turtle.towards(0, 0) # (10,10)到(0,0)的角度为225度 turtle.goto(0, 0)
t.hideturtle() t.pu() # 提笔 t.goto(-50, 0) # 画笔前往坐标(0,0) t.seth(150) t.pd() # 下笔 t.begin_fill() t.color(0, 0, 255) for i in range(300): t.rt(1) t.forward(2 * m.pi * 100 / 360) t.seth(0) t.backward(10) t.seth(30) for i in range(300): t.lt(1) t.forward(2 * m.pi * 80 / 360) t.seth(0) t.backward(10) t.end_fill() #眼睛 t.pu() t.begin_fill() t.pensize(3) t.pencolor(0, 0, 0) t.goto(-15, 40 * m.sqrt(3) + 60) t.pd() t.circle(15) t.color(255, 255, 255) t.end_fill()
else: nowe = (N/2)*(2**(1/2)) fd(N) lt(45) drzewo((N/2)*(2**(1/2))) rt(135) fd(N) lt(135) if nowe >= 1: fd(nowe) rt(90) drzewo(nowe) lt(90) if nowe >= 1: bk(nowe) rt(135+90) fd(N) rt(90) fd(N) rt(90) tracer(0,1) #speed('fastest') lt(90) pu() goto(0,-450) pd() drzewo(200) update() input()
import turtle as t t.shape("turtle") #거북이의모양을거북이로한다 t.bgcolor("black") #바탕색을 검정으로한다 t.color("red") #거북이색을 빨강으로한다 t.speed(0) #거북이를 제일 빠르게 한다 x = input("50+20= ") #문제를 보여주고 입력받은 답을 x에 저장한다 a = int(x) #x에 저장된 문자열을 정수로 바꾼다 if a == 50 + 20: #만약 a가 70이면 for x in range(60): #60번 반복해라 t.circle(5) #반지름이5인원을그린다 t.up() #팬을 투명하게 바꾼다 t.forward(10) #앞으로 10만큼 간다 t.lt(6) #왼쪽으로 6도 튼다 t.down() #펜색이 다시 나오게 한다 else: #다른답이면 t.rt(45) #오른쪽으로 45도 틀고 for x in range(60): #60번반복해라 t.up() #팬색을 없애고 t.forward(3) #앞으로 3만큼가고 t.down() #팬색을 있게한다음 t.circle(5) #반지름이 5인원을 그려라 t.rt(135) #오른쪽으로 135도 틀고 t.up() #팬색을 없앤다음 t.forward(140) #거북이가 140만큼 가게한다 t.down() #다시 팬색을 있게하고 t.rt(135) #오른쪽으로 135도 튼다 for x in range(60): #60번 반복해라 t.circle(5) #반지름이5인원을그려라 t.up() #팬색을없애고 t.forward(3) #앞으로3만큼가고 t.down() #팬색을 다시 있게해라
def draw(a): t.fd(100) t.lt(a)
t.fd(100) # 앞으로 100픽셀 t.rt(90) # 오른쪽으로 90도 t.fd(100) t.rt(90) t.fd(100) t.rt(90) t.fd(100) ex) 삼각형 그리기 import turtle as t t.shape('blank') # 화살표 모양 안나옴 t.fd(100) t.lt(120) # 왼쪽으로 120도 t.fd(100) t.lt(120) t.fd(100) t.lt(120) ex) 오각형 그리기 import turtle as t t.shape('turtle') for i in range(5): # 오각형이므로 5번 반복 t.fd(100) t.rt(360 / 5) # 360을 5로 나누어서 외각을 구함
def circle(fd_val): for i in range(36): turtle.lt(10) turtle.fd(fd_val)
t.fd(150) # 前进150 t.pd() # 落笔 t.fd(10) #前进10 t.up() # 起笔 t.fd(5) # 前进5 t.pd() # 落笔 t.write(i + 1, font=('Arial', 15, 'normal')) t.up() #起笔 t.setx(0) #回来 t.sety(0) # 回来 t.rt(30) # 右转30度 # 再前进 …… #绘指针(时针和分针) t.home() #回到起始状态 t.lt(90) #起始指向是12,即0点,此时角度是90度 t.rt(tim.hour * 30 + 30 / 60 * tim.minute) #向右转的角度 #时针的粗细3 长度80 t.pensize(3) t.pd() # 落笔 t.fd(80) #分针 t.up() #起笔 t.home() #回到起始状态 t.lt(90) #起始指向是12,即0点,此时角度是90度 t.rt(tim.minute * 6) #向右转的角度 #分针的粗细2 长度110
# t.color('brown') # for i in range(n): # t.forward(i) # t.right(91) # input() # 연습문제: 오각별 그리기 # import turtle as t # n = 5 # t = t.Turtle() # t.shape('turtle') # # 핫핑크 색 # t.color('#FF69B4') # for i in range(n): # t.fd(100) # t.rt((360/n)*2) # t.fd(100) # t.lt(360/n) # input() # 심사문제: 별 그리기 import turtle as t n, line = map(int, input().split()) t = t.Turtle() t.shape('turtle') t.color('purple') t.speed('fastest') for i in range(n): t.forward(line) t.rt((360 / n) * 2) t.forward(line) t.lt(360 / n) input()
import turtle as t t.color("blue") t.begin_fill() t.lt(180) t.fd(40) t.rt(90) t.fd(20) t.rt(40) t.fd(10) t.rt(20) t.fd(10) t.rt(20) t.fd(10) t.rt(10) t.fd(35) t.rt(10) t.fd(10) t.rt(20) t.fd(10) t.rt(20) t.fd(10) t.rt(40) t.fd(50) t.rt(40) # 밑 t.fd(10) t.rt(20) t.fd(10)
from turtle import fd, bk, lt, rt,ht, speed, penup, pendown from math import sqrt def kwadrat(bok): for i in range(4): fd(bok) rt(90) i=10 while(i<250): kwadrat(i) lt(135) penup() fd(i/5) pendown() rt(135) i=i+i/5*sqrt(2) input()
def square(size): for i in range(4): tr.forward(size) tr.lt(90)
import turtle as t t.shape("turtle") t.speed(5) n = 6 t.color("brown") t.begin_fill() for x in range(n): t.fd(50) t.lt(360 / n) t.end_fill() t.lt(120) t.color("yellow") t.begin_fill() for x in range(n): t.fd(50) t.lt(360 / n) t.end_fill() t.lt(120) t.color("yellow") t.begin_fill() for x in range(n): t.fd(50) t.lt(360 / n) t.end_fill()
def draw(x): if x == 0: y = t.pos() t.seth(70) t.fd(100) y1 = t.pos() t.seth(0) t.lt(290) t.fd(100) y2 = t.pos() d1 = t.distance(y1) t.bk(d1 / 2) t.seth(180) t.fd(50) t.pu() t.goto(y2) t.pd() t.seth(0) if x == 1: t.seth(0) t.pu() t.fd(10) t.pd() t.lt(90) t.fd(86) t.seth(0) t.circle(-21.5, 180) t.seth(0) t.circle(-21.5, 180) t.seth(0) t.pu() t.fd(25) t.pd() if x == 2: t.seth(0) t.pu() t.fd(48) y = t.pos() t.pd() t.circle(43.3, -180) t.pu() t.seth(0) t.goto(y) t.fd(10) t.pd() if x == 3: t.seth(0) t.lt(90) t.fd(86) t.seth(0) t.circle(-43, 180) t.seth(0) t.pu() t.fd(50) t.pd() if x == 4: t.fd(60) y = t.pos() t.bk(50) y1 = t.pos() t.lt(90) t.fd(43.3) y2 = t.pos() t.dot(2, "blue") t.fd(43.3) t.rt(90) t.fd(50) t.pu() t.goto(y2) t.pd() t.seth(0) t.fd(30) t.pu() t.goto(y) t.seth(0) if x == 5: y = t.ycor() t.lt(90) t.fd(43.3) y2 = t.pos() t.dot(2, "blue") t.fd(43.3) t.rt(90) t.fd(50) x = t.xcor() t.pu() t.goto(y2) t.pd() t.seth(0) t.fd(30) t.pu() t.goto(x, y) t.seth(0) if x == 6: t.pu() t.seth(0) t.fd(48) t.lt(90) t.fd(86) t.seth(0) t.pd() t.circle(-43.3, -180) t.seth(0) t.lt(90) t.fd(40) t.seth(0) t.bk(10) t.fd(35) t.seth(0) t.rt(90) t.fd(15) t.pu() t.fd(15) t.seth(0) t.fd(15) t.pd() if x == 7: t.lt(90) t.fd(43.3) y2 = t.pos() t.dot(2, "blue") t.fd(43.3) t.goto(y2) t.seth(0) t.fd(50) t.lt(90) t.fd(43.3) t.bk(86.6) t.seth(0) if x == 8: t.pu() t.fd(15) t.pd() y = t.pos() t.lt(90) t.fd(86.6) t.goto(y) t.seth(0) if x == 9: t.seth(10) t.lt(90) t.fd(10) t.seth(90) t.circle(-25, -180) y = t.pos() t.bk(70) t.lt(90) t.fd(10) t.bk(20) t.pu() t.goto(y) t.seth(0) t.lt(-90) t.fd(15) t.seth(0) t.fd(10) if x == 10: t.lt(90) t.fd(43.3) y2 = t.pos() t.dot(2, "blue") t.fd(43.3) t.goto(y2) t.seth(52) t.fd(47) t.goto(y2) t.seth(-50) t.fd(58) t.seth(0) if x == 11: t.lt(90) t.fd(86.6) t.bk(86.6) t.rt(90) t.fd(50) t.seth(0) if x == 12: t.lt(90) t.fd(86.6) t.seth(0) t.seth(-45) t.fd(60) t.seth(0) t.seth(45) t.fd(60) t.seth(0) t.seth(-90) t.fd(86.6) t.seth(0) if x == 13: t.lt(90) t.fd(86.6) t.seth(0) t.seth(-55) t.fd(106) t.seth(0) y = t.pos() t.lt(90) t.fd(86.6) t.goto(y) t.seth(0) if x == 14: t.pu() t.fd(60) y = t.pos() t.lt(90) t.fd(43.3) t.pd() t.circle(43.3) t.pu() t.goto(y) t.fd(43.3) t.seth(0) if x == 15: y = t.pos() t.lt(90) t.fd(35) t.dot(3, "blue") y1 = t.pos() t.fd(35) t.goto(y1) t.seth(0) t.circle(35, 180) t.goto(y) t.seth(0) t.pu() t.fd(35) t.pd() if x == 16: t.pu() t.fd(60) y = t.pos() t.lt(90) y1 = t.pos() t.fd(43.3) t.pd() t.circle(43.3) t.seth(180) t.pu() t.fd(43.3) t.pd() t.seth(0) t.seth(-50) t.fd(60) t.seth(0) if x == 17: y = t.pos() t.lt(90) t.fd(43.3) t.dot(3, "blue") y1 = t.pos() t.fd(43.3) t.goto(y1) t.seth(0) t.circle(30, 180) t.goto(y1) t.seth(0) t.seth(-45) t.fd(60) t.seth(0) if x == 18: t.pu() t.fd(50) t.lt(90) t.fd(30) t.seth(0) y = t.pos() t.pd() t.circle(21.6, -210) t.pu() t.goto(y) t.pd() t.seth(0) t.bk(10) t.circle(-21.6, 230) t.seth(0) t.pu() t.fd(45) t.rt(90) t.fd(10) t.seth(0) if x == 19: t.pu() t.fd(35) t.pd() y = t.pos() t.lt(90) t.fd(86.6) t.lt(90) t.fd(30) t.bk(60) t.lt(90) t.pu() t.fd(86.6) t.seth(0) if x == 20: t.lt(90) t.pu() t.fd(25) t.pd() t.fd(61) t.bk(61) t.seth(0) t.seth(-90) t.circle(25, 180) t.fd(61) t.pu() t.bk(86) t.seth(0) t.pd() if x == 21: t.seth(0) t.pu() t.fd(20) t.pd() y = t.pos() t.seth(65) t.fd(94) t.goto(y) t.seth(0) t.seth(115) t.fd(94) t.goto(y) if x == 22: t.seth(0) t.lt(90) t.fd(86.6) t.bk(86.6) t.seth(0) t.seth(54) t.fd(68) t.seth(0) t.seth(-54) t.fd(68) t.seth(0) t.lt(90) t.fd(86.6) t.bk(86.6) t.seth(0) if x == 23: t.seth(0) t.pu() t.fd(10) t.pd() t.seth(45) t.fd(90) t.bk(45) t.seth(0) t.seth(130) t.fd(45) t.bk(90) t.seth(0) if x == 24: t.seth(0) t.pu() t.fd(10) t.pd() t.seth(45) t.pu() t.fd(90) t.pd() t.bk(45) t.seth(0) t.seth(130) t.fd(45) t.bk(45) t.seth(0) t.seth(-90) t.fd(60) t.seth(0) t.pu() t.fd(30) t.pd() if x == 25: t.fd(65) y = t.pos() t.bk(65) t.seth(0) t.seth(45) t.fd(90) t.seth(0) t.seth(180) t.fd(65) t.pu() t.goto(y) t.seth(0) if x == 26: t.seth(0) t.pu() t.fd(25) t.pd() if x == 27: t.pu() t.seth(0) t.fd(10) y = t.pos() t.lt(90) t.fd(25) t.pd() t.dot(12, "blue") t.pu() t.goto(y) t.seth(0) t.fd(10) t.seth(0) t.pd()
t.seth(-130) t.pd() t.circle(250, 28) # 1 t.circle(10, 140) # 2 t.circle(-250, 25) # 3 t.circle(-200, 25) # 4 t.circle(-50, 85) # 5 t.circle(8, 145) # 6 t.circle(90, 45) # 7 t.circle(550, 5) # 8 # 【尾巴】 t.seth(0) t.circle(60, 85) # 1 t.circle(40, 65) # 2 t.circle(40, 60) # 3 t.lt(150) t.circle(-40, 90) # 4 t.circle(-25, 100) # 5 t.lt(5) t.fd(20) t.circle(10, 60) # 6 # 【背部】 t.rt(80) t.circle(200, 35) # 【项圈】 t.pensize(20) t.color('#F03C3F') t.lt(10) t.circle(-200, 25) # 5 # 【爱心铃铛】 t.pu()
def haus(size): quad(size) t.bk(size) t.lt(90) l = math.sqrt(size**2 / 2) dreieck(size, l, 45)
def square(size): for i in range(4): turtle.fd(size) turtle.lt(90)
t.fd(90) t.rt(90) t.fd(45) t.rt(90) t.fd(90) t.rt(90) t.fd(45) import turtle as t t.reset() tgoto(-200, 200) giyeok() tgoto(-80, 220) t.lt(30) t.forward(140) tgoto(-180, 60) t.lt(90) m() tgoto(-50, 200) t.rt(90) m() tgoto(60, 220) t.bk(140) tgoto(-30, 60) t.bk(45) t.rt(90) t.fd(90) tgoto(110, 200) giyeok()
''' 使用循环绘制五条射线 ''' import turtle as t for i in range(0, 5): t.fd(100) t.bk(100) t.lt(45) t.done()
# -*- coding:utf-8 -*- # @Author : GaoXu # @Time : 2019/8/24 16:44 # @File : AutoTraceDraw.py # @Software : web_auto_test import turtle as t t.title('自动轨迹绘制') t.setup(800, 600, 0, 0) t.pencolor("red") t.pensize(5) #数据读取 datals = [] f = open("data.txt") for line in f: line = line.replace("\n", "") datals.append(list(map(eval, line.split(",")))) f.close() #自动绘制 for i in range(len(datals)): t.pencolor(datals[i][3], datals[i][4], datals[i][5]) t.fd(datals[i][0]) if datals[i][1]: t.rt(datals[i][2]) else: t.lt(datals[i][2])
import turtle as tr tr.penup() tr.goto(-100, 150) tr.pendown() for i in range(3): tr.forward(100) tr.lt(120) tr.done()
# 完成下方底座和横线 t.fd(30) t.rt(90) t.fd(10) t.rt(90) t.fd(30) t.rt(90) t.fd(10) t.rt(90) t.bk(10) t.fd(50) # 开始画右侧平行四边形 t.rt(45) t.fd(30) t.lt(135) t.fd(30) t.lt(45) t.fd(30) t.lt(135) t.fd(30) #调整方向开始画火箭 t.lt(180) t.fd(100) t.lt(30) t.fd(50) t.lt(120) t.fd(50) t.lt(30) t.fd(100)
t.pd() t.begin_fill() t.circle(4) t.end_fill() t.pu() t.goto(-30, 160) t.pensize(4) t.pd() t.color('black', 'white') t.begin_fill() a = 0.4 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.08 t.lt(3) #向左转3度 t.fd(a) #向前走a的步长 else: a = a - 0.08 t.lt(3) t.fd(a) t.end_fill() t.pu() t.goto(30, 160) t.pensize(4) t.pd() t.color('black', 'white') t.begin_fill() for i in range(120): if 0 <= i < 30 or 60 <= i < 90:
def draw(): t.pensize(4) # 设置画笔的大小 t.colormode(255) # 设置GBK颜色范围为0-255 t.color((0, 0, 255), "blue") # 设置画笔颜色和填充颜色(pink) t.setup(800, 600) # 设置主窗口的大小为840*500 t.tracer(1, 0) t.speed(10) # 设置画笔速度为10 t.ht() # 头部 t.hideturtle() t.pu() # 提笔 t.goto(-50, 0) # 画笔前往坐标(0,0) t.seth(150) t.pd() # 下笔 t.begin_fill() t.color(0, 0, 255) for i in range(300): t.rt(1) t.forward(2 * m.pi * 100 / 360) t.seth(0) t.backward(10) t.seth(30) for i in range(300): t.lt(1) t.forward(2 * m.pi * 80 / 360) t.seth(0) t.backward(10) t.end_fill() # 眼睛 t.pu() t.begin_fill() t.pensize(3) t.pencolor(0, 0, 0) t.goto(-15, 40 * m.sqrt(3) + 60) t.pd() t.circle(15) t.color(255, 255, 255) t.end_fill() t.pu() t.begin_fill() t.pensize(3) t.pencolor(0, 0, 0) t.goto(-15, 40 * m.sqrt(3) + 60) t.pd() t.circle(5) t.color(0, 0, 0) t.end_fill() t.pu() t.begin_fill() t.pensize(3) t.pencolor(0, 0, 0) t.goto(15, 40 * m.sqrt(3) + 60) t.pd() t.circle(15) t.color(255, 255, 255) t.end_fill() t.pu() t.begin_fill() t.pensize(3) t.pencolor(0, 0, 0) t.goto(15, 40 * m.sqrt(3) + 60) t.pd() t.circle(5) t.color(0, 0, 0) t.end_fill() # 鼻子 t.pu() t.pensize(3) t.pencolor(255, 0, 0) t.goto(0, 40 * m.sqrt(3) + 40) t.pd() t.begin_fill() t.color(255, 0, 0) t.circle(10) t.end_fill() # 嘴巴 t.pu() t.pensize(3) t.pencolor(0, 0, 0) t.goto(0, 40 * m.sqrt(3) + 40) t.pd() t.seth(-90) t.forward(50) t.pu() t.goto(-50, 90 - 10 * m.sqrt(3)) t.seth(-30) t.pd() for i in range(60): t.lt(1) t.forward(2 * m.pi * 100 / 360) # 胡须 t.pu() t.pensize(3) t.pencolor(0, 0, 0) t.goto(-30, 40 * m.sqrt(3) + 25) t.seth(0) t.pd() t.backward(40) t.pu() t.pensize(3) t.pencolor(0, 0, 0) t.goto(-30, 40 * m.sqrt(3) + 15) t.pd() t.seth(30) t.backward(40) t.pu() t.pensize(3) t.pencolor(0, 0, 0) t.goto(-30, 40 * m.sqrt(3) + 35) t.pd() t.seth(-30) t.backward(40) t.pu() t.pensize(3) t.pencolor(0, 0, 0) t.goto(30, 40 * m.sqrt(3) + 25) t.seth(0) t.pd() t.forward(40) t.pu() t.pensize(3) t.pencolor(0, 0, 0) t.goto(30, 40 * m.sqrt(3) + 35) t.pd() t.seth(30) t.forward(40) t.pu() t.pensize(3) t.pencolor(0, 0, 0) t.goto(30, 40 * m.sqrt(3) + 15) t.pd() t.seth(-30) t.forward(40)