Как сделать так, чтобы черепахи кружили вокруг точки - PullRequest
0 голосов
/ 29 апреля 2018

Так что мои черепахи должны кружить вокруг точки. Мой первоначальный подход состоял в том, чтобы они вращали каждый тик перпендикулярно точке, в которой они должны вращаться, и заставляли их двигаться вперед. Это, однако, приводит к тому, что они притягиваются к одной и той же окружности с фиксированным радиусом. Так как же подойти к этой проблеме?

1 Ответ

0 голосов
/ 01 мая 2018
; move in a circle
; by
; Jose M Vidal

to setup
  clear-all
  create-n-turtles num-turtles
  reset-ticks
end

to create-n-turtles [n]
  crt n [
    fd random 20
    shake]
end

to update
  if (count turtles < num-turtles)[
    create-n-turtles num-turtles - count turtles]
  while [count turtles > num-turtles][
    ask one-of turtles [die]]
  ask turtles [move]
  tick
end

;
to move
  let cx 0
  let cy 0

  set cx mean [xcor] of turtles
  set cy mean [ycor] of turtles
  set heading towardsxy cx cy
  if (distancexy cx cy < radius) [
    set heading heading + 180]
  if (abs distancexy cx cy - radius > 1)[
    fd speed / 1.414]
  set heading towardsxy cx cy
  ifelse (clockwise) [
    set heading heading - 90]
  [
    set heading heading + 90]
  fd speed / 1.414
end

to shake
  set heading heading + (random 10) - 5
  set xcor xcor + random 10 - 5
  set ycor ycor + random 10 - 5
end
...