Python7个炫酷代码

Python7个炫酷代码

一.炫酷彩虹代码:

from turtle import *

colors = ["red", "yellow", "blue", "lime"]

bgcolor("black")

x = 6

t = [Turtle(), Turtle()]

for index, i in enumerate(t):

i.speed(0)

i.color("white")

i.shape("circle")

i.shapesize(0.3)

i.width(3)

i.pu()

i.seth(90)

i.fd(350)

i.seth(-180)

i.pd()

t[0].pu()

delay(0)

speed(0)

ht()

for i in colors:

color(i)

for i in range(360):

t[0].fd(x)

t[0].lt(1)

pu()

goto(t[0].pos())

pd()

t[1].fd(2 * x)

t[1].lt(2)

goto(t[1].pos())

done()

效果:

2.温柔的狮子代码:

import turtle as t

def hair(): # 画头发

t.penup()

t.goto(-50, 150)

t.pendown()

t.fillcolor('#a2774d')

t.begin_fill()

for j in range(10): # 重复执行10次

t.setheading(60 - (j * 36)) # 每次调整初始角度

t.circle(-50, 120) # 画120度的弧

t.end_fill()

def face(): # 画脸

t.penup()

t.goto(0, 100)

t.pendown()

t.fillcolor('#f2ae20')

t.begin_fill()

t.setheading(180)

t.circle(85)

t.end_fill()

# 下巴

t.circle(85, 120)

t.fillcolor('white')

t.begin_fill()

t.circle(85, 120)

t.setheading(135)

t.circle(100, 95)

t.end_fill()

def ears(dir): # 画眼睛,dir用来设置方向,左右眼对称

t.penup()

t.goto((0 - dir) * 30, 90)

t.setheading(90)

t.pendown()

t.fillcolor('#f2ae20')

t.begin_fill()

t.circle(dir * 30)

t.end_fill()

t.penup()

t.goto((0 - dir) * 40, 85)

t.setheading(90)

t.pendown()

t.fillcolor('white')

t.begin_fill()

t.circle(dir * 17)

t.end_fill()

def nose(): # 画鼻子

t.penup()

t.goto(20, 0)

t.setheading(90)

t.pendown()

t.fillcolor('#a2774d')

t.begin_fill()

t.circle(20)

t.end_fill()

def eye(dir): # 画耳朵,dir用来设置方向,左右耳对称

t.penup()

t.goto((0 - dir) * 30, 20)

t.setheading(0)

t.pendown()

t.fillcolor('black')

t.begin_fill()

t.circle(10)

t.end_fill()

def mouth(): # 画嘴巴

t.penup()

t.goto(0, 0)

t.setheading(-90)

t.pendown()

t.forward(50)

t.setheading(0)

t.circle(80, 30)

t.penup()

t.goto(0, -50)

t.setheading(180)

t.pendown()

t.circle(-80, 30)

hair()

ears(1)

ears(-1)

face()

eye(1)

eye(-1)

mouth()

nose()

t.done()

效果:

3.旋转的爱心代码:

from turtle import *

from colorsys import *

def curve():

for i in range(200):

right(1)

forward(1)

tracer(10)

delay(0)

speed(0)

pensize(3)

bgcolor("black")

left(140)

cycles_number = 2

for _ in range(cycles_number):

s = 1

for i in range(36):

color("#C90055", hsv_to_rgb(0.92, s, 1))

begin_fill()

forward(111.65)

curve()

left(120)

curve()

forward(111.65)

end_fill()

hideturtle()

right(90)

s -= 0.02

done()

效果:

4.玫瑰代码:

import turtle

import time

t = turtle.Turtle()

t.speed(1)

# 设置初始位置

t.penup()

t.left(90)

t.fd(200)

t.pendown()

t.right(90)

# 花蕊

t.fillcolor("red")

t.begin_fill()

t.circle(10, 180)

t.circle(25, 110)

t.left(50)

t.circle(60, 45)

t.circle(20, 170)

t.right(24)

t.fd(30)

t.left(10)

t.circle(30, 110)

t.fd(20)

t.left(40)

t.circle(90, 70)

t.circle(30, 150)

t.right(30)

t.fd(15)

t.circle(80, 90)

t.left(15)

t.fd(45)

t.right(165)

t.fd(20)

t.left(155)

t.circle(150, 80)

t.left(50)

t.circle(150, 90)

t.end_fill()

# 花瓣1

t.left(150)

t.circle(-90, 70)

t.left(20)

t.circle(75, 105)

t.setheading(60)

t.circle(80, 98)

t.circle(-90, 40)

# 花瓣2

t.left(180)

t.circle(90, 40)

t.circle(-80, 98)

t.setheading(-83)

# 叶子1

t.fd(30)

t.left(90)

t.fd(25)

t.left(45)

t.fillcolor("green")

t.begin_fill()

t.circle(-80, 90)

t.right(90)

t.circle(-80, 90)

t.end_fill()

t.right(135)

t.fd(60)

t.left(180)

t.fd(85)

t.left(90)

t.fd(80)

# 叶子2

t.right(90)

t.right(45)

t.fillcolor("green")

t.begin_fill()

t.circle(80, 90)

t.left(90)

t.circle(80, 90)

t.end_fill()

t.left(135)

t.fd(60)

t.left(180)

t.fd(60)

t.right(90)

t.circle(200, 60)

time.sleep(5)

效果:

5.小爱心代码:

from turtle import *

def curvemove():

for i in range(200):

right(1)

forward(1)

setup(600,600,600,600)

hideturtle()

pencolor('black')

fillcolor("red")

pensize(2)

begin_fill()

left(140)

forward(111.65)

curvemove()

left(120)

curvemove()

forward(111.65)

end_fill()

penup()

goto(-27, 85)

pendown()

done()

效果:

6.微信轰炸神器(需打开微信,并点击对话框,千万注意不要恶搞,否则后果自负,要先去Python编辑器把pynput下载才能用。) 代码:

import time

from pynput import mouse, keyboard

m_keyboard = keyboard.Controller() # 创建一个键盘

qty = int(input("轰炸次数:"))

content = input("轰炸内容:")

time_Span = int(input("开始轰炸时间(s):"))

frequency = float(input("轰炸频率(0.1-0.5):"))

print("选择轰炸区域", time_Span, "秒后开始轰炸")

time.sleep(time_Span)

for i in range(qty):

m_keyboard.type(content) # 打字

m_keyboard.press(keyboard.Key.enter) # 按下enter

m_keyboard.release(keyboard.Key.enter) # 松开

time.sleep(frequency) # 间隔0.1秒

7.微信表情“笑”代码:

import turtle

# 画指定的任意圆弧

def arc(sa, ea, x, y, r): # start angle,end angle,circle center,radius

turtle.penup()

turtle.goto(x, y)

turtle.setheading(0)

turtle.left(sa)

turtle.fd(r)

turtle.pendown()

turtle.left(90)

turtle.circle(r, (ea - sa))

return turtle.position()

turtle.hideturtle()

# 画脸

turtle.speed(5)

turtle.setup(900, 600, 200, 200)

turtle.pensize(5)

turtle.right(90)

turtle.penup()

turtle.fd(100)

turtle.left(90)

turtle.pendown()

turtle.begin_fill()

turtle.pencolor("#B26A0F") # head side color

turtle.circle(150)

turtle.fillcolor("#F9E549") # face color

turtle.end_fill()

# 画嘴

turtle.penup()

turtle.goto(77, 20)

turtle.pencolor("#744702")

turtle.goto(0, 50)

turtle.right(30)

turtle.fd(110)

turtle.right(90)

turtle.pendown()

turtle.begin_fill()

turtle.fillcolor("#925902") # mouth color

turtle.circle(-97, 160)

turtle.goto(92, -3)

turtle.end_fill()

turtle.penup()

turtle.goto(77, -25)

# 画牙齿

turtle.pencolor("white")

turtle.begin_fill()

turtle.fillcolor("white")

turtle.goto(77, -24)

turtle.goto(-81, 29)

turtle.goto(-70, 43)

turtle.goto(77, -8)

turtle.end_fill()

turtle.penup()

turtle.goto(0, -100)

turtle.setheading(0)

turtle.pendown()

# 画左边眼泪

turtle.left(90)

turtle.penup()

turtle.fd(150)

turtle.right(60)

turtle.fd(-150)

turtle.pendown()

turtle.left(20)

turtle.pencolor("#155F84") # tear side color

turtle.fd(150)

turtle.right(180)

position1 = turtle.position()

turtle.begin_fill()

turtle.fillcolor("#7EB0C8") # tear color

turtle.fd(150)

turtle.right(20)

turtle.left(270)

turtle.circle(-150, 18)

turtle.right(52)

turtle.fd(110)

position2 = turtle.position()

turtle.goto(-33, 90)

turtle.end_fill()

# 画右边眼泪

turtle.penup()

turtle.goto(0, 0)

turtle.setheading(0)

turtle.left(90)

turtle.fd(50)

turtle.right(150)

turtle.fd(150)

turtle.left(150)

turtle.fd(100)

turtle.pendown()

turtle.begin_fill()

turtle.fd(-100)

turtle.fillcolor("#7EB0C8") # tear color

turtle.right(60)

turtle.circle(150, 15)

turtle.left(45)

turtle.fd(66)

turtle.goto(77, 20)

turtle.end_fill()

# 画眼睛

turtle.penup()

turtle.pencolor("#6C4E00") # eye color

turtle.goto(-65, 75)

turtle.setheading(0)

turtle.left(27)

turtle.fd(38)

turtle.pendown()

turtle.begin_fill()

turtle.fillcolor("#6C4E00") # eye color

turtle.left(90)

turtle.circle(38, 86)

turtle.goto(position2[0], position2[1])

turtle.goto(position1[0], position1[1])

turtle.end_fill()

# 画手

turtle.pencolor("#D57E18") # hand side color

turtle.begin_fill()

turtle.fillcolor("#EFBD3D") # hand color

# 第一个手指

arc(-110, 10, 110, -40, 30)

turtle.circle(300, 35)

turtle.circle(13, 120)

turtle.setheading(-50)

turtle.fd(20)

turtle.setheading(130)

# 第二个手指

turtle.circle(200, 15)

turtle.circle(12, 180)

turtle.fd(40)

turtle.setheading(137)

# 第三个手指

turtle.circle(200, 16)

turtle.circle(12, 160)

turtle.setheading(-35)

turtle.fd(45)

turtle.setheading(140)

# 第四个手指

turtle.circle(200, 13)

turtle.circle(11, 160)

turtle.setheading(-35)

turtle.fd(40)

turtle.setheading(145)

# 第五个手指

turtle.circle(200, 9)

turtle.circle(10, 180)

turtle.setheading(-31)

turtle.fd(50)

# 画最后手腕的部分

turtle.setheading(-45)

turtle.pensize(7)

turtle.right(5)

turtle.circle(180, 35)

turtle.end_fill()

turtle.begin_fill()

turtle.setheading(-77)

turtle.pensize(5)

turtle.fd(50)

turtle.left(-270)

turtle.fd(7)

turtle.pencolor("#EFBD3D")

turtle.circle(30, 180)

turtle.end_fill()

turtle.done()

效果:

以上就是我的代码和效果,如果有错误还请多多指教。

相关文章

《梦幻西游2》三十六部天罡揭秘星灵秘史
365bet网上娱乐网址

《梦幻西游2》三十六部天罡揭秘星灵秘史

📅 10-10 👁️ 3465
深圳入职体检全攻略:如何轻松预约与了解体检项目
彩票365官网下载安装

深圳入职体检全攻略:如何轻松预约与了解体检项目

📅 09-18 👁️ 3669
买游艇去哪里买便宜,分享几种游艇购买途径
365beatapp官方下载

买游艇去哪里买便宜,分享几种游艇购买途径

📅 08-29 👁️ 6511