Python之turtle库画各种有趣的图及源码(更新中) 您所在的位置:网站首页 海龟绘图五边形代码 Python之turtle库画各种有趣的图及源码(更新中)

Python之turtle库画各种有趣的图及源码(更新中)

2024-06-01 16:47| 来源: 网络整理| 查看: 265

Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行的路径上绘制了图形。

1、安卓小人 #!/usr/bin/env python import turtle aj=turtle.Pen() y=0 aj.speed(5) #turtle.screensize(200,800) turtle.bgcolor("black") #aj.shape("turtle") def head(): aj.color("green") aj.fd(160) x=aj.xcor() aj.seth(90) aj.begin_fill() #aj.color("green") aj.circle(x/2,180) aj.end_fill() aj.penup() aj.goto(33,37) aj.pendown() aj.dot(13,"black") aj.penup() aj.goto(126,37) aj.pendown() aj.dot(13,"black") aj.penup() aj.home() aj.pendown() aj.hideturtle() aj.fd(160) aj.seth(90) aj.circle(x/2,60) aj.right(90) aj.pensize(5) aj.fd(30) aj.penup() aj.home() #aj.pendown() aj.hideturtle() aj.fd(160) aj.seth(90) aj.circle(x/2,120) aj.right(90) aj.pensize(5) aj.pendown() aj.fd(30) aj.penup() aj.home() aj.penup() def body(): aj.pensize(0) aj.home() aj.showturtle() aj.goto(0,-7) aj.pendown() aj.begin_fill() aj.fd(160) aj.right(90) aj.fd(120) aj.right(90) aj.fd(160) y=aj.ycor() aj.right(90) aj.fd(120) aj.end_fill() def legs(): aj.penup() #turtle.color("red") aj.goto(33,-169) aj.pendown() aj.pensize(32) aj.fd(43) aj.penup() aj.goto(130,-169) aj.pendown() aj.fd(43) aj.penup() def hands(): aj.home() aj.pensize(30) aj.goto(-18,-77) aj.pendown() aj.left(90) aj.fd(65) aj.penup() aj.goto(179,-77) aj.pendown() aj.fd(65) aj.penup() aj.hideturtle aj.fd(100) aj.hideturtle() aj.circle(100) aj.circle(100,360,59) aj.reset() turtle.bgcolor("black") turtle.pencolor("green") turtle.hideturtle() turtle.goto(-300,0) aj.hideturtle turtle.write("Thank you for watching....", font = ("Bodoni MT Black", 28, "bold")) turtle.penup() turtle.goto(-40,-170) turtle.pendown() turtle.pencolor("yellow") turtle.write("Developed by 一个超会写Bug的安太狼", font = ("Palatino Linotype", 22, "bold")) head() body() legs() hands() turtle.done()

效果图: 在这里插入图片描述

2、龙形曲线(Dragon Curve)

又叫分形龙,是一种自相似碎形曲线的统称,因形似龙的蜿蜒盘曲而得名。

# -*- coding: utf-8 -*- from turtle import * length = 5 angle = 90 setup(1280,720) up() goto(300,-100) down() def draw_path(path): for symbol in path: if symbol == 'f': import random colormode(255) color(random.randint(0,255),random.randint(0,255


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有