MIHS-18 Flower Petal Evolution Lina Winiski & Lauren Ball P4

No preview image

1 collaborator

Default-person Lina Winiski (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.0.4 • Viewed 91 times • Downloaded 10 times • Run 0 times
Download the 'MIHS-18 Flower Petal Evolution Lina Winiski & Lauren Ball P4' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; spawners are hidden turtles at the center of each "flower" that
;; are always hatching the petals you actually see
breed [spawners spawner]
breed [petals petal]
breed [bees bee]

globals [
  first-parent     ;; the first parent chosen if sexual reproduction is being used
]

spawners-own [
  num-colors       ;; how many colors the petals will have
  step-size        ;; how fast petals move out (the flower's rate of growth)
  turn-increment   ;; how much each petal is rotated before moving out from
                   ;; the center; for example, a turn-increment of 0 will
                   ;; cause all the petals to move out on the same line
  size-modifier    ;; how quickly the petals grow as they move away from
                   ;; their starting location
]

petals-own [
  step-size        ;; same as for spawners
  size-modifier    ;; same as for spawners
  parent           ;; spawner that spawned this petal; distance from parent
                   ;; is used for calculating the petal's size as it grows
]

to setup
  clear-all
  create-spawners initial-number-sunflowers
  [
    set num-colors random 14 + 1
    set step-size random-float 0.5
    set turn-increment random-float 4.0
    set size-modifier random-float 2.0
    set shape "circle"
    set size 0.5

  ]
  arrange-spawners
  set first-parent nobody
  ask patches [ set pcolor cyan + 2 ]
  reset-ticks
  create-bees initial-number-bees ;; makes bees
  [
    set color yellow
    set size 2 ;; stands out against petals
    setxy random-xcor random-ycor
    set shape "butterfly"
  ]
end 

to arrange-spawners
  ;; arrange the spawners around the world in a grid
  let i 0
  while [i < initial-number-sunflowers ]
  [
    ask turtle i
    [
      setxy random-xcor random-ycor
    ]
    set i i + 1
  ]
end 

to go
  ask spawners
  [
    hatch-petals 1
    [
      set parent myself
      set color 10 * (ticks mod ([num-colors] of parent + 1)) + 15
      rt ticks * [turn-increment] of parent * 360
      set size 0
      show-turtle  ;; the petal inherits the hiddenness of its parent,
                   ;; so this makes it visible again
    ]
  ]
  ask petals
  [
    fd step-size
    set size size-modifier * sqrt distance parent
    ;; Kill the petals when they would start interfering with petals from other flowers.
    if abs (xcor - [xcor] of parent) > max-pxcor / (columns * 1.5) [ die ]
    if abs (ycor - [ycor] of parent) > max-pycor / (rows * 1.5) [ die ]
  ]
  tick
  if mouse-down? [ handle-mouse-down ]
  ask bees [
    move
 ]
end 

to move
  rt random 50
  lt random 50
  fd 1
end 

to repopulate-from-two [parent1 parent2]
  ask petals [ die ]
  ask spawners
  [
    ;;if controlled-mutation? then the mutation a flower experiences is relative to its spawner's who number.
    if controlled-mutation? [set mutation who * 1 / (rows * columns)]

    ;; select one value from either parent for each of the four variables
    set num-colors ([num-colors] of one-of list parent1 parent2) + int random-normal 0 (mutation * 10) mod 15 + 1
    set step-size ([step-size] of one-of list parent1 parent2) + random-normal 0 (mutation / 5)
    set turn-increment ([turn-increment] of one-of list parent1 parent2) + random-normal 0 (mutation / 20)
    set size-modifier ([size-modifier] of one-of list parent1 parent2) + random-normal 0 mutation

    ;;We clamp size-modifier so none of the sunflowers get too big.
    if size-modifier > 1.5 [set size-modifier 1.5]
  ]
  ask patches [ set pcolor cyan + 2 ]
end 

to repopulate-from-one [parent1]
  ask petals [ die ]
  ask spawners
  [
    if controlled-mutation? [ set mutation who * 1 / (rows * columns) ]
    set num-colors ([num-colors] of parent1 + int random-normal 0 (mutation * 10)) mod 15 + 1
    set step-size [step-size] of parent1 + random-normal 0 (mutation / 5)
    set turn-increment [turn-increment] of parent1 + random-normal 0 (mutation / 20)
    set size-modifier [size-modifier] of parent1 + random-normal 0 mutation

    ;;We clamp size-modifier so none of the sunflowers get too big.
    if size-modifier > 1.5 [ set size-modifier 1.5 ]
  ]
  ask patches [ set pcolor cyan + 2 ]
end 

to handle-mouse-down
  ;; get the spawner closest to where the user clicked
  let new-parent min-one-of spawners [distancexy mouse-xcor mouse-ycor]
  ifelse asexual?
  [ repopulate-from-one new-parent ]
  [
    ifelse first-parent != nobody
    [
      repopulate-from-two first-parent new-parent
      set first-parent nobody
      ask patches [ set pcolor black ]
    ]
    [
      set first-parent new-parent
      ask patches
      [
        ;; This is a little tricky; some patches may be equidistant
        ;; from more than one spawner, so we can't just ask for the
        ;; closest spawner, we have to ask for all the closest spawners
        ;; and then see if the clicked spawner is among them
        if member? new-parent spawners with-min [distance myself]
          [ set pcolor gray - 3 ]
      ]
    ]
  ]
  ;; wait for the user to release mouse button
  while [mouse-down?] [ ]
  ask patches [ set pcolor cyan + 2 ]
end 


; Copyright 2006 Uri Wilensky.
; See Info tab for full copyright and license.

There is only one version of this model, created over 5 years ago by Lina Winiski.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.