Alice 3.3: различия между версиями

Материал из Викиучебника — открытых книг для открытого мира
Содержимое удалено Содержимое добавлено
м <source> -> <syntaxhighlight> (phab:T237267)
Строка 2: Строка 2:
=Одновременное движение объектов=
=Одновременное движение объектов=
==Движение в одном направлении==
==Движение в одном направлении==
<source lang="c++">
<syntaxhighlight lang="c++">
constant DecimalNumber Force = 0.25
constant DecimalNumber Force = 0.25
constant DecimalNumber Duration = 0.25
constant DecimalNumber Duration = 0.25
Строка 25: Строка 25:
MoveRight = nextRandomBoolean()
MoveRight = nextRandomBoolean()
}
}
</syntaxhighlight>
</source>


==Броуновское движение==
==Броуновское движение==
<source lang="c++">
<syntaxhighlight lang="c++">
constant DecimalNumber Force = 0.25
constant DecimalNumber Force = 0.25
constant DecimalNumber Duration = 0.25
constant DecimalNumber Duration = 0.25
Строка 40: Строка 40:
}
}
}
}
</syntaxhighlight>
</source>


=Поиск и сортировка=
=Поиск и сортировка=
==Линейный поиск==
==Линейный поиск==
<source lang="c++">
<syntaxhighlight lang="c++">
constant DecimalNumber Arr = new DecimalNumber[] {0.25, 1.0, 2.0, 0.5, 1.0}
constant DecimalNumber Arr = new DecimalNumber[] {0.25, 1.0, 2.0, 0.5, 1.0}
WholeNumber i = 0
WholeNumber i = 0
Строка 61: Строка 61:
if (NOT Found) is true then
if (NOT Found) is true then
this.alice say("X не найден")
this.alice say("X не найден")
</syntaxhighlight>
</source>


==Сортировка выбором==
==Сортировка выбором==
<source lang="c++">
<syntaxhighlight lang="c++">
constant DecimalNumber Arr = new DecimalNumber[] {0.25, 1.0, 2.0, 0.5, 1.0}
constant DecimalNumber Arr = new DecimalNumber[] {0.25, 1.0, 2.0, 0.5, 1.0}
WholeNumber i = 0
WholeNumber i = 0
Строка 86: Строка 86:
for each (DecimalNumber n) in Arr
for each (DecimalNumber n) in Arr
this.alice say("n:" + n)
this.alice say("n:" + n)
</syntaxhighlight>
</source>


=Camera Markers=
=Camera Markers=
Облёт кубика с трех сторон.
Облёт кубика с трех сторон.
<source lang="c++">
<syntaxhighlight lang="c++">
constant CameraMarker Arr = new CameraMarker[] {this.cameraMarker1, this.cameraMarker2, this.cameraMarker3}
constant CameraMarker Arr = new CameraMarker[] {this.cameraMarker1, this.cameraMarker2, this.cameraMarker3}
for each (CameraMarker cameraMarker) in Arr
for each (CameraMarker cameraMarker) in Arr
Строка 98: Строка 98:
this.camera orientTo(target = this.cameraMarker)
this.camera orientTo(target = this.cameraMarker)
}
}
</syntaxhighlight>
</source>
=Анимации=
=Анимации=
==Качание объекта==
==Качание объекта==

Версия от 16:12, 16 апреля 2020

Код описан на алгоритмическом языке.

Одновременное движение объектов

Движение в одном направлении

constant DecimalNumber Force = 0.25
constant DecimalNumber Duration = 0.25
Boolean MoveForward = true
Boolean MoveRight = true
while (true) is true
{
  each (Sphere sphere) in (new Sphere[] {this.sphere, this.sphere2, this.sphere3}) together
    do together
    {
      if (MoveForward) is true then
        sphere  move(direction = FORWARD, amount = Force, duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY)
      else
        sphere  move(direction = BACKWARD, amount = Force, duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY)
      
      if (MoveRight) is true
        sphere  move(direction = RIGHT, amount = Force, duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY)
      else
        sphere  move(direction = LEFT, amount = Force, duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY)
    }
    MoveForward = nextRandomBoolean()
    MoveRight = nextRandomBoolean()
}

Броуновское движение

constant DecimalNumber Force = 0.25
constant DecimalNumber Duration = 0.25
while true is true
{
  each (Sphere sphere) in (new Sphere[] {this.sphere, this.sphere2, this.sphere3}) together
    do together
    {
      sphere  move(direction = FORWARD, amount = Force - nextRandomRealNumberRange(0.0, 2.0 * Force), duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY)
      sphere  move(direction = RIGHT, amount = Force - nextRandomRealNumberRange(0.0, 2.0 * Force), duration = Duration, animationStyle = BEGIN_AND_END_ARBUTLY)
    }
}

Поиск и сортировка

Линейный поиск

constant DecimalNumber Arr = new DecimalNumber[] {0.25, 1.0, 2.0, 0.5, 1.0}
WholeNumber i = 0
DecimalNumber X = this.getDoubleFromUser("X")
Boolean Found = false
while (BOTH (NOT Found) and (i < Arr.Length)) is true
{
  if (X == Arr[i]) is true then
  {
    this.alice  say("X найден в позиции " + i)
    Found = true
  }
  else
    i = i + 1
}
if (NOT Found) is true then
  this.alice  say("X не найден")

Сортировка выбором

constant DecimalNumber Arr = new DecimalNumber[] {0.25, 1.0, 2.0, 0.5, 1.0}
WholeNumber i = 0
WholeNumber j = 0
DecimalNumber X = 0.0
while (i < Arr.Length) is true
{
  j = i + 1
  while (j < Arr.Length) is true
  {
    if (Arr[i] < Arr[j]) is true then
    {
      C = Arr[i]
      Arr[i] = Arr[j]
      Arr[j] = C
    }
    j = j + 1
  }
  i = i + 1
}
for each (DecimalNumber n) in Arr
  this.alice  say("n:" + n)

Camera Markers

Облёт кубика с трех сторон.

constant CameraMarker Arr = new CameraMarker[] {this.cameraMarker1, this.cameraMarker2, this.cameraMarker3}
for each (CameraMarker cameraMarker) in Arr
  do together
  {
    this.camera  moveTo(target = this.cameraMarker)
    this.camera  orientTo(target = this.cameraMarker)
  }

Анимации

Качание объекта