如何用Python画一些简单形状你知道吗

 更新时间:2021年08月17日 11:13:58   作者:我帅的是不是无可救药  
这篇文章主要介绍了用Python作图的一个简单实例,通过turtle模块实现作图,具有一定参考价值,需要的朋友可以了解下希望能给你带来帮助

进入主题

1.

import turtle as t
import math
t.pensize(3)
t.tracer(10)
t.hideturtle()
start_x = -200
for y in range(-150,150,5):
    t.penup()
    t.goto(start_x,y)
    t.pendown()
    for x in range(-200,200,1):
        if ((y-50*(math.cos(0.05*x)) <= 80) and
            (y-50*(math.cos(0.05*x)) >= 60)):
            t.pencolor('yellow')
        elif ((y-50*(math.cos(0.05*x)) <= 40) and
            (y-50*(math.cos(0.05*x)) >= -20)):
            t.pencolor('blue')
        elif ((y-50*(math.cos(0.05*x)) <= -20) and
            (y-50*(math.cos(0.05*x)) >= -80)):
            t.pencolor('red')
        elif ((y-50*(math.cos(0.05*x)) <= -60) and
            (y-50*(math.cos(0.05)) <= -80)):
            t.pencolor('green')
        else:
            t.pencolor('black')
        t.setx(x)
t.update()
t.done()

import turtle as t
t.speed(0)
t.tracer(20)
t.hideturtle()
t.colormode(255)
angle = 90
for x in range(255,0,-5):
    for n in range(360//angle):
        t.pencolor((x,255,255))
        t.fillcolor((25,x,255))
        t.begin_fill()
        for i in range(2):
            t.forward(x)
            t.right(angle)
            t.forward(x)
            t.right(180-angle)
        t.end_fill()
        t.right(angle)
t.update()
t.done()

import turtle as t
t.speed(0)
t.tracer(20)
t.colormode(255)
angle = 60
angle2 = 3
for x in range(255,0,-5):
    for n in range(360//angle):
        t.pencolor((x,255,255))
        t.fillcolor((255,x,255))
        t.begin_fill()
        for i in range(2):
            t.forward(x)
            t.right(angle)
            t.forward(x)
            t.right(180-angle)
        t.end_fill()
        t.right(angle)
    t.right(angle2)
t.update()
t.done()

from turtle import *       
colormode(255)
tracer(5)
a1=39
a2=1
for x in range(255,0,-5):
    pencolor(x,255,255)
    fillcolor(255,x,255)
    for y in range(360//a1):
        begin_fill()
        for z in range(2):
            fd(x)
            rt(a1)
            fd(x)
            rt(180-a1)
        end_fill()
        rt(a1)
    rt(a2)
update()
ht()
done()

import turtle as t
t.speed(0)
t.hideturtle()
t.penup()
t.setx(-200)
t.pendown()
r = 20
i = 6
for x in range(10):
    if x % 2 == 0:
        t.fillcolor("skyblue")
        t.begin_fill()
        t.circle(r)
        t.end_fill()
        add = 0
    else:
        t.fillcolor("green")
        t.begin_fill()
        for n in range(4):
            t.forward(r*2)
            t.left(90)
        t.end_fill()
        add = r*2
    t.penup()
    t.forward(r+i+add)
    t.pendown()
t.done()

import turtle as t
t.pensize(5)
t.tracer(10)
t.hideturtle()
start_x = -200
for y in range(-150,150,20):
    t.penup()
    t.goto(start_x,y)
    t.pendown()
    for x in range(-200,200,1):
        if ((x < 100 and x > 0) and 
            (y < 80 and y > 0)):
            t.pencolor('yellow')
        elif ((x < 100 and x > 0) and
            (y < 0 and y > -80)):
            t.pencolor('blue')
        elif ((x < 0 and x > -100) and
            (y < 80 and y > 0)):
            t.pencolor('red')
        elif ((x < 0 and x > -100) and
            (y < 0 and y > -80)):
            t.pencolor('orange')
        else:
            t.pencolor('green')
        t.setx(x)
t.update()
t.done()

import turtle as t
t.pensize(5)
t.tracer(10)
t.hideturtle()
start_x = -200
for y in range(-150,150,20):
    t.penup()
    t.goto(start_x,y)
    t.pendown()
    for x in range(-200,200,1):
        if ((y-x <= 40) and
            (y-x >= -40)):
            t.pencolor('yellow')
        elif ((y+x <= 40) and
            (y+x >= -40)):
            t.pencolor('blue')
        else:
            t.pencolor('green')
        t.setx(x)
t.update()
t.done()

import turtle as t
t.speed(0)
t.tracer(20)
t.hideturtle()
t.colormode(255)
angle = 60
for x in range(255,0,-5):
    for n in range(360//angle):
        t.pencolor((x,255,255))
        t.fillcolor((255,x,255))
        t.begin_fill()
        for i in range(2):
            t.forward(x)
            t.right(angle)
            t.forward(x)
            t.right(180-angle)
        t.end_fill()
        t.right(angle)
t.update()
t.done()

总结

本篇文章就到这里了,希望能给你带来帮助,也希望您能够多多关注脚本之家的更多内容!

相关文章

  • python抓取网页内容示例分享

    python抓取网页内容示例分享

    这篇文章主要介绍了python抓取网页内容示例,在抓取的时候对于gbk编码网页还需要转化一下,具体看下面的示例吧
    2014-02-02
  • python实现的分析并统计nginx日志数据功能示例

    python实现的分析并统计nginx日志数据功能示例

    这篇文章主要介绍了python实现的分析并统计nginx日志数据功能,结合实例形式分析了Python针对nginx日志ip、访问url、状态等数据的相关读取、解析操作技巧,需要的朋友可以参考下
    2019-12-12
  • Sanic框架流式传输操作示例

    Sanic框架流式传输操作示例

    这篇文章主要介绍了Sanic框架流式传输操作,结合实例形式分析了Sanic通过流请求与响应传输操作相关实现技巧与注意事项,需要的朋友可以参考下
    2018-07-07
  • 浅谈keras保存模型中的save()和save_weights()区别

    浅谈keras保存模型中的save()和save_weights()区别

    这篇文章主要介绍了浅谈keras保存模型中的save()和save_weights()区别,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-05-05
  • opencv 傅里叶变换的实现

    opencv 傅里叶变换的实现

    本文主要介绍了opencv 傅里叶变换,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧<BR>
    2022-06-06
  • python中isdigit() isalpha()用于判断字符串的类型问题

    python中isdigit() isalpha()用于判断字符串的类型问题

    这篇文章主要介绍了python中isdigit() isalpha()用于判断字符串的类型问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-11-11
  • 老生常谈Python startswith()函数与endswith函数

    老生常谈Python startswith()函数与endswith函数

    下面小编就为大家带来一篇老生常谈Python startswith()函数与endswith函数。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-09-09
  • Python爬取读者并制作成PDF

    Python爬取读者并制作成PDF

    本文是在学习了beautifulsoup之后,制作的一个爬取读者杂志并使用reportlab制作成pdf的python小工具,咱也文艺一下:),分享给大家,有需要的小伙伴参考下吧。
    2015-03-03
  • Python使用multiprocessing如何实现多进程

    Python使用multiprocessing如何实现多进程

    这篇文章主要介绍了Python使用multiprocessing如何实现多进程问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-02-02
  • python实现将range()函数生成的数字存储在一个列表中

    python实现将range()函数生成的数字存储在一个列表中

    这篇文章主要介绍了python实现将range()函数生成的数字存储在一个列表中,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-04-04

最新评论