Παρακαλώ εγγραφείτε για να ξεκινήσετε να δημιουργείτε τα δικά σας διασκεδαστικά προγράμματα

TurtleAcademy learn programming for freeYour browser is not supporting canvas We recomand you to use Chrome or Firefox browsers

Turtle Motion

forward X , fd X

Moves the turtle x points

Παράδειγμα:

forward 50

Εξηγείται στο μάθημα:

Logo's turtle

back X , bk X

The turtle back x points

Παράδειγμα:

back 50

Εξηγείται στο μάθημα:

Logo's turtle

left X , lt X

Rotate the turtle left x degrees

Παράδειγμα:

left 90

Εξηγείται στο μάθημα:

Logo's turtle

right X , rt X

Rotate the turtle right x degrees

Παράδειγμα:

right 90

Εξηγείται στο μάθημα:

Logo's turtle

home

Moves the turtle to center, pointing upwards

Παράδειγμα:

home

Εξηγείται στο μάθημα:

Turtle world

setx NUM_x

Move turtle to the specified X location

Παράδειγμα:

setx 100

Εξηγείται στο μάθημα:

Turtle world

sety NUM_y

Move turtle to the specified Y location

Παράδειγμα:

sety 200

Εξηγείται στο μάθημα:

Turtle world

setxy NUM_X NUM_Y , set pos [ NUM_X NUM_Y ]

Move turtle to the specified location

Παράδειγμα:

setxy 100 100

Εξηγείται στο μάθημα:

Turtle world

setheading , seth

Rotate the turtle to the specified heading

Παράδειγμα:

sh 145

Εξηγείται στο μάθημα:

Turtle world

arc ANGLE RADIUS

Will create an arc distance RADIUS covering ANGLE angle

Παράδειγμα:

ARC 360 5

Εξηγείται στο μάθημα:

Turtle world

ellipse WIDTH HEIGHT

Will create an ellipse with Width and height

Παράδειγμα:

ellipse 80 90

Turtle Motion Queries

pos

Outputs the current turtle position as [ x y ], x or y respectively

Παράδειγμα:

pos

Εξηγείται στο μάθημα:

The turtle answer

xcor

Outputs the current turtle position as [ x y ], x or y respectively

Παράδειγμα:

xcor

Εξηγείται στο μάθημα:

The turtle answer

ycor

Outputs the current turtle position as [ x y ], x or y respectively

Παράδειγμα:

ycor

Εξηγείται στο μάθημα:

The turtle answer

heading

Outputs the current turtle heading

Παράδειγμα:

heading

Εξηγείται στο μάθημα:

The turtle answer

towards

Outputs the heading towards the specified [ x y ] coordinates

Παράδειγμα:

towards

Εξηγείται στο μάθημα:

The turtle answer

Turtle and Window Control

showturtle , st

Show the turtle

Παράδειγμα:

ht wait st

Εξηγείται στο μάθημα:

Controlling the Turtle and Pen

hideturtle , ht

Hide the turtle

Παράδειγμα:

hideturtle

Εξηγείται στο μάθημα:

Controlling the Turtle and Pen

clean , cs

Will clear the screen

Παράδειγμα:

fd 60 clean

Εξηγείται στο μάθημα:

Logo's turtle

cleanscreen , cs

Will clear the screen and return the turtle home

Παράδειγμα:

cs

Εξηγείται στο μάθημα:

Logo's turtle

fill

Does a paint bucket flood fill at the turtle's position

Παράδειγμα:

cs repeat 4 [ fd 50 rt 90 ] pu setxy 50 50 pd fill

Εξηγείται στο μάθημα:

Background

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 rt 90]]

Εξηγείται στο μάθημα:

Background

label expr

Draw a word (same logic as print) on the graphics display at the turtle location

Παράδειγμα:

label "logo ht

Εξηγείται στο μάθημα:

Background

setlabelheight expr

Set the height for text drawn by label, in pixels

Παράδειγμα:

setlabelheight 100 label "Logo ht

Εξηγείται στο μάθημα:

Background

wrap

If the turtle moves off the edge of the screen it will continue on the other side

Παράδειγμα:

cs wrap fd 800

Εξηγείται στο μάθημα:

The turtle borders

window

The turtle can move past the edges of the screen, unbounded.

Παράδειγμα:

cs window fd 600 rt 90 fd 100 rt 90 fd 70

Εξηγείται στο μάθημα:

The turtle borders

fence

If the turtle attempts to move past the edge of the screen it will stop.

Παράδειγμα:

cs fence fd 600 rt 90 fd 100 rt 90 fd 70

Εξηγείται στο μάθημα:

The turtle borders

Turtle and Window Queries

shownp , shown?

Outputs 1 if the turtle is shown, 0 if the turtle is hidden

Παράδειγμα:

show shown?

Εξηγείται στο μάθημα:

Interactive

labelsize

Outputs the height of text drawn by label, in pixels

Παράδειγμα:

show labelsize

Εξηγείται στο μάθημα:

Interactive

Pen and Background Control

penup , pu

Turtle stops leaving a trail

Παράδειγμα:

penup

Εξηγείται στο μάθημα:

Controlling the Turtle and Pen

pendown , pd

The turtle will leave a trail

Παράδειγμα:

pendown

Εξηγείται στο μάθημα:

Controlling the Turtle and Pen

setcolor X , setpencolor X
Will set the turtle color accroding to the following table
0: black 1: blue 2: lime
3: cyan 4: red 5: magenta
6: yellow 7: white 8: brown
9: tan 10: green 11: aquamarine
12: salmon 13: purple 14: orange
15: gray

Παράδειγμα:

setcolor 1

Εξηγείται στο μάθημα:

Colors and printing

setcolor [r,g,b] , setpencolor [r,g,b]

Will set the turtle color accroding to the amount of red , green and blue

Παράδειγμα:

setcolor [50 100 50]

setwidth X , setpensize X

Will set the pen width to X

Παράδειγμα:

setwidth 4 fd 50

Εξηγείται στο μάθημα:

The pen width

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

Εξηγείται στο μάθημα:

Turtle world

Pen Queries

pendownp , pendown?

Outputs 1 if the pen is down, 0 otherwise

Παράδειγμα:

show pendown?

Εξηγείται στο μάθημα:

Interactive

pencolor , pc

Outputs the current pen color. This will be a CSS color string, not necessarily the value passed in.

Παράδειγμα:

show pencolor

Εξηγείται στο μάθημα:

Interactive

pensize

Outputs a two element list with the pen width and height (usually the same).

Παράδειγμα:

show pensize

Εξηγείται στο μάθημα:

Interactive

Procedure Definition

to PROCNAME inputs ... statements ... end

Define a new named procedure with optional inputs

Παράδειγμα:

to TURTLE repeat 4 [ fd 50 rt 90] end

Εξηγείται στο μάθημα:

The turtle is learning

define PROCNAME inputs ... statements ... end

Define a new named procedure with optional inputs

Παράδειγμα:

define "star [[n][repeat 5 [fd :n rt 144]]]

def PROCNAME

Outputs the definition of a named procedure as a string

Παράδειγμα:

show def "star

Variable Definition

make varname expr

Update a variable or define a new global variable. The variable name must be quoted

Παράδειγμα:

make "foo 5

Εξηγείται στο μάθημα:

Variables

name expr varname

Like make but with the inputs reversed

Παράδειγμα:

name 5 "myvar

Εξηγείται στο μάθημα:

No lesson yet

localmake varname expr

Define a variable in the local scope (shortcut for local then make

Παράδειγμα:

localmake "myvar 5

Εξηγείται στο μάθημα:

No lesson yet

: VARNAME , thing VARNAME

Outputs the value of variable. :foo is a shortcut for thing "foo

Παράδειγμα:

show thing "myvar

Εξηγείται στο μάθημα:

Variables

Control Structures

repeat X [ statements ... ]

Repeat statements X times

Παράδειγμα:

repeat 4 [ fd 50 rt 90]

Εξηγείται στο μάθημα:

Loops

for controllist [ statements ...]

Typical for loop. The controllist specifies three or four members: the local varname, start value, limit value, and optional step size

Παράδειγμα:

for [i 1 10 1] [print :i]

Εξηγείται στο μάθημα:

The for loop

repcount

Outputs the current iteration number of the current repeat or forever

Παράδειγμα:

repeat 4 [ repcount ]

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]

wait X

Will cause the turtle to wait X ( 60ths of seconds ) time before executing the command

Παράδειγμα:

repeat 4 [ wait 10 fd 50]

Εξηγείται στο μάθημα:

Hi wait

bye

Ternimante the program

Παράδειγμα:

bye

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 [ make "a random 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 [ make "a random 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

Λίστες

list thing1 thing2 ...

Create a new list from the inputs

Παράδειγμα:

make "mylist (list "turtle "academy)

Εξηγείται στο μάθημα:

Λίστες

first listname

Outputs the first item from the list

Παράδειγμα:

print first :mylist

Εξηγείται στο μάθημα:

Λίστες

butfirst listname

Outputs all the items of listname except for the first item

Παράδειγμα:

print butfirst :mylist

Εξηγείται στο μάθημα:

Accessing the list

last listname

Outputs the last item from the list

Παράδειγμα:

print last :mylist

Εξηγείται στο μάθημα:

Λίστες

butlast listname

Outputs all the items of listname except for the last item

Παράδειγμα:

print butlast :mylist

Εξηγείται στο μάθημα:

Accessing the list

item index listname

Outputs the indexlist item of the list or array

Παράδειγμα:

print item 1 :mylist

Εξηγείται στο μάθημα:

Accessing the list

pick index listname

Outputs one item from a list, at random

Παράδειγμα:

print pick :mylist

Εξηγείται στο μάθημα:

Accessing the list

Μαθηματικά

sum X Y

Will sum x+y

Παράδειγμα:

print sum 2 3

Εξηγείται στο μάθημα:

Variables

minus X Y

return the distance between x and y x-y

Παράδειγμα:

print minus 8 2

random X

Will choose a random number between 0 - (X-1)'

Παράδειγμα:

cs print sum random 10 3

Εξηγείται στο μάθημα:

Colors and printing

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 print modulo 10 3

power expr expr

3 power 4 = 81

Παράδειγμα:

show power 3 4

Receivers

readword

Prompt the user for a line of input. The result (including spaces) is the single word output.

Παράδειγμα:

make "name (readword [What is your name?]) show :name

Εξηγείται στο μάθημα:

Interactive

leerlista

Prompt the user for a line of input. The result is a list of words.

Παράδειγμα:

make "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

Παράδειγμα:

print listp [1 2 3]

arrayp thing , array? thing

Returns true (1) or false (0) if thing is an array

Παράδειγμα:

print arrayp array 2

numberp thing , member? thing

Returns true (1) or false (0) if thing is a number

Παράδειγμα:

print numberp 25

emptyp thing , empty? thing

Test if thing is an empty list or empty string.

Παράδειγμα:

print 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.

Παράδειγμα:

print before? "bye "hi

substringp thing1 thing2 , substring? thing1 thing2

Test if thing1 is a substring of thing2.

Παράδειγμα:

print substringp "hello "helloworld