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

总结

今天到这了~~

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

相关推荐
笃励10 分钟前
Java面试题二
java·开发语言·python
ん贤12 分钟前
贪心算法.
算法·贪心算法
jyan_敬言18 分钟前
【Linux】Linux命令与操作详解(一)文件管理(文件命令)、用户与用户组管理(创建、删除用户/组)
linux·运维·服务器·c语言·开发语言·汇编·c++
cndes21 分钟前
大数据算法的思维
大数据·算法·支持向量机
FL162386312922 分钟前
[C#]C# winform部署yolov11-pose姿态估计onnx模型
开发语言·yolo·c#
速盾cdn22 分钟前
速盾:网页游戏部署高防服务器有什么优势?
服务器·前端·web安全
小白求学124 分钟前
CSS浮动
前端·css·css3
什么鬼昵称25 分钟前
Pikachu-csrf-CSRF(POST)
前端·csrf
易雪寒28 分钟前
IDEA在git提交时添加忽略文件
java·git·intellij-idea
笑非不退33 分钟前
C++ 异步编程 并发编程技术
开发语言·c++