用户:
执着的胆小菇tCrJ查看:0 回复:0 评论:0 创建时间:2021-05-03T18:10:27
【作品展示】

【作品介绍】
本作品 主要通过简图的方式直观对比太阳系中的恒星——太阳,与其他行星的大小对比(比例可能不准确,请见谅)
【作品源代码】
# 导入库
import turtle
# turtle设置
pen = turtle.Pen()
pen.speed(0)
pen.pensize(1)
pen.color("white")
pen.hideturtle()
screen = turtle.Screen()
screen.bgcolor("sky blue")
width, height = 1500, 1000
screen.setup(width, height, )
# 变量
radius = 115
sun_color = "yellow"
earth_color = "blue"
saturn_color = "brown"
mars_color = "red"
jupiter_color = "gold"
title_s = "太阳"
title_e = "地球"
title_sa = "土星"
title_m = "火星"
title_j = "木星"
angle = 90
distance = 50
x, y = 0, 0
# 太阳系——主程序
class The_Solar_System():
# 初始化
def __init__(self, radius
, sun_color,earth_color, saturn_color,
mars_color,jupiter_color, angle, distance, x, y):
self.radius = radius
self.sun_color = sun_color
self.earth_color = earth_color
self.saturn_color = saturn_color
self.mars_color = mars_color
self.jupiter_color = jupiter_color
self.angle = angle
self.distance = distance
self.x = x
self.y = y
self.setup()
# 函数的调用
def setup(self):
self.draw_sun(pen, self.radius, self.sun_color)
self.draw_star(pen, self.radius // 6, self.earth_color, self.distance)
self.draw_star(pen, self.radius // 4, self.saturn_color, self.distance * 4)
self.draw_star(pen, self.radius // 18, self.mars_color, self.distance * 2)
self.draw_star(pen, self.radius // 3, self.jupiter_color, self.distance * 6)
pen.right(30)
self.write(pen, self.x, self.y - radius, title_s)
self.write(pen, self.x - radius - radius // 6, self.y, title_e)
self.write(pen, self.x - radius*2 + 12 , self.y , title_m)
self.write(pen, self.x - radius*2 - radius // 2, self.y, title_sa)
self.write(pen, self.x - radius*3 - radius // 3, self.y, title_j)
# 新goto
def new_goto(self, pen, x, y):
pen.penup()
pen.goto(x, y)
pen.pendown()
# 新forward
def new_for(self, pen, length):
pen.penup()
pen.forward(length)
pen.pendown()
# 画太阳
def draw_sun(self, pen, radius, sun_color):
pen.right(angle)
self.new_goto(pen, -radius, 10)
pen.fillcolor(sun_color)
pen.begin_fill()
pen.circle(radius)
pen.end_fill()
self.sun_x = pen.xcor()
self.sun_y = pen.ycor()
# 画行星
def draw_star(self,pen, radius, color, distance):
self.new_goto(pen, self.sun_x - distance, self.sun_y)
pen.fillcolor(color)
pen.begin_fill()
pen.circle(radius)
pen.end_fill()
# 写字
def write(self, pen, x, y, title):
self.new_goto(pen, x, y)
pen.forward(100)
self.new_for(pen, 50)
pen.write(title, font=("Monaco", 20, "normal"))
# main代码块
if __name__ == "__main__":
The_Solar_System(radius, sun_color
, earth_color, saturn_color, mars_color,jupiter_color, angle, distance, x, y)
# 保持窗口显示
turtle.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn