Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson1_1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0dea1e58
authored
Apr 24, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
b4e39faf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
hello.py
hello.py
0 → 100644
View file @
0dea1e58
#导入turtlt库
import
turtle
as
x
#创建海龟画图窗口
x
.
TurtleScreen
.
_RUNNING
=
True
#设置窗口大小
x
.
setup
(
width
=
960
,
height
=
720
)
#设置窗口颜色
x
.
bgcolor
(
"white"
)
#创建海龟
turtle_1
=
x
.
Turtle
()
turtle_2
=
x
.
Turtle
()
turtle_1
.
shape
(
"turtle"
)
turtle_2
.
shape
(
"turtle"
)
turtle_1
.
goto
(
100
,
100
)
#改变画笔图标大小
turtle_1
.
shapesize
(
2
)
turtle_2
.
shapesize
(
2
)
#改变颜色
turtle_1
.
color
(
'gray'
)
turtle_2
.
color
(
'pink'
)
#乌龟前进
#限制活动范围
def
front
():
turtle_1
.
forward
(
10
)
if
turtle_1
.
xcor
()
>
200
:
turtle_1
.
goto
(
200
,
turtle_1
.
ycor
())
if
turtle_1
.
xcor
()
<-
200
:
turtle_1
.
goto
(
-
200
,
turtle_1
.
ycor
())
if
turtle_1
.
ycor
()
>
200
:
turtle_1
.
goto
(
turtle_1
.
xcor
(),
200
)
if
turtle_1
.
ycor
()
<-
200
:
turtle_1
.
goto
(
turtle_1
.
xcor
(),
-
200
)
def
back
():
turtle_1
.
backward
(
10
)
def
left
():
turtle_1
.
left
(
45
)
def
right
():
turtle_1
.
right
(
45
)
#按下w键前进
x
.
onkeypress
(
front
,
'w'
)
x
.
onkeypress
(
back
,
's'
)
x
.
onkeypress
(
left
,
'a'
)
x
.
onkeypress
(
right
,
'd'
)
#窗口监听
x
.
listen
()
#抬起画笔
turtle_1
.
penup
()
#向着乌龟方向
while
True
:
turtle_2
.
setheading
(
turtle_2
.
towards
(
turtle_1
))
#乌龟2移动
turtle_2
.
forward
(
5
)
#判断两只乌龟的距离
if
turtle_2
.
distance
(
turtle_1
)
<
50
:
x
.
bye
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment