python画图猪_用Python的turtle画一只小猪乔治【刚学python两天,记念一下】

本文是一篇Python初学者的实践记录,通过turtle库绘制了一只可爱的小猪乔治。内容包括使用turtle进行图形绘制的基本操作,如设置颜色、线条宽度、移动画笔等,逐步构建出小猪、草地、天空和泥坑等元素,是学习Python图形绘制的好例子。
摘要由CSDN通过智能技术生成

import turtle as t

'''

t.pu() 提起画笔

t.pd() 移动时绘制图形,缺省时也为绘制

t.seth 设置当前朝向为angle角度

t.begin_fill() 准备开始填充图形

t.color 同时设置pencolor=color1, fillcolor=color2

t.goto 设置笔的坐标

t.circle(70,20) 半径 度数

15,124,215 乔治裤子颜色外面

66,163,242 乔治裤子颜色里面

134 196 247 天空的颜色

123,245,95 草地的颜色

253,6,6 鞋子外面

253,70,70 鞋子里面

130,119,100 泥坑

'''

r_a=0.8

wight = 1100

height = 700

#t.pensize(4)

t.hideturtle()

t.colormode(255)

t.color((255,155,192),"pink")

t.setup(wight,height)

t.speed(10)

def move_pen(x,y):

t.pu()

t.goto(x-wight/2+50,y-height/2+50)

t.pd()

def pen_set(size,r1,g1,b1,r2=0,g2=0,b2=0):

t.pensize(size)

t.color((r1,g1,b1),(r2,g2,b2))

def draw_grid():

pen_set(1,0,0,0,0,0,0)

for i in range(20):

move_pen(0+i*50,0)

t.seth(90)

t.fd(600)

for i in range(12):

move_pen(0,0+i*50)

t.seth(0)

t.fd(1000)

def draw_bg():

#画草地

move_pen(0,350)

pen_set(4,123,245,95, 123,245,95)

t.begin_fill()

t.seth(-90)

t.fd(350)

t.seth(0)

t.fd(1000)

t.seth(90)

t.fd(350)

t.end_fill()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值