【Pyhton TurtleArt】画一幅极简渐变风景图

冬

代码如下:

import turtle as tu
import random as ra

#天空
tu.colormode(255)
tu.setup(515,315)
tu.bgcolor('midnight blue')
tu.speed(100)

#云层
tu.color('dark slate blue')
tu.pu()
tu.pensize(5)
tu.goto(ra.randint(-700,-258),128)
tu.pd()
tu.begin_fill()
tu.seth(-40)
for i in range(10):
    tu.circle(40,80)
    tu.circle(-40,80)
tu.goto(258,-158)
tu.goto(-258,-158)
tu.goto(-258,108)
tu.end_fill()
tu.pu()

tu.goto(ra.randint(-700,-258),108)
tu.color('MediumPurple3')
tu.pd()
tu.begin_fill()
tu.seth(-40)
for i in range(10):
    tu.circle(40,80)
    tu.circle(-40,80)
tu.goto(258,-158)
tu.goto(-258,-158)
tu.goto(-258,108)
tu.end_fill()
tu.pu()

tu.goto(ra.randint(-700,-258),88)
tu.color('SlateBlue3')
tu.pd()
tu.begin_fill()
tu.seth(-40)
for i in range(10):
    tu.circle(40,80)
    tu.circle(-40,80)
tu.goto(258,-158)
tu.goto(-258,-158)
tu.goto(-258,108)
tu.end_fill()
tu.pu()

tu.goto(ra.randint(-700,-258),68)
tu.color('SlateBlue2')
tu.pd()
tu.begin_fill()
tu.seth(-40)
for i in range(10):
    tu.circle(40,80)
    tu.circle(-40,80)
tu.goto(258,-158)
tu.goto(-258,-158)
tu.goto(-258,108)
tu.end_fill()
tu.pu()

tu.goto(ra.randint(-700,-258),48)
tu.color('MediumPurple2')
tu.pd()
tu.begin_fill()
tu.seth(-40)
for i in range(10):
    tu.circle(40,80)
    tu.circle(-40,80)
tu.goto(258,-158)
tu.goto(-258,-158)
tu.goto(-258,108)
tu.end_fill()
tu.pu()

tu.goto(ra.randint(-700,-258),8)
tu.color('medium purple')
tu.pd()
tu.begin_fill()
tu.seth(-40)
for i in range(10):
    tu.circle(40,80)
    tu.circle(-40,80)
tu.goto(258,-158)
tu.goto(-258,-158)
tu.goto(-258,108)
tu.end_fill()
tu.pu()

tu.goto(ra.randint(-700,-258),-28)
tu.color('SlateBlue1')
tu.pd()
tu.begin_fill()
tu.seth(-40)
for i in range(10):
    tu.circle(40,80)
    tu.circle(-40,80)
tu.goto(258,-158)
tu.goto(-258,-158)
tu.goto(-258,108)
tu.end_fill()
tu.pu()

tu.goto(ra.randint(-700,-258),-58)
tu.color('light slate blue')
tu.pd()
tu.begin_fill()
tu.seth(-40)
for i in range(10):
    tu.circle(40,80)
    tu.circle(-40,80)
tu.goto(258,-158)
tu.goto(-258,-158)
tu.goto(-258,108)
tu.end_fill()
tu.pu()

tu.goto(ra.randint(-700,-258),-88)
tu.color('light steel blue')
tu.pd()
tu.begin_fill()
tu.seth(-40)
for i in range(10):
    tu.circle(40,80)
    tu.circle(-40,80)
tu.goto(258,-158)
tu.goto(-258,-158)
tu.goto(-258,108)
tu.end_fill()
tu.pu()

#山

tu.pensize(50)
tu.pencolor('lavender')
tu.goto(-258,-108)
tu.seth(60)
tu.pd()
tu.forward(30)
tu.seth(-60)
tu.forward(500)
tu.seth(60)
tu.forward(500)
tu.seth(-60)
tu.forward(400)
tu.pu()

tu.pencolor('royal blue')
tu.goto(ra.randint(-700,0),-118)
tu.seth(60)
tu.pd()
tu.forward(30)
tu.seth(-60)
tu.forward(400)
tu.seth(60)
tu.forward(400)
tu.seth(-60)
tu.forward(400)
tu.pu()

tu.pencolor('RoyalBlue3')
tu.goto(ra.randint(-700,-150),-98)
tu.seth(60)
tu.pd()
tu.forward(30)
tu.seth(-60)
tu.forward(400)
tu.seth(60)
tu.forward(400)
tu.seth(-60)
tu.forward(400)
tu.pu()


#地面
tu.pensize(100)
tu.pencolor('SlateBlue4')
tu.goto(-258,-158)
tu.seth(0)
tu.pd()
tu.forward(500)
tu.pu()

#小石头
tu.pencolor('Royalblue2')
for i in range(4):
    x=ra.randint(-258,258)
    y=ra.randint(-158,-120)
    tu.goto(x,y)
    tu.pd()
    tu.write('🔺',font=("Arial Rounded" , 60 , "normal"))
    tu.pu()

tu.done()

生成效果是这样的
生成效果是这样的

第一张图是公式计算递减的颜色排布,看上去渐变得跟舒服一点。我在一个列表文件中保存了这些数据

| 在这里插入图片描述
换成其他色调的效果:

在这里插入图片描述

在这里插入图片描述

  • 4
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要使用Python绘制折线,你可以使用pandas和matplotlib这两个库。首先,你需要导入这两个库,并读取你的数据文件。可以使用pandas的`read_excel`函数来读取Excel文件。然后,你需要指定你要绘制的曲线的x轴和y轴的数据。在这个例子中,x轴是姓名,y轴分别是语文、数学、英语、物理和化学的成绩。 为了解决中文乱码问题,你可以使用matplotlib的`rcParams`来设置字体为SimHei。然后,你可以创建一个8x7大小的布,使用`figure`函数。接下来,使用`plot`函数绘制五条折线,分别对应不同科目的成绩。你可以指定每个折线的颜色、标记点的样式和线条的样式。使用`grid`函数可以添加网格线。设置x轴和y轴的标题,使用`ylabel`和`xlabel`函数。通过`legend`函数设置例,用于标识每个折线对应的科目。最后,使用`yticks`函数设置y轴刻度的范围,并使用`show`函数显示表。 下面是一个代码示例,可以参考一下: ```python import pandas as pd import matplotlib.pyplot as plt # 导入excel文件 df = pd.read_excel('成绩表.xlsx') # 取df中某一列数据 x = df['姓名'] y1 = df['语文'] y2 = df['数学'] y3 = df['英语'] y4 = df['物理'] y5 = df['化学'] # 解决中文乱码 plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置布宽度 plt.figure(figsize=(8, 7)) # 绘制折线 plt.plot(x, y1, label='语文', color='r', marker='p') plt.plot(x, y2, label='数学', color='g', marker='p', linestyle='--') plt.plot(x, y3, label='英语', color='b', marker='p', linestyle='-.') plt.plot(x, y4, label='物理', color='y', marker='p', linestyle='-.') plt.plot(x, y5, label='化学', color='r', marker='p', linestyle='--') # 添加网格线 plt.grid() # 设置坐标轴的标题 plt.ylabel('分数') plt.xlabel('姓名') # 设置例 plt.legend(['语文', '数学', '英语', '物理', '化学']) # 设置y轴刻度 plt.yticks(range(80, 150, 10)) # 显示表 plt.show() ``` 这段代码可以帮助你使用Python绘制折线。你只需要将数据文件路径更改为你的文件路径,然后运行代码即可。希望对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值