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

总结

今天到这了~~

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

相关推荐
言乐63 小时前
Python关于老游复刻与创新2
前端·javascript·css·python·css3
ly76893 小时前
前端测试完整指南:从单元测试、组件测试到端到端测试与 CI/CD
前端·ci/cd·单元测试
迷枫7124 小时前
SQL性能排查记录
java·数据库·sql
渡我白衣4 小时前
深入理解 Transformer:Transformer 究竟是什么?
java·linux·开发语言·c++·人工智能·深度学习·transformer
无限码力5 小时前
8.26华为OD机试真题 新系统【字符串回文判断】
算法·华为od·华为od机考·华为od机试·华为od上机考试真题·华为od最新机试真题题解·华为od机试真题题库
Tisfy7 小时前
LeetCode 1927.求和游戏:抵消+看最值
java·leetcode·游戏·题解·博弈论
玖玥拾7 小时前
LeetCode 125 验证回文串
算法·leetcode
青 春 记 忆11 小时前
Dify Docker Compose 通用无损升级指南:从备份、双版本预演到切换与回滚
运维·人工智能·python·docker·容器
GlueNa2SiO311 小时前
03-Flask模板引擎Jinja2详解
笔记·python·flask
钛态12 小时前
Vite 中的 CSS 工程化:从 CSS Modules 到 UnoCSS 的渐进式迁移
前端·vue·react·web