import math
from turtle import *
def fillblack():
tom.pensize(0)
tom.penup()
tom.goto(cors[0])
tom.begin_fill()
for p in cors:
tom.goto(p)
tom.end_fill()
def draw_oval(a,b=None,width=5,fill=''):
""" 以角色为中心点画椭圆,这个方法不会根据角色的方向对椭圆进行倾斜,所以速度快.
a:长半轴,b:短半轴,
width:边框像素值
fill:填充颜色,
outline:边框颜色
"""
def draw_oval2(a,b=None,width=2,fill=''):
"""以海龟为中心点画椭圆,这个方法会根据角色的方向对椭圆进行倾斜,所以速度慢
a:长半轴,b:短半轴,
width:边框像素值
fill:填充颜色,如果为空字符串,则无颜色
"""
def two_point_distance(p1,p2):
"""返回两点之间的距离"""
a,b = p1
c,d = p2
return math.sqrt((a-c)**2 + (b-d)**2)
def get_triangle_angle_by_length(a,b,c):
"""a:边1 b:边2 c:边3
返回ab夹角,ac夹角,bc角度
"""
bc=math.degrees(math.acos((a*a-b*b-c*c)/(-2*b*c))) # bc边的夹角
ac=math.degrees(math.acos((b*b-a*a-c*c)/(-2*a*c))) # ac边的夹角
ab=math.degrees(math.acos((c*c-a*a-b*b)/(-2*a*b))) # ab边的夹角
return ab,ac,bc
def get_triangle_angle_by_points(p1,p2,p3):
"""根据三角形的三点得到三个角度"""
a = two_point_distance(p1,p2)
b = two_point_distance(p1,p3)
c = two_point_distance(p3,p2)
return get_triangle_angle_by_length(a,b,c)
def circle_center(p0, p1, r):
"""得到圆心点坐标"""
pass
def draw_arc(start,end,radius):
"""两点之间画弧,radius是圆半径"""
drawarc = draw_arc
def draw_arc2(start,end,radius):
"""两点之间画弧,radius是圆半径"""
pass
drawarc2 = draw_arc2
def draw_line(start,end):
"""start:起点坐标,二元组,end终点坐标二元组"""
tom.penup()
tom.goto(start)
tom.pendown()
tom.goto(end)
drawline = draw_line # 取别名
def draw_lines():
am = len(cors)
for i in range(am-1):
start = tuple(cors[i])
end = tuple(cors[i+1])
drawline(start,end)
drawlines = draw_lines
screen = Screen()
tom = Turtle()
tom.penup()
tom.pensize(2)
# 轮廓
cors = [[-265.0, 44.0], [-250.0, 72.0], [-208.0, 85.0], [-157.0, 124.0], [-44.0, 144.0], [22.0, 143.0], [102.0, 123.0], [172.0, 57.0], [203.0, 43.0], [219.0, 42.0], [244.0, 26.0], [260.0, -2.0], [269.0, -78.0], [269.0, -94.0], [258.0, -113.0], [253.0, -115.0], [-24.0, -137.0], [-82.0, -135.0], [-88.0, -142.0], [-134.0, -144.0], [-147.0, -107.0], [-204.0, -74.0], [-209.0, -81.0], [-249.0, -83.0], [-265.0, -30.0], [-265.0, 33.0], [-264.0, 44.0]]
draw_lines()
# 挡风玻璃
cors = [[-188.0, 102.0], [-157.0, 123.0], [-139.0, 130.0], [-120.0, 129.0], [-110.0, 123.0], [-105.0, 110.0], [-108.0, 42.0], [-48.0, 40.0], [105.0, 45.0], [176.0, 55.0],[107.0, 120.0], [29.0, 120.0], [-64.0, 114.0], [-103.0, 110.0]]
draw_lines()
# 门
cors = [[-193.0, 97.0], [-156.0, 118.0], [-143.0, 123.0], [-126.0, 120.0], [-116.0, 104.0], [-118.0, 79.0], [-118.0, 56.0], [-120.0, 39.0], [-141.0, 19.0], [-148.0, -0.0], [-149.0, -29.0], [-148.0, -89.0], [-146.0, -103.0], [-204.0, -73.0], [-226.0, -61.0], [-234.0, -39.0], [-207.0, -57.0], [-206.0, -45.0], [-219.0, -34.0], [-225.0, -26.0], [-228.0, 2.0], [-231.0, 20.0], [-231.0, 47.0], [-222.0, 65.0], [-208.0, 75.0], [-198.0, 88.0], [-190.0, 97.0]]
draw_lines()
# 门2
cors = [[-168.0, 111.0], [-190.0, 68.0], [-208.0, 54.0], [-211.0, 43.0], [-213.0, 32.0], [-214.0, -4.0], [-207.0, -44.0], [-204.0, -47.0], [-197.0, -41.0], [-196.0, -29.0], [-198.0, 3.0], [-199.0, 27.0], [-178.0, 20.0], [-201.0, 29.0], [-201.0, 34.0], [-202.0, 37.0], [-206.0, 39.0], [-211.0, 39.0]]
draw_lines()
# 前进风
cors =[[-111.0, -28.0], [-77.0, -34.0], [-80.0, -24.0], [-76.0, -21.0], [52.0, -47.0], [63.0, -43.0], [160.0, -36.0], [200.0, -37.0], [205.0, -42.0], [256.0, -7.0], [260.0, -16.0], [260.0, -23.0], [256.0, -38.0], [259.0, -77.0], [251.0, -86.0], [213.0, -99.0], [224.0, -30.0], [205.0, -41.0], [207.0, -61.0], [199.0, -98.0], [196.0, -99.0], [189.0, -108.0], [109.0, -115.0], [82.0, -116.0], [76.0, -114.0], [72.0, -109.0], [54.0, -50.0]]
draw_lines()
cors =[[-77.0, -27.0], [-68.0, -53.0], [-57.0, -92.0], [-45.0, -102.0], [36.0, -109.0], [12.0, -61.0], [32.0, -61.0], [-64.0, -51.0], [-64.0, -68.0], [36.0, -77.0]]
draw_lines()
# 车盖
cors=[[-97.0, 33.0], [8.0, -26.0]]
draw_arc(tuple(cors[0]),tuple(cors[1]),300)
cors=[[197.0, 37.0], [219.0, 7.0]]
draw_arc(tuple(cors[0]),tuple(cors[1]),100)
cors=[ [219.0, 7.0], [220.0, -22.0]]
draw_arc(tuple(cors[0]),tuple(cors[1]),100)
# 右前轮
tom.penup()
tom.goto(-140.0, -78.0)
draw_oval(6,40,3)
tom.goto(-140.0, -78.0)
draw_oval(10,55,3)
tom.goto(-134.0, -78.0)
draw_oval(12,65,3)
# 前轮填充
cors=[[-139.0, -13.0], [-133.0, -9.0], [-126.0, -8.0], [-126.0, -4.0], [-123.0, -5.0], [-110.0, -28.0], [-93.0, -124.0], [-83.0, -134.0], [-89.0, -142.0], [-133.0, -144.0], [-135.0, -139.0], [-131.0, -137.0], [-124.0, -122.0], [-123.0, -112.0], [-123.0, -63.0], [-127.0, -33.0], [-132.0, -21.0], [-137.0, -15.0], [-138.0, -15.0], [-140.0, -12.0],[-139.0, -13.0]]
fillblack()
cors=[[-148.0, -9.0], [-141.0, -11.0], [-140.0, -3.0], [-135.0, 2.0], [-128.0, -0.0], [-124.0, -4.0], [-122.0, -8.0]]
tom.pensize(3)
cors=[[-149.0, -6.0], [-140.0, -15.0], [-142.0, -4.0], [-140.0, -2.0],[-138.0, 0.0],[-131.0, -2.0], [-125.0, -5.0], [-113.0, -26.0]]
draw_lines()
tom.penup()
# 右后轮
tom.goto(-254.0, -25.0)
draw_oval(7,30,3)
draw_oval(11,50,3)
tom.goto(-254.0, -20.0)
draw_oval(12,65,3)
# 后轮填充
cors=[[-202.0, -74.0], [-205.0, -73.0], [-206.0, -75.0], [-209.0, -81.0], [-211.0, -82.0], [-223.0, -82.0], [-252.0, -82.0], [-254.0, -79.0], [-252.0, -78.0], [-246.0, -75.0], [-243.0, -60.0], [-242.0, -45.0], [-242.0, -1.0], [-239.0, -5.0], [-238.0, -9.0], [-232.0, -36.0], [-223.0, -62.0], [-203.0, -73.0]]
fillblack()
# 车把手填充
cors=[[-204.0, -48.0], [-198.0, -40.0], [-197.0, -21.0], [-199.0, -13.0], [-199.0, 5.0], [-200.0, 28.0], [-213.0, 31.0], [-214.0, -5.0], [-206.0, -48.0],[-204.0, -48.0]]
fillblack()
# 前挡填充
cors=[[-31.0, -135.0], [-19.0, -128.0], [-3.0, -124.0], [79.0, -122.0], [163.0, -118.0], [209.0, -113.0], [250.0, -105.0], [252.0, -105.0], [254.0, -115.0], [223.0, -126.0], [89.0, -137.0], [-17.0, -137.0], [-27.0, -136.0]]
fillblack()
tom.goto(-189.0, 86.0)
tom.setheading(60)
draw_oval2(12,4)
tom.pensize(2)
cors=[-206.0, -55.0], [-148.0, -90.0]
drawlines()
tom.ht()
# 右反光镜
cors=[[-191.0, 68.0], [-178.0, 62.0], [-158.0, 67.0], [-148.0, 67.0], [-142.0, 48.0], [-147.0, 44.0], [-156.0, 44.0], [-174.0, 47.0], [-183.0, 49.0], [-182.0, 58.0], [-178.0, 63.0]]
drawlines()
cors=[[-121.0, 39.0], [-142.0, 48.0], [-145.0, 42.0], [-140.0, 37.0], [-148.0, 31.0], [-156.0, 43.0], [-144.0, 45.0]]
drawlines()
# 左反光镜
cors=[[168.0, 59.0], [169.0, 73.0], [173.0, 83.0], [188.0, 83.0], [198.0, 77.0], [199.0, 66.0], [183.0, 58.0], [173.0, 58.0], [172.0, 54.0], [179.0, 50.0], [182.0, 59.0]]
drawlines()
cors=[[-246.0, 26.0], [-232.0, 20.0]]
drawlines()
cors=[[60.0, -55.0], [66.0, -49.0], [193.0, -43.0], [199.0, -48.0], [200.0, -56.0], [190.0, -96.0], [183.0, -101.0], [106.0, -107.0], [88.0, -108.0], [78.0, -102.0], [61.0, -56.0], [61.0, -53.0]]
drawlines()
# 左进风
tom.pensize(6)
cors=[[222.0, -45.0], [247.0, -38.0], [259.0, -39.0], [264.0, -21.0], [259.0, -8.0], [259.0, -48.0], [223.0, -61.0], [219.0, -76.0], [245.0, -67.0], [259.0, -60.0], [259.0, -55.0], [259.0, -73.0], [266.0, -71.0], [249.0, -80.0], [218.0, -88.0], [214.0, -97.0]]
drawlines()
tom.pensize(3)
cors=[[224.0, -30.0], [221.0, -76.0], [217.0, -88.0], [215.0, -99.0]]
drawlines()
#右进风
tom.pensize(7)
cors=[[-76.0, -23.0], [-56.0, -54.0], [28.0, -58.0], [18.0, -40.0]]
drawlines()
tom.pensize(4)
cors=[[-71.0, -65.0], [5.0, -76.0], [37.0, -77.0]]
drawlines()
cors=[[-67.0, -79.0], [-24.0, -87.0], [27.0, -89.0], [46.0, -91.0]]
drawlines()
cors=[[-61.0, -93.0], [-13.0, -98.0], [30.0, -100.0], [53.0, -105.0]]
drawlines()
screen.mainloop()
所有的坐标点是通过自己编制的辅助程序手动选取的,当然不需要自己去一个一个输入。
最终的车是像下面这样的:

本代码有偿提供,需要所有源代码及素材请联系scratch8微信。

