python turtle 画海洋世界 潜水艇

本文展示了如何使用Python的turtle库创建了一个包含鱼类、海星、水草、潜艇和座舱的海洋世界动画,通过函数定义了各种海洋元素的绘制方法。
部署运行你感兴趣的模型镜像

import turtle
import random

screen = turtle.Screen( )
screen.setup(1100,650)
screen.bgcolor("#0B1748")

t = turtle.Turtle()
t.pensize(2)
t.speed(0)
t.color("black")


list_color=["#E30B5C","#FFC000","#FFBF00","#FF3131","#AAFF00","#FAFA33","#FFFF00","#FF10F0","#BF40BF"]

fish_pos=[(363,284),(478,133)]

fish2_pos=[(368,-126),(-143,286),(-433,89)]

star_pos=[(-323,-245),(192,-286),(-433,-212)]

grass_pos=[(-147,-270),(-130,-270),(-110,-270),(442,-191),(462,-191),(497,-206),(515,-207),(525,-207),(-453,-143),(-413,-148),(-403,-148),(-431,-147)]

#########################################################
def fish1(a):
	#身体
	t.seth(a)
	t.fillcolor ('sky blue')
	t.begin_fill()
	t.circle(40,170)
	t.left(120)
	t.circle(-10,190)
	t.left(-90)
	t.circle(-38,-190)
	t.end_fill()
	
	#尾巴
	t.fillcolor(random.choice(list_color))
	t.begin_fill()
	t.left(120)
	t.forward(20)
	t.right(140)
	t.forward(50)
	t.right(120)
	t.forward(16)
	t.end_fill()
	
	#眼睛
	t.pu()
	t.forward(60)
	t.dot(20)
	t.pu()
	t.forward(1)
	t.dot(5,"white")
	
def fish2(a,r):
	#尾巴
	t.seth(a)
	t.fillcolor(random.choice(list_color))
	t.begin_fill()
	t.forward(r)
	t.left(135)
	t.forward(r*0.8)
	t.end_fill()
	
	#身体
	t.seth(a)
	t.fillcolor(random.choice(list_color))
	t.begin_fill()
	t.forward(r*2)
	t.left(135)
	t.forward(r*3)
	t.left(90)
	t.forward(r*3)
	t.end_fill()

	#眼睛
	t.pu()
	t.seth(a)
	t.forward(r*2)
	t.left(90)
	t.forward(r)
	t.dot(r/2)
	t.pu()
	t.forward(1)
	t.dot(r/6,"white")

#海星
def drawstar(r):
	t.left(10)
	t.fd(40/r)#臂长
	t.circle(5/r,155)#手末端
	t.fd(40/r)

#水草
def grass(a):
	r=random.randint(10,20)#宽度
	n=random.randint(2,4)#长度
	t.fillcolor("#228B22")
	t.begin_fill()
	t.seth(a)#角度
	for i in range(n):
		t.circle(r, 80)
		t.circle(-r, 80)
	random.randint(160,170)
	t.seth(a+170)
	for i in range(n):
		t.circle(r, 80)
		t.circle(-r, 80)
	t.end_fill()

def qipao(x1,y1,r):
	t.pensize(2)
	t.pencolor('white')
	t.penup()
	t.goto(x1,y1)
	t.pendown()
	t.circle(r)
	t.penup()
	t.goto(x1-r*0.5,y1+r*1.5)
	t.dot(r/2)
	
qipao(412,-108,5)
qipao(405,-50,10)
qipao(389,0,15)
qipao(389,50,20)


t.pencolor('black')


for i in grass_pos:
	t.pu()
	t.goto(i)
	grass(50)

for i in fish_pos:
	t.pu()
	t.goto(i)
	fish1(random.randint(70,110))

for i in range(8):
	t.pu()
	if i==0:
		t.goto(-320,250)
		fish2(-90,30)
	else:
		t.goto(random.randint(-550,-320),random.randint(200,300))
		fish2(-90,random.randint(8,20))
		

#沙滩
t.fillcolor("#DAA06D")
t.begin_fill()
t.pu()
t.goto(568,-195)
# t.down()
t.seth(161)
t.circle(883,62)
t.goto(575,-401)
t.goto(568,-195)
t.end_fill()


t.fillcolor("#C19A6B")
t.begin_fill()
t.pu()
t.goto(-563,-125)
# t.down()
t.seth(184)
t.circle(519,-61)
t.goto(-557,-367)
t.goto(-563,-128)
t.goto(-563,-125)
t.end_fill()


#海星
for i in star_pos:
	t.fillcolor(random.choice(list_color))
	t.begin_fill()
	t.pu()
	t.goto(i)
	r=random.randint(1,4)
	t.seth(random.randint(1,270))
	for j in range(5):
		drawstar(r)
		t.right(93)
	t.end_fill()
	
	
#潜艇
t.pu()
t.goto(194,126)
t.down()
t.fillcolor("#B2BEB5")
t.begin_fill()
t.seth(141)
t.circle(306,72)
t.seth(215)
t.circle(132,109)
t.seth(325)
t.circle(291,74)
t.goto(195,123)
t.goto(194,126)
t.end_fill()

#座舱
t.pu()
t.goto(-70,182)
t.down()
t.fillcolor("red")
t.begin_fill()
t.goto(-79,68)
t.seth(87)
t.circle(42,-66)
t.goto(-219,17)
t.goto(-216,-5)
t.goto(-119,9)
t.seth(7)
t.circle(74,59)
t.goto(-54,184)
t.goto(-54,187)
t.goto(-70,182)
t.end_fill()

#驾驶室

t.pu()
t.goto(-70,182)
t.fillcolor("white")
t.begin_fill()
t.down()
t.goto(-79,68)
t.seth(87)
t.circle(42,-66)
t.goto(-219,17)
t.seth(277)
t.circle(152,-89)
t.goto(-72,185)
t.goto(-70,182)
t.end_fill()

您可能感兴趣的与本文相关的镜像

Python3.11

Python3.11

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值