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()

总结

今天到这了~~

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

相关推荐
lly202406几秒前
Ruby CGI方法详解
开发语言
XiYang-DING1 分钟前
【Java】从源码深入理解HashMap和TreeMap
java·开发语言
霪霖笙箫5 分钟前
「JS全栈AI Agent学习」六、当AI遇到矛盾,该自己决定还是问你?—— Human-in-the-Loop
前端·面试·agent
七颗糖很甜5 分钟前
基于 OpenCV 的 FY2 云顶图云块追踪算法实现
人工智能·opencv·算法
__Wedream__6 分钟前
NTIRE 2026 Challenge on Efficient Super-Resolution——冠军方案解读
人工智能·深度学习·算法·计算机视觉·超分辨率重建
煜bart7 分钟前
使用 TypeScript 实现算法处理
开发语言·前端·javascript
♛识尔如昼♛8 分钟前
C 基础(7) - 字符输入/输出和输入验证
c语言·开发语言
FL162386312910 分钟前
基于深度学习mediape实现人员跌倒人体姿势跌倒检测算法源码+说明文件
人工智能·深度学习·算法
wangwangmoon_light11 分钟前
1.23 LeetCode总结(树)_一般树
算法·leetcode·职场和发展
不知名XL11 分钟前
day01 agent开发基础铺垫
python