python运用turtle库画图 您所在的位置:网站首页 医护人员和警察的图画 python运用turtle库画图

python运用turtle库画图

2024-07-08 20:23| 来源: 网络整理| 查看: 265

初学python中的turtle库,个人认为画图前要先建立好直角坐标系,确定好各主要点的坐标,这样提笔的时候更加容易画出准确的图。 使用turtle库画出了这样一张关于疫情主题的图片,寄托我们美好的祝愿。 在这里插入图片描述 代码如下:

import turtle as t import random def wheregoto(x,y): #x,y表示坐标 t.up() t.goto(x,y) t.down() t.speed(0) t.pensize(4) t.screensize(690,764) #设置画布 t.pensize(4) wheregoto(-325,352) t.setheading(270) t.pencolor("gray1") for j in range (2): t.forward(734) t.left(90) t.forward(650) t.left(90) t.pencolor("red3") t.penup() #枕头 t.speed(0) t.fillcolor("mint cream") t.setheading(180) wheregoto(-86,-22) t.begin_fill() t.pendown() t.left(-10) t.circle(160,12) t.left(-41) t.circle(60,10) t.left(70) t.circle(60,10) t.left(40) t.circle(200,8) t.left(-8) t.circle(200,4) t.left(-18) t.circle(200,4) t.right(10) t.circle(200,4) t.left(10) t.circle(200,4) t.left(10) t.circle(200,4) t.left(10) t.circle(200,3) t.right(15) t.circle(200,3) t.right(25) t.circle(200,3) t.left(55) t.circle(200,3) t.left(25) t.circle(200,14) t.fd(150) t.setheading(-5) t.pendown() t.circle(200,8) t.right(40) t.circle(200,2) t.left(30) t.circle(200,3) t.left(20) t.circle(200,2) t.left(45) t.circle(70,40) t.right(30) t.circle(200,17) t.right(20) t.circle(200,3) t.left(10) t.circle(200,3) t.left(20) t.circle(200,3) t.left(20) t.circle(60,3) t.left(60) t.circle(60,5) t.left(20) t.circle(60,5) t.right(50) t.circle(300,9) t.seth(176) t.fd(168) t.end_fill() #杯子 t.setheading(0) wheregoto(-100,90) t.fillcolor("floral white") t.begin_fill() t.left(-80) t.forward(160) t.left(30) t.circle(100,95) t.left(35) t.forward(163) t.end_fill() t.fillcolor("khaki1") t.begin_fill() t.left(57) t.circle(150,85) t.left(103) t.circle(180,68) t.end_fill() #面 #面底色 wheregoto(-86,81) t.pencolor("red3") t.fillcolor("khaki") t.begin_fill() t.setheading(56) t.circle(-103,114) t.pensize(2) t.setheading(212) t.circle(-154,70) t.end_fill() #大面 wheregoto(-76,78) t.pencolor("Darkgoldenrod3") t.setheading(36) t.pensize(4) t.circle(-140,70) wheregoto(-76,90)#面条1 t.pencolor("Darkgoldenrod3") t.setheading(30) t.pensize(4) t.circle(-160,50) wheregoto(-54,110)#2 t.pencolor("Darkgoldenrod3") t.setheading(18) t.pensize(4) t.circle(-150,50) wheregoto(-36,115)#3 t.pencolor("Darkgoldenrod3") t.setheading(19) t.pensize(4) t.circle(-90,60) wheregoto(-36,115)#4 t.pencolor("Darkgoldenrod3") t.setheading(24) t.pensize(4) t.circle(-90,60) wheregoto(-66,75)#5 t.pencolor("Darkgoldenrod3") t.setheading(41) t.circle(-90,90) wheregoto(-10,103)#6 t.pencolor("Darkgoldenrod3") t.setheading(0) t.circle(-110,47) wheregoto(-10,103)#7 t.pencolor("Darkgoldenrod3") t.setheading(0) t.circle(-150,37) #小面 t.pensize(5) t.pencolor("red3") wheregoto(-63,71) t.setheading(39) t.circle(-110,30) t.setheading(10) t.circle(-56,76) wheregoto(-63,71)#面条1 t.pencolor("Darkgoldenrod3") t.setheading(34) t.circle(-110,30) t.setheading(10) t.circle(-56,72) wheregoto(-54,67)#2 t.pencolor("Darkgoldenrod3") t.setheading(30) t.circle(-130,24) t.setheading(6) t.circle(-56,61) wheregoto(-42,63)#3 t.pencolor("Darkgoldenrod3") t.setheading(30) t.circle(-130,20) t.setheading(6) t.circle(-56,52) wheregoto(-28,60)#4 t.pencolor("Darkgoldenrod3") t.setheading(30) t.circle(-130,16) t.setheading(6) t.circle(-56,48) wheregoto(-15,56)#5 t.pencolor("Darkgoldenrod3") t.setheading(32) t.circle(-130,14) t.setheading(6) t.circle(-40,48) wheregoto(-1,56)#6 t.pencolor("Darkgoldenrod3") t.setheading(34) t.circle(-120,9) t.setheading(6) t.circle(-30,48) wheregoto(13,56)#7 t.pencolor("Darkgoldenrod3") t.setheading(30) t.circle(-120,9) t.setheading(6) t.circle(-10,60) #面轮廓 wheregoto(-86,81) t.pencolor("red3") t.setheading(56) t.circle(-103,114) t.pensize(4) t.setheading(212) t.circle(-154,70) #酱汁 wheregoto(-34,110) t.pensize(3) t.pendown() t.pencolor("orange4") t.fillcolor("orange4") t.begin_fill() t.setheading(56) t.circle(-40,50) t.setheading(26) t.circle(-40,70) t.setheading(-15) t.circle(-70,30) t.circle(-30,30) t.circle(-10,30) t.circle(-10,100) t.circle(-190,10) t.circle(-5,360) t.seth(-170) t.circle(-180,20) t.seth(145) t.circle(-30,50) t.end_fill() t.penup() wheregoto(55,75) t.begin_fill() t.circle(3,360) t.end_fill() wheregoto(40,90) t.begin_fill() t.circle(5,360) t.end_fill() wheregoto(-45,95) t.begin_fill() t.circle(2,360) t.end_fill() #葱 t.pencolor("lawn green") t.fillcolor("lawn green") wheregoto(0,110) t.begin_fill() t.circle(3,360,4) t.end_fill() t.pencolor("lawn green") t.fillcolor("lawn green") wheregoto(35,65) t.begin_fill() t.circle(2,360,4) t.end_fill() t.pencolor("DarkOliveGreen1") t.fillcolor("DarkOliveGreen1") wheregoto(45,90) t.begin_fill() t.circle(2,360,5) t.end_fill() t.pencolor("lawn green") t.fillcolor("lawn green") wheregoto(10,70) t.begin_fill() t.circle(2,360,5) t.end_fill() t.pencolor("DarkOliveGreen1") t.fillcolor("DarkOliveGreen1") wheregoto(-30,90) t.begin_fill() t.circle(3,360,5) t.end_fill() t.pencolor("lawn green") t.fillcolor("lawn green") wheregoto(-15,85) t.begin_fill() t.circle(2,360,4) t.end_fill() t.pencolor("lawn green") t.fillcolor("lawn green") wheregoto(15,80) t.begin_fill() t.circle(2,360,4) t.end_fill() t.pencolor("DarkOliveGreen1") t.fillcolor("DarkOliveGreen1") wheregoto(-35,70) t.begin_fill() t.circle(2,360,4) t.end_fill() t.pencolor("DarkOliveGreen1") t.fillcolor("DarkOliveGreen1") wheregoto(25,95) t.begin_fill() t.circle(3,360,4) t.end_fill() t.pencolor("DarkOliveGreen1") t.fillcolor("DarkOliveGreen1") wheregoto(70,85) t.begin_fill() t.circle(2,360,4) t.end_fill() t.pencolor("DarkOliveGreen1") t.fillcolor("DarkOliveGreen1") wheregoto(30,120) t.begin_fill() t.circle(3,360,4) t.end_fill() #辣椒 t.pensize(3) t.pencolor("OrangeRed2") t.fillcolor("OrangeRed2") wheregoto(-15,120) t.begin_fill() t.circle(3,360,4) t.end_fill() wheregoto(19,78) t.pensize(2) t.pencolor("OrangeRed2") t.fillcolor("OrangeRed2") t.pendown() t.begin_fill() t.circle(-4,260) t.end_fill() wheregoto(20,80) t.pensize(1) t.pencolor("Salmon") t.fillcolor("Salmon") t.begin_fill() t.seth(23) t.circle(-3,360,4) t.end_fill() t.pensize(3) t.pencolor("OrangeRed2") t.fillcolor("OrangeRed2") wheregoto(-15,85) t.begin_fill() t.circle(3,360,4) t.end_fill() wheregoto(55,100) t.pensize(1) t.pencolor("Salmon") t.fillcolor("Salmon") t.begin_fill() t.seth(23) t.circle(-3,360,4) t.end_fill() t.pensize(3) t.pencolor("OrangeRed2") t.fillcolor("OrangeRed2") wheregoto(15,113) t.begin_fill() t.circle(5,360) t.end_fill() wheregoto(15,115) t.pensize(1) t.pencolor("Salmon") t.fillcolor("Salmon") t.begin_fill() t.seth(23) t.circle(3,360,4) t.end_fill() t.pensize(3) t.pencolor("OrangeRed2") t.fillcolor("OrangeRed2") wheregoto(5,93) t.begin_fill() t.circle(3,360,6) t.end_fill() t.pencolor("OrangeRed2") t.fillcolor("OrangeRed2") wheregoto(38,99) t.begin_fill() t.circle(3,360,4) t.end_fill() t.pencolor("OrangeRed2") t.fillcolor("OrangeRed2") wheregoto(25,105) t.begin_fill() t.circle(3,360,4) t.end_fill() wheregoto(-10,70) t.pensize(1) t.pencolor("Salmon") t.fillcolor("Salmon") t.begin_fill() t.seth(23) t.circle(4,360,4) t.end_fill() wheregoto(32,105) t.pensize(1) t.pencolor("Salmon") t.fillcolor("Salmon") t.begin_fill() t.seth(23) t.circle(3,360) t.end_fill() #眼睛 t.speed(0) t.pensize(1) t.setheading(180) t.fillcolor("red3") t.begin_fill() wheregoto(-25,37) len = 0.12 for k in range(2): for j in range(60): if j


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有