python画树叶-Python_Turtle库画一只派大星

本文介绍了如何使用Python的Turtle库绘制派大星,并通过实例展示了派大星的各个组成部分,如肢体、眼睛、裤子、叶子等。同时,文中还包含了一段动态心形的代码,使左上角的心形能够跳动,增加了图形的趣味性。
摘要由CSDN通过智能技术生成

一、网上找的一个喜欢又不难画的派大星图片

画出好看的图形的方法就是找到画各种基础形状的代码,将他们拼凑起来,整体图形的布局是否合适就需要一遍一遍的试出来。

我绘制的图形中,左上方的四个心形可以跳动。

81a307f0d7df

派大星.jpg

二、一些基本语法

1.turtle的绘图窗体

turtle.setup(width,hight,startx,starty)

#(窗体的宽,窗体的长,窗体在屏幕上的x方向位置,y方向位置)

setup()#设置窗体大小及位置;4个参数后两个可选;

2.turtle控件坐标体系

绝对坐标:窗体中心为原点

海龟坐标:以海龟自己为基准的前后左右

3.turtle角度坐标体系

绝对角度:

turtle.seth(angle)

#seth()改变海龟行进方向,但不行进

#angle为绝对度数

海龟角度:

turtle.left(angle)

turtle.right(angle)

4.RGB色彩体系

取色范围:0-255的整数或0-1的小数

常用RGB色彩

英文 RGB整数值 RGB小数值 中文名称

white 255,255,255 1,1,1 白色

yellow 255,255,0 1,1,0 黄色

magenta 255,0,255 1,0,1 洋红

cyan 0,255,255 0,1,1 青色

blue 0,0,255 0,0,1 蓝色

black 0,0,0 0,0,0 黑色

turtle.colormode(mode)

mode=1.0 #RGB小数值模式

mode=255 #RGB整数值模式

三、代码如下

# coding:utf-8 #由于要使用汉字

import turtle as t

import time #引用turtle库和time库

画派大星肢体的一只

def drawLag():

t.left(10)

t.pendown()

t.fd(160)#臂长

t.circle(30,155)#手末端

t.fd(160)

画半片叶子

def drawLeaf():

t.pencolor('#CC6699')

t.

好的,以下是用Pythonturtle库画一只裸熊的代码: ```python import turtle # 设置布大小和背景颜色 turtle.setup(800, 600) turtle.bgcolor("#F5DEB3") # 裸熊的头部 turtle.penup() turtle.goto(-100, 100) turtle.pendown() turtle.begin_fill() turtle.circle(50) turtle.end_fill() # 裸熊的耳朵 turtle.penup() turtle.goto(-70, 150) turtle.pendown() turtle.begin_fill() turtle.circle(20) turtle.end_fill() turtle.penup() turtle.goto(-30, 150) turtle.pendown() turtle.begin_fill() turtle.circle(20) turtle.end_fill() # 裸熊的眼睛 turtle.penup() turtle.goto(-70, 120) turtle.pendown() turtle.begin_fill() turtle.circle(10) turtle.end_fill() turtle.penup() turtle.goto(-30, 120) turtle.pendown() turtle.begin_fill() turtle.circle(10) turtle.end_fill() # 裸熊的鼻子 turtle.penup() turtle.goto(-50, 100) turtle.pendown() turtle.begin_fill() turtle.circle(5) turtle.end_fill() # 裸熊的嘴巴 turtle.penup() turtle.goto(-60, 80) turtle.pendown() turtle.right(45) turtle.forward(20) turtle.left(90) turtle.forward(20) # 裸熊的身体 turtle.penup() turtle.goto(-100, 0) turtle.pendown() turtle.begin_fill() turtle.circle(80) turtle.end_fill() # 裸熊的手臂 turtle.penup() turtle.goto(-150, 50) turtle.pendown() turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.penup() turtle.goto(-50, 50) turtle.pendown() turtle.begin_fill() turtle.circle(30) turtle.end_fill() # 裸熊的腿 turtle.penup() turtle.goto(-100, -80) turtle.pendown() turtle.begin_fill() turtle.circle(30) turtle.end_fill() turtle.penup() turtle.goto(-20, -80) turtle.pendown() turtle.begin_fill() turtle.circle(30) turtle.end_fill() # 隐藏turtle.hideturtle() # 等待用户关闭窗口 turtle.done() ``` 希望这个代码对你有帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值