画汽车男孩(少儿学编程系列---使用python turtle画汽车)
时间:2024-06-02
浏览量:次
turtle简介
Turtle库是Python语言中一个很流行的绘制图像的函数库,利用它可以绘制图形,非常适合于引导少儿学习编程。
汽车效果展示
画汽车代码
from turtle import *def draw_car_body(x, y): color('#2B2BF6') fillcolor('#2B2BF6') penup() setpos(x, y) pendown() begin_fill() for i in range(2): forward(340) left(90) forward(50) left(90) end_fill()def draw_car_window(x, y): fillcolor('green') begin_fill() penup() setpos(x, y) pendown() setheading(45) forward(70) setheading(0) forward(100) setheading(-45) forward(70) setheading(-180) forward(200) end_fill() setpos(x+100, y) setheading(90) pendown() forward(49.50)def draw_car_tyre(x,y): penup() setpos(x, y) pendown() color('#000000') fillcolor('#000000') begin_fill() circle(20) end_fill()def main(): speed(20) draw_car_body(-350, 0) draw_car_window(-250, 50) draw_car_tyre(-250, -10) draw_car_tyre(-50, -10) penup() home() draw_car_body(0, 0) draw_car_window(100, 50) draw_car_tyre(100, -10) draw_car_tyre(300, -10) hideturtle() done()if __name__ == "__main__": hideturtle() up() goto(-260, 270) write("今天头条-cloudcoder出品", align='left', font=('fangsong',14, 'normal')) showturtle() main() hideturtle()