|
本帖最后由 宫崎峻Miyazaki 于 2021-7-30 22:41 编辑
我想说的其实和楼上一样,e.g.用
import可以导入
比如说,
import turtle
这个是导入海归模块,如果不知道怎么用这个模块的话,我还有个例子可以看比如说- import turtle as t
- t.speed(3)
- t.color('chocolate')
- t.begin_fill()
- for i in range(1):
- t.forward(100)
- t.left(90)
- t.forward(100)
- t.left(90)
- t.forward(100)
- t.left(90)
- t.forward(100)
- t.goto(100,0)
- t.end_fill()
- t.color('skyblue')
- t.begin_fill()
- for i in range(1):
- t.left(120)
- t.forward(40)
- t.left(60)
- t.forward(100)
- t.left(120)
- t.forward(40)
- t.end_fill()
- t.color('red')
- t.begin_fill()
- for i in range(1):
- t.goto(134,120)
- t.right(30)
- t.forward(100)
- t.left(30)
- t.forward(40)
- t.end_fill()
- t.penup()
- t.goto(3000,-2000)
- t.done()
复制代码
还有如果不知道开头的
里面的t是什么意思,其实就是把这个turtle模块当作t,这样就可以更方便的写代码,我还有一个例子
- import ybc_box
- import ybc_turtle as t
- import ybc_tuya
- import random
- print('电脑艺术家')
- op = ybc_box.buttonbox('请选择你想要的画风',['翩地球', '点和线', '大小球'])
- print('正在搭画板')
- print('正在找画笔')
- print('正在准备颜料')
- print('一切准备就绪')
- if op == '翩地球':
- i = 1
- while i < 5:
- t.speed(0)
- x = random.randint(0, 250)
- xx = random.randint(0, 250)
- xxx = random.randint(0, 250)
-
- t.penup()
- y = random.randint(-220, 300)
- x = random.randint(-500, 500)
- t.goto(x,y)
- t.color(x,xx,xxx)
- t.begin_fill()
- for i in range(1):
- t.pendown()
- t.circle(10)
- t.end_fill()
- t.penup()
- t.done()
- elif op == '点和线':
- i = 1
- while i < 5:
- t.speed(0)
- x = random.randint(0, 250)
- xx = random.randint(0, 250)
- xxx = random.randint(0, 250)
-
- t.color(x,xx,xxx)
- t.begin_fill()
- for i in range(1):
- t.penup()
- y = random.randint(-220, 300)
- x = random.randint(-500, 500)
- t.goto(x,y)
- t.pendown()
- t.circle(10)
- t.penup()
- t.end_fill()
- t.done()
- elif op == '大小球':
- i = 1
- while i < 5:
- t.speed(0)
- x = random.randint(0, 250)
- xx = random.randint(0, 250)
- xxx = random.randint(0, 250)
- d = random.randint(1, 200)
- t.penup()
- y = random.randint(-220, 300)
- x = random.randint(-500, 500)
- t.goto(x,y)
- t.color(x,xx,xxx)
- t.begin_fill()
- for i in range(1):
- t.pendown()
- t.circle(d)
- t.end_fill()
- t.penup()
- t.done()
复制代码 |
|