python画彩虹和小熊

前言

今天,我们来画两个简单的图形。

一、彩虹

彩虹,又称天弓(客家话)、天虹、绛等,简称为"虹",是气象中的一种光学现象。当太阳光照射到半空中的水滴时,光线被折射及反射,在天空上形成拱形的七彩光谱,雨后常见。形状弯曲,通常为半圆状。色彩艳丽。东亚、中国对于七色光的最普遍说法(按波长从大至小排序):红、橙、黄、绿、蓝、靛、紫。

python 复制代码
from turtle import *
 
 
rainbow_color = ["red", "orange", "yellow", "green", "cyan", "blue", "purple"]
pensize(12)  
for i in range(7):
    fd(i*10) 
    left(90)  
    pendown()  
    pencolor(rainbow_color[i])  
    circle(i*10+100, 180)
    penup()  
    home()  
ht() 

二、小熊

很简单,黑白的。

python 复制代码
import turtle as t
 
t.pensize(2)
t.speed(0)
 
t.pu()
t.goto(-150, 0)
t.pd()
t.left(90)
t.circle(-300, 30)
 
t.seth(180)
t.circle(-40, 270)
 
t.seth(20)
t.circle(-150, 40)
 
t.seth(90)
t.circle(-40, 270)
 
t.seth(-60)
t.circle(-300, 30)
 
t.seth(-80)
t.circle(-(t.pos()[0]--150+4)/2, 200)
 
t.pu()
t.goto(-84, 50)
t.dot(20)
t.goto(47.5, 50)
t.dot(20)
 
t.goto(-18.25, 25)
t.dot(30)
t.goto(-18.25, 10)
t.pd()
t.seth(-90)
t.circle(-20, 90)
t.pu()
t.goto(-18.25, 10)
t.seth(-90)
t.pd()
t.circle(20, 90)
 
t.pu()
h = 0
pos = -74, -25
for i in range(3):
    t.pu()
    t.goto(pos[0], pos[1])
    t.seth(h)
    t.pd()
    t.circle(-35, 40)
    h = t.heading()
    pos = t.pos()
    t.seth(-135)
    t.fd(20)
t.seth(-135)
t.fd(20)
 
t.pu()
h = 180
pos = 47.5, -25
for i in range(3):
    t.pu()
    t.goto(pos[0], pos[1])
    t.seth(h)
    t.pd()
    t.circle(35, 40)
    h = t.heading()
    pos = t.pos()
    t.seth(-45)
    t.fd(20)
t.seth(-45)
t.fd(20)
 
t.hideturtle()
t.done()

总结

今天到这了~~

站在巨人的肩上是为了超过巨人。

相关推荐
森林古猿15 分钟前
再论斜率优化
c++·学习·算法
leo__52012 分钟前
基于导航数据的扩展卡尔曼滤波(EKF)MATLAB 实现
开发语言·matlab
万法若空14 分钟前
【数学-简单数论】同余中的逆
线性代数·算法
胡哈20 分钟前
React Compiler:让开发者忘掉 memo 这件事
前端·react.js
xiyueyezibile27 分钟前
“自迭代” Skill 的 team-pitfalls 的演进
前端·后端·ai编程
gugucoding31 分钟前
25. 【C语言】二进制文件与随机读写
c语言·开发语言
北极星日淘32 分钟前
中古货品品相评级算法实战|Java权重计分实现标准化五级品相体系
开发语言·python
聚美智数34 分钟前
黄历查询-运势查询-国际法定节假日查询-API接口介绍
android·java·数据库
hangyuekejiGEO38 分钟前
临沂GEO服务企业技术选型分析
人工智能·python
林恒smileZAZ38 分钟前
`Array(100).map(() => 1)` 为什么全为空?
前端·javascript