游乐天地
海龟动态
ellipse WIDTH HEIGHT
创作一个椭圆,并设置椭圆的宽度和高度
例如::
ellipse 80 90
海龟动态查询
Turtle and Window Control
fill
Does a paint bucket flood fill at the turtle's position
例如::
cs 重复 4 [ 前 50 右 90 ] 提笔 setxy 50 50 放笔 fill
课程里的解释:
filled fillcolor [ statements ... ]
Execute statements without drawing but keeping track of turtle movements. When complete, fill the region traced by the turtle with fillcolor and outline the region with the current pen style
例如::
filled "blue [repeat 4 [fd 100 右 90]]
课程里的解释:
label expr
Draw a word (same logic as print) on the graphics display at the turtle location
例如::
label "logo ht
课程里的解释:
setlabelheight expr
Set the height for text drawn by label, in pixels
例如::
setlabelheight 100 label "Logo ht
课程里的解释:
envolver
If the turtle moves off the edge of the screen it will continue on the other side
例如::
cs envolver 前 800
课程里的解释:
ventana
The turtle can move past the edges of the screen, unbounded.
例如::
cs ventana 前 600 右 90 前 100 右 90 前 70
课程里的解释:
fence
If the turtle attempts to move past the edge of the screen it will stop.
例如::
cs fence 前 600 右 90 前 100 右 90 前 70
课程里的解释:
Turtle and Window Queries
shownp , shown?
Outputs 1 if the turtle is shown, 0 if the turtle is hidden
例如::
show shown?
课程里的解释:
labelsize
Outputs the height of text drawn by label, in pixels
例如::
show labelsize
课程里的解释:
Pen and Background Control
设置颜色 X , 设置画笔的颜色 X
0: 黑色 | 1: 蓝色 | 2: 绿黄色 |
3: 青色 | 4: 结束 | 5: 紫红色 |
6: 您好 | 7: 白色 | 8: 棕色 |
9: tan | 10: 绿色 | 11: 碧绿色 |
12: 浅橙色 | 13: 紫色 | 14: 橙色 |
15: 灰色 |
例如::
设置颜色 1
课程里的解释:
设置颜色 [r,g,b] , 设置画笔的颜色 [r,g,b]
Will set the turtle color accroding to the amount of red , green and blue
例如::
设置颜色 [50 100 50]
changeshape X or STR , csh X or STR
Will change the turtle to another shape accordin to the following 0 = "turtle", 1 = "cat", 2 = "fish", 3 = "dog", 4 = "horse", 5 = "tiger", 6 = "crab", 7 = "snail"
例如::
csh 1 or csh "dog
课程里的解释:
Pen Queries
pendownp , pendown?
Outputs 1 if the pen is down, 0 otherwise
例如::
show pendown?
课程里的解释:
pencolor , pc
Outputs the current pen color. This will be a CSS color string, not necessarily the value passed in.
例如::
show pencolor
课程里的解释:
pensize
Outputs a two element list with the pen width and height (usually the same).
例如::
show pensize
课程里的解释:
Procedure Definition
到 PROCNAME inputs ... statements ... end
Define a new named procedure with optional inputs
例如::
到 TURTLE 重复 4 [ 前 50 右 90] 结束
课程里的解释:
define PROCNAME inputs ... statements ... end
Define a new named procedure with optional inputs
例如::
define "star [[n][repeat 5 [fd :n 右 144]]]
def PROCNAME
Outputs the definition of a named procedure as a string
例如::
show def "star
Variable Definition
定义 varname expr
Update a variable or define a new global variable. The variable name must be quoted
例如::
定义 "foo 5
课程里的解释:
localmake varname expr
Define a variable in the local scope (shortcut for local then make
例如::
localmake "myvar 5
课程里的解释:
: VARNAME , thing VARNAME
Outputs the value of variable. :foo is a shortcut for thing "foo
例如::
show thing "myvar
课程里的解释:
Control Structures
循环 controllist [ statements ...]
Typical for loop. The controllist specifies three or four members: the local varname, start value, limit value, and optional step size
例如::
循环 [i 1 10 1] [print :i]
课程里的解释:
重复次数
Outputs the current iteration number of the current repeat or forever
例如::
重复 4 [ 重复次数 ]
if expr [statement]
Execute statment if expressoin is true
例如::
if 2>1 [print "hello]
ifelse expr [statementTrue] [statementFalse]
Execute StatementTrue if tru else execute statementFalse
例如::
ifelse 0>1 [print "true] [print "false]
test expr
Test the specified expression save the result in the local scope for the subsequent use by iftrue iffalse
例如::
test 3>4 iftrue [print "true] iffalse [print "false]
iftrue [statements]
例如::
test 3>4 iftrue [print "true] iffalse [print "false]
iffalse [statements]]
例如::
test 3>4 iftrue [print "true] iffalse [print "false]
等 X
Will cause the turtle to wait X ( 60ths of seconds ) time before executing the command
例如::
重复 4 [ 等 10 前 50]
课程里的解释:
再见
Ternimante the program
例如::
再见
dotimes [varname times] [ statements ...]
Run the statements the specified number of times. The variable varname is set to the current iteration number.
例如::
dotimes [ i 5 ] [ show :i * :i ]
do.while [ statements ...] expr
Runs the specified statements at least once, and repeats while the expression is non-zero (true).
例如::
do.while [ 定义 "a 随机 10 show :a ] :a < 8
while [expr] [ statements ...]
Runs the specified statements only while the expression remains non-zero (true).
例如::
while (random 2) = 0 [ show "zero ] show "one
do.until [ statements ...] [expr]
Runs the specified statements at least once, and repeats while the expression is zero (false).
例如::
do.until [ 定义 "a 随机 10 show :a ] :a < 8
until [expr] [ statements ...]
Runs the specified statements only while the expression remains zero (false).
例如::
until (random 2) = 0 [ show "one ] show "zero
Lists
列表 thing1 thing2 ...
Create a new list from the inputs
例如::
定义 "mylist (list "turtle "academy)
课程里的解释:
butfirst listname
Outputs all the items of listname except for the first item
例如::
打印 butfirst :mylist
课程里的解释:
butlast listname
Outputs all the items of listname except for the last item
例如::
打印 butlast :mylist
课程里的解释:
item index listname
Outputs the indexlist item of the list or array
例如::
打印 item 1 :mylist
课程里的解释:
pick index listname
Outputs one item from a list, at random
例如::
打印 pick :mylist
课程里的解释:
Math
减 X Y
return the distance between x and y x-y
例如::
打印 减 8 2
随机 X
Will choose a random number between 0 - (X-1)'
例如::
cs 打印 合计 随机 10 3
课程里的解释:
modulo expr expr
Outputs the remainder (modulus). For remainder and % the result has the same sign as the first input; for modulo the result has the same sign as a the second input.
例如::
cs 打印 modulo 10 3
power expr expr
3 power 4 = 81
例如::
show power 3 4
Receivers
leerpalabra
Prompt the user for a line of input. The result (including spaces) is the single word output.
例如::
定义 "name (readword [What is your name?]) show :name
课程里的解释:
leerlista
Prompt the user for a line of input. The result is a list of words.
例如::
定义 "colors (readlist [Type some colors:]) show :colors
Predicates
word thing , word? thing
Returns true (1) or false (0) if thing is a word
例如::
show word "hello
listp thing , list? thing
Returns true (1) or false (0) if thing is a list
例如::
打印 listp [1 2 3]
arrayp thing , array? thing
Returns true (1) or false (0) if thing is an array
例如::
打印 arrayp array 2
numberp thing , number? thing
Returns true (1) or false (0) if thing is a number
例如::
打印 numberp 25
emptyp thing , empty? thing
Test if thing is an empty list or empty string.
例如::
打印 emptyp []
equalp expr expr , equal? expr expr
Test if xper expr are equal.
例如::
equalp "no "yes
notequalp expr expr , notequal? expr expr
Test if xper expr are not equal.
例如::
notequalp "no "yes
beforep thing1 , before? thing1
Test string collation order.
例如::
打印 before? "bye "hi
substringp thing1 thing2 , substring? thing1 thing2
Test if thing1 is a substring of thing2.
例如::
打印 substringp "hello "helloworld