Вы находитесь на странице: 1из 578

1

Small Basic
3

-, ,
, .

www.rvGames.de/buy.htm

.
.


, .

Copyright 2012-2013

4


, ,
, .


. ( -
), ( ).
- , -
, -
.
. -
, ! -
.

-

;
- ,
-;
- - ,
;
- ;
- ,
;
- ;
- ;
- ;
- .
5

-
;
- , ,
;
- - -
;
- ;
- ;
- ;
-
( , -

);
- -
,
;
- ;
- ;
- ;
- ;
- , , ;
-

, ! ,
!

, :

,
Small Basic 1.0 _Small Basic Projects.

: www.rvGames.de

.
7

............................................................ 2
....................................................................................................................... 3
.................................................................................................................... 7
1. Small Basic .............................................................................. 8
2. Small Basic .................................................................................... 18
3. ................................................................................... 29
4. !................................................................................ 37
5. ........................................................................................ 47
6. ................................................................................ 61
7. While........................................................................................................ 74
8. ....................................................................................... 85
9. ................................................................................................. 99
10. .......................................................................................................... 114
11. ................................................................................................ 125
12. .................................................................. 144
13. ....................................................................... 158
14. .......................................................................... 170
15. ......................................................................... 180
16. Math ................................................................................................... 192
17. ............................................................................... 202
18. ..................................................................... 221
19. ............................................................. 230
20. ............................................................. 241
21. ......................................................................... 252
22. .................................................................................... 267
23. ................................................................... 285
24. .................................................................................................... 312
25. ................................................................................ 341
26. ................................................................ 353
27. ............................................................................... 363
28. ....................................................................................................... 381
29. ......................................................................... 386
30. ................................................................ 390
31. ........................................................................... 393
32. .................................................................... 399
33. ........................................................................... 413
34. ........................................................................ 425
35. ............................................................................................. 436
36. ! ...................................................................................... 442
37. - ................................................... 449
38. ................................................................................ 475
39. .......................................................................... 485
40. .......................................................................................... 492
41. , ................................................ 503
42. ......................................................................... 525
43. .................................................................................. 545
................................................................................................................. 569
8

1. Small Basic

.
: -
, !
, -
. ,
, -
.
. -
, , ,
. ,
: !
-
, . ,
,
- ,
! ,
,
.
9

!
,
!

-
. -
-
. , -
. , , 1969
, , -
-
.

(1623
1662), -
Beginners All-purpose Symbolic
Instruction Code ( -
) BASIC.

: - basic .
-
, -
.

-
-
.
Small Basic ( -
), -
. ,
. , , -

, .
10

Small Basic SB .

-
, -
, -
,
!

, !
:
1. - !
2. -
Windows XP (
), Windows Vista Windows 7.
3. .
4. .NET Framework 3.5 4.0.
5. Microsoft Small Basic.
6. , -
!
, -
. ? - ,
- -
, , - .
,
- !
, Small Basic
. .
!
SmallBasic.msi -
, www.smallbasic.com.
Down-
load (. 1.1).
11

. 1.1. www.smallbasic.com
(. 1.2).

. 1.2.
12

,
, -
( ,
),
!
Small Basic ,
.
,
(. 1.3).

. 1.3. :

, Next ().
, -
(. 1.4).
13

. 1.4.

-
Windows
.

Next -
, (.
1.5).

. 1.5.
14

-
, -
.

Install () (.
1.6).

. 1.6.

(. 1.7).

. 1.7.
15

! -
!

,
Finish () (. 1.8).

. 1.8.

C:\Program Files\Microsoft\Small
Basic\ ( Windows).
, -
!

SB.exe,
,
Windows (.
1.9).
16

. 1.9.

,
(. 1.10).

. 1.10.

, (. 1.11).
17

. 1.11.

: Small Basic,
1.0.

: -
...

, -
.

1. , Small
Basic, .
2. ,
.
3. , -
.
4. .
18

2. Small Basic

Small Basic, !

(. 2.1).

. 2.1.
-
(. 2.2).

. 2.2.
19

: !
, -
( ) .

Samples -
. , -
,
, , -
.

- -
(. 2.3)
(. 2.4),

. 2.3.

. 2.4. !
20


(. 2.5).

. 2.5.

, -
, .
(. 2.6).

. 2.6.

, - (.
2.7).

. 2.7.
21

(,
, ) . , ,
: ? - :
www.smallbasic.com ,
- . -
. , -
. -
, - -
, .
-
Snakebite ( ).
(. 2.8).

. 2.8.

(), -
-,
!

-
- SNKBITE - (. 2.9).
- , ,
.
22

. 2.9.

,
.
F5 (. 2.10).

. 2.10.

, -
(. 2.11).
23

. 2.11.

-
! - ,
.
(. 2.12).

. 2.12. !
24

, ,
. - ! : ,
? -
, , -
,
, -
.

.
.
10 . ,
, -
-- - -
. ,
.
.
( ),
,
, -
Windows.
:
, ()

,
, ,
(. 2.13).

,
-
!

!
, , , : -
()
.
25

. 2.13.

,
. ,
. ,
, . -
, .

,
, (. 2.14, 2.15).

. 2.14.
26

. 2.15.

(.
2.18, 2.19).

. 2.18.
27

. 2.19.

(. 2.20, 2.21).

. 2.18.
28

. 2.19.

1. .
2. www.smallbasic.com,
, -
.
29

3.

- , !
: -
SNKBITE - * (. 3.1).

. 3.1. ( )

, - -
, -
( ) . -
, (
), .
, -
, , -
30

.
, -
,
, . -
, , ,
. -
-
, .
: .
, -
-
. -
-
(, , !), -
. -
, . -
,
, -
.
, -
. -
,
, -
-. -
, -
. ,
. - -
,
! ,
-
,
, .
-:
, -
.
,
, , -
31

, , (
, , ,
).
, -
Windows .
EXE (-
execute - , -
). ,
.
: - ? -
, , , -
!
, , -
.
, -
(. 3.2).

. 3.2. !

, , , ,
(, ,
!) .
-
. (. 3.3).

. 3.3.
32

(. 3.4).

. 3.4.

.
,
.
? - ! -
-
,
. ,
( My Projects). ( ) -
Small Basic ( My Small Basic
Projects). -
(__ ),
Windows ( -
) .
, , .

33

. ,
Snikebite.

,
!

, , ( -
, -
, -
) .
! - snkbite.sb. -
( ) ,
, ( ) - ,
,
. , .
,
- -
,
snkbite.sb.
, .
: . -
, .
( )
- ,
, , ,
. , -
.
, -
(. 3.5).

. 3.5.

, , ,
. !
34


! , -
, ,
. ,
, ,
, ,
( bug,
, ,
). -
.


. _ARCHIV, _,
, ,
. -
, ,
, .sb.
, .
,
,
.
,
:
( !) -
. , -
, , :
! -
!

, ,
,
.

,
F5. ,
,
35

. ! :
SmallBasicLibrary.dll, snkbite.pdb snkbite.exe.
( !),
:
Small Basic -
.
Small Basic , -
,
CIL (- - Common
Intermediate Language),
.NET. , C#, Managed C++, Visual Basic.NET,
Visual J#.NET.

Small Basic ,
, , , -
,
(- - Integrated development
environment , IDE).

, -
.
Micro-
soft .NET Framework 3.5 4.0.
-
.

1. www.smallbasic.com , -
.

2. ,
(. 3.6).
36

. 3.6.

(. 3.7) -
-
, , -
( ).

. 3.7.

3. -
, ,
. ,
, .
, . -
, .
37

4. !

, !
!

-
,
Hello, World!. -
, Small Basic -
Hello .
,
, -
. hello.sb,
, , -
- ,
!
:

,
!
, -
. , -
. -
, () ,
, -,
.
, -
,
.
!
(. 4.1).
38

. 4.1. !

, , ? - -
:

( ENTER), -
, -
, .

, -
. , ,
. , -
, ,
!
, -
.

, , -
, . ,
,
T, -
(. 4.2).
39

. 4.2.

,
, , t.
TextWindow, , -
(. 4.3).

. 4.3.

(. 4.4).

. 4.4.

-
, ,
40

. (. 4.5),
.

. 4.5.

:
, , -
!

,
, ,

-. ,
-
.

,
CTRL+.

, -
(. 4.4) (
).
, , . -
, -
, !


(. 4.6). , ,
TextWindow , -
. -
, .


. TextWindow,
,
(. 4.7).
41

(. 4.8).

, ,
() WriteLine. , -
,
. , , :
.
.

. 4.6. . 4.8. WriteLine

.
4.7.
TextWindow
42

-
, ,
.
!


- (
) - (. 4.9).

. 4.9.

, , ,
, , -
. -
-
! , -
,
. , -
,
:

(. 4.10).

. 4.10. , !
43

- - -
, hello.exe.
, ,
. -
: ,
Windows!
, , ,
Windows
,
.
(. 4.11),

.

. 4.11.
:

- Windows,
(. 4.12).

. 4.12. Windows
, , -
, , ,
.
44

, ,
, , .

, Windows, ,
.
, -
, -
, -
. (. 4.13).

. 4.13.

- -
,
, . -

,
-
.
-
.
-
. -
.
,
.
Hello
- - , - -
. , -
, , .
45

-
. ,
-
,
, . , ! -
, :
.
, ,
, .
:

(.
4.14).

. 4.14.

, !
, , ,


(. 4.15), , -
C++, .

. 4.15.

, :
-
46

,
, - Windows -
.

,
-
.
47

5.

, ,

.
, -
, . -
, , ,
.
: , ,
?
: , ,
!

-
N, : N =
{1, 2, 3, ...}.
( ): N = {0, 1, 2, 3, ...}. -

.
(
), .
Z = {... 0, -2, -1, 0, 1, 2, ...}.
, .
,
,
.

() m/n,
m - ;
48

n - , (, , ,
!).
Q.
1, ,
n. ,
( -
). !

(1/2 = 0,5) -
(1/7 = 0,1428571...).
!
(

), , -
, -
.
. -
, -
.
I.
, -
.
-
(. 5.1).

. 5.1.

R
( numerus realis).
- (-
) (
).
49


, .
, , , -
, . -
, -.

-
, , -
,
,
-

,
-
. -
-
-
! - ,
.
,
. ,
, -
,
, , -
.
,
, Rome, -
-
.
50

-?
- Parla italiano?
Italiano = FALSE
Basic = TRUE


, . ,
, -
.
,
.


, .
().

Rome
. , ,
.
-
,
. ,
,
. ,
,
: , -
, .

,
.

. ,
, ,

:
51

123
"Z"
Math.Cos(1)
string1
Text.GetCharacter(111-32)


(), .
.

, - ,
,
. ,
.
-
, -
,
, .
,
,
. -
,
.

:
'variables

( -
)
,
,
-
.
, .
52

:
'

'variables
number=0
sNumber=""
n=0
num[1]=1000
num[2]= 900
num[3]= 500
num[4]= 400
num[5]= 100
num[6]= 90
num[7]= 50
num[8]= 40
num[9]= 10
num[10]=9
num[11]=5
num[12]=4
num[13]=1

sNum[1]="M"
sNum[2]="CM"
sNum[3]="D"
sNum[4]="CD"
sNum[5]="C"
sNum[6]="XC"
sNum[7]="L"
sNum[8]="XL"
sNum[9]="X"
sNum[10]="IX"
sNum[11]="V"
sNum[12]="IV"
sNum[13]="I"

. number -
, .
,
- . - ,
!
53

number , -
sNumber - ,
. ,

, .

,
, , , number
:
number=

, -
.
.

. , i (integer - ) n
(number - ) - , s (string - ) -
.
-
, .
, , -
. ,
, ,
-
, :
fNumber= -1.12345678912345
fNumber= .12345678912345
,
f (float - -
).

- 14 . !

54

, - 15 .
. ,
.
,
, : .5.
- 0.5,
.

sNumber. -
-
.
(, ).
,
!
n -
.
, -
, -
.
( -
, , ) . -
, -
!

,
number -
. ,
, -
,
.

-.
.
,
If, For, While, Goto - -
TextWindow, Math, Array.
55

, -. -
.
- ! ,
, .
,
. ,
, -
:
num1=1000
num2= 900
num3= 500
,
-,
.
. , , -
-
( ).
( , ), -
. , , , -
!

()
, ()
. ,

, .

.
,
.


Primitive, Small Basic
Microsoft - Visual Basic.
, .
56

Rome : - num[] -
, - sNum[] - . 13
, -
.
,
,
.
, -
1 3999 - -
, ,
num 13 -
, .
3999 1 (
), -
.

, ,
, - -
. .

ReadNumber
, ,
number , :
'=========================================
'
'=========================================
start:
number=TextWindow.ReadNumber()
sNumber=""
n=0

, , -
:

' , :
if (number = 0) then
57

goto exit
EndIf


n sNumber. -
While.
number , -
num, . While -
, , number -
, , ( -
900, 500, 400, 90, 50, 9, 5, 4 -
). number ,
, , -
:

' ,
number:
if (number < 1) or (number> 3999) then
sNumber= " " 1 3999!"
goto print
else
while number>0
n= n+1
while num[n] <= number
sNumber= sNumber + sNum[n]
number= number - num[n]
EndWhile
EndWhile
Endif

( -
While), ,
-
:

' :
print:
TextWindow.WriteLine(sNumber)
58

Goto start

' :
exit:

, !
, ,
- (. 5.2).
9999 -1.
(. 5.3).

. 5.2. , !

. 5.3. - !
59

Rome.

, ,
!

,
- , ,
!


Rome2
!

! -
ForegroundColor -
"Yellow":

start:
TextWindow.ForegroundColor="Yellow"
number=TextWindow.ReadNumber()
sNumber=""
n=0

,
.

,
:

TextWindow.ForegroundColor="Green"
60

' ,
number:
if (number < 1) or (number> 3999) then
sNumber= " 1 3999!"
TextWindow.ForegroundColor="Red"
goto print
else
while number>0
n= n+1
while num[n] <= number
sNumber= sNumber + sNum[n]
number= number - num[n]
EndWhile
EndWhile
Endif

, -
, , (. 5.4).

. 5.4. !

Rome2.

1. . -
, .

2. , ,
-
2 * 2. -
, .
61

6.

-
,
.
,
, , C#
System.Console .
C#, -
-
, , ,
.
, Microsoft Visual C# 2010 (. 6.1).

. 6.1.


. ,
:

Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.Red;
Console.Title= " C#";
Console.WriteLine(" C#");
Console.Read();

,
Console C# ,
TextWindow .
62

Desktop ( )

,
,
Desktop, -
.

Desktop -
.

, , -
, (,
, , ,
) (-
- !).

Desktop.Width,

Desktop.Height.

, ,
, -
. ,
, ,
. :
, -
,
.

Desktop.SetWallPaper(fileName)

, -
. -
63

(
).

,
!

TextWindow ( )

TextWindow.Show()


, .

TextWindow.Hide()

, .

Program.Delay(10000)

,
10 .

680
340 (. 6.2).

,
-
, .
64

. 6.2.

,
, - ;
.

,
.
, ,
- ...

, -
80 .
8
640 .

TextWindow.Left
TextWindow.Top
65


. , :

TextWindow.Left = 200
TextWindow.Top = 300


. -
.


, Y (. 6.3).

. 6.3.

-
. , -
:

GraphicsWindow.Left= (- GraphicsWindow.Width) / 2
GraphicsWindow.Top = (Desktop.Height-GraphicsWindow.Height)/2
66

Width Height, -
, , -
680 340 ,
TextWindow.Left= (Desktop.Width - 680) / 2
TextWindow.Top = (Desktop.Height - 340) / 2


, ,
.
-
, :
TextWindow.Left = 200
TextWindow.Top = 300

-
,
, -
, .
:
TextWindow.Left = 2000

. , -
, , , -
, .

, ,

(, ):

Left = TextWindow.Left
Top = TextWindow.Top

,
, ,
, -
, -
. , ,
(. 6.4):
67

TextWindow.Title =

. 6.4. !

-
, , -
.
TextWindow.WriteLine()
TextWindow.Write()

( )
.
(. 6.5).

. 6.5. WriteLine

(.
6.6).

. 6.6. Write

- ,
.
68

TextWindow.Read()

, - -
,
.
.

:
TextWindow.Write(" ! ")
str = TextWindow.Read()
TextWindow.WriteLine("str = " + str)

Write, -
, . -
- -
, , -
str,
WriteLine (. 6.7).

. 6.7. Read

Press any key to continue


.

TextWindow.ReadKey()
,
(. 6.8).
TextWindow.WriteLine(" !")
str = TextWindow.ReadKey()
69

TextWindow.WriteLine("str = " + str)

. 6.8. ReadKey

. -
, Shift.

TextWindow.ReadNumber()
Read, ,
, .
ReadNumber -
, (. 6.9):
TextWindow.Write(" ! ")
num = TextWindow.ReadNumber()
TextWindow.WriteLine("num = " + num)

. 6.9. ReadNumber

TextWindow.CursorLeft
TextWindow.CursorTop
( )
.
, . -
70

0, 0.
79-. . -
-
(. 6.10):
For i= 1 To 20
x= Math.GetRandomNumber(20)
TextWindow.CursorLeft=x
y= Math.GetRandomNumber(20)
TextWindow.CursorTop=y
TextWindow.WriteLine(Math.GetRandomNumber(10)-1)
EndFor

TextWindow.CursorLeft= 0
TextWindow.CursorTop= 21

. 6.10. !

, -
, .

TextWindow.Clear()
71

, -
(. 6.11, ).
.

, -
, (. 6.11, ):

TextWindow.BackgroundColor = "Blue"
TextWindow.Clear()

. 6.11.

-
.

TextWindow.ForegroundColor

,
TextWindow.BackgroundColor

, .

TextWindow.ForegroundColor = "Yellow"

For i= 1 To 20
= Math.GetRandomNumber(20)
TextWindow.CursorLeft=x
y= Math.GetRandomNumber(20)
TextWindow.CursorTop=y
TextWindow.WriteLine(Math.GetRandomNumber(10)-1)
EndFor
72

TextWindow.BackgroundColor = "Red"
TextWindow.CursorLeft= 0
TextWindow.CursorTop= 21

(. 6.12)!

, -
, -
(. 6.13).

. 6.12. !

( ),
( -
).
1. - .
2. , .
.
73

. 6.13.
74

7. While

Rome
While,
. ,
.
For
While.

While .
Repeat ( Do-While)
- . While ,
,
. , Repeat -
, While
. ,
While. For - -
.

:
- (
- ),
- ( - ),
- ,
-
,
- ,
- ,
- ,
- ,
- ,
- ,
, -
.
75

While :

While __

1
2
...
N
EndWhile

1. .

2. ( ), ,
, -
EndWhile.

3. , -
1, 2, , N,
, .1.

, -

.

, ,
.
? , -
, .
. : While
, ,
!
76

(
- ) n= n+1:

while number>0
'n= n+1
while num[n] <= number
sNumber= sNumber + sNum[n]
number= number - num[n]
EndWhile
EndWhile
endif

,
,
. .
( ),
! -
, ,
! -
While For, , , -
.

For, -
, While.

EndWhile !

-
, 1 2 .

-
, , .

:
77

- , -
. -
. -
, ,
, .
,
.

,


Width = 100 100
Height = Width + 20 120
Mas[12] =
Mas[13] = + 1 1
String = Mas[13] + Height 1120
GraphicsWindow.Width = 640 640
Width = GraphicsWindow.Width
max = Math.Max(1,11) 11


. -
:

x = 10
x = x +1

: -
, x 10. -
, -
:

0=1
78

! ,
! -
,
.
: x
10. : 10 + 1 = 11.
x
11.

-
- :=. , , -
.
.


IF ,
. C++, C#
- ==.
, -
.


. ,
,
!
, , ,
2000- . ,

, 1999- 99-.
99-, , 00.
2000-,
79

1900-. ,

,
2000- .

.
: .
0 , 0 . ,
.
.
. ,
,
. ,
, .

,
bug
.

1945 , ,
,
, .
debugging, ,
.

()
- .
,
,
(. 7.1).
80

. 7.1.

,
, .


(. 7.2).

. 7.2.


. ,
-, ,
:

TextWindow.WriteLine(str)
81

7.2 ,
, , .
. ,

.


, (. 7.3).


,
,
. ,
.

. 7.3.

,
,
, ,
. ,
.


,
: MyProgram1, MyProgram2 . ,

,
82

, ?
!

,
,
.

.
,
, ,
.

,
:

GraphicsWindow.Title = "Debug"

n= 0
m= 6
While (n < 10) And (m > 5)
Draw()
EndWhile

Sub Draw
height=GraphicsWindow.Height
width= GraphicsWindow.Width
radius=Math.GetRandomNumber(2)
x = Math.GetRandomNumber(width-2*radius)
y = Math.GetRandomNumber(height-2*radius-40) + 40
r= Math.GetRandomNumber(163) + 92
g= Math.GetRandomNumber(163) + 92
b= Math.GetRandomNumber(163) + 92
clr= GraphicsWindow.GetColorFromRGB(r,g,b)
GraphicsWindow.BrushColor=clr
GraphicsWindow.FillEllipse(x, y, 2*radius,2*radius)
EndSub

, ,
:

(n < 10) And (m > 5)


83

While (n < 10) And (m > 5)


Draw()
TextWindow.WriteLine("n = " + n + " m= " + m)
EndWhile

,
n m,
.
!
(. 7.4).

. 7.4.
84

,
:

While (n < 10) And (m > 5)


Draw()
n= n+1
m= Math.GetRandomNumber(20)
TextWindow.WriteLine("n = " + n + " m= " + m)
EndWhile

, ,
n 10,
m (. 7.5).

,
.

. 7.5.


,
, .


. ,

,
. ,
.
85

8.
.

,
( !).

( )
, .
. -
, , - 1
. , -
. , -
( ) .

2
: 2 ,
0, 2, 4, 6 8.
2, , - . -
: 2012, 92, 4, 76, 58.
: 2
, .

3
3 ,
3. , 2010 3,
3: 2 + 1 = 3 ( ).
,
.
3, 6 9,
3. . ,
123456789 45.
: 4 + 5 = 9. ,
123456789 .
86

4
, , .
,
.
, . -
, -
.
4,
.

? , ,
4 . , -
4, ,
.
. -
. , 4,
. 2010.
10. 4 ,
2010 . - 4567896.
- 96. 9 6,
12. , -
, 4567896 4.
5
.
5, 0 5.

6
6,
2 3.

7 ,
87

.
.

, , , -
. , 4567896,
:
4 567 896
, -
, ,
.
( !) ,
, .
. -
:
896-567+4 = 333
7, 7.
.
333 7 , ,
4567896.

8
8, . , ,
, ,
8. 8 ,
,
4.
8 .
8, -
.
. , -
, , -
.
, 8.
88

.
2010. 10,
8 . , . -
- 123457928. -
928. 92. -
- 4 - 96. -
, 4: 9 + 3 = 12.
, 123457928 8.

9
.
9 , 9.
, 2010 3
. , ,
9 .
,
. ,
3.

10
, 5. 10
, 0. ,
2010 10.

11
; ,
, , , -
11.
, 11, -
, -
. , 11.
.
11, 11.
89

, 123453 11, 1 + 3 + 5 = 2 + 4
+ 3 = 9. 123456 ( !).

11 -
7, 11.

12
12 ,
3 4.

13
13 , 7 11
( ), 13.
.
, , -
7, 11 13, 7 11 13 = 1001, -
.
,
, -
, 19 [9].

- ?

,
- .

, -
, , -
, . ,
.
. -
, Rome2 -
90

Delimost ( ,
).
? -
- -
. -
,
.
, - , -
.
,
, :

'

'variables
number= 0
sNumber=""

:
.
, , -
? - : , ,
, , -
? - ! -
-
? , , -
.
. 'variables.

,
,
.
! ,
, -
. -
:
91


, ,
.
i.
, -
, :
. - ,
-
, . -
-
.
( ), -
,
,
.
, -
, qwertzuiopasdfghjklyxcvbnm1234567890, -
! ,

: sobakaGryzlaKost,
sobaka_gryzla_kost.
, , -
: sobakagryzlakost.
! , -
, -
, sobakaGryzlaKost
, sobakagryzlakost,
SoBaKaGrYzLaKoSt. .
,
. , -
( , ) ,
-
, .
()
ru.wikipedia.org/wiki/Translit.
, ,
.
92

'=========================================
'
'=========================================
' :
TextWindow.Left= 200
TextWindow.Top= 200
TextWindow.Show()


, ,
, , -
,
, .
-
.
, -, ,
:
'=========================================
'
'
'
'=========================================

. -
-
.
,
. -
() , -
. -
, -

goto gosub.
(label).

, ,
, .
93

Left Top
200.
, -
, .
number :
start:
' :
TextWindow.ForegroundColor="Yellow"
number=TextWindow.ReadNumber()

start:.
, , -
(
). , -
goto. -
goto ,
.
' , :
if (number = 0) then
program.End()
EndIf
, , -
, -
-
.
- ,

. :
, ( -
) End Program.
', 2..31:
For i= 2 To 31
If Math.Remainder(number, i) = 0 Then
TextWindow.ForegroundColor="Green"
sNumber= " "
Else
TextWindow.ForegroundColor="Red"
sNumber= " "
94

EndIf
' :
If i < 10 then
sNumber= sNumber + " "
endif
TextWindow.WriteLine(sNumber + i)
EndFor

, ,
2, 3, 4 , 31. -
, ,
. -
Remainder Math.
-
, . -
: , i,
- .
-
: ,
- , - . -
sNumber , -
10,
.

,
!

-
( ,
i).
(. 8.1).
95

. 8.1. !

-
, -
, ,
start:
TextWindow.WriteLine("")
Goto start

, -
, -
, .
, ,
15-16 , -
!

Delimost.
96

For

For , -
- .
,
2 31, -
, -
.

For :

For _=_ To _

1
2
...
N
EndFor

1. .

2.
.
, -
1, 2, , N,
.
EndFor, , -
, -
( -
i = i + 1).
, .2. -
, i
2 31, . -
97

,
: For i = 1 To 100.
3. ,

EndFor .

-
, i, j, k, l, m, n.
For -
.
-
, , -
,
EndFor.
- -
i, .

,
!
EndFor !

,
, !
1. For ,
, , 57.
2. delimost2 (. 8.2),
number dividend (-
) divisor ( ),

. :
TextWindow.Write(" : ")
dividend=TextWindow.ReadNumber()
98

. 8.2. delimost2
300 , -
-
.
,
.
,
.


Delimost.

3. ,
, 15,
16, 18, 20, 22, 24, 25, 100, 1000. !
4. , ,
, , 11.
5. , 4 -
, 12.
99

9.

, -
. ,
, .
, - ,
( -
). , -
, . : 11,
13, 17, 23, 29, 31. , -
,
.
2011? , 2010-,
. ,
,
. , 2011 -
, 2017?
514229? - 39916801!
, -
. .
delimost, -
-
Prime.
,
. -
, :
'

'variables
number=0

,
:
'=========================================
'
'=========================================
' :
100

TextWindow.Left= 200
TextWindow.Top= 200
TextWindow.Show()

start:
' :
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" : ")
number=TextWindow.ReadNumber()

' , :
if (number = 0) then
program.End()
EndIf

' , :
If number < 2 Then
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" !")
Goto start
EndIf

- : ,
(, , , -
, ):

' ,
'2..
For i= 2 To Math.SquareRoot(number)
If Math.Remainder(number, i) = 0 Then
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" ")
TextWindow.WriteLine("")
Goto start
EndIf
EndFor

TextWindow.ForegroundColor="Green"
TextWindow.WriteLine(" ")
TextWindow.WriteLine("")

Goto start
101

:

2.. .
1.414,
, , -
, -
EndFor, , - .
.
, 1
.
, , - .
:
, -
. -
,
(, , ). -
, -
: -
.

. 9.1. !

, , -
(. 9.1).
102

,
, -
.
, ,
!

, -
.

Prime.

If

-
If, :
, .


-
. : -
, ,
.
:

If Then
1
Else
2
EndIf

:
;
1 ;
103

2 .

:
, , -
.

, ,
: -
, .
,
: ,
:

If Then

EndIf

,
-.

, !

If ,

.
():

If Then

1
2
...
N
EndIf
104

():

If Then
1
2
...
N
Else
N+1
N+2
...
N+M
EndIf

,
=, <, > .

( ), ( ).

,
Then. ,
,
EndIf .

Else EndIf.

, (max)
n1 n2, :

If n1 > n2 Then
max= n1
105

Else
max= n2
EndIf
,
, :
If (n1 > n2) Then

, -
, -
:
if (a=1) and (b=1) then
if (a=1) or (b=1) then

AND - .
,
:

(7 > 13) and (7 < 13)


(7 <> 13) and (7 < 13)

OR - .
,
:

(7 > 13) or (7 < 13)


(7 <> 13) or (7 < 13)

, -
,
Windows.
106

,
.
-
.

, , -
,
. -
, -
.

,
CTRL + A.

,
, -
.
:

, -
:
107

,
.

Del Backspace.

CTRL + X.

CTRL + .

CTRL + V.

( -
),

CTRL + Z.

CTRL + Y.
108

, -
-
.

, -
(. 9.2), -
.

. 9.2.

,
.
(. 9.3).

. 9.3.
109

-
, (. 9.4).

F3,
.

. 9.4. !

,
F3.

, -
.

: , -
:


( ,
, !).
-
:
110

-
, -
.

, .
,
TAB (). , -
, -
! , -
. , 63
EndWhile, While:

,
:

, While
EndWhile.
111

! -
, -
,

.
!


. .

1. , -
.

:

2. -
, ,
.

3.
.
- , -
.


.
Prime OSH-W97.sb.
, .

, .
, :
112

-
.sb, .txt . , -
, -
.

-
. ,
, .
,
(. 9.5).

. 9.5. -

, ,
:
113

-
, (. 9.6).

. 9.6. - !

.
F3 (. 9.7).

. 9.7. -

(. 9.8).

. 9.8. -

F3, .

, -
, ,
. -
,
.

: -
!
114

10.
,
!

,
!

,
.
,
- , 2 10000.
-
, !
,
, , -
.

, -
,
.

'
'

'variables
begin=0
end=0


,
:
'===========================================
'
'===========================================
' :
TextWindow.Left= 200
115

TextWindow.Top= 200
TextWindow.Show()

start:
' :
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" : ")
begin=TextWindow.ReadNumber()
' 0, :
If begin=0 Then
program.End()
EndIf
If begin < 2 Then
begin = 2
EndIf

TextWindow.Write(" : ")
end=TextWindow.ReadNumber()
If end < begin Then
end = begin
EndIf

, For
, j -
begin end:

TextWindow.ForegroundColor="Green"
For j= begin To end
',
'2..
For i= 2 To Math.SquareRoot(j)
If Math.Remainder(j, i) = 0 Then
Goto next
EndIf
EndFor
TextWindow.WriteLine(j)
File.AppendContents("primes.txt", j)
next:
EndFor
116

TextWindow.WriteLine("")
Goto start

For , ,
j. , -
. , (.
10.1).

. 10.1.

-
, , 2..10000. ,
300 , -
. , -
, -
. : -
,
. -
File

AppendContents("primes.txt", j)

-
, .
, .
, -
. ,
, -
117

. , -

.

Primes.

-
, .
,
,
, .

-
( end), -
,
number:

'variables
number[0]=0
end=0
prime=0

prime .
'=========================================
'
'=========================================
' :
TextWindow.Left= 200
TextWindow.Top= 200
TextWindow.Show()

start:
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" : ")
118

' 0, :
end=TextWindow.ReadNumber()
TextWindow.WriteLine("")
If end < 2 Then
end = 2
EndIf
If end=0 Then
program.End()
EndIf

1. , , :
' 2..end:
For i= 2 To end
number[i]= i
EndFor

2. :
prime=2

3. prime*prime, -
, , prime:

4 6 8 - prime= 2,
9 12 15 - prime= 3.

:
nextPrime:
For i= prime*prime To end Step prime
number[i]=0
EndFor

, , -
,
, - .

4.
:
119

' :
prime= prime+1
While (number[prime]=0)
prime= prime+1
EndWhile

prime .

5. prime -
end, .3.
If prime <= Math.SquareRoot(end) Then
Goto nextPrime
EndIf

,
- . -
. -
:
' :
s=""
perevodStroki=Text.GetCharacter(13) + Text.GetCharacter(10)
TextWindow.ForegroundColor="Green"
For j= 2 To end
If number[j]<>0 Then
TextWindow.WriteLine(number[j])
' :
s= Text.Append(s,j) + perevodStoki
EndIf
EndFor

,
:
File.AppendContents("resheto.txt", (number[j]))

,
.
-
. ,
,

120

, -
.

s, -
. .
Text.Append(s,j), +,
, .

, -

. -
perevodStroki. -
,
.
' :
File.AppendContents("resheto.txt", s)

,
:
TextWindow.WriteLine("")
Goto start

. 10.2. !

, -
. -
121

, -
(. 10.2).

Resheto.

For


For. . -

(). -
-
prime, .
For:

For _=_ To _
Step

1
2
...
N
EndFor

, ,
Step. -
Step . -
, -
.

, -
:
122

For i = 32 To 2 Step -2

i 32 2 2: 32 30 - - 4 2.

While -
, Step -
.

,
. -
.
:
:

For

For

For

EndFor
EndFor
EndFor

, !


For, While - .
123

-
: ,
1 1000
: 2, 3, 5, 7, 11, (, 24 = 2 * 2 * 2 * 3; 25 = 5 *
5). , -
, :
'

'variables
n5=0 '

'=========================================
'
'=========================================

TextWindow.Show()

' :
for i= 1 to 1000
n = i
uslovie=1
while uslovie=1
' 5,
' :
if math.Remainder(n, 5) = 0 then
n= n / 5
n5 = n5 + 1
else
uslovie=0
EndIf
EndWhile
EndFor

TextWindow.ForegroundColor="Green"
TextWindow.WriteLine("n5= " + n5)
TextWindow.WriteLine("")
124

TextWindow.ForegroundColor="Yellow"

For, -
, While, -
. 5 ,
1, -
.
, 5
5, . -
,
: 1000 : 5 = 200. ,
200 5. 40 25 (5*5), 8 125
(5*5*5) 625 (5*5*5*5). , -
, (. 10.3)!

. 10.3. !

1000.

Primes fileName, -

.
:

TextWindow.Read().


Primes.
125

11.
,


, , , -

. ,

, -
. , -
,
, .

?
-, !

, , -
, -
.
- ( ), -
, . -
,

. ! ( -
).
.

.

, -

, . ,
126

, -
?


, . -
. ,
,
,
.
, .
!

-
( - - ),
. -
,
,
, -
. ,
. , ,
, . , -
,
.

Palindrome
-,
.

:
string1= ""
string2= ""

string2 -
string1. , :
len = Text.GetLength(string1)
127

for i= 1 to len
chr=Text.GetSubText(string1,len-i+1,1)
string1= Text.Append(string2, chr)
endfor

,
, string1 = string2. -
, - :
if string1 <> string2 then
TextWindow.WriteLine(" ")
else
TextWindow.WriteLine("")
EndIf

-
. , -
-
, -
( ,
).
len = Text.GetLength(string1)
for i= 1 to len / 2
if Text.GetSubText(string1,len-i+1,1) <>
Text.GetSubText(string1, i,1) then
TextWindow.WriteLine(" ")
Goto exitFor
EndIf
EndFor

TextWindow.WriteLine(""))
exitFor:

,
. -
, . -
, -
.
OSH-W97.sb , 27407
.
128

.
:
'

'variables
spisok[0]="" '-
nWords=0 '

:
'=================================================

nWords=1
' :
fileName="OSH-W97.txt"
read()

-
:
'=================================================
Sub read
For i= 1 To 27407
' :
word=file.ReadLine(fileName,nWords)
' :
If word = "" Then
Goto exitSub
EndIf
' :
spisok[nWords]= word
' :
TextWindow.WriteLine(nWords + " " + spisok[nWords])
nWords= nWords+1
EndFor
exitSub:
EndSub

, 27407 , -
For,
. , , -
: -
129

, , . -
-
.


, . , -
,
.
, -
!

, , ! -
,
!

,
,
, !

- , -
,
.

word=file.ReadLine(fileName,nWords).

,
. , .

. ,
, -
. ,
-.
, :
, ,
.

, -
.
130

, , -
. , ,
.


, , -
? -
, .
, . -
spisok.
, -
:
spisok[1]= word

, ,
.
-
.
. -
,
. OSH-
W97.txt , -
, :

OSh_frc2-4.txt
OSh_frc5.txt
OSh_frc6.txt
OSh_frc7.txt

.
131

, -
. ,
, , -
, -
.

nWords=1

fileName="OSh_frc2-4.txt"
read()

fileName="OSh_frc5.txt"
read()

fileName="OSh_frc6.txt"
read()

fileName="OSh_frc7.txt"
read()

. ,
, .
. !


Palindrome.
132

: File2 read -
4 . -
,
. , -
,
. ,
, -
, -
.
, ,
. , -, ,
, , -, -
,
.

Sub
1
2
...
N
EndSub
133

Sub,
,
EndSub.

, -
.

,
.

( ), -
.

, ,

: ().
? -, -
, -
. -, -
, -
. -
, -
, ,
.

,
(),
, , -
.
:
! -
-
.

: -
(), .
, , .
134

, , -
, - . -
: -
(, -
, , ), -
(,
- ).

.
, -
, -
, -
.

,
, , - -
, .


, -
. , Sound
, Input . -

. ,
. -
, -
:
Sub prepareTextWindow
' :
TextWindow.Left= 200
TextWindow.Top= 200

TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(NAME_PROG)
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
TextWindow.Show()
EndSub
135


(. 11.1):
'const
NAME_PROG = " "

' :
prepareTextWindow()

. 11.1. !


NAME_PROG .

, .
, -
, -
, -
.
.

Sub.

, ,
( ): -
, . -
, OSH-W97.txt.

, ,
. ,
136

, ,
.
:
'

'variables
spisok[0][0]="" '-
nWords[0]=0 ' -
nAll=0 ' -

,
( ).

:
'================================================
nAll=0

For i= 2 to 30
nWords[i]=0
EndFor

,
.
fileName="OSH-W97.txt"
read()


:
fileNameOut="OSH-W97-frc.txt"
write()

,
.
'
Sub read
For i= 1 To 100000
word=file.ReadLine(fileName, nAll)
len = Text.GetLength(word)
137

If len = 0 Then
Goto exitSub
EndIf
nWords[len]= nWords[len]+1
nAll= nAll+1
spisok[len][nWords[len]]= word
TextWindow.WriteLine(n + " " + spisok[len][nWords[len]])
EndFor
exitSub:
EndSub

! ,

, 24 .

'
Sub write
For i= 2 To 30
For j= 1 To nWords[i]
File.AppendContents(fileNameOut, spisok[i][j])
TextWindow.WriteLine(i + " " + j+ " " + spisok[i][j])
EndFor
EndFor
EndSub

, -
, -
(, WordPad),
MS Word
(UTF-8). , ,
, .

,
, , -
!


Palindrome.
138

, -
. -
: , -
, .


, -
. , -
:
'

'variables
spisok[0]="" '-
nWords=0 '

txt="" '

chr1="" '
chr2="" '
index=0 '
beg=0 '
len=0 '

, :
'=========================================
'
'=========================================
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" ")
TextWindow.WriteLine("")
TextWindow.Show()

' 1:
fileName= "OSh_frc2-4.txt"
readFile()

' 2:
fileName= "OSh_frc5.txt"
readFile()
139

' 3:
fileName= "OSh_frc6.txt"
'readFile()

' 4:
fileName= "OSh_frc7.txt"
readFile()

:
, ! 6-
.
,
, .

readFile:
'
Sub readFile
txt= File.ReadContents(fileName)
index=1
beg=1
' , :
While (text.GetCharacterCode(text.GetSubText(txt,index,1))>
0)

' :
While text.GetCharacterCode(text.GetSubText(txt,index,1))>
32
index=index+1
EndWhile

' :
len= index-beg
' :
nWords= nWords+1
spisok[nWords]= text.GetSubText(txt,beg,len)
' :
index=index+2
beg=index
EndWhile
EndSub
140

, -
txt, ReadContents
File. ,
, .
.
, ,
. , -
16- . -
, -
(. 11.2).

. 11.2. 16-

,
,
, , .
,
!

, -
. 0D 0A, -
.
13 10, .

txt ,
:
spisok.
GetSubText Text:
spisok[nWords]= Text.GetSubText(txt,beg,len)

len txt, -
beg.
141

. -
, ,
:
beg=1

:
index=1

While
txt. 32 ( ,
):
While text.GetCharacterCode(text.GetSubText(txt,index,1))> 32
index=index+1
EndWhile

While , 13 -
, :
len= index-beg


txt:

index=index+2
beg=index

txt , -
While
While(text.GetCharacterCode(text.GetSubText(txt,index,1))> 0),

readFile -
, . -

, spisok . -
, , , !

-
. spisok
142

s ( -
; -
spisok[i]) .
- :
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
' :
for i=1 to nWords
s= spisok[i]
len= Text.GetLength(s)
for j= 1 to len / 2
chr1= Text.GetSubText(s,len-j+1,1)
chr2= Text.GetSubText(s, j, 1)
if chr1 <> chr2 then
goto break
EndIf
EndFor

'' :
TextWindow.WriteLine(s)

break:
EndFor

TextWindow.WriteLine("")
TextWindow.ForegroundColor="Red"

chr1 chr2, -
, -
. , , -
, !

, , , -
. , -

.
, -
, (. 11.3)!
143

. 11.3. - !


Palindrome.

Palindrome ,
.
144

12.

- ,
(, ) - . -
1666
.
,
.

,
. , -
, -
,
-
.

-
: , , , -
.

.
, ,
, - {, , }. ,
, .

, -
, :

1.

, , -
. .
,
:

2.

, - .
145

3.

( ,
, -: -, -),
. , -
:

4.

5.

, -
.

, -
:

6.

,
, ,
. ,
.

,
? .
.
,
. ,
3 2 1 = 6 .
, ,
(,
!).
146

, , -
, , -
4 3 2 1 = 24 .
,
( n), . -
:

n! (: -).

, -
:

n! = 1 2 . . . (n-1) n

, , -
n .


For, ,
27 ( -
).

:
'
'

'variables
number=0
fact= 0

:
start:
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" 0..27 > ")
number=TextWindow.ReadNumber()
147

'

' ,
' :
if (number < 0) then
goto exit
EndIf

if (number > 27) then


TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" 0 27!" )
goto start
EndIf

,
, -
(. 12.1). -
.
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Green"
'
' number:

fact = number
for i= number -1 to 2 step -1
fact = fact * i
EndFor
If number=0 Then
fact = 1
EndIf

' :
TextWindow.WriteLine(number+"! = " + fact)

exit:
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
Goto start

, :
, !
148

: ,
2 * 3 * number, :
number * (number-1) * 2. ,
,
.

, , .

. 12.1. !

Factorial.

. ,
, 3! -
, Factorial -
149

: ?
, -
, , ?

, , .

, -
. ,
:

.
.
.

, , , -
. ,
, 1963 17
8! =
40320 . , , -
- , , ,
,
-
.
,

.

. ,

1234

,
, . - -
-, -, - ,
, (. 12.2).
150

Fac-
torial, Permutation -
.

'
' 1..nElem

'var
nElem=0 '
nPerm=0 '
p[0]= 0 ' ,

-
. ,
.

'=========================================
'
'=========================================
start:
TextWindow.ForegroundColor="Yellow"
TextWindow.WriteLine("")
TextWindow.Write(" 1..8 > ")
nElem=TextWindow.ReadNumber()

' -->

' ,
' :
if (nElem <= 0) then
Program.End()
EndIf

if (nElem > 8) then


TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" 1 8!")
goto start
EndIf
151

1
.. nElem:

For i= 1 to nElem
p[i]= i
c[i]=1
pr[i]=1
endFor
nPerm=0
c[nElem]=0
' :
writePerm()
i= 1

'
'
Sub writePerm
nPerm= nPerm + 1
TextWindow.ForegroundColor="Green"
TextWindow.Write(nPerm + "> ")
For wp_i= 1 to nElem
TextWindow.Write(p[wp_i]+ " ")
endFor
TextWindow.WriteLine("")
endSub

, , -

TextWindow.Write(nPerm + "> ")

, -
. -
. , .

While (i < nElem)


i= 1
x= 0
While (c[i] = nElem - i + 1)
pr[i] = - pr[i]
c[i] = 1
152

If (pr[i]= 1) then
x= x +1
endIf
i= i +1
endWhile
If (i < nElem) Then
If (pr[i]= 1) then
k= c[i] + x
Else
k= nElem - i + 1 - c[i] + x
EndIf
tmp= p[k]
p[k]= p[k+1]
p[k+1] = tmp
' :
writePerm()
c[i]= c[i] + 1
EndIf
endWhile

(.
12.3):
Goto start

. 12.2. ! . 12.3.

1..8 - !

Permutation.
153

. ,

, 16 . , -
11 , 16
11.

, , -
, , -
. !

-
, -
. ,
. -
- -
, .
, 11 -
, (, ,
), .


-
Subset.

'
' k n=1..nElem

'var
nElem=0 '
k= 0 '
a[0]= 0 ' ,
nSubset=0 '

, -
, .
154

,
, .

'=========================================
'
'=========================================
start:
TextWindow.ForegroundColor="Yellow"
TextWindow.WriteLine("")
TextWindow.Write(" 1..30
> ")
nElem=TextWindow.ReadNumber()
' -->

' ,
' :
if (nElem <= 0) then
Program.End()
EndIf

if (nElem > 30) then


TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" 1 30!")
goto start
EndIf

TextWindow.Write(" 1.."
+ nElem + " > ")
k= TextWindow.ReadNumber()
if (k < 1) Or (k > nElem) then
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" 1 " + nElem +
"!")
goto start
EndIf

, -
:

For i= 1 to k
a[i]= i
endFor
155

nSubset=0
p= k

While (p >= 1)
' :
writeSubset()
if (k = nElem) then
Goto start
endIf
If (a[k]= nElem) then
p= p - 1
else
p= k
endIf

If (p >= 1) Then
For i= k to p step-1
a[i]= a[p] + i - p + 1
endFor
EndIf
endWhile

Goto start

-
:

'
'
Sub writeSubset
nSubset = nSubset + 1
TextWindow.ForegroundColor="Green"
TextWindow.Write(nSubset + "> ")
For wp_i= 1 to k
TextWindow.Write(a[wp_i]+ " ")
endFor
TextWindow.WriteLine("")
endSub
156

: 16 -
11 ,
4368 (. 12.4)!
,
, !

. 12.4. !

,
-
, !
:

n = nElem.
157

, !

Subset.

1.
, -
.

2. , ,
, .

3. ,
.

4. Factorial ,
2 .
158

13.
,

.


, , ,
( ),
, , 1202 .

, ,
,
, .

, ,
.
, ,
,
n.

, :
' ,
'

'variables
number=0
f= 0
f1= 0
f2= 0


, :
start:
TextWindow.ForegroundColor="Yellow"
number=TextWindow.ReadNumber()
159

, , :
' ,
' :
if (number < 0) then
goto exit
EndIf

if (number < 1) or (number> 40000000) then


TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" 1 40000000!")
goto start
EndIf

, :
f= 0
f1= 1
f2= 1

TextWindow.WriteLine("")
TextWindow.ForegroundColor="Green"
'
' , number:
TextWindow.WriteLine(0)
While f2 <= number
TextWindow.WriteLine(f2)
f2 = f1+f
f = f1
f1 = f2
EndWhile

exit:
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
Goto start

:
f= 0
f1= 1
f2= 1
160

, , -
:
TextWindow.WriteLine(0)

1,
, - 0 + 1 = 1, - 1 + 1= 2,
- 1 + 2 = 3 , :
f2 = f1+f
f = f1
f1 = f2

f, f
. f1 f2, -
-
, .
!

While ,
. -
(. 13.1), ,
.

. 13.1.

Fibonacci.
161


(
) ( ).
( , ,
, !).

()


- number1 number2:
'
' ()

'variables
number1=0
number2=0
NOD=0

'=========================================
'
'=========================================
start:
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" > ")
number1 = TextWindow.ReadNumber()
' ,
' :
if (number1 < 0) then
Program.End()
EndIf

TextWindow.Write(" > ")


number2 = TextWindow.ReadNumber()

, -
, -
, , -
, :

' ,
162

' :
if number1 < number2 then
n= number1
number1=number2
number2=n
EndIf

( ) , , -
, :

if number2=0 then
NOD = number1
else
speed_euklid()
EndIf

,
:

Sub speed_euklid
while number2 > 0
n = Math.Remainder(number1, number2)
number1 = number2
number2 = n
EndWhile
NOD = number1
EndSub

While -
, -
, - . -
, .
,
.

(.
13.2):
163

TextWindow.WriteLine("")
TextWindow.ForegroundColor="Green"
' :
TextWindow.WriteLine(" = " + NOD)

exit:
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
Goto start

. 13.2.


number1 = 42
number2 = 14
, -
:
n = Math.Remainder(42, 14) = 0
:
number1 = 14
164

number2 = 0
, ,
, 14.
:
number1 = 56
number2 = 42
n = Math.Remainder(56, 42) = 14
number1 = 42
number2 = 14
.
, -
(. 13.3)!

. 13.3. !

NOD.
165


,
(. 13.4).

. 13.4.

, (.
13.5).

. 13.5. smallbasic.com

() ,
! , -
-
. ,
.
, -
,
, Internet Explo-
rer (. 13.6).
166

:
smallbasic.com/program/?pgf620

,
.

,
Silverlight. -
.
, ,
smallbasic.com.

. 13.6.
167

,
. ,

, smallbasic.com.
, Embed this in your website
, -
( , ),
.

-
(, , , , ),
,
!

()

,
:

= 1 * 2 / (1, 2)


calcNOD:
' -
'number1 number2
' NOD
Sub calcNOD
' ,
' :
if n1 < n2 then
n= n1
n1=n2
n2=n
EndIf

if n2=0 then
NOD = n1
168

else
while n2 > 0
n = Math.Remainder(n1, n2)
n1 = n2
n2 = n
EndWhile
NOD = n1
EndIf
EndSub

,
, number1 number2
, .
NOD!
:
'
' ()

'variables
number1=0
number2=0
NOD=0
NOK=0


(. 13.7):
'=========================================
'
'=========================================
start:
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" > ")
number1 = TextWindow.ReadNumber()
' ,
' :
if (number1 < 0) then
Program.End()
EndIf

TextWindow.Write(" > ")


number2 = TextWindow.ReadNumber()
169

if number1 * number2=0 then


NOK = 0
Else
'
' calcNOD:
n1= number1
n2= number2
' NOD:
calcNOD()
NOK= number1 * number2 / NOD
EndIf

TextWindow.WriteLine("")
TextWindow.ForegroundColor="Green"
' :
TextWindow.WriteLine("K = " + NOD)

exit:
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
Goto start

. 13.7.

NOK.
170

14.

Windows -
,
-
.
- -
,
GraphicsWindow.

GraphicsWindow ( )

-
(. 14.1).
-
. , :
GraphicsWindow.Show()
Program.Delay(10000)
GraphicsWindow.Hide()

. 14.1. !
171

Show -
, Hide (
). -
, :
For i= 1 To 10
GraphicsWindow.Show()
Program.Delay(1000)
GraphicsWindow.Hide()
Program.Delay(1000)
EndFor

, Windows,
4 (. 14.2).

. 14.2.

: -
, , , , .

SmallBasic Graphics Window,


, Title
(. 14.3):
GraphicsWindow.Title=" "

. 14.3. - !
172

, , , -
, :
s = GraphicsWindow.Title

, -
, ,
:

time=0
Timer.Interval = 1000
Timer.Tick = OnTimer

Sub OnTimer
time= time+1
GraphicsWindow.Title= time
EndSub


, , .
, -
, -
.
,
CanResize :
GraphicsWindow.CanResize=0

"False":

GraphicsWindow.CanResize= "False"

- ,
(. 14.4).

,
:
GraphicsWindow.CanResize= "True"
173

. 14.4. !

CanResize , ,
,
.

. ,
640 480 -
. -
!

.

GraphicsWindow.Width=400
GraphicsWindow.Height=200,

(. 14.5).

. 14.5. !
174

(. 14.6).
GraphicsWindow.Width=0
GraphicsWindow.Height=0

. 14.6. !


(. 14.7), :
GraphicsWindow.Left=400
GraphicsWindow.Top =400


6.

. 14.7. !
175

""
Width Height -
. -
.
(Timer). Interval 200-400
:
Timer.Interval = 200
Timer.Tick = OnTimer

, 0,2-0,4
OnTimer:
rele=1
Sub OnTimer
if rele=1 then
GraphicsWindow.Left= GraphicsWindow.Left+ 5
GraphicsWindow.Top= GraphicsWindow.Top+ 5
else
GraphicsWindow.Left= GraphicsWindow.Left- 5
GraphicsWindow.Top= GraphicsWindow.Top- 5
EndIf

' :
rele= -rele
EndSub

rele
-, . -
, -
.

, -
!


GraphicsWindow.
176

, -
. -
, :

-
Windows , .

-
Title .

- () -
, -
( ) .
, .

- () -
( ,
),
, -
.

-
.

,
. -
.

-
. ,
,
.

.
177


,
, .
,
. BackgroundColor
(. 14.8):
GraphicsWindow.BackgroundColor="Green"

. 14.8. !

- -
.
, -
:
'
rele=1
Sub OnTimer
GraphicsWindow.BackgroundColor=
GraphicsWindow.GetRandomColor()
if rele=1 then
GraphicsWindow.Show()
else
GraphicsWindow.Hide()
178

EndIf
rele=-rele

EndSub

, -
.


GetRandomColor, .
,
.

, -
, :
Timer.Interval = 10
Timer.Tick = OnTimer

'
rele=1
n=1
Sub OnTimer
if n= 100 Then
rele=-rele
n=0
GraphicsWindow.BackgroundColor=
GraphicsWindow.GetRandomColor()
else
n=n+1
EndIf

GraphicsWindow.Width=GraphicsWindow.Width + rele
GraphicsWindow.Height = GraphicsWindow.Height + rele
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width)
/ 2
GraphicsWindow.Top = (Desktop.Height -
GraphicsWindow.Height) / 2

EndSub
179


GetColorFromRGB,
( - Red, - Green - - Blue) ,
:
'
Sub OnTimer
red= Math.GetRandomNumber(256)-1
green= Math.GetRandomNumber(256)-1
blue= Math.GetRandomNumber(256)-1

GraphicsWindow.BackgroundColor=GraphicsWindow.GetColorFromRG
B(red, green, blue)

EndSub


GraphicsWindow.

LastKey -
(. 14.9):
While "True"
GraphicsWindow.Title= GraphicsWindow.LastKey
EndWhile

. 14.9. , ?


, .
180

15.
,
.
, .

,
. FontName
(. 15.1):
GraphicsWindow.FontName="Arial"

, -
!
, (.
15.2).

. 15.1. Arbat . 15.2. Arbat

(.
15.3).

, :
GraphicsWindow.BackgroundColor="Black"
GraphicsWindow.FontName="Arial"

For i= 0 To 6
GraphicsWindow.FontSize= 12+ i*2
181

GraphicsWindow.BrushColor= GraphicsWindow.GetRandomColor()
GraphicsWindow.DrawText(10,10+i*30, "Text Text")
EndFor

. 15.3. Arial Courier New Times New Roman

, FontSize,
BrushColor. -
DrawText(x,y,).

,
.

, -
.
()
.

. -
,
FontBold (. 15.4) :
GraphicsWindow.FontBold= "False"

,
:
GraphicsWindow.FontBold= "True"
182

. 15.4. Arial

(.
15.5):
GraphicsWindow.FontItalic= "True"

. 15.5.

:
GraphicsWindow.FontItalic= "False"


DrawBoundText(x,y, width, ), -
DrawText , -
183

width, -
.

, -
:

GraphicsWindow.FontSize= 24
GraphicsWindow.BrushColor= "Yellow"
GraphicsWindow.FontBold= "False"
GraphicsWindow.BrushColor= GraphicsWindow.GetRandomColor()
GraphicsWindow.DrawBoundText(10,10+i*30, 150,
"12345678901234567890")

,
, ,
(. 15.6).

. 15.6. !

(. 15.7):

GraphicsWindow.DrawBoundText(10,10+i*30,350,
"12345678901234567890")

. 15.7. !


.
184

Windows
, .
. ,
- , Windows
WM_KEYDOWN.
, KeyDown.
, -

:

GraphicsWindow.KeyDown= OnKeyDown

Sub OnKeyDown
GraphicsWindow.ShowMessage(" ", "")
EndSub

, , -
(. 15.8).

. 15.8. !

, ,
LastKey (. 15.9).
185

. 15.9. !

KeyUp,
(. 15.10):
GraphicsWindow.KeyUp= OnKeyUp

Sub OnKeyUp
GraphicsWindow.ShowMessage(" " +
GraphicsWindow.LastKey, " ")
EndSub

. 15.10. !


ShowMessage(, ), -
, -
, , .
186

,
, .

, -
, -
:
' """

GraphicsWindow.Width=490
GraphicsWindow.Height=60
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.Title= " !"
GraphicsWindow.BackgroundColor="Black"
GraphicsWindow.FontSize= 24

GraphicsWindow.KeyDown= OnKeyDown
'GraphicsWindow.KeyUp= OnKeyUp

Sub OnKeyDown
GraphicsWindow.Clear()
GraphicsWindow.BrushColor= "Red"
GraphicsWindow.DrawText(10,10," ,
!")
EndSub

Sub OnKeyUp
GraphicsWindow.Clear()
GraphicsWindow.BrushColor= "Green"
GraphicsWindow.DrawText(10,10," ,
!")
EndSub

,
(. 15.11).
187

. 15.11. , , ?!

, -
(. 15.12).

. 15.12. !


, , !

Clear,
,
BackgroundColor.

, , -
!

,
, ,
.
: , !
188


, , -
.

.

.
.
GraphicsWindow.Width=300
GraphicsWindow.Height=60
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.Title= " !"
GraphicsWindow.BackgroundColor="White"
GraphicsWindow.FontSize= 32

GraphicsWindow.MouseDown= OnMouseDown
GraphicsWindow.MouseUp= OnMouseUp

Sub OnMouseDown
GraphicsWindow.Title= " !"
GraphicsWindow.Clear()
GraphicsWindow.BrushColor= "Blue"
GraphicsWindow.DrawText(10,10," !")
EndSub

Sub OnMouseUp
GraphicsWindow.Title= " !"
GraphicsWindow.Clear()
GraphicsWindow.BrushColor= "Green"
GraphicsWindow.DrawText(10,10," !")
EndSub

, , -
-
(. 15.13).
189

. 15.13. !


(. 15.14).

. 15.14. , !

, .
,
, .
.

. -
: ,
(. 15.15).
GraphicsWindow.Title=" "

GraphicsWindow.Width=420
GraphicsWindow.Height=60
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
190

GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)


/ 2
GraphicsWindow.FontSize= 32
GraphicsWindow.BrushColor= "Blue"
GraphicsWindow.CanResize="False"

GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /


2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2

GraphicsWindow.BackgroundColor="Black"
GraphicsWindow.DrawText(10,10," !")

Timer.Interval = 10
Timer.Tick = OnTimer

Sub OnTimer
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width)
/ 2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
EndSub

. 15.15.

. 10 -
, - OnTimer
.

,
, , -
.
191

,
TextInput, LastText , -
, - , , .. -
-
(. 15.16),
- .

. 15.16. , !

s=""
GraphicsWindow.FontSize= 24
GraphicsWindow.BrushColor= "Yellow"
GraphicsWindow.FontBold= "False"
GraphicsWindow.TextInput =OnText

Sub OnText
GraphicsWindow.Clear()
s= s+GraphicsWindow.LastText
GraphicsWindow.DrawText(10,10, s)
EndSub

-
, ,
. -
, ,
,
.


.
192

16. Math


:


+
-
*
/

, , ,
, :
,
(
). , -
, .

-
: 2 -2; x -x.

a=6
b=3

Num
Num = a + b 9
Num = a - b 3
Num = a * b 18
Num = a / b 2


, . -
, -
193

.
( !) -
:


Num
Num = (2 + 4 - 1) / 5 * 11 11
Num = (3.1415 1.0) / 7.78 * (45 - 7) 10,459768637532133676092544987

Num = -2.67 * 3.14 + -3/2 7.01 -16,8938


Num = 3 * 4 + 5 6/2 14

-
, {} .


, -
.


Math, Pi, -
, , .
, -
.

Math,
.

,
,
Math .
,
.
194

Pi 3,14159265358979
Abs()
ArcCos() , -

ArcSin() , -

ArcTan() , -

Ceiling()
.
Cos() , -

Floor()
.
GetDegrees() , ,

GetRadians() , ,

1 -
GetRandomNumber( , . -
GetRandomNumber(30)
)
1, 2, 3, , 30
Log() -

Max(1, 2)
Min(1, 2)
NaturalLog() -

Power(, )

Remainder(1, 2)

Round()
.
Sin() , -

SquareRoot()
Tan() , -

195

GraphicsWindow.Title=" Math"

'const
ps= Text.GetCharacter(13) + Text.GetCharacter(10)
BackgroundColor="#2F4F4F"

GraphicsWindow.Width= 300
GraphicsWindow.Height=400
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"
GraphicsWindow.BackgroundColor= BackgroundColor

txtMath=Controls.AddMultiLineTextBox(10,10)
Controls.SetSize(txtMath, GraphicsWindow.Width-20,
GraphicsWindow.Height-20)


. , ,
, . -
: ,
? :
.
, :

ps= Text.GetCharacter(13) + Text.GetCharacter(10)

-
:

s= " = " + Math.Pi + ps


s= s + "Abs(-2) = " + Math.Abs(-2) + ps
s= s + "ArcCos(0.5) = " + Math.ArcCos(0.5) + ps
s= s + "ArcSin(0.5) = " + Math.ArcSin(0.5) + ps
s= s + "ArcTan(0.5) = " + Math.ArcTan(0.5) + ps
s= s + "Ceiling(0.5) = " + Math.Ceiling(0.5) + ps
s= s + "Ceiling(1) = " + Math.Ceiling(1) + ps
s= s + "Cos(0.5) = " + Math.Cos(0.5) + ps
s= s + "Floor(0.5) = " + Math.Floor(0.5) + ps
s= s + "Floor(1) = " + Math.Floor(1) + ps
196

s= s + "GetDegrees(0.5) = " + Math.GetDegrees(0.5) + ps


s= s + "GetRadians(30) = " + Math.GetRadians(30) + ps
s= s + "GetRandomNumber(30) = " + Math.GetRandomNumber(30) +
ps
s= s + "Log(100) = " + Math.Log(100) + ps
s= s + "NaturalLog(100) = " + Math.NaturalLog(100) + ps
s= s + "Max(-1, -2) = " + Math.Max(-1, -2) + ps
s= s + "Min(-1, -2) = " + Math.Min(-1, -2) + ps
s= s + "Power(2, 32) = " + Math.Power(2, 32) + ps
s= s + "Remainder(15, 4) = " + Math.Remainder(15, 4) + ps
s= s + "Round(0.5) = " + Math.Round(0.5) + ps
s= s + "Round(1.6) = " + Math.Round(1.6) + ps
s= s + "Sin(0.5) = " + Math.Sin(0.5) + ps
s= s + "SquareRoot(2) = " + Math.SquareRoot(2) + ps
s= s + "Tan(0.5) = " + Math.Tan(0.5) + ps

(. 16.1):
Controls.SetTextBoxText(txtMath, s)

. 16.1. Math !
197

Math ,
. , , -
, Math.Sin(Math.GetRadians(30)) 0,5.
, , -
:
sinus= Math.Sin(Math.GetRadians(30))

sinus
0,5.
,
- -
:
if (Math.Sin(Math.GetRadians(30)) = 0.5) Then
. . . . .
EndIf

:
sinus= Math.Sin(Math.GetRadians(30))

if (sinus = 0.5) Then


. . . . .
EndIf


. , ,

, .


Math.

Math,
( -
, -
).
198


1706 ..
periferia (-
, , -
), . -
1736 -
.

,
,
.

, (16/9)2,
3,1604938, = 3,16227766 -
, ,
3 1/7, , 3 10/71 = 3,1428 3,1408.
3,14185,
. , -
-
- 3,1415927... -
-,
16 . 1615
-
32 . 1873 -
20 707 , 1944
. ,
527 .
. :

1706 100
.
199

.
1949 70
. -
3000 13
. 1959 -
,
. ,
.

1655 , -
. -
. , -
, -
. , , -
. , :

GraphicsWindow.Title=" "

'const
ps= Text.GetCharacter(13) + Text.GetCharacter(10)
BackgroundColor="#2F4F4F"

GraphicsWindow.Width= 640
GraphicsWindow.Height=480
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"
GraphicsWindow.BackgroundColor= BackgroundColor

txtMath=Controls.AddMultiLineTextBox(10,10)
200

Controls.SetSize(txtMath, GraphicsWindow.Width-20,
GraphicsWindow.Height-20)
' :
pi=1
For n= 1 To 1000000
pi= pi * (4*n*n/(2*n-1)/(2*n+1))
EndFor

s= " = " + 2* pi + ps
Controls.SetTextBoxText(txtMath, s)

= 3,1415918681921207145964766354

! .

-
, -
. :

, :
' :
pi=0
For n= 0 To 1000001
pi= pi + Math.Power(-1, n) / (2*n+1)
EndFor

s= " = " + 4* pi + ps
Controls.SetTextBoxText(txtMath, s)

= 3,1415916535917932347126500740
201

, !

,
.

-
.
202

17.
,
.

, -
, ,

.

, .
, -
.

,
, !
, !
, ,
...
:
- ?

. ,
, . -
, . , -
, - ,
. -
. :
, -
.

SetPixel(x, y, color) -
( -
203

) .
, , -
, .


: Y () , , ,
Y, . -
X -
, -
, , (.
17.1).

. 17.1.

, -
(Microsoft Paint Image Editor, , -
), ,
,
,
.
,
SetPixel.
204

, -
(. 17.2).

. 17.2. -!

Pixel.

-
, .
, !

GraphicsWindow.Title=" "

GraphicsWindow.Width= 320
GraphicsWindow.Height=240
GraphicsWindow.Left= (Desktop.Width-GraphicsWindow.Width)/ 2
GraphicsWindow.Top = (Desktop.Height-GraphicsWindow.Height)/ 2
GraphicsWindow.CanResize="False"
GraphicsWindow.BackgroundColor="Black"

While -
SetPixel:

'
height=GraphicsWindow.Height
width=GraphicsWindow.Width
While "True"
205

for y=0 to height-1


for x=0 to width-1
' :
clr= GraphicsWindow.GetRandomColor()
' :
GraphicsWindow.SetPixel(x,y,clr)
EndFor
EndFor
EndWhile

, -
: -
(. 17.3).

. . .
GraphicsWindow.FontSize= 56
GraphicsWindow.BrushColor = "Red"
. . .
GraphicsWindow.SetPixel(x,y,clr)
GraphicsWindow.DrawText(40,height/2-40,"")

. 17.3.

Pixel.
206

-
, (-
) . ,
, -
GetPixel(x,y).

, -
. -
(. 17.4)

. 17.4.

GraphicsWindow.Title=" "

GraphicsWindow.Width= 320
GraphicsWindow.Height=240
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"
207

, -

.

' :
height=GraphicsWindow.Height
width= GraphicsWindow.Width
for y=0 to height-1
for x=0 to width-1
' :
clr= GraphicsWindow.GetRandomColor()
' :
GraphicsWindow.SetPixel(x,y,clr)
EndFor
EndFor

( ,
)
MouseX MouseY .

' :
While "True"
x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY
clr=GraphicsWindow.GetPixel(x,y)
GraphicsWindow.Title=" (" + x + "," + y + ") =
" + clr
EndWhile

(
) 16-
(. 17.5).

, ,
, -
, (.
17.6).
208

. 17.5. !

While "True"
x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY
clr=GraphicsWindow.GetPixel(x,y)
':
GraphicsWindow.BrushColor=clr
GraphicsWindow.FillRectangle(GraphicsWindow.Width-32-6, 20,
32,32)
GraphicsWindow.Title=" (" + x + "," + y + ") =
" + clr
EndWhile

. 17.6. !
209

- ,
. , :

GraphicsWindow.BrushColor= #46f9fe

, -
, . -
, -
,
, , -
(. 17.7).

,
.

GraphicsWindow.Title=" "

GraphicsWindow.Width= 640
GraphicsWindow.Height=480
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width= GraphicsWindow.Width
210

. 17.7. -!

' "":
radius=10
for i= 1 to 10000
' "":
x = Math.GetRandomNumber(width-radius)
y = Math.GetRandomNumber(height-radius)
' "":
clr= GraphicsWindow.GetRandomColor()
GraphicsWindow.BrushColor=clr
GraphicsWindow.Title=" (" + x + "," + y + ") = "
+ clr
' "":
GraphicsWindow.FillEllipse(x, y, 2*radius,2*radius)
EndFor

, , ,
( - ). -
FillEllipse(x, y, width, height). -
-
, (. 17.8).
BrushColor.
211

. 17.8.


DrawEllipse(x, y, width, height). ,
, ,
.
PenColor. :
' "":
'GraphicsWindow.FillEllipse(x, y, 2*radius,2*radius)
GraphicsWindow.PenColor=clr
GraphicsWindow.DrawEllipse(x, y, 2*radius,2*radius)

- (.
17.9).
,
(.
17.10). .

GetRandomNumber:
height=GraphicsWindow.Height
width= GraphicsWindow.Width
for i= 1 to 10000
radius= Math.GetRandomNumber(10)+4
' "":
x = Math.GetRandomNumber(width-radius)
y = Math.GetRandomNumber(height-radius)
212

' "":
clr= GraphicsWindow.GetRandomColor()
GraphicsWindow.BrushColor=clr
GraphicsWindow.Title=" (" + x + "," + y + ") = " +
clr
' "":
GraphicsWindow.FillEllipse(x, y, 2*radius,2*radius)
EndFor

. 17.9.

. 17.10. , !

.
213

, , -
, . -
, , -

. , Pointilize (. 17.11),
.
,
, ( -
) (. 17.12).


, ,
, -
.

. 17.11. Pointilize
214

- -
, ,
. -
, , .

. 17.12. .

,
.

r, -

. -
. -
215

.
,
(. 17.13).

'

'var
' :
r=5

GraphicsWindow.Title=""

GraphicsWindow.Width= 800-10
GraphicsWindow.Height=533-10
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width= GraphicsWindow.Width

background = ImageList.LoadImage(Program.Directory +
"/.jpg")
GraphicsWindow.DrawImage(background, 0, 0)

' :
'Filter()
Filter2()

' :
While "True"
x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY
clr=GraphicsWindow.GetPixel(x,y)
':
GraphicsWindow.BrushColor=clr
GraphicsWindow.FillRectangle(GraphicsWindow.Width-32-6, 20,
32,32)
GraphicsWindow.Title=" (" + x + "," + y + ") =
" + clr
EndWhile
216

. 17.13.

,
, , - -
. , , -
, , -
, .
. -
l
For .
,
(. 17.14).
'
Sub Filter
l= 2*r
For j= 1 To height/l
For i= 1 To width/l
' :
xc = (i-1)*l + r
yc = (j-1)*l + r
217

clr=GraphicsWindow.GetPixel(xc,yc)
GraphicsWindow.BrushColor=clr
' :
GraphicsWindow.FillRectangle(xc-r, yc-r, l, l)
EndFor
EndFor
EndSub

. 17.14.

, -
.
. ,
,
,
.

.
,
.
218

,
.
!

, - :

Sub Filter2
l= 2*r
For j= 1 To height/l
For i= 1 To width/l
' :
xc = (i-1)*l + r
yc = (j-1)*l + r
clr=GraphicsWindow.GetPixel(xc,yc)
' :
GraphicsWindow.BrushColor= "Black"
'GraphicsWindow.BrushColor= "White"
GraphicsWindow.FillRectangle(xc-r, yc-r, l, l)
' :
GraphicsWindow.BrushColor=clr
GraphicsWindow.FillEllipse(xc-r, yc-r, l, l)
EndFor
EndFor
EndSub

( -
), -
(. 17.15). -
-
!

.
219

. 17.15.

1.
. -
, -
. -
, .

2.
(. 17.16):

' :
Filter()
drawGrid()

'
Sub drawGrid
l= 2*r
GraphicsWindow.PenColor="Black"
220

GraphicsWindow.PenWidth=1
' :
For j= 0 To height/l
GraphicsWindow.DrawLine(0, j*l, width, j*l)
EndFor
' :
For i= 0 To width/l
GraphicsWindow.DrawLine(i*l, 0, i*l, height)
EndFor
EndSub

. 17.16. !
221

18.
,-

,
, .
, .
, -
, , - -
R Z.

-.
- .

, ,
. ,
OL Z,
. -
,
Z R,
.
(. 18.1).


OL
,

R
Z

. 18.1.
222


, -
, -
.
,
(. 18.2).

. 18.2.

.
x y
OPx,
:

x = R * cos(Z) (1)
y = R * sin(Z) (2)

: -
, ?
, -
, .

, :
223

R = 1
R = r r

x2 + y2 2x = 0
x2 + y2 2rx = 0

- , , , , -
.
,
, .

Polar .

(. 18.3) -
. , res -
, :

'
'

'var
res="False" ' ="False",

R=0 '
Z=0 '

GraphicsWindow.Title=" "

GraphicsWindow.Width= 320
GraphicsWindow.Height=320
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width=GraphicsWindow.Width
224

' :
CX= width/2
CY= height/2

' :
GraphicsWindow.PenColor= "Black"
GraphicsWindow.PenWidth=1

, Z
360 ( 0 ... 2*Math.Pi).
-
,
.

(Step 0.01) ,
.
, -
,
.
. ,
.

,
, , ,
. , -
calc3.
, calc3, , -
calc1 calc5.

For
calc5 .

'
'For i=0 to 7
for Z =0 to 2*Math.Pi+0.01 Step 0.01
calc3()
If (res="False") Then
Goto nextZ
EndIf

' :
225

If (Z=0) Then
x1=x
y1=y
EndIf

' ""
GraphicsWindow.DrawLine(x,y,x1,y1)
nextZ:
'TextWindow.WriteLine("x= " + x + " y= " + y)
x1=x
y1=y
EndFor
'endFor

res
"False", , -
. x y
, -
() (1)
(2), .

-
.
, ,
.
, -
, .

, R= sin(2*Z) ( 18.3)
, R= sin(12*Z) ( 18.3) .
R= sin(k*Z) -
k, .


, !

'
Sub calc1
' :
R= 150
res="True"
226

x= CX + Math.Cos(z)*R
If (x<0) Or (x> width) Then
res="False"
Goto exit1
EndIf
y= CY + Math.Sin(z)*R
If (y<0) Or (y> height) Then
res="False"
Goto exit1
EndIf
exit1:
EndSub

' ,
Sub calc2
k=12
res="True"
R= Math.Sin(k*Z)*160
x= CX + Math.Cos(z)*R
If (x<0) Or (x> width) Then
res="False"
Goto exit2
EndIf
y= CY + Math.Sin(z)*R
If (y<0) Or (y> height) Then
res="False"
Goto exit2
EndIf
exit2:
EndSub

'
Sub calc3
k=2
l=2
res="True"
R= (1+l*Math.Cos(k*Z))* 50'80'100
x= CX + Math.Cos(z)*R '- width/4
If (x<0) Or (x> width) Then
res="False"
Goto exit3
EndIf
y= CY + Math.Sin(z)*R
If (y<0) Or (y> height) Then
227

res="False"
Goto exit3
EndIf
exit3:
EndSub

'
Sub calc4
k=5
res="True"
R= Z/k* 100
x= CX + Math.Cos(z)*R
If (x<0) Or (x> width) Then
res="False"
Goto exit4
EndIf
y= CY + Math.Sin(z)*R
If (y<0) Or (y> height) Then
res="False"
Goto exit4
EndIf
exit4:
EndSub

'
Sub calc5
k=5
res="True"
F= Z + i*Math.Pi*2
R= 60/(2+ Math.Cos(F*k + ((Math.Floor(0.1*F)/5 -
Math.Floor(Math.Floor(0.1*F)/5)))))*2.5
x= CX + Math.Cos(F)*R
If (x<0) Or (x> width) Then
res="False"
Goto exit5
EndIf
y= CY + Math.Sin(F)*R
If (y<0) Or (y> height) Then
res="False"
Goto exit5
EndIf
exit5:
EndSub
228

) R = 1 - ) R= sin(2*Z) -

) R= sin(12*Z) - ) R= 1 + cos(Z) -

) R= 1 + 2*cos(Z) ) R= 1 + 2*cos(2*Z)
229

) R= Z/k )

. 18.3.

Polar.

1. .

2. -
, . , , -

.

3. -

.
x y -
,
.
230

19.

, -
, ,
,
.
, !

1D sine. -

( , ,
). -
:

clr = 255*(1+ Math.Sin(y/wl))/2 (1)

, -
.
wl, ,
.
255 (1). , -
0..2,
0..1.
0 255,
. -
. , -

GraphicsWindow.Title=" (" + x + "," + y + ") = "


+ clr

:
GraphicsWindow.Title=" "
GraphicsWindow.Width= 320
GraphicsWindow.Height=240
231

GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /


2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width=GraphicsWindow.Width
' :
wl= 10
for y=0 to height-1
' :
clr = 255*(1+ Math.Sin(y/wl))/2
clr=GraphicsWindow.GetColorFromRGB(clr,clr, clr)
GraphicsWindow.Title=" (" + x + "," + y + ") =
" + clr
for x=0 to width-1
' :
GraphicsWindow.SetPixel(x,y,clr)
EndFor
EndFor

, - (. 19.1).

. 19.1.

,
GetColorFromRGB (. 19.2 19.3).
232

. 19.2. GetColorFromRGB(clr,0,0) . 19.3. GetColorFromRGB(0,0,clr)

1D sine.

-
:
' :
wX= 20
' :
wY= 20

clr = 255*(1+Math.Sin(x/wX) * Math.Sin(y/wY))/2

-
:

for y=0 to height-1


233

for x=0 to width-1


' :
clr = 255*(1+Math.Sin(x/wX) * Math.Sin(y/wY))/2
clr=GraphicsWindow.GetColorFromRGB(0,clr,100)
GraphicsWindow.Title=" (" + x + "," + y + ")
= " + clr
' :
GraphicsWindow.SetPixel(x,y,clr)
EndFor
EndFor

(. 19.4).

. 19.4.

2D sine.


,
:
' :
clr = 255*(1+ Math.Abs(Math.Sin(x/wX)) *
Math.Abs(Math.Sin(y/wY)))/2
234

, ,
,
(. 19.5).

. 19.5.

Abs sine.


, ,
;
.

, , ,
, , ,
- -
. ,
,
:

rad = Math.SquareRoot((x-CX)*(x-CX) + (y-CY) * (y-CY)) / wl


235

clr = 255*(1+Math.Sin(rad))/2

-
:

GraphicsWindow.Title=" "

GraphicsWindow.Width= 320
GraphicsWindow.Height=320
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"
height=GraphicsWindow.Height
width=GraphicsWindow.Width

' :
CX= width/2
CY= height/2
' :
wl= 6
for y=0 to height-1
for x=0 to width-1
:
rad = Math.SquareRoot((x-CX)*(x-CX) + (y-CY) * (y-CY)) /
wl
clr = 255*(1+Math.Sin(rad))/2
clr=GraphicsWindow.GetColorFromRGB(0, 0, clr)
GraphicsWindow.Title=" (" + x + "," + y + ")
= " + clr
' :
GraphicsWindow.SetPixel(x,y,clr)
EndFor
EndFor

(. 19.6)!
236

. 19.6. !

Polar sine.

,
,
(. 19.7).
GraphicsWindow.Title=""

. . .

' :
wl= 60
for y=0 to height-1
for x=0 to width-1
' :
clr = 255*2*(Math.Abs(math.Remainder(x, wl) -wl/2) +
Math.Abs(math.Remainder(y, wl) -wl/2))/wl
clr=GraphicsWindow.GetColorFromRGB(clr,0,clr)
' :
GraphicsWindow.SetPixel(x,y,clr)
EndFor
EndFor
237

. 19.7.


(. 19.8) , -
( ).

9 , -
, :

GraphicsWindow.Title=" "

. . .

' :
wX= 10
wY= 10
For i= 1 To 9
238

a[i]= Math.GetRandomNumber(2)
EndFor

,
.
!

, . -
, -
?

,
:

for y=0 to height-1


for x=0 to width-1
' :
clr = 256*(1 + (a[4]*Math.Sin(a[0]*Math.Sin(a[6] * x/wX) +
a[1]*Math.Cos(a[7] * y/wY)) +
a[5]*Math.Cos(a[2]*Math.Cos(a[8]* x/wX) + a[3]*Math.Sin(a[9]*
y/wY)))) /2
clr=GraphicsWindow.GetColorFromRGB(0,0,clr)
' :
GraphicsWindow.SetPixel(x,y,clr)
EndFor
EndFor
239

. 19.8.
, !

Sine the
pooh.

,
, , -
(. 19.9):

GraphicsWindow.Title=" "
. . .
For i = 1 to 6
a[i] = Math.Pi * (1-2*Math.GetRandomNumber(1000)/1000)
Endfor

While ("True")
x = math.Sin (a[1]*a[6]) - math.Cos (a[2]*a[5])
y = math.Sin (a[3]*a[5]) - math.Cos (a[4]*a[6])
clr= GraphicsWindow.GetColorFromRGB(128*(x+y),
128*(x+y),255)
GraphicsWindow.SetPixel(CX+x*100, CY+y*100,clr)
240

a[5] = x
a[6] = y
EndWhile

. 19.9.

-
.
241

20.
, ,
.
,
.

, , -
.
, .

GraphicsWindow

GraphicsWindow.DrawLine( x1, y1, x2, y2 )

(x1, y1) , (x2,


y2) , ,
(. 20.1).

. 20.1.

PenWidth,
PenColor GraphicsWindow.
242

,
,
Pixel .

,
.
:

'
'

'var
' :
penWidth= 20

GraphicsWindow.Title=" "

GraphicsWindow.Width= 480
GraphicsWindow.Height=320
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"
GraphicsWindow.BackgroundColor="Black"
height=GraphicsWindow.Height
width=GraphicsWindow.Width

, ,
,
DrawLine
:

GraphicsWindow.PenWidth = penWidth

'
While "True"
' -->
' :
x1= Math.GetRandomNumber(width - penWidth / 2 - 1)
y1= Math.GetRandomNumber(height - penWidth / 2 - 1)
' :
243

x2= Math.GetRandomNumber(width - penWidth / 2 - 1)


y2= Math.GetRandomNumber(height - penWidth / 2 - 1)
' :
clr= GraphicsWindow.GetRandomColor()
GraphicsWindow.PenColor= clr
' :
GraphicsWindow.DrawLine(x1, y1, x2, y2)
Program.Delay(30)
EndWhile

:
, (. 20.2). ,
20 (. 20.3):

penWidth= 20

,
.

. 20.2.


.
244

. 20.3.

,
.
.
, -
(. 20.4).
' " "

GraphicsWindow.Title=" "

GraphicsWindow.Width= 640
GraphicsWindow.Height=480
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width= GraphicsWindow.Width
' :
ratio= height / width
245

GraphicsWindow.PenWidth=1
GraphicsWindow.BackgroundColor="Black"
for x= 0 to width Step 10
GraphicsWindow.PenColor= "Red"
GraphicsWindow.DrawLine(0, x*ratio, width-x, 0)
GraphicsWindow.PenColor= "Yellow"
GraphicsWindow.DrawLine(0, (width-x)*ratio, width-x,
width*ratio)
GraphicsWindow.PenColor= "Blue"
GraphicsWindow.DrawLine(width-x, 0*ratio, width, (width-
x)*ratio)
GraphicsWindow.PenColor= "Green"
GraphicsWindow.DrawLine(width-x, width*ratio, width,
x*ratio)
EndFor

. 20.4.
246

,
-
PenColor.
,
Step.
, , -
.

,
, .
,
. ,
,
,
.
-
!
-
- ,
:
'
'

'var
' :
penWidth= 3
' :
r=0
g=0
b=0
247

GraphicsWindow.Title=" "
. . .

, , -
.
6 -
, -
, -
.
btn:

-
.

'

y= 10
dy=32
x= width-85
n=1
btn[n]=Controls.AddButton(" --> ", x, y+dy*(n-1))
Controls.SetSize(btn[n], 80, 24)
n=n+1
btn[n]=Controls.AddButton(" --> ", x, y+dy*(n-1))
Controls.SetSize(btn[n], 80, 24)
n=n+1
btn[n]=Controls.AddButton(" --> ", x, y+dy*(n-1))
Controls.SetSize(btn[n], 80, 24)
n=n+1
btn[n]=Controls.AddButton(" --> ", x, y+dy*(n-1))
Controls.SetSize(btn[n], 80, 24)
n=n+1
btn[n]=Controls.AddButton(" --> ", x, y+dy*(n-1))
Controls.SetSize(btn[n], 80, 24)
n=n+1
btn[n]=Controls.AddButton(" --> ", x, y+dy*(n-1))
Controls.SetSize(btn[n], 80, 24)

Controls.ButtonClicked=OnClick
248

-
,
:






- OnClick, -
, :
'
Sub OnClick
button= Controls.LastClickedButton
If (button= btn[1]) Then
YR()
ElseIf (button= btn[2]) Then
YG()
ElseIf (button= btn[3]) Then
CG()
ElseIf (button= btn[4]) Then
CB()
ElseIf (button= btn[5]) Then
MB()
ElseIf (button= btn[6]) Then
MR()
EndIf
EndSub


, ,
.
, , -
, . -
.
249

(. 20.5) -
255 ( -
), ( ), -
-
255 0.
. -
,
:
' - Cyan To Blue
Sub CB
b = 255
r = 0
for i = 0 to height
' :
g= 255 * (1 - i / height)
' :
clr= GraphicsWindow.GetColorFromRGB(r,g,b)
GraphicsWindow.PenColor= clr
' :
GraphicsWindow.DrawLine(0, i, width-90, i)
Program.Delay(1)
EndFor
EndSub

. 20.5.
250

-
(. 20.6) . -
:
' - Magenta To Red
Sub MR
r = 255
g = 0
for i = 0 to height
' :
b= 255 * (1 - i / height)
' :
clr= GraphicsWindow.GetColorFromRGB(r,g,b)
GraphicsWindow.PenColor= clr
' :
GraphicsWindow.DrawLine(0, i, width-90, i)
Program.Delay(1)
EndFor
EndSub

. 20.6.

,
, !
251

, -
!

1. , -
( ) (. 20.7)!

2. , (. 20.8), -
(. 20.9) (. 20.10) .

. 20.7. . 20.8.

. 20.9. . 20.10.
252

21.

,

.

GraphicsWindow.DrawRectangle(x, y, width, height)

,
(X, Y),
width height.
PenColor ,
PenWidth (. 21.1).

. 21.1.

GraphicsWindow.FillRectangle(x, y, width, height)


253

,
, ,
BrushColor
(. 21.2).

. 21.2.

,
.

,
.

.
.
:

'
'

'var
' :
penWidth= 5
254

GraphicsWindow.Title=" "

. . .

'
While "True"
' :
x= Math.GetRandomNumber(width - penWidth / 2 - 1)
y= Math.GetRandomNumber(height - penWidth / 2 - 1)
' :
w= Math.GetRandomNumber(width - x - penWidth / 2 - 1)
h= Math.GetRandomNumber(height - y - penWidth / 2 - 1)
' :
clr= GraphicsWindow.GetRandomColor()
GraphicsWindow.PenColor= clr
' :
GraphicsWindow.DrawRectangle(x, y, w, h)
Program.Delay(30)
EndWhile


(. 21.3).

. 21.3.
255

, -
, -
(. 21.4):

While "True"
' :
x= Math.GetRandomNumber(width)
y= Math.GetRandomNumber(height)
' :
w= Math.GetRandomNumber(width - x)
h= Math.GetRandomNumber(height - y)
' :
clr= GraphicsWindow.GetRandomColor()
GraphicsWindow.BrushColor=clr
' :
GraphicsWindow.FillRectangle(x, y, w, h)
Program.Delay(30)
EndWhile

. 21.4.
256


, -
. ,
, -
.

GraphicsWindow.DrawEllipse(x, y, width, height)

(. 21.5).

. 21.5.

GraphicsWindow.FillEllipse(x, y, width, height)

(. 21.6).
257

. 21.6.

, .

,
!

-
.

, , -
(.
21.7 21.8):
GraphicsWindow.DrawTriangle(x1, y1, x2, y2, x3, y3)

GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)


258

. 21.7.

. 21.8.
259


, -
.

, -
,
. !


.
.
-
:

'
'

'var
' :
penWidth= 2
' :
size= 32
' :
penColor= "Yellow"

GraphicsWindow.Title=""

GraphicsWindow.Width= 480
GraphicsWindow.Height=440
. . .


, -
.

-
(x1, y1),
size/4*3*(j) . ,
j*dy*1.5 .
260

, (.
21.9)

GraphicsWindow.PenWidth = penWidth
GraphicsWindow.PenColor= penColor
' :
x1= width/2- size/2
y1= 10
' :
dy= size*math.Sin(Math.GetRadians(60))
' :
yt=y1
xt=x1

' :
For j= 0 to 14
' :
y1=yt+j*dy*1.5
x1=xt- size/4*3*j
For i= 1 to 15-1.5*j
drawTre()
y1= y1+dy
endFor
' :
y1=yt+j*dy*1.5
x1=xt+ size/4*3*j
For i= 1 to 15-1.5*j
drawTre()
y1= y1+dy
endFor
endFor

drawTre :

'
Sub drawTre
GraphicsWindow.DrawTriangle(x1,y1, x1+size, y1, x1 + size/2,
y1 + dy)
EndSub
261

. 21.9.

-
.

:
! -
.
,
, .

Rectangular ( , -
).
262

, -
, :

'
'

'var
' :
penWidth= 2
' :
x0=0
y0=0
' :
xmax=0
ymax=0
' :
x1=0
y1=0
x2=0
y2=0
' :
figura="Rect"

GraphicsWindow.Title="Rectangular"

GraphicsWindow.Width= 480 + 100


GraphicsWindow.Height=320
. . .

, (x1, y1) (x2, y2) -


-
, DrawRectangle
, -
. ,
figura -
.

, :

'
263

y= 10
dy=48
x= width-90
n=1
btn[n]=Controls.AddButton("-", x, y+dy*(n-1))
Controls.SetSize(btn[n], 80, 32)
n=n+1
btn[n]=Controls.AddButton("", x, y+dy*(n-1))
Controls.SetSize(btn[n], 80, 32)
Controls.ButtonClicked=OnClick

-
OnClick:

' :
Sub OnClick
GraphicsWindow.BrushColor="Black"
button= Controls.LastClickedButton
If (button= btn[1]) Then
GraphicsWindow.FillRectangle(x0, y0, xmax+4, ymax)
GraphicsWindow.PenWidth = 2
figura="Rect"
Else
GraphicsWindow.FillRectangle(x0, y0, xmax+4, ymax)
GraphicsWindow.PenWidth = 1
figura="Ellipse"
EndIf
EndSub

, , , -
-
( )
, .
,
:
' :
x0= 0
y0= 0
xmax= width - 100
264

ymax= height

. 21.10.

, While -
. ,
, -

, , ,
/ .
-
DrawRectangle, !

GraphicsWindow.PenWidth = penWidth

While "True"
for i= 6 To 1 Step -1
for j= 0 to 5
' :
x1= x0
y1= y0
x2= xmax
265

y2= ymax
' :
clr= GraphicsWindow.GetRandomColor()
GraphicsWindow.PenColor= clr
'
:
while (x1<= xmax) and (y1<= ymax)
If (x1 > x2) Then
x= x2
Else
x= x1
EndIf
If (y1 > y2) Then
y= y2
Else
y= y1
EndIf
if (figura="Rect") Then
' :
GraphicsWindow.DrawRectangle(x, y, Math.Abs(x2-x1),
Math.Abs(y2-y1))
Else
' :
GraphicsWindow.DrawEllipse(x, y, Math.Abs(x2-x1),
Math.Abs(y2-y1))
EndIf
Program.Delay(20)
' :
x1= x1+i
y1= y1+j
x2= x2-i
y2= y2-j
EndWhile
EndFor
EndFor
EndWhile

,
,
(. 21.10 21.11)!
266

. 21.11.


Rectangular.
267

22.


, GraphicsWindow, -
, , -
. , -
. -

. ,
, -
(
). ,

,
. , , -
!

-
(Logo), 1967
. , -

. -
,
- -
. -
(Turtle),
.
70-80- ,

LISP, SCHEME .
, Turtle.

, -
Turtle.Show (. 22.1).
268

. , -
, !

, -
, !

22.1.


. , -
-
(. 22.2).
-
.

22.2.

,
, ,
-
, X Y
.

, , ,
:
269

GraphicsWindow.Title=" - Turtle"
GraphicsWindow.Width= 320
GraphicsWindow.Height=320
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width=GraphicsWindow.Width

' :
CX= width/2
CY= height/2

' :
GraphicsWindow.PenColor= "Black"
GraphicsWindow.PenWidth=1

Turtle.Show()
' :
Turtle.X = CX
Turtle.Y = CY

,
,
, Y !

. -
, :

Turtle.Move(100)

,
( , !) 100 -
(. 23.3).

- -
!

Turtle.Move(-100),
270

, , (. 22.4).

. 22.3. ! . 22.4. !

- . -
, , -
! ,
, .
, -
, -
:

GraphicsWindow.PenColor= "Red"
GraphicsWindow.PenWidth=10

(. 22.5).

. 22.5.
271

.
, -
, . -
PenDown PenUp.
, . -
,
.

,
(. 22.6).
GraphicsWindow.PenColor= "Green"
GraphicsWindow.PenWidth= 4

For i= 1 to 10
if (Math.Remainder(i,2)= 0) then
Turtle.PenUp()
Else
Turtle.PenDown()
EndIf
Turtle.Move(10)
endFor

. 22.6.
272


, : -
.
Turtle.Hide(),

-.
, -
(. 22.7).

, , , , -
, , , Turtle.Speed
, .
,
10 1 10.

. 22.7.

,
, -
, .
Turtle.MoveTo(x,y)

.
273

-
:

Turtle.X = CX
Turtle.Y = CY
Turtle.MoveTo(300,300)
Turtle.MoveTo(20,300)

, -
,
(. 22.8). , ,
, !

, -
.
, -
.

. 22.8. MoveTo

, -
. , -
274

.
, .

Turtle

Turtle.TurnLeft()
Turtle.TurnRight()
Turtle.Turn()

.
90 , 90
, .
,
, .

, :

For i= 1 to 10
Turtle.TurnLeft()
Turtle.TurnRight()
endFor

For i= 1 to 10
Turtle.Turn(300)
Turtle.Turn(-320)
endFor

-
, .
,

Z=45
R=120
Turtle.Turn(Z)
Turtle.Move(R),

,
(. 22.9).
275

. 22.9.

-
, -
:

R=120
Z=0
Turtle.Turn(Z)
For i= 1 to 8
Turtle.PenUp()
Turtle.Move(R-4)
Turtle.PenDown()
Turtle.Move(4)
Turtle.PenUp()
Turtle.MoveTo(CX,CY)
Turtle.Angle = Z
Turtle.Turn(360/8* i)
endFor

,
(. 22.10).
276

. 22.10.

, -
, ? -
, -
, -
. -
, . ,
60 -
, 120,
(. 22.11), , -
.
, -
:

R=120
Turtle.TurnRight()
For i= 1 to 3
Turtle.Turn(-120)
Turtle.Move(R)
endFor
277

. 22.11.

, -
n, :

Turtle.X = width-100
Turtle.Y = height-30
R=120
Turtle.TurnRight()
n=6
For i= 1 to n
Turtle.Turn(-360/n)
Turtle.Move(R)
endFor

(. 22.12)

!
278

. 22.12.

,
, (.
22.13).

Turtle.X = width-160
Turtle.Y = height-20
R=12
Turtle.TurnRight()
n=80
For i= 1 to n
Turtle.Turn(-360/n)
Turtle.Move(R)
endFor

,
(. 22.14).

':
Turtle.X = CX
Turtle.Y = CY
R=1
Turtle.TurnRight()
For i= 1 to 240
Turtle.Move(R)
Turtle.Turn(10)
279

R = R + 0.1
endFor

Turtle.Turn(-10),

(
).

. 22.13. . 22.14.

,
, -
.
-
:
'
Sub polyRoll
For i= 1 to 12
polyStop()
Turtle.Turn(angle2)
endFor
EndSub
Sub polyStop
280

ps_next:
Turtle.Move(side)
Turtle.Turn(angle1)
_turn= _turn+angle1
If (Math.Remainder(_turn, 360) <> 0) Then
Goto ps_next
EndIf
EndSub

angle1 angle2, -
, (.
22.15).

Turtle.X = CX
Turtle.Y = CY
GraphicsWindow.PenColor= "Black"
GraphicsWindow.PenWidth= 2
_turn=0
angle1=90
angle2=30
side=100

angle1=60
angle2=45
side=80
polyRoll()
TextWindow.Read()

. 22.15.
281

polySpi -

(. 22.16)!
'
Sub polySpi
If (side > maxside) Then
goto ps_exit
EndIf
Turtle.Move(side)
Turtle.Turn(angle)
side = side + inc
polySpi()
ps_exit:
EndSub
Turtle.X = CX -30
Turtle.Y = CY +30
GraphicsWindow.PenColor= "Black"
GraphicsWindow.PenWidth= 2
maxside=240
inc=1
side=60
angle=95
TextWindow.Read()
' :
inc= 3
angle=90
angle=87
polySpi()
TextWindow.Read()
' :
inc= 5
angle=120
Turtle.X = CX -20
Turtle.Y = CY +20
inc= 4
angle=117
maxside=280
TextWindow.Read()
inc= 1
angle=30
side= 3
polySpi()
TextWindow.Read()
282

. 22.16.
283


(. 22.17).

'
Sub newPoly
For i= 1 to 24
Turtle.Move(side)
Turtle.Turn(angle)
Turtle.Move(side)
Turtle.Turn(2*angle)
endFor
EndSub

Turtle.X = CX-30
Turtle.Y = CY-20
GraphicsWindow.PenColor= "Black"
GraphicsWindow.PenWidth= 2
side=80
angle=30
' :
angle=144
newPoly()
TextWindow.Read()
GraphicsWindow.Clear()
'angle=45

' :
Turtle.X = CX-80
Turtle.Y = CY-100
Turtle.Angle=0
side=36
angle=125
newPoly()
TextWindow.Read()
GraphicsWindow.Clear()

angle.
284

. 22.17.

Turtle.

, -
(. 22.18).

. 22.18.
285

23.

-
, .
,
, , ,
.
-
, -
.
.

Cyber-Turtle .

, -
x0 y0, , -
a0:
'
'

'var
' :
x0=0
y0=0
a0=0

() -
, -
:

' :
size=0
' :
teta=0
' :
speed= 9
' :
penColor="Red"
' :
286

penWidth=2
' , :
instinct=""

, , , ,
. -
(), -
.

GraphicsWindow.Title=" - CyberTurtle"

GraphicsWindow.Width= 320
GraphicsWindow.Height=320
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width=GraphicsWindow.Width

' :
CX= width/2
CY= height/2

-
.
. :

x0= CX - 100
y0= CY + 100

a0= 0

size=100
287

' :
instinct="F"

,
, :

'
Sub start
Turtle.Speed= speed
GraphicsWindow.PenColor= penColor
GraphicsWindow.PenWidth= penWidth
Turtle.PenDown()
Turtle.X= x0
Turtle.Y= y0
Turtle.Angle= a0
Turtle.Show()
EndSub

, -
, -
Forward. -
.
, ,
. ,
:

'
Sub execute
' :
For i= 1 To Text.GetLength(instinct)
' :
cmd= Text.GetSubText(instinct,i,1)
' :
If (cmd="F") Then
Turtle.Move(size)
EndIf
EndFor
EndSub
288

, ,
, :

start()
execute()

, -
size (. 23.1).

. 23.1.

-
+ -,
teta. -
:

If (cmd="+") Then
Turtle.Turn(teta)
EndIf
If (cmd="-") Then
Turtle.Turn(-teta)
EndIf
289

-
. ,
, 120 ,
, 120 , , -
. , -
120 , :
':
teta=120
instinct="F+F+F+"

.
(. 23.2)!

. 23.2.

':
teta=90
instinct="F+F+F+F+"
':
teta=72
290

instinct="F+F+F+F+F+"
':
teta=60
instinct="F+F+F+F+F+F+"

, ,
F+ n ,
n .
!

,
, ,
-
. -
:

axiom="F"

, -
size. .


, :

newF="F+F"

. (
iter) F,
, newF, F+F:

iter= 1 axiom="F+F"

, ( !) -
(. 23.3).
291

. 23.3. -

iter= 2 axiom="(F)+(F)" "(F+F)+(F+F)" "F+F+F+F"

F F+F.
, -
.


(. 23.4).

, , ,
"F+F+F+",
. , , -
.
292

. 23.4.

, , -
:

'
Sub createInstinct
For i= 1 to iter
instinct=""
For j= 1 To Text.GetLength(axiom)
' :
cmd= Text.GetSubText(axiom,j,1)
If (cmd="F") Then
instinct= instinct + newF
Else
instinct= instinct + cmd
EndIf
endFor
axiom=instinct
endFor
endSub

. F -
newF, (
+ - ) .
293


instinct, -
createInstinct ,
axiom.

':
Sub Triangle
teta=120
size=100
speed=5
iter= 2
axiom="F"
newF="F+F"
endSub

Triangle()
createInstinct()
start()
execute()

,
.
teta,
:

':
Sub Quadrat
teta=90
size=100
iter= 2
speed=10
axiom="F"
newF="F+F"
endSub

,
(. 23.5).
294

':
Sub Pentagon
teta=72
size=100
iter= 3
speed=10
axiom="F"
newF="F+F"
endSub

':
Sub Hexagon
teta=60
size=100
iter= 3
speed=10
axiom="F"
newF="F+F"
endSub

':
Sub Octagon
teta=45
size=100
iter= 3
speed=10
axiom="F"
newF="F+F"
endSub

,
,
, -

.
295

. 23.5.

, -
, . -
, -
, ,
(. 23.6).
296

. 23.6.

-
(. 23.7).

. 23.7.

:
, , ,
(. 23.8), , ,
, , ,
(. 23.9),

. 23.8.
297

. 23.9.


1904
. ,
(. 23.10).
,
(. 23.10).
(. 23.10).

. 23.10.
298

, -
, . -
,
, , -
, -
, 60 ,
. , teta -
. , , -

:

' :
Sub Koch
teta=60
size=4
iter= 1'4
speed=10
axiom="F++F++F"
newF="F-F++F-F"
endSub

:
Koch()
createInstinct()
start()
execute()

-
, , 3
(. 23.12 ).

, 6 ,
(. 23.11).

. 23.11.
299

. 23.12. iter=1 iter=4

,

(. 12 )!

1890 , ,
, (, -
, ) .
, -
, (.
23.13). ( iter) -
.

' :
Sub Peano
a0= 45
teta=90
size=10
iter= 3
speed=10
axiom="F"
newF="F-F+F+F+F-F-F-F+F"
endSub
300

. 23.13. iter= 3

, -
(. 23.14).

' 32- :
Sub sc32
teta=90
size=4
iter= 2
speed=10
axiom="F+F+F+F"
newF="-F+F-F-F+F+FF-F+F+FF+F-F-FF+FF-FF+F+F-FF-F-F+FF-F-
F+F+F-F+"
endSub

, -
b. ,
, .
301

. 23.14. 32- iter= 2

createInstinct
:
. . .
ElseIf (cmd="b") Then
instinct= instinct + newb
. . .

b
F. execute
, :

If (cmd="b") Then
Turtle.PenUp()
Turtle.Move(size)
Turtle.PenDown()
EndIf

, -
(.
23.15).
302

':
Sub Mozaic
a0= 0
teta=90
size=10
iter= 2
x0= CX
y0= CY
speed=10
axiom="F-F-F-F"
newF="F-b+FF-F-FF-Fb-FF+b-FF+F+FF+Fb+FFF"
newb= "bbbbbb"
endSub

: b
newb!

. 23.15. iter= 2

, -
. -
, -
.

, -
. -
303

,
createInstinct:

ElseIf (cmd="W") Then


instinct= instinct + newW
ElseIf (cmd="X") Then
instinct= instinct + newX
ElseIf (cmd="Y") Then
instinct= instinct + newY
ElseIf (cmd="Z") Then
instinct= instinct + newZ

execute , -
.
,
!

,
(. . 21.9)?
:
':
Sub triangles
a0=30
teta=120
size= 20
iter= 6
speed=10
axiom="bX"
newb = "b"
newF="F"
newX="--FXF++FXF++FXF--"
endSub

,
(. 23.16).
304

. 23.16. iter= 6

-
, , , ,
(. 23.17).

' -:
Sub PeanoGosper
teta=60
size=10
iter= 4
speed=10
axiom="FX"
newF="F"
newX="X+YF++YF-FX--FXFX-YF+"
newY="-FX+YFYF++YF+FX--FX-Y"
endSub
305

. 23.17. - iter= 4

-
, . [ -
, ]
.

,
createInstinct ,
execute :

If (cmd="[") Then
Stack.PushValue(_stack, Turtle.Angle)
Stack.PushValue(_stack, Turtle.X)
Stack.PushValue(_stack, Turtle.Y)
EndIf
If (cmd="]") Then
Turtle.Y= Stack.PopValue(_stack)
Turtle.X= Stack.PopValue(_stack)
Turtle.Angle= Stack.PopValue(_stack)
EndIf
306

, : -
,
.

-
, . -
(. 23.18):
' :
Sub Snowflake
size=4
iter= 2
teta=60
x0= CX
y0= CY+100
speed=10
axiom="[F]+[F]+[F]+[F]+[F]+[F]"
newF="F[++F][-FF]FF[+F][-F]FF"
endSub

. 23.18. iter= 2

-
, (. 23.19):
':
307

Sub Rhombes
a0= 0
teta=60
size=10
iter= 6
x0= CX
y0= CY
speed=10
axiom="F"
newF="-F+F+[+F+F]-"
endSub

. 23.19. iter= 6

(. 23.20) ,
,
:

' :
Sub Penrose
teta=36
size= 24
iter= 4
308

speed=10
axiom="[Y]++[Y]++[Y]++[Y]++[Y]"
newW="YF++ZF----XF[-YF----WF]++"
newX="+YF--ZF[---WF--XF]+"
newY="-WF++XF[+++YF++ZF]-"
newZ="--YF++++WF[+ZF++++XF]--XF"
newF=""
endSub

. 23.20. iter= 4


[8].

, , - -
, (. 23.21):

':
Sub Bush
size=8
iter= 4
teta=180/8
x0= CX
y0= CY+100
speed=10
309

axiom="F"
newF="-F+F+[+F-F-]-[-F+F+F]"
endSub

. 23.21. iter= 4

L-

, , , ,
. , -
L-,
-
( )
. -
(. 23.22) - ,
-
(
).
':
Sub Tree
size=8
310

iter= 4
teta=180/6
x0= CX
y0= CY+100
speed=10
axiom="F"
newF="F[-F]F[+F][F]"
endSub

. 23.22.

(. 23.23):

'2:
Sub Tree2
size=4
iter= 4
teta=180/6
x0= CX
y0= CY+160
speed=10
axiom="F"
newF="F[+F]F[-F]F"
endSub

'3:
311

Sub Tree3
size=6
iter= 4
teta=180/6
x0= CX
y0= CY+160
speed=10
axiom="F"
newF="FF-[-F+F+F]+[+F-F-F]"
endSub

. 23.23.

,
-
, iter
( ,
).
, -

, ,
L-.

Cyber-
Turtle.
312

24.
- ,
.
. ,

, -
, -

, .

, , -
,
. , ,

: .
,
.
(1912
1954) 1936 -
, .
,
, , -
.
, -
.

, -
, . -
:

1. .
2. 90 .
3. .
4. .

, ,
. ,
, ,
313

-
, .

- -
, . -
, .
, -
, 16 .


Thurmits.
, .

iColor ,
:
'
'

nColor = 16 '- 16
' :
iColor [0] = "Black"
iColor [1] = "Maroon"
iColor [2] = "Green"
iColor [3] = "Olive"
iColor [4] = "Navy"
iColor [5] = "Purple"
iColor [6] = "Teal"
iColor [7] = "Gray"
iColor [8] = "Silver"
iColor [9] = "Red"
iColor[10] = "Lime"
iColor[11] = "Yellow"
iColor[12] = "Blue"
iColor[13] = "Fuchsia"
iColor[14] = "Aqua"
iColor[15] = "White"
314

, -
- - ,
, (. 24.1):

' :
LEFT = -1 '- /
FORWARD = 0 '-
RIGHT = 1 '- /
UP = Forward '-
DOWN = 2 '-

. 24.1.

26 ,
:
nStatus=26 '- - A..Z

,
.

,
:
'vars:
' :
315

Direction = Forward
' :
CurStatus="A"
'x- :
xThurmit=0
'y- :
yThurmit=0
' :
nMoves= 0
' :
cmd[0]="END"
' :
commands[0][0]=0

, -
:

' :
wCell = 10
' :
hCell = 10
' :
OffsetX= 10
' :
OffsetY= 60
' :
nRow = 65
' :
nCol = 65
' :
nCell = nRow*nCol
' :
masPole[nCell]="Black"

-
:

'=============================================

' :
prepareProg()

'=============================================
316

-
.
, -
,
, , -
,
.

Sub prepareProg
' :
GraphicsWindow.BackgroundColor= "#58804E"
'GraphicsWindow.BackgroundColor= "Black"
GraphicsWindow.Clear()

' :
GraphicsWindow.Title=""

' :
GraphicsWindow.Width = OffsetX + (wCell*nCol)
GraphicsWindow.Height = OffsetY+(hCell*nRow) + 60

' :
GraphicsWindow.Top= (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width)
/ 2

GraphicsWindow.CanResize="False"
height=GraphicsWindow.Height
width=GraphicsWindow.Width

' :
CX= width/2
CY= height/2

'
btnPlay=Controls.AddButton("Play Turmit", 10,10)
Controls.SetSize(btnPlay, 100,32)
Controls.ButtonClicked= play
317

'
txtMove=Controls.AddTextBox(200,10)
Controls.SetSize(txtMove, 120,26)
' :
txtDebug=Controls.AddTextBox(10,height-40)
Controls.SetSize(txtDebug, width-20,32)

, ,
:

' :
nMoves= 0
' :
ShowNumMoves()

' :
drawGrid ()

' - :
For i=1 To nCell
masPole[i] = 0
EndFor
EndSub

, -
For, -
, .

Controls.HideControl(btnPlay),
:
Controls.ShowControl(btnPlay).


,
.

:
318

'
Sub ShowNumMoves
s= "Move: " + nMoves
Controls.SetTextBoxText(txtMove, s)
EndSub

.
.
, -
:

'
Sub drawGrid
' :
pgHeight = hCell*nRow
pgWidth = wCell*nCol
' :
GraphicsWindow.PenWidth=2

' :
pgYPosition= OffsetY
For i=0 to nRow
' :
If (i=0) or (i= nRow) Then
GraphicsWindow.PenColor="#FF0000"
Else
GraphicsWindow.PenColor="#808080"
EndIf
GraphicsWindow.DrawLine(OffsetX, pgYPosition,
OffsetX+pgWidth, pgYPosition)
pgYPosition= pgYPosition+ hCell
endfor

' :
pgXPosition= OffsetX
For i=0 to nCol
' :
If (i=0) or (i= nCol) Then
GraphicsWindow.PenColor="#FF0000"
Else
GraphicsWindow.PenColor="#808080"
EndIf
319

GraphicsWindow.DrawLine(pgXPosition, OffsetY, pgXPosition,


OffsetY+pgHeight)
pgXPosition= pgXPosition+ wCell
endfor
EndSub

,
(. 24.2).

. 24.2.

' :
Sub prepareThurmit
' :
nMoves= 0
320

ShowNumMoves()

' -->

' :
xThurmit = math.Floor(nCol/2)
yThurmit = math.Floor(nRow/2)
' - :
CurStatus= "A"

' - :
Direction = Forward

' :
Thurmit1()
readCommands()
EndSub

, ,
, -
.

,
, -
:

'////////////////////////////////////////////////////
'// //
'// //
'// //
'///////////////////////////////////////////////////

Sub Thurmit1
cmd[1]="A 0 15 1 A"
cmd[2]="END"
EndSub

,
cmd.
"END" .

(. 24.3) .
321

,
.
.

0 15 , -
. ,
,
iColor.

0 15 , -
.

. -
:

-1 90
0
1 90

, -
. -
. -
, .

. 24.3.

-
(. 24.4). , -
,
: 0.

Sub Thurmit1
322

cmd[1]="A 0 15 0 A"
cmd[2]="END"
EndSub

, , -
.
,
-
.

, -
.
0, ,
. (,
, ), , -
.
(. 24.5).
15, .

. 24.4. . 24.5.


. ,
,
. , ,
,
(. 24.6).
323

. 24.6.

, , -
, -
, , ,
.


, ,
, .
() (.
24.7).

,
, -
, ,
.

. 24.7.
324

, -
:

' 4 x 4:
Sub GreenSquare44
cmd[1]="A 0 2 0 B"
cmd[2]="B 0 2 0 C"
cmd[3]="C 0 2 1 A"
cmd[4]="END"
endSub

.
( 2), -
( )
. (. 24.8).

. 24.8.

,
0, -
. :

cmd[2]="B 0 2 0 C"

,
(. 24.9).
325

. 24.9.

cmd[3]="C 0 2 1 A",

.
,
( ). -
(. 24.10).

. 24.10.

,
:

cmd[1]="A 0 2 0 B"

,
, (. 24.11).
326

. 24.11.

cmd[2]="B 0 2 0 C",

(. 24.12).

. 24.12.

cmd[3]="C 0 2 1 A",

(.
24.13).
327

. 24.13.

cmd[1]="A 0 2 0 B" (. 24.14, )


cmd[2]="B 0 2 0 C" (. 24.14, )
cmd[3]="C 0 2 1 A" (. 24.15, )
cmd[1]="A 0 2 0 B" (. 24.15, )

. 24.14.
328

. 24.15.

cmd[2]="B 0 2 0 C" (. 24.16)

. 24.16.

-
, ,
2, , .

, ,
, -
.

'
Sub readCommands
i=1
' , :
329

While (cmd[i] <> "END")


' :
str= cmd[i]
' :
commands[i][1]= Text.GetSubText(str, 1, 1)
' :
n= 3
clr=0
While (Text.GetSubText(str, n, 1) <> " ")
clr= clr*10 + Text.GetSubText(str, n, 1)
n= n+1
EndWhile
commands[i][2]= clr
' :
n= n+1
clr=0
While (Text.GetSubText(str, n, 1) <> " ")
clr= clr*10 + Text.GetSubText(str, n, 1)
n= n+1
EndWhile
commands[i][3]= clr

' :
n= n+1
s= Text.GetSubText(str, n, 1)
' :
If (s= "-") Then
n= n+1
s= s + Text.GetSubText(str, n, 1)
EndIf
commands[i][4]= s
' :
commands[i][5]= Text.GetSubText(str,
Text.GetLength(str),1)
i = i + 1
EndWhile
' :
nCommands= i-1
EndSub

,
, END.
330

: () - -
() () ()
().
, .
-
, - -
, , -
.

( !)
Play Thurmit -
:

'
Sub Play
' :
prepareThurmit()


,
( A 0):

' :
curString=1
While ("True")
' :
CurStatus= commands[curString][5]
s=s+ " CurStatus= " + CurStatus
' :
NewColor= commands[curString][3]
s=s+ " NewColor= " + NewColor

' :
masPole[nCol*yThurmit+xThurmit]=NewColor
' , :
DrawTurmit()

' :
newDirection= commands[curString][4]
s=s+ " newDirection= " + newDirection
Controls.SetTextBoxText(txtDebug, s)
331

Direction= Direction+newDirection
' :
If Direction < LEFT Then
Direction=DOWN
EndIf
If Direction > DOWN Then
Direction =LEFT
EndIf

', :
If Direction = LEFT Then
xThurmit= xThurmit-1
yThurmit= yThurmit+0
EndIf

If Direction = UP Then
xThurmit= xThurmit+0
yThurmit= yThurmit-1
EndIf

If Direction = RIGHT Then


xThurmit= xThurmit+1
yThurmit= yThurmit+0
EndIf

If Direction = DOWN Then


xThurmit= xThurmit+0
yThurmit= yThurmit+1
EndIf

' :
'WRAP=1
' ,
:
WRAP=0 if WRAP=0 Then
If xThurmit = nCol Then
s=" Too big X! "
Goto exit
EndIf

If yThurmit = nRow Then


s=" Too big Y! "
Goto exit
EndIf
332

If xThurmit < 0 Then


s=" Too small X! "
Goto exit
EndIf

If yThurmit < 0 Then


s=" Too small Y! "
Goto exit
EndIf
EndIf

' :
if WRAP=1 Then
If xThurmit = nCol Then
xThurmit = 0
EndIf
If xThurmit < 0 Then
xThurmit = nCol-1
EndIf

If yThurmit = nRow Then


yThurmit = 0
EndIf
If yThurmit < 0 Then
yThurmit = nRow-1
EndIf
EndIf

, -
.
, , , , -
:

' :
For i=1 to nCommands
if (commands[i][1]= CurStatus) and
(masPole[nCol*yThurmit+xThurmit]= commands[i][2]) then
curString=i
Goto break
EndIf
EndFor
333

' --> :
s= " END of TURMIT "
Goto exit
break:

-
While:

' :
nMoves= nMoves +1
ShowNumMoves()
EndWhile

exit:
' :
GraphicsWindow.ShowMessage(s, "")
EndSub

-
:

'
Sub DrawTurmit
clr=iColor[masPole[nCol*yThurmit+xThurmit]]
GraphicsWindow.BrushColor= clr
x=OffsetX+xThurmit*wCell
y=OffsetY+yThurmit*hCell
GraphicsWindow.FillEllipse(x,y,8,8)
'Program.Delay(50)
endsub 'DrawTurmit

-
, . -
, , -
, ,
-
.
, -
.
334

,

. ,
.
, -
!

, -
,
-
. -
. -
(. 24.17).

. 24.17.

-
(. 24.18):

Sub Thurmit2
cmd[1]="A 0 15 1 A"
cmd[2]="END"
EndSub
335

. 24.18.


- 3 3 (. 24.19):

Sub GreenSquare33
cmd[1]="A 0 2 0 B"
cmd[2]="B 0 2 1 A"
cmd[3]="END"
endSub

. 19. 3

4 4 ( ) (. 24.20):
336

. 24.20. 4

, ,
(. 24.21):

'Cross!
Sub Thurmit5
cmd[1]="A 0 2 0 B"
cmd[2]="B 0 2 0 C"
cmd[3]="C 0 2 1 A"
cmd[4]="A 2 1 -1 A"
cmd[5]="END"
endSub

. 24.21.

, , ,
, -
337

, , -
. !
(. 24.22
24.23) ,
.

'
Sub Thurmit4
cmd[1]="A 0 2 -1 A"
cmd[2]="A 2 0 0 B"
cmd[3]="B 0 2 1 A"
cmd[4]="B 2 2 1 A"
cmd[5]="END"
endSub

. 24.22. . 24.23.

'
Sub KnopSquare
cmd[1]="A 0 2 0 C"
cmd[2]="A 2 0 0 B"
cmd[3]="B 2 2 1 A"
cmd[4]="B 15 2 1 A"
cmd[5]="C 2 0 -1 A"
cmd[6]="C 0 15 -1 A"
cmd[7]="C 15 2 -1 A"
cmd[8]="END"
338

EndSub


, :
, (. 23.24):

'
Sub ChessBoard2
cmd[1]="A 0 15 -1 B"
cmd[2]="B 0 9 0 C"
cmd[3]="C 0 15 0 D"
cmd[4]="D 0 9 0 E"
cmd[5]="E 0 15 0 F"
cmd[6]="F 0 9 0 G"
cmd[7]="G 0 15 0 H"
cmd[8]="H 0 9 1 I"
cmd[9]="I 0 15 1 J"
cmd[10]="J 0 9 0 C"
cmd[11]="I 15 15 1 K"
cmd[12]="K 9 9 1 L"
cmd[13]="L 15 15 1 L"
cmd[14]="L 9 9 -1 A"
cmd[15]="A 15 15 1 A"
cmd[16]="END"
EndSub

, , (. 23.25)!

'GridSpiral
Sub GridSpiral
cmd[1]="A 0 14 0 J"
cmd[2]="J 0 13 -1 A"
cmd[3]="A 14 13 0 A"
cmd[4]="A 13 14 0 A"
cmd[5]="J 14 13 0 A"
cmd[6]="J 13 14 1 A"
cmd[7]="END"
EndSub
339

. 24.24. . 24.25. -

-
(. 24.26) - (. 24.27).

-
.

'
Sub Klubok
cmd[1]="A 0 15 1 B"
cmd[2]="C 0 10 -1 A"
cmd[3]="B 15 15 1 C"
cmd[4]="A 15 15 1 B"
cmd[5]="B 10 10 1 C"
cmd[6]="B 0 15 1 A"
cmd[7]="C 15 15 0 B"
cmd[8]="END"
EndSub

'
Sub RombGridSpiral
cmd[1]="A 0 14 0 B"
cmd[2]="B 0 14 0 C"
cmd[3]="C 0 14 0 E"
cmd[4]="E 0 14 0 F"
cmd[5]="F 0 14 0 J"
340

cmd[6]="J 0 13 -1 A"
cmd[7]="A 14 13 0 A"
cmd[8]="A 13 14 0 A"
cmd[9]="J 14 13 0 A"
cmd[10]="J 13 14 1 A"
cmd[11]="END"
EndSub

. 24.26. . 24.27.

Thurmits.

,
, -
. -
, . -
,
.
341

25.
0.9 , ,
.
, , -
. -
, -
( -
) -
. -
() Controls.

, Windows
, -
. .

Controls.AddButton(caption, left, top)

caption , -
.

, (.
25.1):

GraphicsWindow.Title=" "

GraphicsWindow.Width= 320
GraphicsWindow.Height=240
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

btnTimer=Controls.AddButton(" ", 10,


GraphicsWindow.Height-48)
342

. 25.1. !

, , -
.
, -
btn.
button, .

, -
. -
,

Controls.SetSize(control, width, height)

.
:
Controls.SetSize(btnTimer,164,32)

(. 25.2).

. 25.2.
343

Controls.Move(control, x, y)

, -
.

, -
. :
offset=-1
left=10
top= GraphicsWindow.Height-48
While "True"
For i= 1 To 40
left=left-offset
top=top+offset
Controls.Move(btnTimer, left, top)
Program.Delay(10)
EndFor
offset= - offset
EndWhile

, , -
, , ,
. , ,
-
ButtonClicked, :
Controls.ButtonClicked = OnClick

Sub OnClick
Controls.SetButtonCaption(btnTimer, " ")
EndSub

Controls.SetButtonCaption(buttonName, caption)

, -
(. 25.3).
344

. 25.3.

, , ,
. :
,
, . :
Sub OnClick
If Controls.GetButtonCaption(btnTimer) = " "
then
Controls.SetButtonCaption(btnTimer, " ")
Else
Controls.SetButtonCaption(btnTimer, " ")
EndIf
EndSub

. -
, , -
().
Timer.Interval=1000
Timer.Pause()
Timer.Tick=OnTick
time=0

Interval .
1000 ,
. , -
345

Tick, -
OnTick.

Interval ,
, 1000.
-
:

Sub OnTick
time= time+ Timer.Interval/1000
GraphicsWindow.Title= " : " + time
EndSub

,
, -
Pause.

-
:
Sub OnClick
If Controls.GetButtonCaption(btnTimer) = " "
then
Controls.SetButtonCaption(btnTimer, " ")
Timer.Resume()
Else
Controls.SetButtonCaption(btnTimer, " ")
Timer.Pause()
EndIf
EndSub

Resume
Pause. (. 25.4)!
346

. 25.4. !

, ,
, -
(
). ,

Controls.AddTextBox(left, top).


:
txtTime=Controls.AddTextBox(10, 10)

:
Sub OnTick
time= time+ Timer.Interval/1000
GraphicsWindow.Title= " : " + time
Controls.SetTextBoxText(txtTime, " : " + time)
EndSub

Controls.SetTextBoxText(textBoxName, text).
347

(. 25.5).
,
?
.
, -
.

. 25.5. !

,
:
Controls.SetSize(txtTime,164,32)


(. 25.6).

. 25.6. !

, -
- .
348

, ,
.
GraphicsWindow.Title= " "

GraphicsWindow.Width= 320
GraphicsWindow.Height=240
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2

txtInfo=Controls.AddTextBox(10, 10)
Controls.SetSize(txtInfo,164,32)
Controls.TextTyped=OnText

, -
. ,
. TextTyped, -
OnText:
Sub OnText
GraphicsWindow.Title= Controls.GetTextBoxText(txtInfo)
EndSub

GetTextBoxText , -
, .

s = Controls.GetTextBoxText(txtInfo)

, .

:
, , -
!

, , ,
, .
,
. , ,
349

txtInfo=Controls.AddMultiLineTextBox(10, 10)
Controls.SetSize(txtInfo,GraphicsWindow.Width-
20,GraphicsWindow.Height-20)
Controls.TextTyped=OnText

Sub OnText
GraphicsWindow.Title= Controls.GetTextBoxText(txtInfo)
EndSub

, -
AddMultiLineTextBox(left, top), -
-
.

- - (. 25.7).

. 25.7. !

,
. -
, , ,
(. 25.8).
350

. 25.8. -!

, ,
,
.

,
, (. 25.9).
'Button1:
btnStart=Controls.AddButton(" ", 8,
GraphicsWindow.Height-32)
'Button2:
btnStop=Controls.AddButton(" ", 180,
GraphicsWindow.Height-32)
Controls.ButtonClicked=OnClick

. 25.9. ?
351

, , .
, .

, -
, -
(. 25.10):
Controls.HideControl("Button2")

. 25.10. -

HideControl(controlName), -
. ,
, -
. Button#,
.
btnStop, btnStart,
btnStop. , , :
btn=Controls.LastClickedButton
Controls.SetTextBoxText(txtTime," ": " + btn)

, -
- Controls.ButtonClicked=OnClick. :
, ?
,
GetButtonCaption , ,
. , -
. LastClickedButton -
: Button1, Button2 .
, :
352

Sub OnClick
btn=Controls.LastClickedButton
If btn="Button1" then
Controls.HideControl("Button1")
Controls.ShowControl("Button2")
Timer.Resume()
Else
Controls.HideControl("Button2")
Controls.ShowControl("Button1")
Timer.Pause()
EndIf
EndSub

, -
(. 25.11).

. 25.11. -

, -
:
btnStop=Controls.AddButton(" ", 8,
GraphicsWindow.Height-32)

LastTypedTextBox
LastClickedButton, .
: TextBox1, TextBox2,

Remove(controlName)
-
.


.
353

26.
.

, -
, , . -
, ,
-
, .
,
. ,
, -
. , ,
(. 26.1).

-

.
, -
-
, -
. -
.
,


.
,
, , -
.

,
, ,
, .
.
354

,
,
, -
,
, , .

.

, ,
, -

.

,
.

. 26.1. -

355

- ,
4-5 ,
!

,
, -
.

(, )
,
.
,
.


, -
, .

, ,
.

,
.

,
.

, -
. ,
.

-
,
,
5 .
356

,
. .
26.2. , -
, 21 , 34 , -
55 , 89 , 144 ,
233 . , -
, -
233 .
11 , 9 , .


- ,
, ,
.
,
.

-
, .

, -
, .
XIX , -
,
, .

, -
, , .
, -
, , ,
.
357

. 26.2.
358

-
nRabbit nFox, . -
, ,
. -
, ,
-
. ,
- -
. , -
. ,
.
-
.

,
, .

dR/dt = k1GR k2RF


dF/dt = k2RF k3F

, -
, - .

R, F G ,
.

k1, k2, k3 -
, -
- .

-
, -
-
.
'
'

'var
359

' :
Q1= 1 'k3/k2
Q2= 1 'k1/k2
' :
Grass= 1
' :
nRabbit= 0.44
nFox= 0.40
' :
D= 4000
' :
T=1

GraphicsWindow.Title=" "

GraphicsWindow.Width= 1000
GraphicsWindow.Height=320
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
height=GraphicsWindow.Height
width=GraphicsWindow.Width


-
:

' :
x= nRabbit
y= nFox

minx= 1000000
maxx=0
miny= 1000000
maxy=0

,
:
360

k= Q1/(Q2*Grass)
' :
n= 1 + d/t

, For
.

:

' :
For j= 1 to n
' :
x2= x + (1 - y) * x * t/100
' dt= t/100 -
y2= y - (1 - x) * y * k * t/100
' :
x= x2
y= y2
' :
draw()

If (x< minx) Then


minx=x
EndIf
If (x> maxx) Then
maxx=x
EndIf
If (y< miny) Then
miny=y
EndIf
If (y> maxy) Then
maxy=y
EndIf
endFor

,
, -
, -
:

' , :
GraphicsWindow.PenWidth=3
361

GraphicsWindow.PenColor="Green"
GraphicsWindow.DrawLine(0, height-nRabbit*zoom, width, height-
nRabbit*zoom)
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(0, height-nFox*zoom, width, height-
nFox*zoom)
' 0.1 :
GraphicsWindow.PenWidth=1
GraphicsWindow.PenColor="Gray"
For i= 0 to maxy Step 0.10
GraphicsWindow.DrawLine(0, height-i*zoom, width, height-
i*zoom)
endFor

' . . :
TextWindow.WriteLine("minx= " + minx)
TextWindow.WriteLine("maxx= " + maxx)
TextWindow.WriteLine("miny= " + miny)
TextWindow.WriteLine("maxy= " + maxy)

'
Sub draw
zoom=100
' "":
GraphicsWindow.BrushColor="Green"
GraphicsWindow.FillEllipse(j/4,height-x*zoom, 3,3)
GraphicsWindow.BrushColor="Red"
GraphicsWindow.FillEllipse(j/4,height-y*zoom, 3,3)
endSub

, , -
-
(. 26.3). , , -

,
-
, .
362

. 26.3. ( )
( )

-
(. 26.4). -
,
, . -
14-.

. 26.4.



.
363

27.

XVII . ,
,
.

,
,
, , ,
.
,
.

,
,
. -
, ,
.

, -
.
, -

. , -
, .

-
, -
.
, ,
,
, -
-
.

, -

. , -
364

. 1 (-
, , -
), - 4 , 9 , ,

.

, -
. -
57 ,
, , 50
(. 27.1).

h -

mg

. 27.1.

, -
,
365

. , -
, .


,
g. .
9,8 /2.

-
:

vt = v0 + gt,

v0 , -
h .
,
, :

vt = gt

, , -
:

St = v0t + gt2,

v0 = 0:

St = gt2

, t = 0 -
h . ,
S = h .

gt2 = h,

t=

50 3,19 .
366

, -
.

Fall.

-
:

'
'

GraphicsWindow.Title=" "

'const
' :
g= 9.8

,
:

'var
' :
xShar= 322
' :
hpix0= 176
' :
h= 50
' :
dShar= 20
' :
yZemli= 660

, -
,
(. 27.2).

' :
GraphicsWindow.Hide()
367

GraphicsWindow.Width= 438
GraphicsWindow.Height=667
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width= GraphicsWindow.Width

' :
background = ImageList.LoadImage(Program.Directory +
"/pisa.jpg")
GraphicsWindow.DrawImage(background, 0, 0)

':
GraphicsWindow.BrushColor="Blue"
GraphicsWindow.FontBold="True"
GraphicsWindow.FontSize=16

, -
:

'

' :
btnStart=Controls.AddButton("!", 10, height-64)
Controls.ButtonClicked=OnClick

'

' :
txtTIme=Controls.AddTextBox(10, 10)
Controls.SetSize(txtTime,100,26)
GraphicsWindow.DrawText(120, 14, "<- ")

' :
txtRasst=Controls.AddTextBox(10, 48)
Controls.SetSize(txtRasst,100,26)
GraphicsWindow.DrawText(120, 52, "<- ")

GraphicsWindow.BrushColor="Red"
GraphicsWindow.Show()
368

,
, -
:

' :
GraphicsWindow.PenWidth=5
GraphicsWindow.PenColor="Yellow"
GraphicsWindow.DrawLine(0, yZemli, 480, yZemli)

' :
GraphicsWindow.BrushColor="Red"
shar=Shapes.AddEllipse(dShar,dShar)
drawShar()

(. 27.2), -
!

shar - -
Shapes,
. -
, -
.

Sub drawShar
'ht -
' 50 htpix
:
htpix= yZemli - hpix0 - dShar
' =
' , 1 :
kpix= htpix/h
' :
ypix= hpix0 + kpix*s

' :
Shapes.Move(shar, xShar, ypix)

' :
If (Math.Remainder(n,10)=0) Then
GraphicsWindow.BrushColor= "Yellow"
369

GraphicsWindow.FillEllipse(xShar+7, ypix, 6, 6)
EndIf
' :
ds_t= Math.Floor(t*100)/100
Controls.SetTextBoxText(txtTime, ds_t)
' :
ds_s= g * t * t /2
ds_s= Math.Floor(ds_s*100)/100
Controls.SetTextBoxText(txtRasst, ds_s)
EndSub

. 27.2.
370

-
.
, , -
, .

'
Sub OnClick
fall()
EndSub

, :

'
Sub fall
t=0
' :
dt= 0.01
' :
ht= h
n= 0
While ("True")
' :
s= g*t*t/2
If (s >= h) Then '
s = h
t= Math.SquareRoot(2*50/g)
drawShar()
Sound.PlayClick()
Goto exit
EndIf
drawShar()
t= t+ dt
Program.Delay(10)
n= n +1
EndWhile
exit:
EndSub


. - -
371

50 , , , -
,
,
.
- n.

, -
:

Program.Delay(10)


, , -
(,
, ). -
:

Sound.PlayClick()

-
(. 27.3), :
.

Fall.

, -
,
vh.
, ,
3,19 .
vh t ,
372

, vh t .
, -
(. 27.4).

. 27.3. .

Fall2
.
373

,
:

' , :
vh= 10

GraphicsWindow.Width= 688

' :
background = ImageList.LoadImage(Program.Directory +
"/pisa2.jpg")

, -
, -
!

, -
, -
:

txtRasstH=Controls.AddTextBox(10, 86)
Controls.SetSize(txtRasstH,100,26)
GraphicsWindow.DrawText(120, 90, "<-
")

GraphicsWindow.DrawLine(0, yZemli, 688, yZemli)

, , -
:
374

. 27.4. .

Sub drawShar
. . .

' :
xpix= xShar + kpix* (vh* t)
' :
Shapes.Move(shar, xpix, ypix)

' :
If (Math.Remainder(n,10)=0) Then
375

GraphicsWindow.BrushColor= "Yellow"
GraphicsWindow.FillEllipse(xpix+7, ypix, 6, 6)
EndIf
. . .
' :
ds_h= vh * t
ds_h= Math.Floor(ds_h*100)/100
Controls.SetTextBoxText(txtRasstH, ds_h)
EndSub

, .
!

Fall2.

: ,
, -
.

Fall3 :

' :
alpha= 60
' , :
v0= 15

(. 27.5)

:

' :
alphaR= Math.GetRadians(alpha)
' , :
vh= v0 * Math.Cos(alphaR)
' , :
vv= v0 * Math.Sin(alphaR)
376

. 27.5. , .

'
Sub fall
. . .

,
, -
.
, dt:

sv= sv + Math.Abs((vv - g*t) * dt),

, -

vvt = vv gt
377

' :
sv=0
While ("True")

-
:

' :
curY= h - g*t*t/2 + vv*t
sv= sv + Math.Abs((vv - g*t) * dt)

If (curY <= 0) Then '


curY = 0
drawShar()
Sound.PlayClick()
Goto exit
EndIf
drawShar()
t= t+ dt
Program.Delay(10)
n= n +1
EndWhile
exit:
EndSub

,
:

Sub drawShar
. . .
kpix= htpix/h
' :
ypix= yZemli- dShar - kpix* curY
' :
xpix= xShar + kpix* (vh* t)
' :
Shapes.Move(shar, xpix, ypix)

. . .
' :
ds_s= sv
378

ds_s= Math.Floor(ds_s*100)/100
Controls.SetTextBoxText(txtRasst, ds_s)
' :
ds_h= vh * t
ds_h= Math.Floor(ds_h*100)/100
Controls.SetTextBoxText(txtRasstH, ds_h)
EndSub

,
(. 27.6).

. 27.6. ,

Fall3.
379

1. 1,624 /2,
24,8 /2. ,
!

2. Fall3 ,
, . ,

' :
alpha= 75
' , :
v0= 35

(. 27.7).

. 27.7. , -

380


Fall3.

3. ,
- -
. -
,
. ,
,
.
,
.
, -
, !

4. , ,
, ,
(. 27.8).
, , -
, , 75 . ,
!

. 27.8.
381

28.

""
. , -
, ,
, .
, : -
. ,
, , .
, ,
.

Palindrome
.
,
:

'

'variables
spisok[0]=""
nWords=0
txt=""
chr="" '
tybloko="" ' -
index=0
beg=0
len=0

:
'=========================================
'
'=========================================
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" ")
382

TextWindow.WriteLine("")
TextWindow.Show()

1:
fileName= "OSh_frc2-4.txt"
readFile()
' 2:
'fileName= "OSh_frc5.txt"
'readFile()
' 3:
fileName= "OSh_frc6.txt"
'readFile()
' 4:
fileName= "OSh_frc7.txt"
'readFile()

spisok .
.

TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
' , :
for i=1 to nWords
s= spisok[i]
If Text.IsSubText(s, "")= "True" Then
' -->
' :
tybloko=""
len= Text.GetLength(s)
For j= 1 to len
' :
chr= Text.GetSubText(s, j, 1)
If (chr = "") Then
tybloko= tybloko + ""
Else
tybloko= tybloko + chr
EndIf
EndFor
TextWindow.WriteLine(s + " - " + tybloko)
File.AppendContents("tybloko.txt", s + " - " + tybloko)
EndIf
EndFor

TextWindow.WriteLine("")
383

TextWindow.ForegroundColor="Red"

For .
-
IsSubText Text, - For
. -
tybloko
, , .

,
.

- ,
- (. 28.1).

. 28.1. , !




384

1. ,
- . -
, .

2. ,
.
3. , ,
, ,

(. 28.2).
, -
-
, ( -
).
385

, -
.

. 28.2.


.
386

29.
-,
- !

(,
, ), -
, -
.
, ,
.
, . -
- , !

(, -
, , ): -
, , .

( !)
,
!

'

'variables
chr="" '
logopef="" '
string="" '
len=0 '

:
,
:
GraphicsWindow.Title=" "
GraphicsWindow.Width= 800
GraphicsWindow.Height= 320
387

GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /


2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2

- -

:

txtSource=Controls.AddMultiLineTextBox(10, 10)
Controls.SetSize(txtSource,GraphicsWindow.Width/2-
20,GraphicsWindow.Height-80)
txtLogopef=Controls.AddMultiLineTextBox(GraphicsWindow.Width/2
+10, 10)
Controls.SetSize(txtLogopef,GraphicsWindow.Width/2-
20,GraphicsWindow.Height-80)

btnTLogopef=
Controls.AddButton("",10,GraphicsWindow.Height-40)
Controls.ButtonClicked= OnClick

(
- ),
, OnClick
.

Sub OnClick
string= Controls.GetTextBoxText(txtSource)
len= Text.GetLength(string)

' :
logopef=""
For i= 1 to len
' :
chr= Text.GetSubText(string, i, 1)
c = Text.ConvertToUpperCase(chr)
If (c = "") Then
logopef= logopef + ""
Else
logopef= logopef + chr
EndIf
EndFor
388

Controls.SetTextBoxText(txtLogopef, logopef)
EndSub

: , .
, ,

If (chr = "" Or chr = "") Then ,

,
, . ,
,
.

.
, . ,
(
OJIesYA_EviL_MonKey),
(. 29.1).

, ,
. :

- .

. 29.1. !

.
389

1. -
.

2. ,
.

3. , -
.

4. , ,
.
.

5. :
( , -
, -
).

6. -
, : -
, . -
, , -
. -.

7. , ( ) ,
,
- - .
,
, , -
.

8. , : -,
-, !? (
)
. .

9. , -
: , , , , !
390

30.
-
, , -
, -
. , -
.

,
,
. , - -
.

- . ! -
-
:

'

'variables
spisok[0]=""
nWords=0
txt=""
chr=""
string="" '
index=0
beg=0
len=0

translit[""] = "A"
translit[""] = "B"
translit[""] = "V"
translit[""] = "G"
translit[""] = "D"
translit[""] = "E"
translit[""] = "YO"
translit[""] = "ZH"
translit[""] = "Z"
translit[""] = "I"
translit[""] = "Y"
translit[""] = "K"
translit[""] = "L"
391

translit[""] = "M"
translit[""] = "N"
translit[""] = "O"
translit[""] = "P"
translit[""] = "R"
translit[""] = "S"
translit[""] = "T"
translit[""] = "U"
translit[""] = "F"
translit[""] = "KH"
translit[""] = "TS"
translit[""] = "CH"
translit[""] = "SH"
translit[""] = "SHCH"
translit[""] = "'"
translit[""] = "Y"
translit[""] = "J"
translit[""] = "E"
translit[""] = "YU"
translit[""] = "YA"

:
...
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
' :
for i=1 to nWords
s= spisok[i]
string=""
len= Text.GetLength(s)
For j= 1 to len
' :
chr= Text.GetSubText(s, j, 1)
string=string + translit[chr]
EndFor
TextWindow.WriteLine(s + " - " + string)
File.AppendContents("translit.txt", s + " - " + string)
EndFor

spisok
-
.
(. 30.1).
392

. 30.1. -

translit, -
, -
. , , , . , , -
Y O, -
. , (-
) .
YOGURT,
: -
.
, -
, . -
, .

-
.

-
- , -
,
.
393

31.
Moya tvoya ne ponimaet!

, , ,
,
,
.

, .
?

, -
. ,
.

,
.

, -
latin:

' -

'const
latin=""

,
.

, , -
:

' :
for i=1 to nWords
s= spisok[i]
len= Text.GetLength(s)
' , :
For j= 1 to len
394

' :
chr= Text.GetSubText(s, j, 1)
If Text.IsSubText(latin, chr) = "False" Then
Goto next
EndIf
EndFor
TextWindow.WriteLine(s)
File.AppendContents("latin.txt", s)
next:
EndFor

,
latin. ,
.

.

For IsSub-
Text:

Text.IsSubText(latin, chr) = "False"

(. 31.1).

. 31.1. - !
395

, , -
, , -
, .


, -
. ,
, , -
. , , , , .
-
, ,
.

, .
-
, , ,
,
. , , , ,
.
,
. , ,
.


,
.
,
. .

, , :
396

'

'variables

string="" '

string,
.

,
. ,
, , ,
:

'=========================================
'
'=========================================
TextWindow.WriteLine(", !")
TextWindow.Show()

fileName= "OSh_frc7.txt"
readFile()

TextWindow.Clear()

,
:

start:
TextWindow.ForegroundColor="Red"
TextWindow.BackgroundColor="Yellow"
TextWindow.WriteLine("
")
TextWindow.BackgroundColor="Black"
string= Text.ConvertToUpperCase(TextWindow.Read())

,
,
string.
397

,
.

TextWindow.ForegroundColor="Yellow"
TextWindow.WriteLine("")
TextWindow.WriteLine("")
' :
for i=1 to nWords
s= spisok[i]
len= Text.GetLength(s)
' , :
For j= 1 to len
' :
chr= Text.GetSubText(s, j, 1)
If Text.IsSubText(string, chr) = "False" Then
Goto next
EndIf
EndFor
TextWindow.WriteLine(s)
next:
EndFor

,
, ,

!

TextWindow.WriteLine("")
TextWindow.BackgroundColor="Black"
TextWindow.ForegroundColor="Red"
Goto start

,
,
(. 31.2).
!

1. ,
, ,
, -
398

.
2. !
, -
, -
.

. 31.2. ?

-
.
399

32.
- ! !

.
- , -
. ,
,

.

, 21-
-
, -
. -
:

: ,
,

, ,
, , , :

, .
! .
, , -
: ,

, , -
, - -
.


( !).
, 33
400

. , ,
.

- .
, , , -
. 2005 -
(. 32.1).

. 32.1.

1797 , -
.

.
.

, 16 ,
:


401

,
. ,
. , -
, , , -
.
, .
, -
.

.
, !

'

'const
lit[1]=" "
lit[2]=" "

'variables
chr="" '
pos=0 ' lit
litorea="" '
string="" '
len=0 '

GraphicsWindow.Title=" "
GraphicsWindow.Width= 800
GraphicsWindow.Height= 320
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) / 2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height) / 2

-
:
' :
txtSource=Controls.AddMultiLineTextBox(10, 10)
Controls.SetSize(txtSource,GraphicsWindow.Width/2-
20,GraphicsWindow.Height-80)
txtLitorea=Controls.AddMultiLineTextBox(GraphicsWindow.Width/2
+10, 10)
402

Controls.SetSize(txtLitorea,GraphicsWindow.Width/2-
20,GraphicsWindow.Height-80)

btnLitorea=
Controls.AddButton("",10,GraphicsWindow.Height-40)
Controls.ButtonClicked= OnClick
btnClear=
Controls.AddButton("",100,GraphicsWindow.Height-40)

OnClick.
, -
, .

, .
.

, -
string txtSource,
For.

GetIndexOf ,
lit, , -
. -
. (-
, , , )
litorea.

, -
:

Sub OnClick
btn=Controls.LastClickedButton
If (btn= btnClear) then
Controls.SetTextBoxText(txtSource, "")
Controls.SetTextBoxText(txtLitorea, "")
Goto exit
EndIf

string= Controls.GetTextBoxText(txtSource)
403

len= Text.GetLength(string)
' - :
litorea=""
For i= 1 to len
' :
chr= Text.GetSubText(string, i, 1)
c = Text.ConvertToUpperCase(chr)
pos= Text.GetIndexOf(lit[1], c)
If (pos > 0) Then '
' :
litorea= litorea + Text.GetSubText(lit[2], pos,1)
Else
pos= Text.GetIndexOf(lit[2], c)
If (pos > 0) Then '
' :
litorea= litorea + Text.GetSubText(lit[1], pos,1)
else ' :
litorea= litorea + chr
EndIf
EndIf
EndFor
Controls.SetTextBoxText(txtLitorea, litorea)
exit:
EndSub

,
(. 32.2).

. 32.2. !
404

, lit
.

. -

(. 32.3).

. 32.3. !

.
, -
.

53 :

, -
.
, , -
.
405

. ,


: , , . , -
.

( 56 -
) , -
,
, ,
.

? !

30 ,
10 . -
(. 32.4).

. 32.4. -

(. 32.5),
(. 32.6).

, .
. -
, , ,
(. 32.7).
406

. 32.5. -

. 32.6. -

. 32.7.

-
: - - - - - - - - - -.
(
407

), -
. , !

30, 33 -
, ,
.
11. ,
, -
, .


. , ,
. -
. .
, , :

-
.

, : -
, -
, ,
. .

, -
.

,
,
. .

-
. , -
(. 32.8).
408

. 32.8. !


, .
, ,
- . -
! -
, , ,
. - :
.
,
.

, , , !

'

'const
rus=" "
bukvy="QWRZUISDFGJLYVN"

'variables
chr="" '
tarabar="" '
string="" '
len=0 '

GraphicsWindow.Title=" "
409

. ?
,
, -
, -
, , ,
,
. -
. -
.

-
,
txtTarabar.

, ,
, :

Sub OnClick
. . .
' - :
tarabar=""
For i= 1 to len
' :
chr= Text.GetSubText(string, i, 1)
c = Text.ConvertToUpperCase(chr)
tarabar= tarabar + c
' -->
If (Text.IsSubText(rus, c) = "True") Then
n= Math.GetRandomNumber(100)
' ,
' :
If (n> 33) Then
n= Math.GetRandomNumber(Text.GetLength(bukvy))
chr= Text.GetSubText(bukvy, n, 1)
tarabar= tarabar + chr
EndIf
EndIf
EndFor
Controls.SetTextBoxText(txtTarabar, tarabar)
exit:
EndSub
410

, ,
n > 33,
.

-
.

1. - ? -
,
. -
:

: ,
,

: ,
, !
, , ,
. ,
:

,
, .

, , -
, .

2. ,
. ,
:



411

3.
:

25 - 19,13 19, 2, 5, 13, 10, 13, 19 - 11, 8, 23,


9, 8 - 3, 11, 13, 18, 40 - 8, 18, 12, 2, 7, 2,
12, 40, 18, 25 -25 - 18, 1, 8, 10, 8 - 21, 14,
11, 21 - 21, 14, 11, 21, 12 - 17 - 5, 19, 8, 9,
17, 13 - 11, 10, 21, 9, 17, 13 25 - 11, 2, 7,
19, 8 - 4,50 - 21, 20, 13, 23 19, 8 - 5, 19, 13
- 4, 50, 23, 8 - 17, 19, 12, 13, 10, 13, 18, 19,
8 - 19, 2, 4, 23, 27, 11, 2, 12, 40 - 3, 2 - 7,
2, 5, 17 - 15, 10, 2, 7, 11, 2 - 7, 50 - 5, 19,
8, 9, 8, 9, 8 - 11, 8, 4, 17, 23, 17, 18, 40 -
19, 8 - 7, 18, 13 - 10, 2, 7, 19, 8 21 - 7, 2,
18 - 19, 17, 24, 13, 9, 8 - 19,13 7, 50, 14, 11,
13, 12 - 24, 13, 23, 8, 7, 13, 1 - 15, 10, 13,
6, 11, 13 - 7, 18, 13, 9, 8 - 16, 13, 19, 17, 12
- 18, 7, 8, 4, 8, 11, 21 - 18, 7, 8, 4, 8, 11, 2
- 11,23,25 - 19, 13, 9, 8 - 9, 23, 2, 7, 19, 8,
13 - 7, 50 - 22, 8, 12, 17, 12, 13 - 18, 11, 13,
23, 2, 12, 40 - 7,18,13 - 15, 8 - 11, 10, 21, 9,
8, 5, 21 - 19, 8 - 21 - 7, 2, 18 19, 17, 24, 13,
9, 8 - 19, 13 - 7, 50, 14, 11, 13, 12.

,
( , , -
, ), ,
.

:
. , -
, ,
, -
, . ,
,
,

, .
,
. -
.
412

,
:

0,2005
0,0764 0,0143
0,0732 0,0138
0,0629 0,0133
0,0577 0,0125
0,0549 0,0114
0,049 0,0094
0,0459 0,0083
0,0404 0,0081
0,0355 0,0079
0,033 0,0048
0,0302 0,0042
0,0299 0,0036
0,0275 0,0026
0,0265 0,0023
0,0222 0,0021
0,0153 0,0003

, ,
, -
.

,
. :
-. -
.

4. -.
, . ,
: , .

5. -
, .
413

33.

,
-
, , -
, , -
, -
, , -
.
, -
.

,
.

-
. .

,
:

P = (3 x A - 450 + B) x 0,25 + 45 - ,
P = (3 x A - 450 + B) x 0,225 + 40,4 - ,

-
( ) ( ), .


,
( ) -
.

, -
? - ,
414

, -
, .
, -
-
. , -
,
:


GraphicsWindow.Title=""

'var
ves=0
rost=0
vozrast=0

GraphicsWindow.Hide()
GraphicsWindow.Width= 600
GraphicsWindow.Height=390
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width= GraphicsWindow.Width

background = ImageList.LoadImage(Program.Directory +
"/mw.jpg")
GraphicsWindow.DrawImage(background, 0, 0)

':
GraphicsWindow.BrushColor="Red"
GraphicsWindow.FontBold="True"
GraphicsWindow.FontSize=16

,
.
415

, ,
, -
. ,
(, - -
).

'

' :
btnM=Controls.AddButton("", 290, height-40)
Controls.SetSize(btnM, 48, 32)
' :
btnW=Controls.AddButton("", 10, height-40)
Controls.SetSize(btnW, 48, 32)
Controls.ButtonClicked=OnClick

,
-
:

'

':
txtVozrast=Controls.AddTextBox(180, 210)
Controls.SetSize(txtVozrast,160,26)
GraphicsWindow.DrawText(350, 214, "<- ")

':
txtRost=Controls.AddTextBox(180, 248)
Controls.SetSize(txtRost,160,26)
GraphicsWindow.DrawText(350, 252, "<- ")

,
:

' :
txtVes=Controls.AddMultiLineTextBox(180, 290)
Controls.SetSize(txtVes,300,50)

-
OnClick:
416

'
Sub OnClick
vozrast= Controls.GetTextBoxText(txtVozrast)
rost= Controls.GetTextBoxText(txtRost)

s=""
If (vozrast = "") Or (vozrast < 1) Or (vozrast > 120) Then
s= " !"
ElseIf (rost = "") Or (rost < 60) or (rost > 240) Then
s= " !"
EndIf

If (s<>"") Then
Goto print
EndIf

btn= Controls.LastClickedButton
If (btn= btnM) Then
ves = (3 * rost - 450 + vozrast) * 0.25 + 45 '-

Else
ves = (3 * rost - 450 + vozrast) * 0.225 + 40.4 '-

EndIf

' :
if ves< 0 then
ves = 4
EndIf

GraphicsWindow.BrushColor="Blue"
s= " " + Math.Round(ves) + " "
print:
Controls.SetTextBoxText(txtVes, s)
EndSub

- ( -) .


vozrast rost,
.
, ,
.
417

,
, -
.

-
. , -
,
,
.

, (,
, ,
), txtVes
(. 33.1).

. 33.1. ?

.
418


90-60-90

-
. , -
( ).

,
15%, 22% . -
-
:

= ( - ) : 100 + 15 - ,
= ( - ) : 100 + 22 - ,

,
.

, -
. ,

.

zhir=0

-
. :

':
txtVozrast=Controls.AddTextBox(180, 190)
Controls.SetSize(txtVozrast,160,26)
GraphicsWindow.DrawText(350, 194, "<- ")

':
txtRost=Controls.AddTextBox(180, 224)
Controls.SetSize(txtRost,160,26)
419

GraphicsWindow.DrawText(350, 227, "<- ")

':
txtVes=Controls.AddTextBox(180, 259)
Controls.SetSize(txtVes,160, 26)
GraphicsWindow.DrawText(350, 262, "<- ")

':
txtZhir=Controls.AddMultiLineTextBox(180, 300)
Controls.SetSize(txtZhir,300,50)

, -
:

'
Sub OnClick
vozrast= Controls.GetTextBoxText(txtVozrast)
rost= Controls.GetTextBoxText(txtRost)
v= Controls.GetTextBoxText(txtVes)
s=""
If (vozrast = "") Or (vozrast < 1) Or (vozrast > 120) Then
s= " !"
ElseIf (rost = "") Or (rost < 60) or (rost > 240) Then
s= " !"
ElseIf (v = "") Or (v < 10) or (v > 240) Then
s= " !"
EndIf

If (s<>"") Then
Goto print
EndIf

btn= Controls.LastClickedButton
If (btn= btnM) Then
ves = (3 * rost - 450 + vozrast) * 0.25 + 45 '-

zhir= (v - ves) / v * 100 + 15


Else
ves = (3 * rost - 450 + vozrast) * 0.225 + 40.4 '-

zhir= (v - ves) / v * 100 + 22


EndIf
420

' :
if (zhir< 0) then
zhir= 0
elseIf (zhir > 100) then
zhir= 100
EndIf

GraphicsWindow.BrushColor="Blue"
s= " " + Math.Round(zhir) + "%"
print:
Controls.SetTextBoxText(txtZhir, s)
EndSub

,
, -
(. 33.2).

. 33.2. - !

?
!


421

.

( ). ,
,
.

, -
( -
):
S = (P x 1000) (lg(1/P)+35,75) / 53,2 x H0,3 : 3118,2,


, -
- ,
.
'

GraphicsWindow.Title=""

'var
ves=0
rost=0
s=0

:
'

' :
btnKozha=Controls.AddButton("!", 180, height-40)
Controls.SetSize(btnKozha, 120, 32)
Controls.ButtonClicked=OnClick
422

'

' :
txtVes=Controls.AddTextBox(180, 210)
Controls.SetSize(txtVes,160,26)
GraphicsWindow.DrawText(350, 214, "<- ")

' :
txtRost=Controls.AddTextBox(180, 248)
Controls.SetSize(txtRost,160,26)
GraphicsWindow.DrawText(350, 252, "<- ")

' :
txtKozha=Controls.AddMultiLineTextBox(180, 290)

Controls.SetSize(txtKozha,360,50)

, -
,
.
.

, , On-
Click:
'
Sub OnClick
ves= Controls.GetTextBoxText(txtVes)
rost= Controls.GetTextBoxText(txtRost)
str=""
If (ves = "") Or (ves < 10) Or (ves > 240) Then
str= " !"
ElseIf (rost = "") Or (rost < 60) or (rost > 240) Then
str= " !"
EndIf

If (str<>"") Then
Goto print
EndIf

' :
s= (Math.Log(1 / ves) + 35.75) / 53.2
423

s= Math.Power((ves * 1000), s) * Math.Power(rost, 0.3) /


0.31182

str= " " + Math.Round(s) + " . "


print:
Controls.SetTextBoxText(txtKozha, str)

EndSub

-

( -
Round). : ! (.
33.3).
, s -
, , -
- str.


,
( -
).

. 33.3. !
424

1. ,
. , -
, -
. ! .

2. .
, -
.

3. ,
,
100 .
425

34.
-
, -
: , , .
, !
! -
.

-
,
: , ,
, . -
,
? ? -
. , -
, -
:
, .
, 50 .


. -
, :
, , .
.

(.
34.1). , -
, - , -
, .


.
- . -
,
.
426

. 34.1. ,

1. ___________

2. ___________

3. ___________
427

- ,
, .
, -
( ) -
. ,
,
.

,
, -
:

GraphicsWindow.Title=" "

'const
BackgroundColor="#2F4F4F"

GraphicsWindow.Hide()
GraphicsWindow.Width= 640
GraphicsWindow.Height=480
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"
GraphicsWindow.BackgroundColor= BackgroundColor

height=GraphicsWindow.Height
width= GraphicsWindow.Width

, ,
,
.
':
Timer.Interval=1000
Timer.Pause()
Timer.Tick=OnTick
428

- :

' :
Sub OnTick
time= time+ Timer.Interval/1000
Controls.SetTextBoxText(txtTime,": " + time)
EndSub

:
'

' :
txtTime=Controls.AddTextBox(340, 10)
Controls.SetSize(txtTime,100,26)
Controls.HideControl(txtTime)

:
.
' :
txtOtvet=Controls.AddTextBox(180, 10)
Controls.SetSize(txtOtvet,32,26)
Controls.HideControl(txtOtvet)

:
'

'Button1 - :
btnStart=Controls.AddButton(" ", 10, 10)
'Button2 - :
btnProv=Controls.AddButton("", 220, 10)
Controls.ButtonClicked=OnClick
Controls.HideControl("Button2")

-
(. 34.2):
GraphicsWindow.Show()
429

. 34.2.

-
. ,
, , ,
- OnClick:
Sub OnClick
btn=Controls.LastClickedButton
If btn="Button1" then '
Controls.HideControl(btnStart)
Controls.ShowControl(btnProv)
createTest()
Controls.SetTextBoxText(txtTime,"")
Controls.ShowControl(txtTime)
Controls.SetTextBoxText(txtOtvet,"")
Controls.ShowControl(txtOtvet)
time=0
Timer.Resume()
Else '
Controls.HideControl("Button2")
Controls.ShowControl("Button1")
Timer.Pause()
If nKrug= Controls.GetTextBoxText(txtOtvet) then
s="!"
GraphicsWindow.BrushColor= "Yellow"
Else
430

s="!"
GraphicsWindow.BrushColor= "Red"
endif
GraphicsWindow.FontSize= 48
GraphicsWindow.DrawText(140,height/2-24, s)
EndIf
EndSub


, , , ,
:
btn=Controls.LastClickedButton

, , -
- . -
createTest, -
, -
.

, .

:
Sub createTest
' :
GraphicsWindow.BrushColor=BackgroundColor
GraphicsWindow.FillRectangle(0,40,width,height-40)
' ::
nKrug=Math.GetRandomNumber(30)+ 20
':
'GraphicsWindow.Title= nKrug
for i= 1 to nKrug
' :
radius=Math.GetRandomNumber(16)+ 20
' :
x = Math.GetRandomNumber(width-2*radius)
y = Math.GetRandomNumber(height-2*radius-40) + 40
' :
clr= GraphicsWindow.GetRandomColor()
GraphicsWindow.BrushColor=clr
' :
GraphicsWindow.FillEllipse(x, y, 2*radius,2*radius)
431

EndFor
EndSub

, ,
:
' :
GraphicsWindow.BrushColor=BackgroundColor
GraphicsWindow.FillRectangle(0,40,width,height-40)

GraphicsWindow.Clear , -
, , -
! -
.
, ,
, (.
34.3).

. 34.3. !

,
,
!
432


, .
21 50:
nKrug=Math.GetRandomNumber(30)+ 20

, , -
3 11.

,
, , -
:
':
'GraphicsWindow.Title= nKrug

.
, .

.
, ,
:
radius=Math.GetRandomNumber(16)+ 20

, -
, ,
:
x = Math.GetRandomNumber(width-2*radius)
y = Math.GetRandomNumber(height-2*radius-40) + 40

:
GraphicsWindow.FillEllipse(x, y, 2*radius,2*radius)

,
:
433

Controls.SetTextBoxText(txtTime,"")
Controls.ShowControl(txtTime)
Controls.SetTextBoxText(txtOtvet,"")
Controls.ShowControl(txtOtvet)
time=0
Timer.Resume()

, , -
, -
OnClick.

-
:
Timer.Pause()

,
txtOtvet, -
, (. 34.4):
If nKrug= Controls.GetTextBoxText(txtOtvet) then
s="!"
GraphicsWindow.BrushColor= "Yellow"
Else
s="!"
GraphicsWindow.BrushColor= "Red"
endif
GraphicsWindow.FontSize= 48
GraphicsWindow.DrawText(140,height/2-24, s)
EndIf

. 34.4. ! !
434

( !), -
- -
!

-
.

1.
, .
,
, .

2. , -
BackgroundColor="#2F4F4F"
.
, , , :

nextColor:
clr= GraphicsWindow.GetRandomColor()
If (clr=BackgroundColor) Then
Goto nextColor
EndIf
GraphicsWindow.BrushColor=clr

3. ,
,
. , -
, ,
. -
, .
, ,
. , ,
, :

n=0
nextXY:
435

radius=Math.GetRandomNumber(20)+ 35
x = Math.GetRandomNumber(width-2*radius)
y = Math.GetRandomNumber(height-2*radius-40) + 40
If (n< 100) and
(GraphicsWindow.GetPixel(x+radius,y+radius) <>
BackgroundColor) Then
n=n+1
Goto nextXY
EndIf

n? -
. 100
. ,
,
( -
, )
( !).
, .

,
-
. -
, -
,- .

!


.
436

35.

..

,
.
, -
, . -
: .

,
- . -
,
, .

,
, .

, -
,
!
( ).


, -
, .

, , -
.


(. 35.1, ):
437

GraphicsWindow.Title=" "

'const
BackgroundColor="MidnightBlue" '

, (. 35.1,
), :
BackgroundColor="Black"

:
btnStart=Controls.AddButton(" ", 10, 10)
Controls.ButtonClicked=OnClick

, , -
!

,
. 35.1.
, , , -
!


Sub OnClick
createSky()
EndSub,

createSky,
, :
438

Sub createSky
:
GraphicsWindow.BrushColor=BackgroundColor
GraphicsWindow.FillRectangle(0,40,width,height-40)
' :
nStar=Math.GetRandomNumber(100)+ 400
for i= 1 to nStar
' :
radius=Math.GetRandomNumber(2)
' :
x = Math.GetRandomNumber(width-2*radius)
y = Math.GetRandomNumber(height-2*radius-40) + 40
' :
r= Math.GetRandomNumber(163) + 92
g= Math.GetRandomNumber(163) + 92
b= Math.GetRandomNumber(163) + 92
clr= GraphicsWindow.GetColorFromRGB(r,g,b)
GraphicsWindow.BrushColor=clr
' :
GraphicsWindow.FillEllipse(x, y, 2*radius,2*radius)
EndFor
EndSub

,
. ,
:
GetRandomColor, . -
( ),
r, g, b, 93
( ) 255 ( ),
GetColorFromRGB:
clr= GraphicsWindow.GetColorFromRGB(r,g,b)

,
!


.
439

,
,
, -
.
.

-
, .
,
.

-
(. 35.2). ,
.

() -
:

btnAddOpenCluster=Controls.AddButton(" ",
100, 10)

-:
Sub OnClick
btn=Controls.LastClickedButton
If (btn= btnStart) then
createSky()
EndIf
If (btn= btnAddOpenCluster) then
createOpenCluster()
EndIf
EndSub

'
Sub createOpenCluster
' :
nStar=Math.GetRandomNumber(10)+ 7
' :
rOC=Math.GetRandomNumber(20)+20
' :
xOC = Math.GetRandomNumber(width-2*rOC)
yOC = Math.GetRandomNumber(height-2*rOC-40) + 40
440

for i= 1 to nStar
' :
radius=Math.GetRandomNumber(2)
' :
x = Math.GetRandomNumber(2*rOC)+xOC
y = Math.GetRandomNumber(2*rOC-40) + 40 + yOC
' :
clr=Math.GetRandomNumber(4)
If (clr= 1) Then
clr="White"
EndIf
If (clr= 2) Then
clr="AliceBlue"
EndIf
If (clr= 3) Then
clr="LightSkyBlue"
EndIf
If (clr= 4) Then
clr="DeepSkyBlue"
EndIf
GraphicsWindow.BrushColor=clr
' :
GraphicsWindow.FillEllipse(x, y,
2*radius,2*radius)
EndFor
EndSub

, -
(. 35.3)!

. 35.2.
441

. 35.3. !

2. , , ,
, ,
, ,
(. 35.4).

. 35.4.

,
, -
createSky.


.
442

36. !
,
!

, -
, -
.
(. 36.1).

, , - -
.
. -
!

!, ,
:

GraphicsWindow.Title=" !"

'const
BackgroundColor="#FFFFF0" 'Ivory
N_IMAGE=6

. . .

':
Timer.Interval=1000
Timer.Pause()
Timer.Tick=OnTick

. N_IMAGE,
. ,
:

path= Program.Directory +"/"


443

. 36.1. ,
444

ImageList ( ) -
LoadImage:
img[1]=ImageList.LoadImage(path+"1.png")
img[2]=ImageList.LoadImage(path+"2.png")
img[3]=ImageList.LoadImage(path+"3.png")
img[4]=ImageList.LoadImage(path+"4.png")
img[5]=ImageList.LoadImage(path+"5.png")
img[6]=ImageList.LoadImage(path+"6.png")

!
- .

- , -
2, .
!

OnClick :

Sub OnClick
btn=Controls.LastClickedButton
If btn="Button1" then '
Controls.HideControl(btnStart)
Controls.HideControl(txtOtvet)
createTest()
time=0
Timer.Resume()
Controls.SetTextBoxText(txtTime,": 0")
Controls.ShowControl(txtTime)
Else '
Controls.HideControl("Button2")
Controls.HideControl(txtTime)
Controls.ShowControl("Button1")
If nImage= Controls.GetTextBoxText(txtOtvet) then
s=" - " + nImage + "!"
GraphicsWindow.BrushColor= "Yellow"
Else
s=" - " + nImage + "!"
GraphicsWindow.BrushColor= "Red"
endif
GraphicsWindow.FontSize= 48
445

GraphicsWindow.DrawText(90,height/2-24, s)
EndIf
EndSub

, -
!

,
, -
!
Sub createTest
GraphicsWindow.BrushColor=BackgroundColor
GraphicsWindow.FillRectangle(0,40,width,height-40)
' :
nImage=Math.GetRandomNumber(30)+ 20
' :
w= ImageList.GetWidthOfImage(img[1])
h= ImageList.GetHeightOfImage(img[1])
':
'GraphicsWindow.Title= nImage
for i= 1 to nImage
' :
nImg=Math.GetRandomNumber(N_IMAGE)
' -->
n=0
nextXY:
' :
x = Math.GetRandomNumber(width-w)
y = Math.GetRandomNumber(height-h-40) + 40

' :
if (GraphicsWindow.GetPixel(x+w/2,y+h/2) <>
BackgroundColor) Then
Goto nextattempt
EndIf
':
If (GraphicsWindow.GetPixel(x,y) <> BackgroundColor) Then
Goto nextattempt
EndIf
If (GraphicsWindow.GetPixel(x+w,y) <> BackgroundColor)
Then
Goto nextattempt
446

EndIf
If (GraphicsWindow.GetPixel(x,y+h) <> BackgroundColor)
Then
Goto nextattempt
EndIf
If (GraphicsWindow.GetPixel(x+w,y+h) <> BackgroundColor)
Then
Goto nextattempt
EndIf
Goto place
nextattempt:
If (n< 100) Then
n=n+1
Goto nextXY
EndIf

place:
' :
GraphicsWindow.DrawResizedImage(img[nImg],x,y,w,h)
EndFor
EndSub

,
. 100
.
-
.

' :
Sub OnTick
time= time+ Timer.Interval/1000
Controls.SetTextBoxText(txtTime,": " + time)
If (time>= 10) Then
GraphicsWindow.BrushColor=BackgroundColor
GraphicsWindow.FillRectangle(0,40,width,height-40)
Timer.Pause()
Controls.ShowControl(btnProv)
Controls.ShowControl(txtOtvet)
EndIf
EndSub
447

, , -
(. 36.2). -
,
, .

. 36.2. !

, (. 36.3).

. 36.3. -!

, . , -
-
(. 36.4).

,
!
448

. 36.4. 6 -!


!
449

37. -

,

--!
, , !

-
, ,
- .

- 10
- (. 37.1). ,
,
, .
1,5 2 .
, -
, -
.

. 37.1. !

,

(. 37.2) -
, .
450

. 37.2. (1970)

-
, -
, (. 37.3).

. 37.3.

, , -
( , , -
). , ,
,
.


, .
.
451

, -
.

, -
. ,
. -
, , , -
.

, -
, -
- -
, . ,
, ,
.
, , -
, .

, -
, -
. , -

.

,
. ,
-. , -
,
. ,
37 ( 1
36 0 - ) .

, , -
, -
. -
,
, -
. -
, .
452

- .
1973
- -
, . -
,

. ,

-
.

- 1948 -
. ,
-
, - -
.

,
(, , -
).
GetRandomNumber Math.

, -
.

, 6 -
, :

',

GraphicsWindow.Title=" "

'const
BackgroundColor="#2F4F4F"
N_TARAKAN=6 '
' :
color[1]="Red"
453

color[2]="Yellow"
color[3]="Blue"
color[4]="Green"
color[5]="SandyBrown"
color[6]="LavenderBlush"
' :
perevodStroki=Text.GetCharacter(13) + Text.GetCharacter(10)

-
:

'var
' :
x[1]=0
y[1]=0
zdor[1]=0 '
startTime=0'
' :
flgStart="False"
flgFinish = "False"
' :
xStart= 10
yStart=40
' :
dy= 32
' :
wTar= 32
hTar= 16

, -
:

GraphicsWindow.Hide()
GraphicsWindow.Width= 640
GraphicsWindow.Height=480
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"
GraphicsWindow.BackgroundColor= BackgroundColor

height=GraphicsWindow.Height
454

width= GraphicsWindow.Width

. -
10 (0,01 ) :
':
Timer.Interval= 10
Timer.Pause()
Timer.Tick=OnTick

, ,
txtTime - OnTick:

' :
Sub OnTick
t= Clock.ElapsedMilliseconds - startTime
s= ": " + t/1000
Controls.SetTextBoxText(txtTime,s)
EndSub

, -
ElapsedMilliseconds Clock.

-
!:

'

' :
btnStart=Controls.AddButton(" !", 10, height-32)
Controls.ButtonClicked=OnClick

-
. , -
:

'

' :
txtTime=Controls.AddTextBox(340, 10)
Controls.SetSize(txtTime,100,26)
Controls.HideControl(txtTime)
455

':
txtWin=Controls.AddMultiLineTextBox(10, 300)
Controls.SetSize(txtWin,320,100)
Controls.HideControl(txtWin)

-
:

flgStart="False"
flgFinish = "False"
prepare()

prepare -
.
. ? -,
, . -, :
, , ,
.
,
( ),
, AddEllipse AddImage.


zdor.


,
!

'
Sub prepare
For i= 1 to N_TARAKAN
' :
clr= color[i]
GraphicsWindow.BrushColor= clr
GraphicsWindow.PenColor=clr
' :
Shapes.HideShape(tar[i])
' :
tar[i]=Shapes.AddEllipse(wTar, hTar)
' :
456

x[i]= xStart
y[i]= yStart + dy * (i-1)
Shapes.Move(tar[i], x[i], y[i])
' :
zdor[i]= Math.GetRandomNumber(30)/100 + 1.2
endFor
' :
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(xStart+wTar,yStart, xStart+wTar,
y[N_TARAKAN]+ hTar)

' :
GraphicsWindow.PenColor="Green"
xFinish=width-wTar
GraphicsWindow.DrawLine(xFinish, yStart, xFinish,
y[N_TARAKAN]+ hTar)
' :
Controls.HideControl(txtWin)
endSub

' :
While (flgFinish = "False")
' " !":
If flgStart="True" then
' :
calcNewCoords()
' :
For i= 1 to N_TARAKAN
Shapes.Move(tar[i], x[i], y[i])
endFor
' :
Program.Delay(20)
' , :
testFinish()
endIf
endWhile

, -
flgFinish True.
457

,
flgStart False. , -
.
!, -
:

'
Sub OnClick
Controls.HideControl(btnStart)
Controls.ShowControl(txtTime)
' :
time=0
Controls.SetTextBoxText(txtTime,": " + 0)
' :
Timer.Resume()
' :
startTime=Clock.ElapsedMilliseconds
' :
flgStart="True"
EndSub

- OnClick
.

flgStart="True" ,
. calcNewCoords -
.

,
, -
.
, -
. :

'
Sub calcNewCoords
For i= 1 to N_TARAKAN
' :
dx= Math.GetRandomNumber(43)/10 + 0.9
' :
x[i] = x[i] + dx*zdor[i]
458

endFor
endSub

,
, ,
-
, . , -
, , -
.

testFinish, -
, , ,
. , -
. -
: , -
:

'
Sub testFinish
xEnd=0
n=0
For i= 1 to N_TARAKAN
if (x[i] >= xFinish-wTar) Then
flgFinish="True"
Timer.Pause()
If (x[i] > xEnd) then
' :
n= i
xEnd= x[i]
EndIf
endif
endFor
If (flgFinish="True") then
s= " # " + n + "!"+ perevodStroki
t= Clock.ElapsedMilliseconds - startTime
Controls.SetTextBoxText(txtTime," :" + t/1000)
s=s+ " : " + t/1000 + " ."
flgStart="False"
Controls.SetTextBoxText(txtWin, s)
Controls.ShowControl(txtWin)
Controls.ShowControl(btnStart)
' :
459

While (flgStart="False")
EndWhile

' :
flgFinish ="False"
Controls.SetTextBoxText(txtTime," " + 0)
' :
prepare()
endIf
endSub

, -
(. 37.4) . -
, ,
.

. 37.4. , !

, ,
, -
, .
,
!
460

-
.

2010
-
(),
,
(. 37.5).

. 37.5. ,

,
. - 8 . -
461

- , -
.

,
. , -
,
.

, ,
-
.
,
.
, , , , -
, , -
, .


, .

, -
.
, -

, ()2 = , - ()8 = 1/256. 256
.
, ,
(
5 36 1/45 239 040, 6 49 -
1/10 068 347 520).

-
, , -
, .

-
, .
462

-
.

'

GraphicsWindow.Title=" "

'const
' :
perevodStroki=Text.GetCharacter(13) + Text.GetCharacter(10)

'var
' :
team1=""
team2=""

GraphicsWindow.Hide()
GraphicsWindow.Width= 440
GraphicsWindow.Height=270
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"

height=GraphicsWindow.Height
width= GraphicsWindow.Width

background = ImageList.LoadImage(Program.Directory +
"/paul.jpg")
GraphicsWindow.DrawImage(background, 0, 0)

':
GraphicsWindow.BrushColor="Red"
GraphicsWindow.BrushColor="Green"
GraphicsWindow.FontBold="True"
GraphicsWindow.FontSize=16

,
(. 37.6).
463

. :
-
. , , . 37.6:

'

' :
btnStart=Controls.AddButton("!", 10, height-32)
Controls.ButtonClicked=OnClick

'

' :
txtTeam1=Controls.AddTextBox(10, 10)
Controls.SetSize(txtTeam1,160,26)
GraphicsWindow.DrawText(180, 14, "<- ")

txtTeam2=Controls.AddTextBox(10, 48)
Controls.SetSize(txtTeam2,160,26)
GraphicsWindow.DrawText(180, 52, "<- ")

GraphicsWindow.BrushColor="Red"

' :
txtWin=Controls.AddMultiLineTextBox(10, 180)
Controls.SetSize(txtWin,300,50)

GraphicsWindow.Show()

'
Sub OnClick
s1= Controls.GetTextBoxText(txtTeam1)
s2= Controls.GetTextBoxText(txtTeam2)
If (s1="") Or (s2="") Then
s= " !"
ElseIf (team1=s1) And (team2=s2) Then
s= " !"
ElseIf (s1=s2) Then
s= " !"
Else
464

team1=s1
team2=s2
If (Math.GetRandomNumber(2)=1) Then
s= " " + team1
Else
s= " " + team2
EndIf
EndIf
GraphicsWindow.BrushColor="Blue"
s= s + perevodStroki + " !"
Controls.SetTextBoxText(txtWin, s)
EndSub

-
, -
.
GetRandomNumber, .

. 37.6. !

, ,
,
.
, , -
465


. ,
!

-
-.

S - -
, () -
().

(. 37.7) L (
, ) -
,
( ,
).

-
, . ,

.

N ( . 37.7,
), P ( ),
.
L2, S, :

L2/ S = N / P, S:

S = L2 * P / N (1)
466

, -
(1) , ,
, N .

, ( )
,
, , -
, -
. .

. 37.7.

. ,
-
. -
, . -
, ,
.

N -
, P (. 37.8).
467

. 37.8. ,

P N :

-, ,
. -
:

' -

'const
BackgroundColor="MidnightBlue" '
' :
dx=10
dy=50

'var
' :
468

N=10000
' , :
P=0
' :
D=400
D2= D*D
' :
R= D/2
' :
xc=0
yc=0

,
, !

GraphicsWindow.Title=" -"
GraphicsWindow.Hide()
GraphicsWindow.Width= 410
GraphicsWindow.Height=450
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"
GraphicsWindow.BackgroundColor= BackgroundColor

height=GraphicsWindow.Height
width= GraphicsWindow.Width

,
.
,
:

' A
btnStart=Controls.AddButton("!", 10, 10)
Controls.ButtonClicked=OnClick

'
':
txtPi=Controls.AddTextBox(100, 10)
Controls.SetSize(txtPi,200, 24)
469

'
Timer.Interval= 100
Timer.Pause()
Timer.Tick=OnTick

GraphicsWindow.Show()

' :
clr="Green"
GraphicsWindow.BrushColor = clr
GraphicsWindow.PenColor = "Black"
GraphicsWindow.FillRectangle(dx, dy, D, D)
' :
clr="Blue"
GraphicsWindow.BrushColor = clr
GraphicsWindow.FillEllipse(dx, dy, D, D)
' :
xc= D/2 + dx
yc= D/2 + dy

.
! , -
.

, -
.

Sub OnClick
' :
Timer.Resume()
' :
P=0
setPoints()
EndSub

-
setPoints:

'
Sub setPoints
470

for i= 1 to N
' :
x = Math.GetRandomNumber(D) + dx - 1
y = Math.GetRandomNumber(D) + dy - 1
xx= xc - x
yy= yc - y
' ?
If (xx*xx + yy*yy <= R*R) Then '
p=p+1
clr= "Red"
Else '
clr= "Yellow"
EndIf

' :
GraphicsWindow.BrushColor=clr
' :
GraphicsWindow.FillEllipse(x, y, 2,2)
EndFor
EndSub

, (x, y)
, -
r (. 37.9):

r >= 0, -
:

r R. r <= R,
, .
471

. 37.9. !

.
, ,
(x,y).
, ,
.

, ,
.
, .

,
,
. 37.10. -
, -
(
160 000 , ).
472

. 37.10. N= 10 000 N= 160 000

-
, .
, -
, .
,
, ,
. , -
, -
. ,
, GetRandomNumber, - ,
, -
. -
, ,
,
.


-.
473

1. . -
.

2. , -
.

3.
( ).
.
( -
, ). -
, -
. , -
, ,
. ,

1/6. ,
1 - 1/6 = 5/6 = 0,833.
(5/6)2 = 0,694, - (5/6)6 = 0,335, , -
( -
!). -
, -
.

4. -,
, ,
, -
.
, -
,
(. 37.11). -
, -
.
.
474

-, -
, -
. -
, -
, -
.

. 37.11. !
475

38.

:
,
. ,
,
(- backtracking).

8
, ,
1 1 (.
38.1). ,
, - -
. ,
.

. 38.1. 1 1

- -
.

2 2 . -
, (.
38.2).

. 38.2. 2 2

,
. , ,
. -
(. 38.3).
476

. 38.3.

,
, -
, . -
.

,
. ,
, , -
(. 38.4).

. 38.4.

(. 38.5).

. 38.5. -

, ,
. , ,
- . -
,
. ,
.
, -
(. 38.6).
477

. 38.6.

.
(. 38.7).

. 38.7. !

. -
?
(. 38.8).

. 38.8. !

-
. ,

. . -
, -
. ,
2 2 . .

, -
3 3 ,
,
, .
478

-
:

'

'var
cols=8 ' ( )
rows=8 ' ( )
nLad=8 '
n=0 '
vert[0] = 0 ' = 1..rows - ,

v=0 '
resolution= "False" ' : = True,

nVar=0 '

, cols rows
nLad.
,
. , ,
, ,
. ,
2 2, -
.
8 8. -

.

n -
.
, -
. , , -
vert. ,
vert[1] ( -
!). - vert[2] ,
. , -
v, .
479

resolution . (-
True), n v.
v
test.

nVar
.

' :
n=0

. , , -
. ,
, . -
, nextLad , -
:

nextLad:
n=n+1

,
,
:

If (n > nLad) Then


Goto writeVar
EndIf

,
, , -
. ,
, -
, :

v=0
nextVert:
480

v=v+1
If (v > cols) Then
Goto back
EndIf

, , -
, . -
back.

test()
If resolution="False" then
Goto nextVert
EndIf
vert[n]= v
Goto nextLad

, n v.
,
test. ( test
resolution), nextVert, -
. -
test resolution, n
,
vert. nextLad,
.

-
:

writeVar:
nVar = nVar +1
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" # " + nVar)
TextWindow.ForegroundColor="Yellow"
For i= 1 To nLad
TextWindow.Write(vert[i]+ " ")
EndFor
TextWindow.WriteLine("")
TextWindow.WriteLine("")

4 4 (. 38.9).
481

. 38.9. 4 4


(. 38.10).

. 38.10. ,

.
,
482

. - -
.

, ,
,
:

back:
n=n-1
If (n = 0) Then
Goto end
EndIf
v= vert[n]
Goto nextVert

, -
. -

:

end:
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" " + nVar)
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"

test:

' :
' n v
Sub test
resolution= "True"
If (n = 1) Then
Goto exit
EndIf
For i= 1 To n-1
If (vert[i]=v) then
resolution= "False"
Goto exit
EndIf
EndFor
exit:
483

EndSub

. resolution
, , -
,
. , , -
, v .
, .
.

, -
:



11 1
22 2
33 6
44 24
55 120
66 720
77 5040
88 40320

,
, . -
, n x n, -
n , (n-1)
, - (n-2) , , - -
-.
, , , ,
n!
!

.
484

, -
, . -
, -
.

,
() .
485

39.

,
, .
, , -
.

1848
Schachzeitung ( -
, , !).
. 1854
40 . 21
1850
92 . , ,
.

, -
,
- ,
1850 76 .

.
, ,
.
. ,
1 2 3 4 5 6 7 8. ,
, , -
, .
, -
, -
.

-
: 8! = 40320. , , -
, -
, -
.
486

-
. 5 5
, , 1 3 4 5 2.
, , -
1 5 ( -
)
:

13452 13452
12345 54321
25797 67773


( , ).

, -
, -
. -
, , -
. -
(. 39.1).

. 39.1. ,
1 3 4 5 2

, . -
1..8 ( 1..5,
5 5 ),
,
487

. ,
8 8 -
.

. -
, ,
,
. , ,
, -
,
.

,
.

,
, ,
.
test:

':
' n v
Sub test
resolution= "True"
If (n = 1) Then
Goto exit
EndIf
For i= 1 To n-1
' :
If (vert[i] =v ) then
resolution= "False"
Goto exit
EndIf
' :
If (vert[i]-i=v-n) then
resolution= "False"
Goto exit
EndIf
488

If (vert[i]+i=v+n) then
resolution= "False"
Goto exit
EndIf
EndFor
exit:
EndSub

- ,
, . ,
, ,
, . -
, , -
,
, .


,
92- ( 39.2).

. 39.2. !

,
, 10 10 :
489



11 1
22 0
33 0
44 2
55 10
66 4
77 40
88 92
99 352
10 10 724

,
, .

92 12 ,
,
90
(. 39.3).

10- 3 ,
7. -
92 .

, , .
90 ,
(. 39.4, ). (-
) , 4 -
(. 39.4, ).
8 .
490

. 39.3. 12 .
491

. 39.4. ,

, -
, -
, ,
.

,
, 12 , -
, -
(, !). 11-
. 39.3.

,
() .
492

40.

, -
. , -
.
, -
. . ,
-
, :



----

, (,
, ) -
, -
.


-
. ,
. brute force, -
, -
.
, . , -
, -
. ,

,
-
, .

- exhaustive search - -
.
493

. -
8 64-
64*63*62*61*60*59*58*57 = 178 462 987 637 760. ,
64 , -
63 , . ,
,
.


. -
, , ,
10 - 0 9. -
,
10 000 000 000 .
. , -
, -
.
, -
. -
,
, -
8*8*8*8*8*8*8*8 = 16 777 216,
.

-
,
. -
: . -
. , ,
, ,
.

, ,
. For,
. 6 , -
. , -
, -
494

. ,
:

1000*O + 100*D + 10*I + n + 100*D + 10*V + A <> 1000*A + 100*N


+ 10*O + D

(
), , -

:
'
'

'var
nVar=0 '

TextWindow.Show()

For A= 1 to 9

For V= 0 to 9
If (V=A) Then
Goto nextV
EndIf

For D=1 to 9
If (D=A) Or (D=V) Then
Goto nextD
EndIf

For I= 0 to 9
If (I=A) Or (I=V) Or (I=D) Then
Goto nextI
EndIf

For N=0 to 9
If (N=A) Or (N=V) Or (N=D) Or (N=I) Then
Goto nextN
EndIf

For O=1 to 9
If (O=A) Or (O=V) Or (O=D) Or (O=I) Or (O=N) Then
495

Goto nextO
EndIf
If (1000*O + 100*D + 10*I + n + 100*D + 10*V + A
<> 1000*A + 100*N + 10*O + D) Then
Goto nextO
Else
writeSolution()
EndIf
nextO:
endFor
nextN:
endFor
nextI:
endFor
nextD:
endFor
nextV:
endFor
nextA:
endFor
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" " + nVar)
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"

' :
Sub writeSolution
nVar = nVar +1

TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" # " + nVar)
TextWindow.ForegroundColor="Yellow"

s=""
s= Text.Append(s, O)
s= Text.Append(s, D)
s= Text.Append(s, I)
s= Text.Append(s, N)
TextWindow.WriteLine(s)
s=" "
s= Text.Append(s, D)
s= Text.Append(s, V)
s= Text.Append(s, A)
TextWindow.WriteLine(s)
496

s=""
s= Text.Append(s, A)
s= Text.Append(s, N)
s= Text.Append(s, O)
s= Text.Append(s, D)
TextWindow.WriteLine(s)

TextWindow.WriteLine("")
TextWindow.WriteLine("")
EndSub

(. 40.1).
, -
!

,
, A, D, O -
. ,
. , , D > 4, H <> 0.
, -
,
, .

. 40.1. !
497


Alphametics.


- !
- !
- , ! .

, -
,
. -
.

, , . ,
.


.
10 -
. 10 + 26 + 26 = 62 -
. 62 . -
, . -
: 62 62 = 3844 ,
, -
6 , 626= 56 800 235 584 .
16 -
. 6216 = 4 767 240 170 682 353 345 026 330 816,
.

?
, . -
,
,
, , ,
.
498

, , , -
, ,
. , - , A8xGzOAgm7
, -
.

, , -
,
, . , -
, -
.
.

, -
.

, ,
.
, -
- . , , ,
, . , ,
. -
,
.

, ,
, .

,
:
, . -

,
. ,
.

, -
!
499

,
. !
,
.

,
.

, -
. SYMBOLS
, . ,
- .

'const
SYMBOLS ="1234567890abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ"
MAX_LEN= 16 ' .

'var
pass= "" '

GraphicsWindow.Title=" "

GraphicsWindow.Hide()
GraphicsWindow.Width= 320
GraphicsWindow.Height=140
GraphicsWindow.Left= (Desktop.Width - GraphicsWindow.Width) /
2
GraphicsWindow.Top = (Desktop.Height - GraphicsWindow.Height)
/ 2
GraphicsWindow.CanResize="False"
GraphicsWindow.BackgroundColor= "Black"

height=GraphicsWindow.Height
width= GraphicsWindow.Width


-
:

'
500

'Button:
btnGen=Controls.AddButton("!, 10, 80)
Controls.ButtonClicked=OnClick

'
GraphicsWindow.FontSize= 12
' :
txtLen=Controls.AddTextBox(10, 10)
Controls.SetSize(txtLen,30,20)
Controls.SetTextBoxText(txtLen, 6)
GraphicsWindow.DrawText(70,12, " 1.." +
MAX_LEN)
' :
txtPass=Controls.AddTextBox(10, 40)
Controls.SetSize(txtPass,140,20)
Controls.SetTextBoxText(txtPass, "***************")

, .
, -
. -
!,
. ,
.

'
Sub OnClick
' :
len=Controls.GetTextBoxText(txtLen)
' :
if (len < 1) Then
len = 1
EndIf
if (len > MAX_LEN) Then
len = MAX_LEN
EndIf
Controls.SetTextBoxText(txtLen, len)
pass=""
For i= 1 To len
' :
n= Math.GetRandomNumber(Text.GetLength(SYMBOLS))
501

ch= Text.GetSubText(SYMBOLS,n,1)
pass= Text.Append(pass, ch)
EndFor
Controls.SetTextBoxText(txtPass, pass)
EndSub


OnClick -
pass.
, -
(. 40.2).

. 40.2. !

.
502

1. 283 189 = 53487


2. 1343 6 = 8058
3. 304072 + 304072 = 608144
503

41. ,

- ?
- .
- , ,
?
- .
- , , ,
!
?



,

.



.


,
, ,
( , ).
.
,
. ,
,
.

,
.

n.
,
504

.
, .

:
'

TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" ")
TextWindow.WriteLine("")
TextWindow.Show()

'n -
n= 3
pop()

TextWindow.ForegroundColor="Red"

'
Sub pop
'n -

if n <= 0 then
Goto exit
endif
TextWindow.ForegroundColor="Yellow"
TextWindow.WriteLine(" , ,")
TextWindow.WriteLine(" , .")
TextWindow.WriteLine(" :")
TextWindow.WriteLine("")

n= n-1
pop()

exit:
EndSub

,
. n
, .
1 , n

505

n= n-1

pop

pop()

1 ,
:

n= 3
pop()

, pop 3 (
),
,
, :

n=3
n=2
n=1
n=0

n <= 0,
(. 41.1).

. 41.1. n=3
506

pop
While, ,
:

Sub popWhile
'n -
While n > 0
TextWindow.ForegroundColor="Yellow"
TextWindow.WriteLine(" , ,")
TextWindow.WriteLine(" , .")
TextWindow.WriteLine(" :")
TextWindow.WriteLine("")
n= n-1
EndWhile
EndSub

pop popWhile:

n= 3
'pop()
popWhile()

, ,
.

Pop.


,
. pop
:

n= 3
pop(n)
507

pop(3)

, -
,
.
, -
, -
.

, . -
pop(3) ( )
,
.
, -
. -
.

-
,
.

Stack

.
.

, .
(. 41.2).

. 41.2.

, (. 41.3-6).
508

. 41.3.

. 41.4.

. 41.5.
509

. 41.6.

, -
.


. -
, .
.

(,
),
.
Stack. Stack . -
, .

,
. ,
.
510

, :

'var
_stack="Stack"

, -
_stack. , , ,
,

Stack.GetCount(stackName),

-
stackName.

n= Stack.GetCount(_stack)

n .

n= Stack.GetCount("Stack")

, , , -
.

- ,

Stack.PushValue(stackName, value)

, 1:

Stack.PushValue(_stack, 1)

,
.
511

-
:

For i= 1 to 12
Stack.PushValue(_stack,i)
endfor
Stack.PushValue(_stack," ")

, ,
, ,
. ,
. ,
(
,
, -
),
, .
,

Stack.PopValue(stackName)

, .
,
,
. .

12 :

For i= 1 to 12
Stack.PushValue(_stack,i)
endfor
Stack.PushValue(_stack," :")

, :

writeStack()

Sub writeStack
TextWindow.ForegroundColor = "Red"
TextWindow.WriteLine(" :")
512

TextWindow.ForegroundColor = "Yellow"
n= Stack.GetCount(_stack)
For i = 1 to n
TextWindow.WriteLine(Stack.PopValue(_stack))
EndFor
TextWindow.WriteLine("")
EndSub

TextWindow.ForegroundColor = "Red"

, ,
(. 41.7).

. 41.7.

: ?
PopValue, -
. , , ,
. ,
. , ,

_stack2="Stack2"

Sub writeStack
TextWindow.ForegroundColor = "Red"
TextWindow.WriteLine(" :")
TextWindow.ForegroundColor = "Yellow"
513

n= Stack.GetCount(_stack)
For i = 1 to n
obj= Stack.PopValue(_stack)
TextWindow.WriteLine(obj)
Stack.PushValue(_stack2, obj)
EndFor
TextWindow.WriteLine("")
For i = 1 to n
obj= Stack.PopValue(_stack2)
Stack.PushValue(_stack, obj)
EndFor
EndSub

,
, , -
(. 41.8).

. 41.8.


(,
) , ,
514

. ,
, -
, :

For i = 1 to n
obj= Stack.PopValue(_stack2)
Stack.PushValue(_stack, obj)
EndFor

,
,

_stack3
:
_stack3 =_stack
_stack3 =_stack2

_stack3 ,
, .

Stack.

-
, pop
.

'
'

'var
_stack= "Stack"
515

TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" ")
TextWindow.WriteLine("")
TextWindow.Show()

n , -
pop:
'n -
n= 3
Stack.PushValue(_stack, n)
pop()

TextWindow.WriteLine("n= " + n)

TextWindow.ForegroundColor="Red"

, -
:

Stack.PushValue(_stack, 3)

pop
n. -
- n-1 :

'
Sub pop
'n -
n= Stack.PopValue (_stack)
if n <= 0 then
Goto exit
endif
TextWindow.ForegroundColor="Yellow"
TextWindow.WriteLine(" , ,")
TextWindow.WriteLine(" , .")
TextWindow.WriteLine(" :")
TextWindow.WriteLine("")

Stack.PushValue(_stack, n-1)
pop()

exit:
516

EndSub

TextWindow.WriteLine("n= " + n)

, n -
(. 41.9).

. 41.9.

, , -
.

-
, .

1. . -
, -
, -
n:
n= 3
Stack.PushValue(_stack, n)
Stack.PushValue(_stack, n)
pop()
n= Stack.PopValue(_stack)

2. :
517

n= 3
m= n
Stack.PushValue(_stack, n)
pop()
n= m

3. :

Sub pop
pop_n= Stack.PopValue(_stack)
if pop_n <= 0 then
Goto exit
endif
TextWindow.ForegroundColor="Yellow"
TextWindow.WriteLine(" , ,")
TextWindow.WriteLine(" , .")
TextWindow.WriteLine(" :")
TextWindow.WriteLine("")

Stack.PushValue(_stack, pop_n-1)
pop()

exit:
EndSub

- -
, pop_n . -
- -
, : -
.

Stack.



.
518

Factorial,
.
,
:

'
'
'

'variables
number=0
fact=0
_stack= "Stack"

'=========================================
'
'=========================================
start:
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" 0..27 > ")
number=TextWindow.ReadNumber()

' -->

' ,
' :
if (number < 0) then
goto exit
EndIf

if (number > 27) then


TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" 0 27!")
goto start
EndIf

number , -
Factorial, -
. fact
. -
(. 41.10):
519

Stack.PushValue(_stack, number)
Factorial()
' :
fact = Stack.PopValue(_stack)

TextWindow.WriteLine("")
TextWindow.ForegroundColor="Green"

'
' number:
TextWindow.WriteLine(number + "! = " + fact)

exit:
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
Goto start

Factorial
. ,
. , 1 0,
Factorial 0.
.

.
1 1 = 1.
, .

'
' number
Sub Factorial
'

' :
n=Stack.PopValue(_stack)
' ,
' 1:
If (n = 0) Then
Stack.PushValue(_stack,1)
Else
'
'Factorial = n * Factorial(n-1):
520

Stack.PushValue(_stack,n)
Stack.PushValue(_stack,n-1)
' n-1:
Factorial()
' n * (n-1)!:
Stack.PushValue(_stack, Stack.PopValue(_stack) *
Stack.PopValue(_stack))
EndIf
EndSub

. 41.10.

n=2.
Factorial 2,
n. .

n > 2, Else: 2
1. : 1 2.

Factorial.
(1) n = 1. .

n > 1, Else:
1 0. : 0 1 2.
521

Factorial.
(0) n = 0. 1 2. n =
0 . : 1 1 2.

Factorial .

Stack.PushValue(_stack, Stack.PopValue(_stack) *
Stack.PopValue(_stack))

,
- 1 2.

Factorial.
,
: 2.

Factorial ,

' :
fact = Stack.PopValue(_stack)


,
,
, - .

writeStack:

Sub writeStack
TextWindow.ForegroundColor = "Yellow"
ws_n= Stack.GetCount(_stack)
If (ws_n=0) Then
TextWindow.WriteLine(" !")
Else
For i = 1 to ws_n
obj= Stack.PopValue(_stack)
522

TextWindow.Write(obj + " ")


Stack.PushValue(_stack2, obj)
EndFor
TextWindow.WriteLine("")
For i = 1 to ws_n
obj= Stack.PopValue(_stack2)
Stack.PushValue(_stack, obj)
EndFor
EndIf
EndSub

Stack.

Factorial,
, ,
:

Sub Factorial
n=Stack.PopValue(_stack)
TextWindow.WriteLine("")
TextWindow.WriteLine("n= " + n)
TextWindow.Write("1. ")
writeStack()
If (n = 0) Then
Stack.PushValue(_stack,1)
TextWindow.Write("2. ")
writeStack()
Else
Stack.PushValue(_stack,n)
Stack.PushValue(_stack,n-1)
TextWindow.Write("3. ")
writeStack()
Factorial()
Stack.PushValue(_stack, Stack.PopValue(_stack) *
Stack.PopValue(_stack))
TextWindow.Write("4. ")
writeStack()
EndIf
EndSub

_stack2="Stack2"
523

start:
vyzov=0

,
(. 41.11).

. 41.11. . 41.12.

,

,
(. 41.12).

FactorialR.
524


.
, , .
(.
41.13), ,

.

. 41.13. Number = 20


FibonacciR.
525

42.


,

, -
? , -
. , -
,

. ,
.

:
- ,
.
- .

,
, .
,
, -
, .

( -
, , , !), -
. , -
,
.

()
18 841 916 1 485
16 492 800 289,44
18 140 670 3530
8 566 823 1538,9
8 742 995 621,9
13 922 125 603
- 13 356 715 4000
526

12 725 000 815


12 285 000 636
11 954 217 1483
10 562 099 1081
10 421 782 605,4
10 076 099 10 550
- 10 037 593 1520
9 360 883 999
8 576 788 660
- 8 140 993 1214
8 057 397 804,3
7 947 121 210
7 712 104 1370
7 581 052 1580
7 137 849 1590
7 102 354 1104
6 897 547 660
6 747 238 1010
6 431 839
-- 6 193 265 1180

5 698 435 1100


5 180 533 230
5 090 824
5 021 458
4 974 232 699
4 886 305
- 4 606 888
- 4 600 310 1439

4 562 843
4 406 788
4 305 536
4 262 236 400
4 247 414 2680
4 149 487
4 114 710 1212
4 082 050
3 980 938 170
- 3 975 590 1290
3 882 639 2500
3 915 259
3 900 546 -
3 899 140 771
3 867 336 190
3 682 177
3 667 982
3 599 000
3 573 721
3 528 690
527

,
. -
,
, ,
. -
, ,
. ,
( ) .

, ,
. -
(. .) (
, -
), .txt
UTF-8.

,
. -
( ,
!), -
. -
,
. , .

, spisok,
:

'

'variables
spisok[0]="" '-
nWords=0 '
chr="" '
len=0 '
txt="" '

index=0 '
528

beg=0 '

, -
:

flgChain[0] = "False" ' True, ,



begLetter[0]="" '
endLetter[0]="" '
n=0 '
maxChain=0 '.
idWord[0]=0 ' ,
id=0 ' ,
'


,
spisok:

'=========================================
'
'=========================================
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" ")
TextWindow.WriteLine("")
TextWindow.Show()

' :
fileName= ".txt"
readFile()

readFile ,
.
, spisok,
nWords.

-
begLetter endLetter .
, ,
,
( -
529

, -
). -
, -
, .
, -
. -
,
:
. , -
. flgChain
False, -
, True - .

, , -
:

' :
for i=1 to nWords
begLetter[i]= Text.GetSubText(spisok[i],1,1)
len= Text.GetLength(spisok[i])
endLetter[i]= Text.GetSubText(spisok[i],len,1)
' :
flgChain[i] = "False"
EndFor

' :
maxChain=0
' :
n=0

:
. , -
,
. , -
-
, ,
, .
530

: -
: ( -
), , .
, , - .

' :
nextWord:
n=n+1

, ,
. -
spisok. -
. ,
,
. , ,
, -
.

idWord[n]=0
id=0
nextId:
id= id+ 1
If (id > nWords) Then
Goto back
EndIf

: ,
.
, :

test()
If resolution="False" then
Goto nextId
EndIf

, -
, -
, -
. ,
, -
531

, .
, , -
, :

':
'
Sub test
resolution= "True"
If (n = 1) Then
Goto exit
EndIf
' :
If (flgChain[id] = "True") Then
resolution= "False"
Goto exit
EndIf
'
' :
If (begLetter[id] <> endLetter[idWord[n-1]]) Then
resolution= "False"
Goto exit
EndIf
exit:
EndSub

resolution -
False, , True .

. .
. idWord
, ,
flgChain , -
.
,
.
. maxChain,
. ,
.
, ,
,
.
532

' :
idWord[n]=id
flgChain[idWord[n]]= "True"
' :
If (n > maxChain) Then
maxChain= n
writeChain()
EndIf

Goto nextWord

n > maxChain -
. -
. , -
n >= maxChain.

n -
.
idWord[i], i- -
.

Sub writeChain
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" = " + n)
TextWindow.ForegroundColor="Yellow"
For i= 1 To n
TextWindow.WriteLine(spisok[idWord[i]])
EndFor

TextWindow.WriteLine("")
TextWindow.WriteLine("")
TextWindow.Read()
endsub

, -
: n=2. :
id=1. :
. : id= 2.
. ,
. -
.
533

, -
. . ,
-. ,
: ,
. !

back:
' :
n=n-1
If (n = 0) Then
Goto end
EndIf

id= idWord[n]
' n :
flgChain[idWord[n]]= "False"
Goto nextId

:
, -
,
, (
!)
.

, -
, ,
, -
. , -
!


15 (. 42.1).

.
534

. 42.1. ?

-
, ,
-
. Chain-
word
.

, -
, - -
.txt.

(
!), , -

(. 42.2).
535

. 42.2. !

-
.

, -
,
, . -
, :

'
Sub randomize
For i= 1 to nWords
n1= Math.GetRandomNumber(nWords)
n2= Math.GetRandomNumber(nWords)
s= spisok[n1]
spisok[n1]= spisok[n2]
536

spisok[n2]= s
endfor

randomize:

' :
fileName= ".txt"
readFile()
randomize()


(. 42.3).

. 42.3.


, , -
537

. ,
, -
-
!


Chainword.


. ,
.

, -
. ,
.
.

'

'variables
spisok[0]="" '-
nWords=0 '
chr="" '
len=0 '
txt="" '

index=0 '
beg=0 '

flgChain[0] = "False" ' True, ,



gorod="" '
lenChain=0 '
_stack = "Stack" '

538

-
. 3.txt -
. ,
. -
. ,
, .

,
:

'=========================================
'
'=========================================
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" ")
TextWindow.WriteLine("")
TextWindow.Show()

' :
fileName= "3.txt"
Stack.PushValue(_stack,fileName)
readFile()

readFile
, , :

'
Sub readFile
' :
txt= Stack.PopValue(_stack)
txt= File.ReadContents(txt)
. . .
EndSub

,
-:

'
startGame:
randomize()
' :
for i=1 to nWords
539

flgChain[i] = "False"
EndFor
' :
lenChain=0

, .
:

'
hodIgroka:
TextWindow.ForegroundColor="Yellow
TextWindow.WriteLine("")
TextWindow.Write(" > ")
gorod= Text.ConvertToUpperCase(TextWindow.Read())

,
,
.

, ,
,
( ,
). ,
.

, (
),
.

, -

!

,
:

':
flg="False"
For i=1 to nWords
If gorod = spisok[i] Then
flg="True"
540

Goto test_exit
EndIf
endfor
test_exit:
If (flg="False") then
TextWindow.ForegroundColor="Red"
TextWindow.Write(" !")
goto hodIgroka
ElseIf (flgChain[i]= "True") then
TextWindow.ForegroundColor="Red"
TextWindow.Write(" !")
goto hodIgroka
ElseIf (lenChain > 0) and (Text.GetSubText(spisok[i],1,1) <>
endLetter) Then
TextWindow.ForegroundColor="Red"
TextWindow.Write(" !")
goto hodIgroka
EndIf

, , ,
. -
, . -

endLetter .

.
(, ),
, .
, -
.

-
:

' :
flgChain[i]= "True"
lenChain= lenChain + 1
len= Text.GetLength(spisok[i])
endLetter= Text.GetSubText(spisok[i],len,1)
' "" ,
' :
While (len >= 2) And (endLetter= "" Or endLetter= "")
541

len=len-1
endLetter= Text.GetSubText(spisok[i],len,1)
endwhile

TextWindow.WriteLine("")
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" #" + lenChain + " ")
TextWindow.ForegroundColor="Green"
TextWindow.WriteLine(gorod)

. , , ,
.


test.
.

-
test_n.
, : -
, -
. resolution ( -
) :

':
'
Sub test
' :
test_n= Stack.PopValue(_stack)
resolution= "True"
' :
If (flgChain[test_n] = "True") Then
resolution= "False"
Goto exit
EndIf
'
' :
If (lenChain > 0) and (Text.GetSubText(spisok[test_n],1,1)
<> endLetter) Then
resolution= "False"
EndIf
exit:
542

Stack.PushValue(_stack, resolution)
EndSub

, , -
. ,
:

' :
endGame:
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine("")
TextWindow.WriteLine(" !")
TextWindow.WriteLine("")
' :
Goto startGame

, , ,
.

'
' :
For i= 1 to nWords
' ?
Stack.PushValue(_stack,i)
test()
res= Stack.PopValue(_stack)
' :
If res="True" then
Goto c_yes
EndIf
endfor
' :
Goto endGame

-
, :

' :
c_yes:
gorod= spisok[i]
flgChain[i]= "True"
lenChain= lenChain + 1
543

len= Text.GetLength(spisok[i])
endLetter= Text.GetSubText(spisok[i],len,1)
' "" ,
' :
While (len > 2) And (endLetter= "" Or endLetter= "")
len=len-1
endLetter= Text.GetSubText(spisok[i],len,1)
endwhile
TextWindow.Write("")
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" #" + lenChain + " ")
TextWindow.ForegroundColor="Green"
TextWindow.WriteLine(gorod)

:
' :
goto hodIgroka

(. 42.4)! ,
, , .
. ,
, -
.

. 42.4. .
544

2.

1.
. ,
,
, , , , -
.

.

2. ,
. -
.

3. , -
, , .

4.
, ,
.

5. ,
.

6. -
, .

7. ,
-.
545

43.

,
.
. n () -
( ),
-
1 n2. ,
3 ( 3 3 )
1 32 = 9 (. 43.1).

, ,
. , ,
! -
, -
. -
S.

.

. 43.1.
546

, -

. , -
, -
, .

1.
n2.
n2.

-
. -
3 (. 43.2) -.
, , -
. ,
, - -
.

-
, -
, .
, (. 43.3).
547

. 43.2. -

. 43.3. -

- , -
(. 43.4). (). -
, 4 9, 1 6, 2 7,
3 8. , -
.

. 43.4. -
548

, -
. -
(1486-1536) -
-
.

-, -
, ,
,
, ,
.

-
: , , , , , .

-
, ,
. -
(. 43.5)
. -
, -
- 1514 (. 43.6).

- !

,
, . ,
-
,
.


.
,
(
). 16-17 , -

.
549

-
.

. 43.5. . . 43.6.

?
? -
!

,

, -
,
.
550

, -
.

(Bernard Frnicle de Bes-


sy, 1605 1675) ,
880 .
-
13 , 1973
(Richard Schroeppel)
- 275 305 224.
, -
, 1.77 1019. ,
,
-
.

-
.
. ,
XVII . (De La
Loubre). ,
3 3.
1. 1 (.
43.7).

. 43.7.
551

2. , ,
(. 43.8).

. 43.8.

3. -
, -
(. 43.9).

. 43.9.

4. ,

(. 43.10).
552

. 43.10.

5. , -
(. 43.11).

. 43.11.

2 (. 43.12).

. 43.12.
553

3, 4, 5,
(. 43.13).

. 43.13.

, ,
9 . ,
,
,
, .

-
:
'
'
554

'

'var
n=0 '
mq[0][0]= 0 '
number=0 '
col=0 '
row=0 '

-
, -
. ,
,
(, !).


, -
,
.

, :

'=========================================
'
'=========================================
start:
TextWindow.ForegroundColor="Yellow"
TextWindow.Write(" 3..27 > ")
n=TextWindow.ReadNumber()

' -->

' , :
if (n <= 0) then
Program.End()
EndIf

if (n < 3) Or (n > 27) then


TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" 3 27!")
goto start
EndIf
555

if (Math.Remainder(n,2) <> 1) then


TextWindow.ForegroundColor="Red"
TextWindow.WriteLine(" !")
goto start
EndIf

, n
.

! -
,
, -
, -
. , -
,
, . -
!

' -->

' :
For i= 1 To n
For j= 1 To n
mq[i][j]=0
EndFor
EndFor


-
( , ):

' :
number=1

rule1:
' - :
col= Math.Floor(n/2) + 1
' - :
row=1
' :
mq[row][col]= number
556


n * n:

' :
nextNumber:
number= number+1

tc=col
tr=row

col= col+1
row= row-1

rule3:
If (row < 1) Then
row= n
EndIf

rule4:
If (col > n) then
col=1
Goto rule3
endIf

rule5:
If (mq[row][col] <> 0) Then
col=tc
row=tr+1
Goto rule3
EndIf
557

, ?
: -
, . , -
,
! , -
,
.

-
!

-
:

' :
mq[row][col]= number

,
,
:

' ,
' :
If (number= n*n) Then
Goto complete
' :
Else
Goto nextNumber
EndIf

! -
:

' :
complete:
TextWindow.WriteLine("")
TextWindow.WriteLine(" = " + (n*n*n +n)/2)
writeMQ()

Goto start
558

,
,
-, - :

'
Sub writeMQ
TextWindow.WriteLine("")
TextWindow.ForegroundColor="Green"
' :
For i= 1 To n
s=""
For j= 1 To n
If (n*n > 10) And (mq[i][j] < 10) Then
s= s+ " "
EndIf
If (n*n > 100)And (mq[i][j] < 100) Then
s= s+ " "
EndIf
s= Text.Append(s, mq[i][j]+" ")
EndFor
TextWindow.WriteLine(s)
EndFor
TextWindow.WriteLine("")
EndSub

:
(. 43.14).

-
.

,
(. 43.15), -
, -
.
559

. 43.14. !

-
, , -
, ,
7 7 . -
.

. 43.15.

:
. -
(. 43.16).
560

. 43.16.


. ,
(. 43.17).

. 43.17.

- .
,
- ,
,
(. 43.18).
561

. 43.18.

-
. .
16
1 16.
! ,
.
,
, (.
43.19).

. 43.19.
562

1. (. 43.20).

. 43.20.

2. -
(. 43.21).

. 43.21.

3. -
(. 43.22).
563

. 43.22.

4. -
(. 43.23).

. 43.23.

! , , -
, . , -
, .

(. 43.24).
564

. 43.24. !

, -
, , , .

, , ,
, . , -
34,
, ,

- 2 2 (. 43.25).

. 43.25. 2 2

- 3 3 (. 43.26).
565

. 43.26. 3 3

- 2 4 (. 43.27).

. 43.27. 2 4

- 4 4 (. 43.28).

22 . , , .
, .
566

. 43.28. 2 4

5. . -
, -
.
,
(. 43.29).

. 43.29.

6. (.
43.30).

, , , -
, 30
567

. , 22
, 11:

- ( ) 2 2 ;
- ( ) 2 4 .

. 43.30.

1.
,
. ,
. - -
. ,
(
), ,
. -
.

2. 90 -
,
. -
, -
.
568

!
569


,
, , -
.

Delphi , -
. ,
-

, 2011. 672 .

ISBN: 978-5-94387-664-6

Delphi.
Del-
phi, , -
:

-
-
-
-
-

, :

- , Hangman
-
- (21)
-
570

- Mind Game ( , -)
-
-
-
- ( )

Delphi XE3

+R, 2013. 1269 .

rvGames.de.


. -
:

- XorGame (-)
- ShortGame
-
-
- - Logos
- (Color Lines)
- ,
- :
rvHitori-Solver
rvHitori , -
!
571


Delphi XE3.
FireMonkey,

.


rvGames.de.


Turbo Delphi Delphi XE3.

+R, 2013. 690 .

rvGames.de.

, -
!


PascalABC.NET 1.8. -
,

. PascalABC.NET - !
,
572

, ,
.

-
,
1 . ,
2
( )
, ! ,
PascalABC.NET
.NET -
(C#)!


PascalABC.NET.

2012-13 -
:
573


Delphi XE3

+ R, 2013. 400 .

Del-
phi XE3: FireMonkey,
(Generics),
Windows 8 (Metropolis
UI).

-
Delphi XE3

+ R, 2013. 300 .


Delphi
XE3:
FireMonkey - , -
, -
.
574


-.

+ R, 2013. 746 .

-

GDI+.

-
.

+ R, 2013. 613 .

-
!
575

+ R, 2013. 367 .


-!

+ R, 2013. 468 .

, , -
, , -,
-
-
!
576

- .

+ R, 2013. 500 .

-
-

+ R, 2013. 373 .

-
-

+ R, 2013. 700 .

Processing Java -
. -

+ R, 2013. 700 .
577

, -
. -

Java -

+ R, 2013. 438 .

-
rvGames.de. .
578

, -

1. . - !
, 1982. 238 .

2. . . -
, 1987. 192 .

3. .. -. - , 1978. 64 .

4. .. : . - ,
2005. 208 .

5. . . , 1964.
256 .

6. . . .: ,
2000. 354 .

7. . . .: ,
1993. 417 .

8. . . .: , 1987. 224 .

9. . . - .:, 1972. 495 .