<commit_before>#_"This file is part of brevis.                                                                                                                                                 
                                                                                                                                                                                     
    brevis is free software: you can redistribute it and/or modify                                                                                                           
    it under the terms of the GNU General Public License as published by                                                                                                             
    the Free Software Foundation, either version 3 of the License, or                                                                                                                
    (at your option) any later version.                                                                                                                                              
                                                                                                                                                                                     
    brevis is distributed in the hope that it will be useful,                                                                                                                
    but WITHOUT ANY WARRANTY; without even the implied warranty of                                                                                                                   
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                                                                                                    
    GNU General Public License for more details.                                                                                                                                     
                                                                                                                                                                                     
    You should have received a copy of the GNU General Public License                                                                                                                
    along with brevis.  If not, see <http://www.gnu.org/licenses/>.                                                                                                          
                                                                                                                                                                                     
Copyright 2012, 2013 <NAME>"

(ns brevis.example.swarm
  (:use [brevis.graphics.basic-3D]
        [brevis.physics collision core space utils vector]
        [brevis.shape box sphere cone]
        [brevis.core]))

;; ## Swarm
;;
;; ![](img/brevis_example_swarm.png?raw=true)
;;
;; Swarm simulations are models of flocking behavior in collections of organisms.   
;;
;; These algorithms were first explored computationally in:
;;
;;   Reynolds, <NAME>. "Flocks, herds and schools: A distributed behavioral model." ACM SIGGRAPH Computer Graphics. Vol. 21. No. 4. ACM, 1987.
;;
;;
;; Todo:
;; - auto-centering of camera (and skybox?)
;; - Voronoi neighborhoods (or some other acceleration)
;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ## Globals

(def num-birds 50)

(def memory (atom 0.0))
(def avoidance (atom 3.8))
(def clustering (atom 3.05))
(def centering (atom 0.01))

(def max-acceleration 10)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ## Birds

(defn bird?
  "Is a thing a bird?"
  [thing]
  (= (:type thing) :bird))

(defn random-bird-position
  "Returns a random valid bird position."
  []
  (vec3 (- (rand 100) 50) 
        (+ 9.5 (rand 10));; having this bigger than the neighbor radius will help with speed due to neighborhood computation
        (- (rand 100) 50)))

(defn make-bird
  "Make a new bird with the specified program. At the specified location."
  [position]  
  (move (make-real {:type :bird
              :color [1 0 0]
              ;:shape (create-sphere)})
              :shape (create-cone)})
        position))
  
(defn random-bird
  "Make a new random bird."
  []
  (let [bird (make-bird (random-bird-position))]
    bird))

(defn bound-acceleration
  "Keeps the acceleration within a reasonable range."
  [v]
  v
  #_(if (> (length v) max-acceleration)
    (mul (div v (length v)) max-acceleration)
    v))<commit_msg>Quick backup, may not be needed.<commit_after>#_"This file is part of brevis.                                                                                                                                                 
                                                                                                                                                                                     
    brevis is free software: you can redistribute it and/or modify                                                                                                           
    it under the terms of the GNU General Public License as published by                                                                                                             
    the Free Software Foundation, either version 3 of the License, or                                                                                                                
    (at your option) any later version.                                                                                                                                              
                                                                                                                                                                                     
    brevis is distributed in the hope that it will be useful,                                                                                                                
    but WITHOUT ANY WARRANTY; without even the implied warranty of                                                                                                                   
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                                                                                                    
    GNU General Public License for more details.                                                                                                                                     
                                                                                                                                                                                     
    You should have received a copy of the GNU General Public License                                                                                                                
    along with brevis.  If not, see <http://www.gnu.org/licenses/>.                                                                                                          
                                                                                                                                                                                     
Copyright 2012, 2013 <NAME>"

(ns brevis.example.swarm
  (:use [brevis.graphics.basic-3D]
        [brevis.physics collision core space utils vector]
        [brevis.shape box sphere cone]
        [brevis.core]))

;; ## Swarm
;;
;; ![](img/brevis_example_swarm.png?raw=true)
;;
;; Swarm simulations are models of flocking behavior in collections of organisms.   
;;
;; These algorithms were first explored computationally in:
;;
;;   Reynolds, <NAME>. "Flocks, herds and schools: A distributed behavioral model." ACM SIGGRAPH Computer Graphics. Vol. 21. No. 4. ACM, 1987.
;;
;;
;; Todo:
;; - auto-centering of camera (and skybox?)
;; - Voronoi neighborhoods (or some other acceleration)
;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ## Globals

(def num-birds 50)

(def memory (atom 0.0))
(def avoidance (atom 3.8))
(def clustering (atom 3.05))
(def centering (atom 0.01))

(def max-acceleration 10)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ## Birds

(defn bird?
  "Is a thing a bird?"
  [thing]
  (= (:type thing) :bird))

(defn random-bird-position
  "Returns a random valid bird position."
  []
  (vec3 (- (rand 100) 50) 
        (+ 9.5 (rand 10));; having this bigger than the neighbor radius will help with speed due to neighborhood computation
        (- (rand 100) 50)))

(defn make-bird
  "Make a new bird with the specified program. At the specified location."
  [position]  
  (move (make-real {:type :bird
              :color [1 0 0]
              ;:shape (create-sphere)})
              :shape (create-cone)})
        position))
  
(defn random-bird
  "Make a new random bird."
  []
  (make-bird (random-bird-position)))    

(defn bound-acceleration
  "Keeps the acceleration within a reasonable range."
  [v]
  v
  #_(if (> (length v) max-acceleration)
    (mul (div v (length v)) max-acceleration)
    v))
{'fraction_non_alphanumeric': 0.0802354736727352, 'fraction_numerical': 0.010683527744467458, 'mean_word_length': 0.7414578587699316, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 186, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1527186', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1524, 'n_words': 607}