o Pencil Code CoffeeScript. .
Pencil Code
To Pencil Code CoffeeScript
. , .
Pencil Code
: PhD, MSc,
PhD, .
:
. , .
Copyright: & .. 2017
ISBN: 978-960-473-888-5
Pencil Code CoffeeScript Ark of Inquiry. Ark of Inquiry, 2014 2018, , , , , () . , , , . Ark of Inquiry (http://www.arkofinquiry.eu) 7-18 , .
...................................................................................................................................................................................5
: Pencil Code ...........................................................................................................7 Pencil Code......................................................................................................................................................7 ............................................................................................................................................8
............................................................................................................................................10 ................................................................................................................................10 ............................................................................................................................................................11 .......................................................................................................................................................12 ................................................................................................................................................................12 ......................................................................................................................................................................12Online ...........................................................................................................................................................12 ..............................................................................................................12
2 : .....................................................................................................................12 ........................................................................................................................................13 ......................................................................................................................................................13 .........................................................................................13 ................................................................................15 ...............................................................................................................................................16
Coffeescript..............................................................................................................................19 ........................................................................................................19 write ...................................................................................................................................20 ............................................................................................................................22 ...................................................................................................................................23 : for .....................................................................................................................26 .........................................................................................................................27 ..................................................................................................30 .................................................................................................................................................31 .................................................................................................................33 ...............................................................................................................................................34 ................................................................36 ...........................................................................................................................................................37 ...................................................................................................................................................39 forever ..............................................................................................................................40
: - .........................................................................................431 : ...................................................................................................432 : .........................................................................................................................43
: , , ......................................................................453 : ................................................................................................46
.....................................................................................474-5 : ............................................................................................................48
..............................................................................................................51
6 | To Pencil Code CoffeeScript
6 : : for .....................................................................................52 - for .................................................................................53
7 : for ...................................................................................55 - ...................................................................56
8-10 : - ................................................................................57 ..........................................................................................................................59 - ......................................................................61 - ......................................................................................................63
11 -12 : .....................................................................................64 (1) .....................................................................................66 (2) .....................................................................................68
13-14 : for .................................................................70 (1) for ..................................................................................71 (2) for ..................................................................................72
15 : .......................................................................................................74 .....................................................................................................75
16-17 : if ........................................................................................................77 (1) if.....................................................................................................................79 (2) if.....................................................................................................................80
18 20 : .............................................................................81 ...........................................................................................................................82
- Pencil Code . , , -. .
, 2006 , Logo. - , . , , - Scratch .
, , . - .
Pencil Code - . . , "" .
Pencil Code, - . . .
, , a - Pencil Code www.pencilcode.org .
Pencil Code - Ark of Inquiry, - Inspiring Science Education. H .
:
1 2 1 3 2 1o 1
8 | To Pencil Code CoffeeScript
5 1 2 3 1
: , , , 2 .
: Pencil Code
Pencil Code Pencil Code , - . - . Logo .
Pencil Code - . . . -. .
- . - . , , -. .
Pencil Code (Coffeescript, Javascript, CSS, html).
CoffeeScript1. CoffeeScript . Javascript. To Python Ruby . Pencil Code Pencil Code.
CoffeeScript, CoffeeScript.
1. Jeremy Ashkenas 2009
10 | To Pencil Code CoffeeScript
Pencil Code online http://pencilcode.net. . . Internet . : . ( ). - . .
1:
Draw, Jam, Imagine Get Creative (- 1). . 2 Draw.
2: Draw
(Get Creative) "" (Start on a blank page) .
To Pencil Code CoffeeScript | 11
, 3, - . ( 4) - ( ).
3:
, ( ) code .
4:
( 5).
5:
12 | To Pencil Code CoffeeScript
, , - .
, , - Start on a blank page . myprogram. Pencil Code, . .
. . Pencil Code - .
. Pencil Code , - (mail). . . Pencil Code, Login, . ( ) vang.
6:
. New file . - . .
, , :
To Pencil Code CoffeeScript | 13
1. untitled
2. save
. mk2016 - flower. T https://mk2016.pencilcode.net/edit/flower
. , school diorofo. , : school/diorofo - https://mk2016.pencilcode.net/edit/school/diorofo
New .
o Share .
See it here (output) . Share code . Embed code -.
14 | To Pencil Code CoffeeScript
, , save .
, . , / . .
? ,
Ask a question, googlegroup Pencil Code https://groups.google.com/forum/#!forum/pencilcode, Change password - .
Online
Guide , Online https://guide.pencilcode.net/home/
/ . , ( ) .
2 : ( 7, 8) , . , - .
To Pencil Code CoffeeScript | 15
7
8:
- . , 25 , . . (0,0). - .
(4) - .
.
16 | To Pencil Code CoffeeScript
, , -, . .
9:
, 9, sxima () for ( ), - 10. . , , .
10
. CoffeeScript :
#...
#
###. ..
To Pencil Code CoffeeScript | 17
###
. .
###
# , , - . ###, .
, . ( 7).
"" . , . , -. , ( ) .
- , - , ( 11) .
11:
/ / .
18 | To Pencil Code CoffeeScript
. ( 13, 14)
- . , , . :
12:
- :
To Pencil Code CoffeeScript | 19
Move Art Text Sound
13: Move, Art, Text, Sound
20 | To Pencil Code CoffeeScript
Control Operators Sprites Snippets
14: Control, Operators, Sprites, Snippets
.
To Pencil Code CoffeeScript | 21
Coffeescript Coffeescript . . , , , .
- . . . - . , . .
Text , Sound -.
:
write
label -. write
type
typeline .
append
say . write.
play
tone
22 | To Pencil Code CoffeeScript
alert . write.
2
write, type, append, label
write
. ( )
+ , - , * /
write . .. write 20 / 4 ( 5)
, , .
write . .. write round 6,5
.
(strings), , .
2. .. alert , alert .
To Pencil Code CoffeeScript | 23
) , . .. write ' . 14 . -. . '.
) ( ),
.( HTML) ... ... (bold).
.
, + . .. write 'a' + '3' a3.
write
write ''
write '
.
.
.
'.
.
.
write '10+5' 10 + 5
write 10+5 15
write 2+3*5 17
write (2+3)*5 25
write 'a' + 3 + 5 a35
write 'a' + (3 + 5) a8
write '12 + 8 =' + (12 + 8) 12 + 8 =20
write '12 + 8 =', 12 + 8 12 + 8 = 20
write "12 + 8 = #{12 + 8}" 12 + 8 = 20
write Number('5') + Number('3') 8
write 3 > 2 true
write ' '
write "' ." .
write 'O : " !"' O : " !"
24 | To Pencil Code CoffeeScript
- . .
=
x=5
write x*x
onoma='Maria'
write onoma
say onoma
write 'onoma'
message = ' .'
write 'message'
see message
x = 20
box black, x * 5
box white, x * 4
box black, x * 3
box white, x * 2
x= ''
write ' '+ x
x = - x. y= x2 .
:
x=5
y=4
x=y
H x y
( )
x=(random 6)
write = x + x
x , 4+5=9.
write x + 6
x = 5
-. x = 5 write x + 6
To Pencil Code CoffeeScript | 25
-
( ) pixels (), - . fd 100 - 100 pixels.
: . ( .) . pen, , .. pen blue, 10
15 fd (forward - ) :
15:
lt (left turn - ) rt (right turn - ). - .
16: (rt) (lt)
26 | To Pencil Code CoffeeScript
-
. . - ( 180 ) 100.
17 .
17:
fd 100 100
rt 90 90
lt 90 90
bk 100 100
home()
rt 180, 100lt 180, 100
180 () 100 rt lt
moveto 100, 50movexy 30, 20
moveto - x, y movexy - x, y
jumpto 100, 50jumpxy 30, 20
moveto movexy
To Pencil Code CoffeeScript | 27
dot green, 50
() (50) -
box red, 50
() (50)
pen purple, 10pen erase, 10
. erase .
pu() pen up pen off
. pen up
pd() pen on
speed 10 10
speed Infinity (- )
hide()
show()
fill blue -
cs() .
fill, .
pen purple, 5fd 100rt 90rt 180, 50fill pink
28 | To Pencil Code CoffeeScript
fill (pen) .
fill , . . :
pen purple, 5fd 100rt 180, 50fill pink
jump, pen up, pen down, .
pen purple, 5fd 100rt 180, 50jumpto 100, 0fd 100rt 180, 50fill pink
! pen null, . . fill , .
pen purple, 5fd 100rt 180, 50jumpto 100, 0pen blue, 5fd 100rt 180, 50fill pink
, fill .
: for
.
Pencil Code , for.
To Pencil Code CoffeeScript | 29
for . .
for Control. A , for ( ) .
HelloHelloHello
pen purple, 5for [1..3] fd 100 rt 120
speed 10pen yellow, 10for [1..5] fd 100 rt 144fill orange
wear 'car'grow 0.2pu()for [1..10] movexy -5, 0
- -
, . - . :
., - .
. .
for
30 | To Pencil Code CoffeeScript
: , .
CoffeeScript , - .
write round 6.7 6
write abs -7 7
write max 10, 3 10
( )
Operators .
, , "=", "()" "-->". "" , - , tab.
= () ->
for [1..10]
rt 360, 40
rt 36
dot magenta, 50
, , .
Operators
f
()
()do
To Pencil Code CoffeeScript | 31
( )
, , , .
1: x tetragono , 100 tetragono(100) .
tetragono=(x)-> for [1..4] fd x rt 90
tetragono(100) tetragono 100 x=100tetragono(x)
2: .
= (color, n, x) -> pencolor, n for [1..3] fd x rt 120
(red, 4, 100) red, 4, 100 color=redn=4x=100(color, n, x)
2 :
= -> for [1..3] fd 400 rt 120
32 | To Pencil Code CoffeeScript
= (color, n, x) -> pen color, n for [1..n] fd x rt 360/n
()
, , default . color black, ( ).
. . , . - , , . .
:
x = 5f = () -> x = 10 write xf()write x
10 10 x
x = 5f = (y) -> y = 10 write yf(x)write x
() 10 5
x = 5f = () -> y = 10 write xf()write xwrite y
5 5 ( write x) y
To Pencil Code CoffeeScript | 33
( )
,
x = 5f = (x) -> x = 10write xf(x)write x
5 10
Pencil Code . - read readnum.
H read read ' ', () -> ..read ' ;', (x) -> write ' ' + x
readnum readnum ' ', () -> ..readnum 'Your age?', (n) -> write 'Next year you will be ' + (n + 1)
read readnum Text
().
listen listen '', () -> ..listen 'Say something', (t) -> say 'Yousaid: ' + t
34 | To Pencil Code CoffeeScript
() .
click . click () -> ..click () -> say 'hello'
keydown, . keydown () -> ..keydown 'A', -> tone 'C'
. button. button ( ) -> ..button 'good morning', -> say 'good morning'
click, keydown button - Control
50 Pixels - .
button '', ->
fd 50
. .
To Pencil Code CoffeeScript | 35
button '', ->
pen blue, 10
button '', ->
fd 50
. .
button '', ->
pen blue, 5
for [1..6]
fd 50
rt 60
x=5readnum ' ', (x) -> write xwrite x
H write 5 readnum
.
x , write .
4. .
x, .
36 | To Pencil Code CoffeeScript
readnum ' ', (x) ->
write x
write x
- , :
x=5await readnum , defer xwrite x
10. .
-. - ( ) . - . - ( ):
for x in [blue, red, orange] dot x, 50 fd 50
.
[blue, red, orange] . [ ] . , . x for . x .
.
To Pencil Code CoffeeScript | 37
colors =[blue, red, orange]
colors [blue, red, orange].
, - , :
colors =[blueredorange]
. (index) 0. colors 0 blue, 1 red 2 orange. . colors[0] .. colors -
write colors[1] red
.
color[1] = yellow colors red yellow.
. colors.length.
write colors.length 3.
mikos = colors.lengthwrite mikos
: 0 1. . Pyhton. , 1. length - 1.
, . {1, 2, 3, 4, 5] [1...6]. [1...6] . ( ).
- , (length) . .
Lista = []
38 | To Pencil Code CoffeeScript
write 'length of Lista is' + Lista.length
onomata = ['', ' ', ''] ( )
write onomata , ,
write onomata.length 3 ( 3 ).
write onomata[0] ( 0 )
write onomata[1] ( 1 )
write onomata[2]
onomata[0] = '' ( )
write onomata , ,
for n in [1..5]
write 3 * n
for x in [10, 43, 6, 27]
write ' ', x
for x in ['', '', '']
write ' ', x
To Pencil Code CoffeeScript | 39
for color in [red, orange, yellow, blue]
pen color, 4
fd 100
rt 90
for d in [50, 100, 50, 100]
fd d
rt 90
mycolors = [darkred, red, lime, orange, royalblue, yellow]
for x in mycolors
box x, 70
fd 100
rt 60tetragonox = (x)->
for [1..4]
fd x
rt 90
pen red
for x in [ 100, 150, 200]
tetragonox(x)
pen purple
for x in [50..1] by -1
rt 30, x
, , , . . , , .
40 | To Pencil Code CoffeeScript
, . .
Pencil Code .
:
. Operators.
: x , x
pen black
x = 100
if x > 0
fd x
, . , . - , , , ( ) .
: . x , x , ( ) x
To Pencil Code CoffeeScript | 41
pen black
await read , defer x
if x > 0
fd x
else
fd x
: else fd () - .
"" .
.
if . x is 5, . .
Pencil Code , ( - and, or not).
.. . x > 0 and y > 0, x is 1 or y is 1.
42 | To Pencil Code CoffeeScript
( . x>0 ).
not A not B A and B A or B
. not , and , or . - . ( ) ;
forever
forever , - ( 30 ). . while , "" , . forever .
forever ->pen random colorfd 3rt 2
forever Control
forever -. .
To Pencil Code CoffeeScript | 43
- forever
( ) stop(). if, keydown.
wear 'bird'
grow 0.2
pu()
forever 1, ->
moveto random position
if (pressed 's')
stop()
"s" ( "stop")
To Pencil Code CoffeeScript | 45
: -
. . - , - . - . .
, .
, # ###. - , - .
1 : . . . PencilCode:
.
, .
, #. , .
2 :
:
PencilCode
() .
- .
46 | To Pencil Code CoffeeScript
.
, .
To Pencil Code CoffeeScript | 47
..................................................................... ........................................
..................................................................... ............................ . K .....................
: , ,
: write label Text
H say, play tone Sound
Pencil Code (Output) .
E
write ''
write ' 3 + 5'
write 3+5
write 2+4*5
write (2 + 4)/3
write '3' + '5'
write Number('3') + Number('5')
write "3 + 5 = #{3 + 5}"
write "3 + 5 =", 3 + 5
write ' '
write '
.
.
'alert ''
say 'My name is John'
play 'EDCDEEEzDDDzEEE'
tone 'A'
, , :
E
( )
27 35
-:
: Game over
.
48 | To Pencil Code CoffeeScript
3 :
:
read readnum, click, button keydown. . - read readnum, .
, Pencil Code, .
To Pencil Code CoffeeScript | 49
..................................................................... ........................................
..................................................................... ............................ . K .....................
.
! write read - 2 tab.
read ;, (x) -> write ' ' + x + '. Pencil Code!.'
Submit
.
............................................................................................................................................
............................................................................................................................................
readnum ' ', (n) -> say 'you'+ 'are'+ n + 'years'+' old'
Submit
.
.................................................................................................................................................................................................
.................................................................................................................................................................................................
.................................................................................................................................................................................................
click (e) -> tone 'B', 2 keydown 'A', -> write ' ' button 'Good morning', -> say 'good morning'
50 | To Pencil Code CoffeeScript
4-5 :
:
,, .
4
, .
. , .
dot black, 100dot orange, 50
. - :
Guide
QuickReferenceSheet http://pencilcode.net/material/reference.pdf )
:dot pink, 70fd 100box gold, 60dot midnightblue, 25hide()
-
cs()
To Pencil Code CoffeeScript | 51
:show()home()pen blue, 10fd 100rt 90bk 150lt 90fd 50pu()fd 50dot red, 40jumpto 100,100
.
100 pixels, 5 .
( tab).click (e) ->
moveto e.x, e.y
x y . "" .
pen olive, 5rt 180, 50
100
, fill red
:
( , , , .)
, ,
52 | To Pencil Code CoffeeScript
5
.
. 2 .
: logolike , .
To Pencil Code CoffeeScript | 53
..................................................................... ........................................
..................................................................... ............................ . K ....................
1) N 50 100 pixels. .
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
2) N 100 200 pixels. .
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
3) , , . 5 - 3, . 50 pixels.
4) , - . 50 pixels. - .
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
.......................................................... ..........................................................
54 | To Pencil Code CoffeeScript
6 : : for
:
for
.
. for - Control .
, .
for.
.
, - , "" for. tab.
, .
To Pencil Code CoffeeScript | 55
..................................................................... ........................................
..................................................................... ............................ . K .....................
- for
-. .
- - output
for [1..5]
write ''
for, 4 GOOD MORNING.
, .
.................................................................................................
...................................................................................................
, 50 - 80 . , . , .
) for
............................................................. .............................................................
............................................................. .............................................................
............................................................. .............................................................
............................................................. .............................................................
............................................................. .............................................................
............................................................. .............................................................
) for.
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
....................................................................................................................................
56 | To Pencil Code CoffeeScript
. .
for [1..4]
box purple, 30
fd 50
for [1...4]
box purple, 30
fd 50
( for ) .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
To Pencil Code CoffeeScript | 57
7 : for
:
for
.
. , , , - .
.
58 | To Pencil Code CoffeeScript
..................................................................... ........................................
..................................................................... ............................ . K ....................
-
1) . ; ;
-
pen blackfor [1..3] fd 100 rt 120
2) , for ( ). , .
(
)
:
To Pencil Code CoffeeScript | 59
8-10 : -
:
. Pencil Code .
, - , : - tab .
, , , .
, . .
, "" , .
1
= () -> pen purple, 3 for [1..6] fd 40 rt 60
( )
()
for [1..4] () rt 90
60 | To Pencil Code CoffeeScript
2
circle1=()->
pen black, 10
rt 360, 70
fill red
circle2 = ()->
pen green, 6
rt 360, 50
fill yellow
circle3 = ()->
pen purple, 3
rt 360, 30
fill cyan
( )
speed 20circle1()jumpxy 0, 120circle2()jumpxy 0, 80circle3()
1 . .
. .
2 2 . .
To Pencil Code CoffeeScript | 61
..................................................................... ........................................
..................................................................... ............................ . K .....................
line space. - Operators,
line =()-> pen black, 5 fd 20
space =()-> pen off fd 20
.
, . ;
line()space()
2 , line space. -o line(), space() for - . , .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
tetragono - . ! . - for. , .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
62 | To Pencil Code CoffeeScript
tetragono() for . , .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
To Pencil Code CoffeeScript | 63
..................................................................... ........................................
..................................................................... ............................ . K .....................
-
isopleuro , 60 , 5, . .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
isopleuro for .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
aktina - 50 , 3 (! ).
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
64 | To Pencil Code CoffeeScript
aktina, for , .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
- , for .
To Pencil Code CoffeeScript | 65
..................................................................... ........................................
..................................................................... ............................ . K .....................
-
tetragono , 100 -.
isopleuro ( tetragono) 100 .
tetragono isopleuro - . . . - .
spiti, .
village, 4 , .
66 | To Pencil Code CoffeeScript
11 -12 :
:
11 :
. :
- .
:
tetragonom = (x)-> for [1..4] fd x rt 90
x.
, - .
tetragonom (20)
tetragonom 20
x=20
tetragonom (x)
tetragono3m = (color, x, y)-> pen color, y for[1..4] fd x rt 90
To Pencil Code CoffeeScript | 67
, , .
tetragono3m (red, 100, 5)
tetragono3m red, 100, 5
.
12 :
2 ( 2 ). - . , .
68 | To Pencil Code CoffeeScript
..................................................................... ........................................
..................................................................... ............................ . K .....................
(1)
. o Pencil Code, - . . 40, 60 80 . .
tetragonom = (x)-> for [1..4] fd x rt 90
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
kyklosm . , - .
................................................................................
................................................................................
................................................................................
................................................................................
kyklosm . 40, 60 80 . .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
To Pencil Code CoffeeScript | 69
kyklos3m - , . , .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
kyklos3m :
i. 5 40
...........................................................................................................................................................................................
ii. 10 60
...........................................................................................................................................................................................
iii. 15 80
...........................................................................................................................................................................................
70 | To Pencil Code CoffeeScript
..................................................................... ........................................
..................................................................... ............................ . K .....................
(2)
1. isopleuro3m . (: , ).
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
isopleuro3m :
. 100 5
...........................................................................................................................................................................................
ii. 200 4
...........................................................................................................................................................................................
2. polygono4m : - , , .
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
polygono4m ;
i. 100 15
...........................................................................................................................................................................................
ii. 120 10
...........................................................................................................................................................................................
iii. 80 5
...........................................................................................................................................................................................
To Pencil Code CoffeeScript | 71
3. skala3m , , 5.
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
skala3m ( 50 , 80 ).
................................................................................
4. ilios3m . , - . 3.
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
ilios3m ( 100 , .
................................................................................
72 | To Pencil Code CoffeeScript
13-14 : for
:
13 :
:
tetragonom ( ) . . 40, 60 80 .
, tetragonom :
tetragonom(80)fd 80tetragonom(60)fd 60tetragonom(40)
, ( ).
for x in [80, 60, 40] tetragonom(x) fd x
.
. , .
1o
14 :
2
To Pencil Code CoffeeScript | 73
..................................................................... ........................................
..................................................................... ............................ . K .....................
(1) for
tetragonom ( - ) .
tetragonom for, : ( 30, 40, 50, 60, 70, 80 )
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
kyklosc 100
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
kyklosc for, - : ( 6 ).
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
50 100 , for .
74 | To Pencil Code CoffeeScript
..................................................................... ........................................
..................................................................... ............................ . K .....................
(2) for
for x in [13, 35, 2] write ' ', x
; ___
for x in [0..4] write ' ', x
;___
x 1 ;___
x ;___
for x in [0...4] write ' ', x
;___
x 1 ;___
x ;___
for x in [10..20] by 2 write x
; ___________________
, 1 100 - 5.
:
.....................................................................................................................................
.....................................................................................................................................
.....................................................................................................................................
for . - .
.................................................................................................................
.................................................................................................................
.................................................................................................................
To Pencil Code CoffeeScript | 75
. for . .
.................................................................................................................
.................................................................................................................
.................................................................................................................
for color in [red, orange, yellow, blue] pen color, 4 fd 100 rt 90
.
:
.....................................................................................................................................
.....................................................................................................................................
.....................................................................................................................................
pen purple for x in [50..1] by -1 rt 30, x
.
:
.....................................................................................................................................
.....................................................................................................................................
.....................................................................................................................................
76 | To Pencil Code CoffeeScript
15 :
:
.
.
To Pencil Code CoffeeScript | 77
..................................................................... ........................................
..................................................................... ............................ . K .....................
MIA MIA . ( -)
x=3
write x*x
x='Maria'
write x
say x
write 'x'
5 poso ;
...............................................................................................................
;
...............................................................................................................
write x ;
MIA MIA . (A -)
x=5
x=x+3
write x
write x*2
y=10
for z in [1..5] write y*z
MIA MIA . (A -)
x=7
y=x+6
write y
await read ' ;', defer x alert ' ' + x
78 | To Pencil Code CoffeeScript
Ginomeno await -:
) 1
) 2
) .
) : . ( )
To Pencil Code CoffeeScript | 79
16-17 : if
:
1
doc -, , .
. :
button '2',-> await read ' ', defer x if x is '' wear 'mountain' else wear 'wrong'
button '', -> await read ' ', defer t1 await read ' ', defer t2 await read ' ', defer g V=(t1+t2+g)/3 if V await read '', defer a await read '', defer b write ' '+ a + ' * x = ' + b if a is 0 if b is 0 write ' ' else write ' ' else x= b/a write ' ' + x
80 | To Pencil Code CoffeeScript
button '2', -> await read '', defer a await read '', defer b if a is 0 and b is 0 write ' ' else if a is 0 and b isnt 0 write ' ' else write ' ' + b / a
To Pencil Code CoffeeScript | 81
(1) if
Pencil Code, .
await read ' ', defer x if x > 17 write ' ' else write ' '
2-3 , . - :
button '', -> await read ' ', defer x if x > 17 write ' else write ' '
:
button ' ', -> x = random [1..6] write ' ' + x if x is 1 write ' Pencil Code.' wear 'pencil' else if x is 2 write ' !' wear 'math' else if x is 3 write ' .' wear 'book' else if x is 4 write ' !' wear 'gym' else if x is 5 write ' ' wear 'cinema' else write ' ' wear 'walk'
: ; . - , mountain, wrong.
, . 10, , .
82 | To Pencil Code CoffeeScript
..................................................................... ........................................
..................................................................... ............................ . K .....................
(2) if
Pencil Code. Pencil Code, , :
button '',-> await read ' o ?', defer m await read ' ?', defer h if m < 10 and h < 10 write ' ' else if m > 10 and h > 10 write '' else write ' '
16 1712 89 129 9
Pencil Code. Pencil Code, , :
button 'karavi',-> await read ' ?', defer s await read ' ', defer v if s is '' if v > 1000 kostos = 100 else kostos = 80 else if v > 1000 kostos = 70 else kostos = 50 write ' ' + kostos + ' '
700 1300 1200
600
, ax=b . ( : 0x=0 , =0 0 , x= /)
To Pencil Code CoffeeScript | 83
18 20 : . 2- 3 .
, , . .
:
84 | To Pencil Code CoffeeScript
1) , .
2) , , . .
3) .
4) keydown , , , .
5) , :
forever -> if touches red write '' stop() if touches black home()
1
: forever
turnto lastmousefd 3
2
: (t,
t.fd 40, t.rt 90, t.pu() ...)
To Pencil Code CoffeeScript | 85
t.wear 'treasure' - t.grow 0.2
if touches red if touches t
3
2 . (.. - , -)
4
.
s = newDate forever,
e= newDatetime= (e-s)/1000write " "+ time + "!"
if touches t
86 | To Pencil Code CoffeeScript
5
- . , , ( )
: - . , .
To Pencil Code CoffeeScript | 87
alert, 15append, 14box, 18click, 29cs(), 19dot, 18fd, 17fill, 19hide(), 19home(), 18keydown, 30label, 14listen, 29lt, 17moveto, 18movexy, 18pd(), 19pen, 17pen erase, 18pen off, 19pen on, 19play, 14pu(), 19read, 29readnum, 29rt, 17rt 180, 100, 18say, 14show(), 19speed, 19Speed Infinity, 19tone, 14type, 14typeline, 14write, 14