
美國隊長的鍋
emmmmmmmm…….沒錯就是他的鍋

程式碼
-
# 所需依賴:python3 pycharm -
-
# print 列印 -
print('hello world!') -
-
# 註釋符號 -
# 井號後麵灰色的內容是註釋,相當於筆記,會被機器忽略 -
-
# 變數和值 -
# n 是變數, 100 是值,等號的作用是賦值 -
# n 相當於高中數學的 xyz ,只不過 xyz 的值只能是數字,變數的功能要更強大 -
n = 100 -
m = 'hello' -
print(n) -
print(m) -
-
-
# 資料型別,這裡只講兩個,剩下的需要同學自己去系統地學習了 -
# 字串 和 整數 -
# 100 是整數型別 -
# 'hello' 是字串型別 -
# 匯入 turtle 模組 -
# 模組是 python 自帶的工具箱,這裡將工具箱匯入就能使用了 -
# turtle 模組是 python 用來畫圖的工具箱 -
import turtle -
-
# 將 turtle 裡的工具拿出來,賦給 t 變數 -
# 照貓畫虎用就是了,這些東西要到很後面才能理解 -
t = turtle.Turtle() -
-
# 這一行用來加快畫筆速度,從 1~9 依次變快,但 0 是最快 -
t.speed(0) -
-
# 這是向前走,單位是畫素 -
t.forward(100) -
# 這是轉彎,單位是角度 -
t.right(120) -
t.forward(100) -
t.right(120) -
t.forward(100) -
t.right(120) -
# 複製三次,就畫了一個三角形 -
-
# 正方形 -
# 長方形 -
-
# 如果我們需要改變三角形的邊長怎麼辦? -
# 這就要用到變數了,到時候只需改變變數就能改變長度 -
# 如果有相同的變數,後面定義的會改寫前面的 -
l = 200 -
t.forward(l) -
t.right(120) -
t.forward(l) -
t.right(120) -
t.forward(l) -
t.right(120) -
-
# for 迴圈 -
# 迴圈還有 while 迴圈,考慮到用不著就不講了 -
# 迴圈用來處理重覆的事情 -
-
# range() 是一個區間 -
# range(3) 相當於 0 1 2 -
# range(5) 相當於 0 1 2 3 4 -
-
# i 取的是 range() 裡的值,一次取一個,取一次就迴圈一次 -
# 冒號後面必有縮排,縮排的代表是同一個程式碼塊 -
# 照著用就行了,註意一個字元都不能敲錯,不能用中文符號 -
for i in range(3): -
t.forward(l) -
t.right(120) -
-
-
# 如果想畫兩個三角形怎麼辦,再複製一個 for 迴圈? -
# 我們用函式將程式碼封裝起來,到時候直接呼叫就好了 -
# def 關鍵字用來定義函式, triangle 是函式名 -
# 必須要有冒號接縮排,函式裡面也是一個程式碼塊 -
def triangle(): -
for i in range(3): -
t.forward(l) -
t.right(120) -
-
-
# 函式的呼叫 -
# triangle() -
-
-
# 函式可以傳遞引數進去 -
def triangle2(l): -
for i in range(3): -
t.forward(l) -
t.right(120) -
-
-
# 需要傳遞個引數進去才能呼叫這個函式 -
# triangle2(250) -
-
# 定一個函式畫長方形 -
-
# 四則運算 -
# + 加 -
# - 減 -
# * 乘 -
# / 除 -
# // 整除 -
# % 取餘 -
-
# 寫一個畫 n 邊形的通用函式 -
def polygon(l, n): -
angle = 360 / n -
for i in range(n): -
t.forward(l) -
t.right(angle) -
-
-
# polygon(100, 6) -
-
-
# 畫一個五角星 -
def five_star(l): -
for i in range(5): -
t.forward(l) -
t.right(144) -
-
-
# five_star(100) -
-
-
# 畫一個圓 -
# 邊長在 36 以上就是個圓 -
def circle(): -
for i in range(36): -
t.forward(10) -
t.right(15) -
-
-
# circle() -
-
-
# 在指定的坐標畫圖 -
# 比如要在坐標為 (100, 150) 的位置畫個正方形 -
def square(x, y, l): -
t.penup() -
t.goto(x, y) -
t.pendown() -
for i in range(4): -
t.forward(l) -
t.right(90) -
-
-
# square(100, 150, 100) -
-
# 將畫筆定位封裝成函式使用,就能有效去除重覆程式碼 -
def setpen(x, y): -
t.penup() -
t.goto(x, y) -
t.pendown() -
t.setheading(0) -
-
-
def square(x, y, l): -
setpen(x, y) -
for i in range(4): -
t.forward(l) -
t.right(90) -
-
-
# square(100, 150, 100) -
-
-
# 畫一排正方形,共五個,間隔 10 -
# 蠢方法 -
# square(100, 150, 30) -
# square(140, 150, 30) -
# square(180, 150, 30) -
# square(220, 150, 30) -
# square(260, 150, 30) -
-
-
# 使用 for 迴圈、函式 -
-
def square_line(x, y, l, n, dis): -
for i in range(n): -
inner_x = x + (l + dis) * i -
square(inner_x, y, l) -
-
-
# square_line(100, 150, 30, 6, 10) -
-
-
# 畫一個正方形方陣 -
def square_matrix(x, y, l, n, dis, m): -
for i in range(m): -
inner_y = y - (l + dis) * i -
square_line(x, inner_y, l, n, dis) -
-
-
# square_matrix(100, 150, 30, 5, 10, 6) -
-
-
# 填充顏色,給圖形上色 -
def five_star(l): -
t.fillcolor('yello') -
t.begin_fill() -
for i in range(5): -
t.forward(l) -
t.right(144) -
t.end_fill() -
-
-
# five_star(100) -
-
# 字典的簡單用法 -
-
# 抽象畫 -
# for i in range(500): -
# t.forward(i) -
# t.left(90) -
-
# for i in range(500): -
# t.forward(i) -
# t.left(91) -
-
colors = ['red', 'yellow', 'blue', 'green'] -
-
-
# for i in range(500): -
# t.pencolor(colors[i % 4]) -
# t.circle(i) -
# t.left(91) -
-
# sides = 5 -
# colors = ['red', 'yellow', 'blue', 'orange', 'green', 'purple'] -
# for i in range(360): -
# t.pencolor(colors[i % sides]) -
# t.forward(i * 3 / sides + i) -
# t.left(360 / sides + 1) -
# t.width(i * sides / 200) -
-
# 美隊盾牌 -
def circle(x, y, r, color): -
n = 36 -
angle = 360 / n -
pi = 3.1415926 -
c = 2 * pi * r -
l = c / n -
start_x = x - l / 2 -
start_y = y + r -
setpen(start_x, start_y) -
t.pencolor(color) -
t.fillcolor(color) -
t.begin_fill() -
for i in range(n): -
t.forward(l) -
t.right(angle) -
t.end_fill() -
-
-
def five_star(l): -
setpen(0, 0) -
t.setheading(162) -
t.forward(150) -
t.setheading(0) -
t.fillcolor('WhiteSmoke') -
t.begin_fill() -
t.hideturtle() -
t.penup() -
for i in range(5): -
t.forward(l) -
t.right(144) -
t.end_fill() -
-
-
def sheild(): -
circle(0, 0, 300, 'red') -
circle(0, 0, 250, 'white') -
circle(0, 0, 200, 'red') -
circle(0, 0, 150, 'blue') -
five_star(284) -
-
-
sheild() -
-
# 結尾這一行必須有,照著用就行了 -
turtle.done()
效果圖

小豬佩奇

程式碼
-
# coding:utf-8 -
import turtle as t -
-
t.pensize(4) -
t.hideturtle() -
t.colormode(255) -
t.color((255,155,192),"pink") -
t.setup(840,500) -
t.speed(10) -
-
#鼻子 -
t.pu() -
t.goto(-100,100) -
t.pd() -
t.seth(-30) -
t.begin_fill() -
a=0.4 -
for i in range(120): -
if 0<=i<30 or 60<=i<90: -
a=a+0.08 -
t.lt(3) #向左轉3度 -
t.fd(a) #向前走a的步長 -
else: -
a=a-0.08 -
t.lt(3) -
t.fd(a) -
t.end_fill() -
-
t.pu() -
t.seth(90) -
t.fd(25) -
t.seth(0) -
t.fd(10) -
t.pd() -
t.pencolor(255,155,192) -
t.seth(10) -
t.begin_fill() -
t.circle(5) -
t.color(160,82,45) -
t.end_fill() -
-
t.pu() -
t.seth(0) -
t.fd(20) -
t.pd() -
t.pencolor(255,155,192) -
t.seth(10) -
t.begin_fill() -
t.circle(5) -
t.color(160,82,45) -
t.end_fill() -
-
#頭 -
t.color((255,155,192),"pink") -
t.pu() -
t.seth(90) -
t.fd(41) -
t.seth(0) -
t.fd(0) -
t.pd() -
t.begin_fill() -
t.seth(180) -
t.circle(300,-30) -
t.circle(100,-60) -
t.circle(80,-100) -
t.circle(150,-20) -
t.circle(60,-95) -
t.seth(161) -
t.circle(-300,15) -
t.pu() -
t.goto(-100,100) -
t.pd() -
t.seth(-30) -
a=0.4 -
for i in range(60): -
if 0<=i<30 or 60<=i<90: -
a=a+0.08 -
t.lt(3) #向左轉3度 -
t.fd(a) #向前走a的步長 -
else: -
a=a-0.08 -
t.lt(3) -
t.fd(a) -
t.end_fill() -
-
#耳朵 -
t.color((255,155,192),"pink") -
t.pu() -
t.seth(90) -
t.fd(-7) -
t.seth(0) -
t.fd(70) -
t.pd() -
t.begin_fill() -
t.seth(100) -
t.circle(-50,50) -
t.circle(-10,120) -
t.circle(-50,54) -
t.end_fill() -
-
t.pu() -
t.seth(90) -
t.fd(-12) -
t.seth(0) -
t.fd(30) -
t.pd() -
t.begin_fill() -
t.seth(100) -
t.circle(-50,50) -
t.circle(-10,120) -
t.circle(-50,56) -
t.end_fill() -
-
#眼睛 -
t.color((255,155,192),"white") -
t.pu() -
t.seth(90) -
t.fd(-20) -
t.seth(0) -
t.fd(-95) -
t.pd() -
t.begin_fill() -
t.circle(15) -
t.end_fill() -
-
t.color("black") -
t.pu() -
t.seth(90) -
t.fd(12) -
t.seth(0) -
t.fd(-3) -
t.pd() -
t.begin_fill() -
t.circle(3) -
t.end_fill() -
-
t.color((255,155,192),"white") -
t.pu() -
t.seth(90) -
t.fd(-25) -
t.seth(0) -
t.fd(40) -
t.pd() -
t.begin_fill() -
t.circle(15) -
t.end_fill() -
-
t.color("black") -
t.pu() -
t.seth(90) -
t.fd(12) -
t.seth(0) -
t.fd(-3) -
t.pd() -
t.begin_fill() -
t.circle(3) -
t.end_fill() -
-
#腮 -
t.color((255,155,192)) -
t.pu() -
t.seth(90) -
t.fd(-95) -
t.seth(0) -
t.fd(65) -
t.pd() -
t.begin_fill() -
t.circle(30) -
t.end_fill() -
-
#嘴 -
t.color(239,69,19) -
t.pu() -
t.seth(90) -
t.fd(15) -
t.seth(0) -
t.fd(-100) -
t.pd() -
t.seth(-80) -
t.circle(30,40) -
t.circle(40,80) -
-
#身體 -
t.color("red",(255,99,71)) -
t.pu() -
t.seth(90) -
t.fd(-20) -
t.seth(0) -
t.fd(-78) -
t.pd() -
t.begin_fill() -
t.seth(-130) -
t.circle(100,10) -
t.circle(300,30) -
t.seth(0) -
t.fd(230) -
t.seth(90) -
t.circle(300,30) -
t.circle(100,3) -
t.color((255,155,192),(255,100,100)) -
t.seth(-135) -
t.circle(-80,63) -
t.circle(-150,24) -
t.end_fill() -
-
#手 -
t.color((255,155,192)) -
t.pu() -
t.seth(90) -
t.fd(-40) -
t.seth(0) -
t.fd(-27) -
t.pd() -
t.seth(-160) -
t.circle(300,15) -
t.pu() -
t.seth(90) -
t.fd(15) -
t.seth(0) -
t.fd(0) -
t.pd() -
t.seth(-10) -
t.circle(-20,90) -
-
t.pu() -
t.seth(90) -
t.fd(30) -
t.seth(0) -
t.fd(237) -
t.pd() -
t.seth(-20) -
t.circle(-300,15) -
t.pu() -
t.seth(90) -
t.fd(20) -
t.seth(0) -
t.fd(0) -
t.pd() -
t.seth(-170) -
t.circle(20,90) -
-
#腳 -
t.pensize(10) -
t.color((240,128,128)) -
t.pu() -
t.seth(90) -
t.fd(-75) -
t.seth(0) -
t.fd(-180) -
t.pd() -
t.seth(-90) -
t.fd(40) -
t.seth(-180) -
t.color("black") -
t.pensize(15) -
t.fd(20) -
-
t.pensize(10) -
t.color((240,128,128)) -
t.pu() -
t.seth(90) -
t.fd(40) -
t.seth(0) -
t.fd(90) -
t.pd() -
t.seth(-90) -
t.fd(40) -
t.seth(-180) -
t.color("black") -
t.pensize(15) -
t.fd(20) -
-
#尾巴 -
t.pensize(4) -
t.color((255,155,192)) -
t.pu() -
t.seth(90) -
t.fd(70) -
t.seth(0) -
t.fd(95) -
t.pd() -
t.seth(0) -
t.circle(70,20) -
t.circle(10,330) -
t.circle(70,30) -
t.done()
效果圖

藍胖子

程式碼
-
# !/usr/bin/env python3 -
# -*- coding: utf-8 -*- -
# @Author: dong dong -
# @Env: python 3.6 -
-
-
from turtle import * -
-
-
# 無軌跡跳躍 -
def my_goto(x, y): -
penup() -
goto(x, y) -
pendown() -
-
# 眼睛 -
def eyes(): -
tracer(False) -
a = 2.5 -
for i in range(120): -
if 0 <= i < 30 or 60 <= i < 90: -
a -= 0.05 -
lt(3) -
fd(a) -
else: -
a += 0.05 -
lt(3) -
fd(a) -
tracer(True) -
-
# 鬍鬚 -
def beard(): -
my_goto(-37, 135) -
seth(165) -
fd(60) -
-
my_goto(-37, 125) -
seth(180) -
fd(60) -
-
my_goto(-37, 115) -
seth(193) -
fd(60) -
-
my_goto(37, 135) -
seth(15) -
fd(60) -
-
my_goto(37, 125) -
seth(0) -
fd(60) -
-
my_goto(37, 115) -
seth(-13) -
fd(60) -
-
# 嘴巴 -
def mouth(): -
my_goto(5, 148) -
seth(270) -
fd(100) -
seth(0) -
circle(120, 50) -
seth(230) -
circle(-120, 100) -
-
# 圍巾 -
def scarf(): -
fillcolor('#e70010') -
begin_fill() -
seth(0) -
fd(200) -
circle(-5, 90) -
fd(10) -
circle(-5, 90) -
fd(207) -
circle(-5, 90) -
fd(10) -
circle(-5, 90) -
end_fill() -
-
# 鼻子 -
def nose(): -
my_goto(-10, 158) -
fillcolor('#e70010') -
begin_fill() -
circle(20) -
end_fill() -
-
# 黑眼睛 -
def black_eyes(): -
seth(0) -
my_goto(-20, 195) -
fillcolor('#000000') -
begin_fill() -
circle(13) -
end_fill() -
-
pensize(6) -
my_goto(20, 205) -
seth(75) -
circle(-10, 150) -
pensize(3) -
-
my_goto(-17, 200) -
seth(0) -
fillcolor('#ffffff') -
begin_fill() -
circle(5) -
end_fill() -
my_goto(0, 0) -
-
-
-
# 臉 -
def face(): -
fd(183) -
fillcolor('#ffffff') -
begin_fill() -
lt(45) -
circle(120, 100) -
-
seth(90) -
eyes() -
seth(180) -
penup() -
fd(60) -
pendown() -
seth(90) -
eyes() -
penup() -
seth(180) -
fd(64) -
pendown() -
seth(215) -
circle(120, 100) -
end_fill() -
-
# 頭型 -
def head(): -
penup() -
circle(150, 40) -
pendown() -
fillcolor('#00a0de') -
begin_fill() -
circle(150, 280) -
end_fill() -
-
# 畫哆啦A夢 -
def Doraemon(): -
# 頭部 -
head() -
-
# 圍脖 -
scarf() -
-
# 臉 -
face() -
-
# 紅鼻子 -
nose() -
-
# 嘴巴 -
mouth() -
-
# 鬍鬚 -
beard() -
-
# 身體 -
my_goto(0, 0) -
seth(0) -
penup() -
circle(150, 50) -
pendown() -
seth(30) -
fd(40) -
seth(70) -
circle(-30, 270) -
-
-
fillcolor('#00a0de') -
begin_fill() -
-
seth(230) -
fd(80) -
seth(90) -
circle(1000, 1) -
seth(-89) -
circle(-1000, 10) -
-
# print(pos()) -
-
seth(180) -
fd(70) -
seth(90) -
circle(30, 180) -
seth(180) -
fd(70) -
-
# print(pos()) -
seth(100) -
circle(-1000, 9) -
-
seth(-86) -
circle(1000, 2) -
seth(230) -
fd(40) -
-
# print(pos()) -
-
-
circle(-30, 230) -
seth(45) -
fd(81) -
seth(0) -
fd(203) -
circle(5, 90) -
fd(10) -
circle(5, 90) -
fd(7) -
seth(40) -
circle(150, 10) -
seth(30) -
fd(40) -
end_fill() -
-
# 左手 -
seth(70) -
fillcolor('#ffffff') -
begin_fill() -
circle(-30) -
end_fill() -
-
# 腳 -
my_goto(103.74, -182.59) -
seth(0) -
fillcolor('#ffffff') -
begin_fill() -
fd(15) -
circle(-15, 180) -
fd(90) -
circle(-15, 180) -
fd(10) -
end_fill() -
-
my_goto(-96.26, -182.59) -
seth(180) -
fillcolor('#ffffff') -
begin_fill() -
fd(15) -
circle(15, 180) -
fd(90) -
circle(15, 180) -
fd(10) -
end_fill() -
-
# 右手 -
my_goto(-133.97, -91.81) -
seth(50) -
fillcolor('#ffffff') -
begin_fill() -
circle(30) -
end_fill() -
-
# 口袋 -
my_goto(-103.42, 15.09) -
seth(0) -
fd(38) -
seth(230) -
begin_fill() -
circle(90, 260) -
end_fill() -
-
my_goto(5, -40) -
seth(0) -
fd(70) -
seth(-90) -
circle(-70, 180) -
seth(0) -
fd(70) -
-
#鈴鐺 -
my_goto(-103.42, 15.09) -
fd(90) -
seth(70) -
fillcolor('#ffd200') -
# print(pos()) -
begin_fill() -
circle(-20) -
end_fill() -
seth(170) -
fillcolor('#ffd200') -
begin_fill() -
circle(-2, 180) -
seth(10) -
circle(-100, 22) -
circle(-2, 180) -
seth(180-10) -
circle(100, 22) -
end_fill() -
goto(-13.42, 15.09) -
seth(250) -
circle(20, 110) -
seth(90) -
fd(15) -
dot(10) -
my_goto(0, -150) -
-
# 畫眼睛 -
black_eyes() -
-
if __name__ == '__main__': -
screensize(800,600, "#f0f0f0") -
pensize(3) # 畫筆寬度 -
speed(9) # 畫筆速度 -
Doraemon() -
my_goto(100, -300) -
write('by dongdong', font=("Bradley Hand ITC", 30, "bold")) -
mainloop()
效果圖

知識星球